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
|
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")) {
|
||||||
if (msg.equals("write")) {
|
unstashAll();
|
||||||
// do writing...
|
getContext().become(new Procedure<Object>() {
|
||||||
} else if (msg.equals("close")) {
|
public void apply(Object msg) throws Exception {
|
||||||
unstashAll();
|
if (msg.equals("write")) {
|
||||||
isOpen = false;
|
// do writing...
|
||||||
} else {
|
} else if (msg.equals("close")) {
|
||||||
stash();
|
unstashAll();
|
||||||
}
|
getContext().unbecome();
|
||||||
|
} else {
|
||||||
|
stash();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, false); // add behavior on top instead of replacing
|
||||||
} else {
|
} else {
|
||||||
if (msg.equals("open")) {
|
stash();
|
||||||
unstashAll();
|
|
||||||
isOpen = true;
|
|
||||||
} else {
|
|
||||||
stash();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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` trait’s
|
||||||
|
implementation of :meth:`preRestart` will call ``unstashAll()``, which is
|
||||||
|
usually the desired behavior.
|
||||||
|
|
||||||
|
|
||||||
Killing an Actor
|
Killing an Actor
|
||||||
|
|
|
||||||
|
|
@ -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` trait’s
|
||||||
|
implementation of :meth:`preRestart` will call ``unstashAll()``, which is
|
||||||
|
usually the desired behavior.
|
||||||
|
|
||||||
|
|
||||||
Killing an Actor
|
Killing an Actor
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue