change Java stash sample to become(), see #2642
This commit is contained in:
parent
8eec825f18
commit
657a24dbc8
3 changed files with 25 additions and 22 deletions
|
|
@ -351,24 +351,23 @@ public class UntypedActorDocTestBase {
|
|||
static
|
||||
//#stash
|
||||
public 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();
|
||||
}
|
||||
if (msg.equals("open")) {
|
||||
unstashAll();
|
||||
getContext().become(new Procedure<Object>() {
|
||||
public void apply(Object msg) throws Exception {
|
||||
if (msg.equals("write")) {
|
||||
// do writing...
|
||||
} else if (msg.equals("close")) {
|
||||
unstashAll();
|
||||
getContext().unbecome();
|
||||
} else {
|
||||
stash();
|
||||
}
|
||||
}
|
||||
}, false); // add behavior on top instead of replacing
|
||||
} else {
|
||||
if (msg.equals("open")) {
|
||||
unstashAll();
|
||||
isOpen = true;
|
||||
} else {
|
||||
stash();
|
||||
}
|
||||
stash();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue