use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method dontRestartTransientChildDeadOfNaturalCause.
@Test
public void dontRestartTransientChildDeadOfNaturalCause() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.TRANSIENT, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(Actor1.class, "actor1"))).spawn();
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(3));
a = getChild(sup, "actor1", 200);
assertThat(a, nullValue());
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorActor method shutdownChildren.
private void shutdownChildren() throws SuspendExecution, InterruptedException {
log().info("{} shutting down all children.", this);
for (ChildEntry child : children) {
if (child.actor != null) {
unwatch(child);
ActorUtil.sendOrInterrupt(child.actor, new ShutdownMessage(this.ref()));
}
}
for (ChildEntry child : children) {
if (child.actor != null && isLocal(child.actor)) {
try {
joinChild(child);
} finally {
if (child.actor != null)
// must be done after join to avoid a race with the actor
LocalActor.stopMonitor(child.actor);
}
}
child.actor = null;
}
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class Behavior method shutdown.
/**
* Asks this actor to shut down. Works by sending a {@link ShutdownMessage} via {@link ActorUtil#sendOrInterrupt(ActorRef, Object) ActorUtil.sendOrInterrupt}.
*/
public void shutdown() {
final ShutdownMessage message = new ShutdownMessage(LocalActor.self());
ActorUtil.sendOrInterrupt(this, message);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method startChild.
@Test
public void startChild() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.PERMANENT, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(Actor1.class, "actor1"))).spawn(factory);
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(3));
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorActor method shutdownChild.
private void shutdownChild(ChildEntry child, boolean beforeRestart) throws SuspendExecution, InterruptedException {
if (child.actor != null) {
unwatch(child);
if (!isLocal(child.actor) || !LocalActor.isDone(child.actor)) {
log().info("{} shutting down child {}", this, child.actor);
ActorUtil.sendOrInterrupt(child.actor, new ShutdownMessage(this.ref()));
}
if (isLocal(child.actor)) {
try {
joinChild(child);
} finally {
if (!beforeRestart && child.actor != null)
LocalActor.stopMonitor(child.actor);
}
}
if (!beforeRestart)
child.actor = null;
}
}
Aggregations