Adding Stash section in Actors docs (including docs for the Java API).

Example code added to ActorDocSpec/UntypedActorDocTestBase.
This commit is contained in:
phaller 2012-06-12 15:51:54 +02:00 committed by phaller
parent 370c07b438
commit 8b17099f50
4 changed files with 139 additions and 0 deletions

View file

@ -50,6 +50,10 @@ import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
//#import-askPipe
//#import-stash
import akka.actor.UntypedActorWithStash;
//#import-stash
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
@ -346,6 +350,31 @@ public class UntypedActorDocTestBase {
//#hot-swap-actor
//#stash
public static class ActorWithProtocol extends UntypedActorWithStash {
private Boolean isOpen = false;
public void onReceive(Object msg) {
if (isOpen) {
if (msg.equals("write")) {
// do writing...
} else if (msg.equals("close")) {
unstashAll();
isOpen = false;
} else {
stash();
}
} else {
if (msg.equals("open")) {
unstashAll();
isOpen = true;
} else {
stash();
}
}
}
}
//#stash
//#watch
public static class WatchActor extends UntypedActor {
final ActorRef child = this.getContext().actorOf(Props.empty(), "child");