Java Code Examples for akka.actor.ActorContext#actorOf()

The following examples show how to use akka.actor.ActorContext#actorOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterUtil.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Start a proxy to a singleton actor.
 *
 * @param context context to create the proxy actor in.
 * @param role role of the singleton actor.
 * @param singleton actor reference of the singleton manager.
 * @return actor reference of the proxy to the singleton actor.
 */
public static ActorRef startSingletonProxy(final ActorContext context, final String role,
        final ActorRef singleton) {

    final ClusterSingletonProxySettings settings =
            ClusterSingletonProxySettings.create(context.system()).withRole(role);

    final Props proxyProps = ClusterSingletonProxy.props(singleton.path().toStringWithoutAddress(), settings);
    return context.actorOf(proxyProps, singleton.path().name() + "Proxy");
}
 
Example 2
Source File: ConciergeEnforcerClusterRouterFactory.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ClusterRouterGroup} for the {@code EnforcerActor} at path
 * {@value #CONCIERGE_SERVICE_ENFORCER_PATH} for cluster role of {@value ConciergeMessagingConstants#CLUSTER_ROLE}.
 *
 * @param context the ActorContext in which to create the cluster router (e.g. a RootActor).
 * @param numberOfRoutees the number of routees to which to "dispatch" messages based on the hashing of the sent
 * messages.
 * @return the ActorRef of the crated cluster router
 */
public static ActorRef createConciergeEnforcerClusterRouter(final ActorContext context, final int numberOfRoutees) {

    final List<String> routeesPaths = Collections.singletonList(CONCIERGE_SERVICE_ENFORCER_PATH);
    final Set<String> clusterRoles =
            new HashSet<>(Collections.singletonList(ConciergeMessagingConstants.CLUSTER_ROLE));

    return context.actorOf(
            new ClusterRouterGroup(
                    new ConsistentHashingGroup(routeesPaths),
                    new ClusterRouterGroupSettings(numberOfRoutees, routeesPaths,
                            true, clusterRoles))
                    .props(),
            CONCIERGE_ENFORCER_ROUTER_ACTORNAME);
}
 
Example 3
Source File: SpringExtension.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 4 votes vote down vote up
public ActorRef actorOf(ActorContext actorContext, String actorSpringBeanName, String actorLogicalName, Object... actorParameters) {
	return actorContext.actorOf(get(actorContext.system()).props(actorSpringBeanName, actorParameters), actorLogicalName);
}
 
Example 4
Source File: SpringExtension.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 4 votes vote down vote up
public ActorRef actorOf(ActorContext actorContext, Class<?> requiredType, String actorLogicalName, Object... actorParameters) {
	return actorContext.actorOf(get(actorContext.system()).props(requiredType, actorParameters), actorLogicalName);
}
 
Example 5
Source File: SpringExtension.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 4 votes vote down vote up
public ActorRef actorOf(ActorContext actorContext, String actorSpringBeanName, String actorLogicalName, Class<?> requiredType) {
	return actorContext.actorOf(get(actorContext.system()).props(actorSpringBeanName, requiredType), actorLogicalName);
}
 
Example 6
Source File: SpringExtension.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 4 votes vote down vote up
public ActorRef actorOf(ActorContext actorContext, String actorSpringBeanName, Object... actorParameters) {
	return actorContext.actorOf(get(actorContext.system()).props(actorSpringBeanName, actorParameters));
}
 
Example 7
Source File: DefaultEnforcerActorFactory.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ActorRef startEnforcerActor(final ActorContext context, final ConciergeConfig conciergeConfig,
        final ActorRef pubSubMediator, final ShardRegions shardRegions) {

    final CachesConfig cachesConfig = conciergeConfig.getCachesConfig();
    final Duration askTimeout = cachesConfig.getAskTimeout();
    final ActorSystem actorSystem = context.system();

    final ActorRef policiesShardRegionProxy = shardRegions.policies();

    final ActorRef thingsShardRegionProxy = shardRegions.things();

    final AsyncCacheLoader<EntityIdWithResourceType, Entry<EntityIdWithResourceType>> thingEnforcerIdCacheLoader =
            new ThingEnforcementIdCacheLoader(askTimeout, thingsShardRegionProxy);
    final Cache<EntityIdWithResourceType, Entry<EntityIdWithResourceType>> thingIdCache =
            CacheFactory.createCache(thingEnforcerIdCacheLoader, cachesConfig.getIdCacheConfig(),
                    ID_CACHE_METRIC_NAME_PREFIX + ThingCommand.RESOURCE_TYPE,
                    actorSystem.dispatchers().lookup("thing-id-cache-dispatcher"));

    final AsyncCacheLoader<EntityIdWithResourceType, Entry<Enforcer>> policyEnforcerCacheLoader =
            new PolicyEnforcerCacheLoader(askTimeout, policiesShardRegionProxy);
    final Cache<EntityIdWithResourceType, Entry<Enforcer>> policyEnforcerCache =
            CacheFactory.createCache(policyEnforcerCacheLoader, cachesConfig.getEnforcerCacheConfig(),
                    ENFORCER_CACHE_METRIC_NAME_PREFIX + "policy",
                    actorSystem.dispatchers().lookup("policy-enforcer-cache-dispatcher"));

    final AsyncCacheLoader<EntityIdWithResourceType, Entry<Enforcer>> aclEnforcerCacheLoader =
            new AclEnforcerCacheLoader(askTimeout, thingsShardRegionProxy);
    final Cache<EntityIdWithResourceType, Entry<Enforcer>> aclEnforcerCache =
            CacheFactory.createCache(aclEnforcerCacheLoader, cachesConfig.getEnforcerCacheConfig(),
                    ENFORCER_CACHE_METRIC_NAME_PREFIX + "acl",
                    actorSystem.dispatchers().lookup("acl-enforcer-cache-dispatcher"));

    // pre-enforcer
    final BlockedNamespaces blockedNamespaces = BlockedNamespaces.of(actorSystem);
    final PreEnforcer preEnforcer = newPreEnforcer(blockedNamespaces, PlaceholderSubstitution.newInstance());

    final LiveSignalPub liveSignalPub = LiveSignalPub.of(context);

    final Set<EnforcementProvider<?>> enforcementProviders = new HashSet<>();
    enforcementProviders.add(new ThingCommandEnforcement.Provider(thingsShardRegionProxy,
            policiesShardRegionProxy, thingIdCache, policyEnforcerCache, aclEnforcerCache, preEnforcer));
    enforcementProviders.add(new PolicyCommandEnforcement.Provider(policiesShardRegionProxy, policyEnforcerCache));
    enforcementProviders.add(new LiveSignalEnforcement.Provider(thingIdCache, policyEnforcerCache,
            aclEnforcerCache, liveSignalPub));

    final ActorRef conciergeEnforcerRouter =
            ConciergeEnforcerClusterRouterFactory.createConciergeEnforcerClusterRouter(context,
                    conciergeConfig.getClusterConfig().getNumberOfShards());

    context.actorOf(DispatcherActor.props(pubSubMediator, conciergeEnforcerRouter),
            DispatcherActor.ACTOR_NAME);

    final ActorRef conciergeForwarder =
            context.actorOf(ConciergeForwarderActor.props(pubSubMediator, conciergeEnforcerRouter),
                    ConciergeForwarderActor.ACTOR_NAME);
    pubSubMediator.tell(DistPubSubAccess.put(conciergeForwarder), ActorRef.noSender());

    // start cache invalidator
    final Props cachedNamespaceInvalidatorProps =
            CachedNamespaceInvalidator.props(blockedNamespaces,
                    Arrays.asList(thingIdCache, policyEnforcerCache, aclEnforcerCache));
    context.actorOf(cachedNamespaceInvalidatorProps, CachedNamespaceInvalidator.ACTOR_NAME);

    // start cluster singleton that writes to the distributed cache of blocked namespaces
    final Props blockedNamespacesUpdaterProps = BlockedNamespacesUpdater.props(blockedNamespaces, pubSubMediator);
    ClusterUtil.startSingleton(actorSystem, actorSystem, CLUSTER_ROLE,
            ConciergeMessagingConstants.BLOCKED_NAMESPACES_UPDATER_NAME,
            blockedNamespacesUpdaterProps);

    final Props enforcerProps =
            EnforcerActor.props(pubSubMediator, enforcementProviders, conciergeForwarder,
                    preEnforcer, thingIdCache, aclEnforcerCache,
                    policyEnforcerCache); // passes in the caches to be able to invalidate cache entries

    return context.actorOf(enforcerProps, EnforcerActor.ACTOR_NAME);
}
 
Example 8
Source File: ActorProducer.java    From odata with Apache License 2.0 4 votes vote down vote up
public ActorRef actorRef(String actorId, ActorContext context) {
    return context.actorOf(create(actorId));
}