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

The following examples show how to use akka.actor.ActorSystem#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: QueueActorRouterProducer.java    From usergrid with Apache License 2.0 8 votes vote down vote up
@Override
public void produceRouter(ActorSystem system, String role) {

    ClusterSingletonManagerSettings settings =
            ClusterSingletonManagerSettings.create( system ).withRole( "io" );

    system.actorOf( ClusterSingletonManager.props(
            Props.create( GuiceActorProducer.class, QueueActorRouter.class ),
            PoisonPill.getInstance(), settings ), "queueActorRouter" );

    ClusterSingletonProxySettings proxySettings =
            ClusterSingletonProxySettings.create( system ).withRole( role );

    system.actorOf(
            ClusterSingletonProxy.props( "/user/queueActorRouter", proxySettings ), "queueActorRouterProxy" );
}
 
Example 2
Source File: QueueSenderRouterProducer.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public void produceRouter(ActorSystem system, String role) {

    ClusterSingletonManagerSettings settings =
            ClusterSingletonManagerSettings.create( system ).withRole( "io" );

    system.actorOf( ClusterSingletonManager.props(
            Props.create( GuiceActorProducer.class, QueueSenderRouter.class ),
            PoisonPill.getInstance(), settings ), "queueSenderRouter" );

    ClusterSingletonProxySettings proxySettings =
            ClusterSingletonProxySettings.create( system ).withRole( role );

    system.actorOf(
            ClusterSingletonProxy.props( "/user/queueSenderRouter", proxySettings ), "queueSenderRouterProxy" );
}
 
Example 3
Source File: ThingPersistenceOperationsActorIT.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected ActorRef startEntityActor(final ActorSystem system, final ActorRef pubSubMediator, final ThingId id) {
    final Props props =
            ThingSupervisorActor.props(pubSubMediator,
                    new DistributedPub<ThingEvent>() {
                        @Override
                        public ActorRef getPublisher() {
                            return pubSubMediator;
                        }

                        @Override
                        public Object wrapForPublication(final ThingEvent message) {
                            return message;
                        }
                    },
                    ThingPersistenceActor::props);

    return system.actorOf(props, id.toString());
}
 
Example 4
Source File: ClusterSingleton.java    From ts-reaktive with MIT License 6 votes vote down vote up
/**
 * Starts and returns the an {@link ActorRef} to the {@link ClusterSingletonManager} (and backoff supervisor)
 * that manage this actor singleton.
 *
 * Note that you can't send this ActorRef messages that should go to your actor: use {@link StartProxy} for that.
 *
 * @param constructor Constructor to pass to Props in order to actually create the actor
 */
public ActorRef start(ActorSystem system, Supplier<T> constructor) {
    Config config = system.settings().config().getConfig("ts-reaktive.actors.singleton");
    Props backoffSupervisorProps = BackoffSupervisor.props(
        Backoff.onStop(
            Props.create(type, () -> constructor.get()), "actor",
            FiniteDuration.create(config.getDuration("min-backoff", SECONDS), SECONDS),
            FiniteDuration.create(config.getDuration("max-backoff", SECONDS), SECONDS),
            0.2
        ).withSupervisorStrategy(new OneForOneStrategy(
            DeciderBuilder .matchAny(e -> {
                log.info("{}: Stopping and awaiting restart.", name, e);
                return stop();
            })
            .build()
        ))
    );

    return system.actorOf(
        ClusterSingletonManager.props(backoffSupervisorProps,
            PoisonPill.getInstance(),
            ClusterSingletonManagerSettings.create(system)
        ), name);
}
 
Example 5
Source File: TestConstants.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
public static ActorRef createConnectionSupervisorActor(final ConnectionId connectionId,
        final ActorSystem actorSystem,
        final ActorRef conciergeForwarder,
        final ClientActorPropsFactory clientActorPropsFactory,
        final DittoProtocolSub dittoProtocolSub,
        final ActorRef pubSubMediator) {
    final Props props = ConnectionSupervisorActor.props(dittoProtocolSub, conciergeForwarder,
            clientActorPropsFactory, null, pubSubMediator);

    final Props shardRegionMockProps = Props.create(ShardRegionMockActor.class, props, connectionId.toString());

    final int maxAttempts = 5;
    final long backOffMs = 1000L;

    for (int attempt = 1; ; ++attempt) {
        try {
            return actorSystem.actorOf(shardRegionMockProps, "shardRegionMock-" + connectionId);
        } catch (final InvalidActorNameException invalidActorNameException) {
            if (attempt >= maxAttempts) {
                throw invalidActorNameException;
            } else {
                backOff(backOffMs);
            }
        }
    }
}
 
Example 6
Source File: SimpleClusterMain.java    From akka-kubernetes-example with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  ActorSystem actorSystem = ActorSystem.create(CLUSTER_NAME);
  actorSystem.actorOf(SimpleClusterListener.props());
  final ActorMaterializer materializer = ActorMaterializer.create(actorSystem);

  Cluster cluster = Cluster.get(actorSystem);
  List<Address> addresses = Arrays.asList(System.getenv().get("SEED_NODES").split(","))
      .stream()
      .map(ip -> new Address("akka.tcp", CLUSTER_NAME, ip, 2551))
      .collect(Collectors.toList());
  cluster.joinSeedNodes(addresses);
}
 
Example 7
Source File: Boot.java    From docker-nginx-consul with MIT License 5 votes vote down vote up
public static void main(String[] args) {
  // config
  final String appId = UUID.randomUUID().toString();
  final AppConfiguration appConfig = AppConfiguration.loadConfig(appId);

  // actor system init
  final ActorSystem system = ActorSystem.create();
  final Materializer materializer = ActorMaterializer.create(system);

  // service discovery actor
  final ActorRef serviceDiscoveryActor = system.actorOf(DiscoveryAgentActor.props(appConfig), "example-app-consul-service");

  // http init
  final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = new AppResource(appConfig).routes().flow(system, materializer);
  final CompletionStage<ServerBinding> binding = Http
      .get(system)
      .bindAndHandle(
          routeFlow,
          ConnectHttp.toHost(appConfig.host, appConfig.port),
          materializer
      );

  // exception handling
  binding.exceptionally(failure -> {
    System.err.println("Something very bad happened! " + failure.getMessage());
    system.terminate();
    return null;
  });

}
 
Example 8
Source File: AkkaActorITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static void testForward(final ActorSystem system) throws Exception {
  final ActorRef actorRef = system.actorOf(TestActor.props(true), "forward");
  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2);

  final Future<Object> future = ask(actorRef, "forward", new Timeout(getDefaultDuration()));
  final Boolean isSpanNull = (Boolean)Await.result(future, getDefaultDuration());
  assertFalse(isSpanNull);

  TestUtil.checkSpan(latch, new ComponentSpanCount("java-akka", 2, true));
}
 
Example 9
Source File: MetricQueryService.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the MetricQueryService actor in the given actor system.
 *
 * @param actorSystem The actor system running the MetricQueryService
 * @param resourceID resource ID to disambiguate the actor name
 * @return actor reference to the MetricQueryService
 */
public static ActorRef startMetricQueryService(
	ActorSystem actorSystem,
	ResourceID resourceID,
	long maximumFramesize) {

	String actorName = resourceID == null
		? METRIC_QUERY_SERVICE_NAME
		: METRIC_QUERY_SERVICE_NAME + "_" + resourceID.getResourceIdString();

	return actorSystem.actorOf(Props.create(MetricQueryService.class, maximumFramesize), actorName);
}
 
Example 10
Source File: EventSchedulerRegistryImpl.java    From flux with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize() {
    ActorSystem actorSystem = actorSystemManager.retrieveActorSystem();

    //create cluster singleton actor of {@link AkkaEventSchedulerService}
    Props actorProps = Props.create(AkkaEventSchedulerService.class, eventSchedulerService);
    ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(actorSystem);
    actorSystem.actorOf(ClusterSingletonManager.props(actorProps, PoisonPill.getInstance(), settings), "eventSchedulerServiceActor");
}
 
Example 11
Source File: DittoService.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private ActorRef startActor(final ActorSystem actorSystem, final Props actorProps, final String actorName) {
    logStartingActor(actorName);
    return actorSystem.actorOf(actorProps, actorName);
}
 
Example 12
Source File: Main.java    From learning-akka with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) {
    ActorSystem system = ActorSystem.create("akkademy");
    ActorRef actor = system.actorOf(Props.create(AkkademyDb.class), "akkademy-db");
}
 
Example 13
Source File: UniqueValuesServiceImpl.java    From usergrid with Apache License 2.0 4 votes vote down vote up
private void subscribeToReservations( ActorSystem localSystem ) {
    logger.info("Starting ReservationCacheUpdater");
    localSystem.actorOf( Props.create( ReservationCacheActor.class ), "subscriber");
}
 
Example 14
Source File: Main.java    From ari-proxy with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {

		final Config serviceConfig = ConfigFactory.load().getConfig(SERVICE);

		final ActorSystem system = ActorSystem.create(serviceConfig.getString(NAME));

		system.registerOnTermination(() -> System.exit(0));

		system.actorOf(HealthService.props(serviceConfig.getInt(HTTPPORT)), HealthService.ACTOR_NAME);

		final ActorRef metricsService = system.actorOf(MetricsService.props(), MetricsService.ACTOR_NAME);
		final ActorRef callContextProvider = system.actorOf(CallContextProvider.props(metricsService), CallContextProvider.ACTOR_NAME);

		runAriEventProcessor(serviceConfig, system, callContextProvider, metricsService, system::terminate);

		runAriCommandResponseProcessor(serviceConfig.getConfig(KAFKA), system, callContextProvider, metricsService);
	}
 
Example 15
Source File: UserServer.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  ActorSystem system = ActorSystem.create("userServer");
  ActorRef userActor = system.actorOf(UserActor.props(), "userActor");
  UserServer server = new UserServer(userActor);
  server.startServer("localhost", 8080, system);
}
 
Example 16
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(ActorSystem actorSystem, String actorSpringBeanName, Object... actorParameters) {
	return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName, actorParameters));
}
 
Example 17
Source File: CoffeeHouseApp.java    From oreilly-reactive-architecture-student with Apache License 2.0 4 votes vote down vote up
public CoffeeHouseApp(final ActorSystem system) {
    this.system = system;
    log = Logging.getLogger(system, getClass().getName());
    coffeeHouse = createCoffeeHouse();
    system.actorOf(printerProps(coffeeHouse));
}
 
Example 18
Source File: HelloMainSimple.java    From java-concurrent-programming with MIT License 4 votes vote down vote up
public static void main(String[] args){
    ActorSystem system = ActorSystem.create("Hello",ConfigFactory.load("samplehello.conf"));
    ActorRef a =system.actorOf(Props.create(HelloWorld.class),"helloWorld");
    System.out.println("HelloWorld Actor Path:" + a.path());
}
 
Example 19
Source File: Main.java    From learning-akka with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) {
    ActorSystem system = ActorSystem.create("akkademy");
    ActorRef actor = system.actorOf(Props.create(AkkademyDb.class), "akkademy-db");
}
 
Example 20
Source File: SpringExtension.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 2 votes vote down vote up
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher) {
	return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName).withRouter(routerConfig).withDispatcher(dispatcher));

}