also included: - a complete rewrite of the TCP docs based on real/tested/working code samples - an EchoServer implementation which handles all the edge cases, available in Java & Scala - renamed StopReading to SuspendReading to match up with ResumeReading - addition of Inbox.watch() - Inbox RST docs for Java(!) and Scala not included: - ScalaDoc / JavaDoc for all IO stuff
34 lines
733 B
Java
34 lines
733 B
Java
package docs.io.japi;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import akka.actor.ActorRef;
|
|
import akka.actor.Terminated;
|
|
import akka.actor.UntypedActor;
|
|
|
|
public class Watcher extends UntypedActor {
|
|
|
|
static public class Watch {
|
|
final ActorRef target;
|
|
public Watch(ActorRef target) {
|
|
this.target = target;
|
|
}
|
|
}
|
|
|
|
final CountDownLatch latch;
|
|
|
|
public Watcher(CountDownLatch latch) {
|
|
this.latch = latch;
|
|
}
|
|
|
|
@Override
|
|
public void onReceive(Object msg) throws Exception {
|
|
if (msg instanceof Watch) {
|
|
getContext().watch(((Watch) msg).target);
|
|
} else if (msg instanceof Terminated) {
|
|
latch.countDown();
|
|
if (latch.getCount() == 0) getContext().stop(getSelf());
|
|
}
|
|
}
|
|
|
|
}
|