clu #17565 Invoke OnMemberRemoved callback when
cluster.shutdown * must also be done when the listener actor stops before the MemberRemoved event has been received * add test for this * clarify docs with example that shuts down actor system and exit jvm
This commit is contained in:
parent
ba8756d485
commit
8a7d7715b5
6 changed files with 60 additions and 13 deletions
|
|
@ -1,7 +1,11 @@
|
|||
package sample.cluster.factorial;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Props;
|
||||
import akka.cluster.Cluster;
|
||||
|
|
@ -30,10 +34,23 @@ public class FactorialFrontendMain {
|
|||
|
||||
//#registerOnRemoved
|
||||
Cluster.get(system).registerOnMemberRemoved(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
system.terminate();
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
// exit JVM when ActorSystem has been terminated
|
||||
final Runnable exit = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.exit(-1);
|
||||
}
|
||||
};
|
||||
system.registerOnTermination(exit);
|
||||
// in case ActorSystem shutdown takes longer than 10 seconds,
|
||||
// exit the JVM forcefully anyway
|
||||
system.scheduler().scheduleOnce(FiniteDuration.create(10, TimeUnit.SECONDS),
|
||||
exit, system.dispatcher());
|
||||
// shut down ActorSystem
|
||||
system.terminate();
|
||||
}
|
||||
});
|
||||
//#registerOnRemoved
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue