change Java stash sample to become(), see #2642

This commit is contained in:
Roland 2012-11-06 11:41:50 +01:00
parent 8eec825f18
commit 657a24dbc8
3 changed files with 25 additions and 22 deletions

View file

@ -351,27 +351,26 @@ public class UntypedActorDocTestBase {
static static
//#stash //#stash
public class ActorWithProtocol extends UntypedActorWithStash { public class ActorWithProtocol extends UntypedActorWithStash {
private Boolean isOpen = false;
public void onReceive(Object msg) { public void onReceive(Object msg) {
if (isOpen) { if (msg.equals("open")) {
unstashAll();
getContext().become(new Procedure<Object>() {
public void apply(Object msg) throws Exception {
if (msg.equals("write")) { if (msg.equals("write")) {
// do writing... // do writing...
} else if (msg.equals("close")) { } else if (msg.equals("close")) {
unstashAll(); unstashAll();
isOpen = false; getContext().unbecome();
} else { } else {
stash(); stash();
} }
} else { }
if (msg.equals("open")) { }, false); // add behavior on top instead of replacing
unstashAll();
isOpen = true;
} else { } else {
stash(); stash();
} }
} }
} }
}
//#stash //#stash
static static

View file

@ -627,9 +627,11 @@ The stash is backed by a ``scala.collection.immutable.Vector``. As a
result, even a very large number of messages may be stashed without a result, even a very large number of messages may be stashed without a
major impact on performance. major impact on performance.
Note that the stash is not persisted across restarts of an actor, Note that the stash is part of the ephemeral actor state, unlike the
unlike the actor's mailbox. Therefore, it should be managed like other mailbox. Therefore, it should be managed like other parts of the
parts of the actor's state which have the same property. actor's state which have the same property. The :class:`Stash` traits
implementation of :meth:`preRestart` will call ``unstashAll()``, which is
usually the desired behavior.
Killing an Actor Killing an Actor

View file

@ -752,9 +752,11 @@ major impact on performance.
callback. This means it's not possible to write callback. This means it's not possible to write
``Actor with MyActor with Stash`` if ``MyActor`` overrides ``preRestart``. ``Actor with MyActor with Stash`` if ``MyActor`` overrides ``preRestart``.
Note that the stash is not persisted across restarts of an actor, Note that the stash is part of the ephemeral actor state, unlike the
unlike the actor's mailbox. Therefore, it should be managed like other mailbox. Therefore, it should be managed like other parts of the
parts of the actor's state which have the same property. actor's state which have the same property. The :class:`Stash` traits
implementation of :meth:`preRestart` will call ``unstashAll()``, which is
usually the desired behavior.
Killing an Actor Killing an Actor