Java Code Examples for akka.actor.ActorSystem#registerOnTermination()
The following examples show how to use
akka.actor.ActorSystem#registerOnTermination() .
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: OctopusSystem.java From akka-tutorial with Apache License 2.0 | 5 votes |
protected static ActorSystem createSystem(String actorSystemName, Config config) { // Create the ActorSystem final ActorSystem system = ActorSystem.create(actorSystemName, config); // Register a callback that ends the program when the ActorSystem terminates system.registerOnTermination(new Runnable() { @Override public void run() { System.exit(0); } }); // Register a callback that terminates the ActorSystem when it is detached from the cluster Cluster.get(system).registerOnMemberRemoved(new Runnable() { @Override public void run() { system.terminate(); new Thread() { @Override public void run() { try { Await.ready(system.whenTerminated(), Duration.create(10, TimeUnit.SECONDS)); } catch (Exception e) { System.exit(-1); } } }.start(); } }); return system; }
Example 2
Source File: Main.java From ari-proxy with GNU Affero General Public License v3.0 | 4 votes |
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); }