removing replySafe and replyUnsafe in favor of the unified reply/tryReply
This commit is contained in:
parent
4258abfc9f
commit
b23a8fffeb
20 changed files with 54 additions and 74 deletions
|
|
@ -342,22 +342,22 @@ Supervised actors have the option to reply to the initial sender within preResta
|
|||
// do something that may throw an exception
|
||||
// ...
|
||||
|
||||
getContext().replySafe("ok");
|
||||
getContext().tryReply("ok");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRestart(Throwable reason) {
|
||||
getContext().replySafe(reason.getMessage());
|
||||
getContext().tryReply(reason.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStop() {
|
||||
getContext().replySafe("stopped by supervisor");
|
||||
getContext().tryReply("stopped by supervisor");
|
||||
}
|
||||
}
|
||||
|
||||
- A reply within preRestart or postRestart must be a safe reply via getContext().replySafe() because a getContext().replyUnsafe() will throw an exception when the actor is restarted without having failed. This can be the case in context of AllForOne restart strategies.
|
||||
- A reply within postStop must be a safe reply via getContext().replySafe() because a getContext().replyUnsafe() will throw an exception when the actor has been stopped by the application (and not by a supervisor) after successful execution of receive (or no execution at all).
|
||||
- A reply within preRestart or postRestart must be a safe reply via getContext().tryReply() because a getContext().reply() will throw an exception when the actor is restarted without having failed. This can be the case in context of AllForOne restart strategies.
|
||||
- A reply within postStop must be a safe reply via getContext().tryReply() because a getContext().reply() will throw an exception when the actor has been stopped by the application (and not by a supervisor) after successful execution of receive (or no execution at all).
|
||||
|
||||
Handling too many actor restarts within a specific time limit
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ Step 1: Define the Actor
|
|||
|
||||
public class SerializationTestActor extends UntypedActor {
|
||||
public void onReceive(Object msg) {
|
||||
getContext().replySafe("got it!");
|
||||
getContext().tryReply("got it!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +101,10 @@ Step 1: Define the Actor
|
|||
public void onReceive(Object msg) {
|
||||
if (msg.equals("hello")) {
|
||||
count = count + 1;
|
||||
getContext().replyUnsafe("world " + count);
|
||||
getContext().reply("world " + count);
|
||||
} else if (msg instanceof String) {
|
||||
count = count + 1;
|
||||
getContext().replyUnsafe("hello " + msg + " " + count);
|
||||
getContext().reply("hello " + msg + " " + count);
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid message type");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ Here is an example of coordinating two simple counter UntypedActors so that they
|
|||
});
|
||||
}
|
||||
} else if (incoming.equals("GetCount")) {
|
||||
getContext().replyUnsafe(count.get());
|
||||
getContext().reply(count.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,10 +247,10 @@ which you do by Channel.sendOneWay(msg)
|
|||
|
||||
We recommend that you as first choice use the channel abstraction instead of the other ways described in the following sections.
|
||||
|
||||
Reply using the 'replySafe' and 'replyUnsafe' methods
|
||||
Reply using the 'tryReply' and 'reply' methods
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
If you want to send a message back to the original sender of the message you just received then you can use the 'getContext().replyUnsafe(..)' method.
|
||||
If you want to send a message back to the original sender of the message you just received then you can use the 'getContext().reply(..)' method.
|
||||
|
||||
.. code-block:: java
|
||||
|
||||
|
|
@ -258,15 +258,15 @@ If you want to send a message back to the original sender of the message you jus
|
|||
if (message instanceof String) {
|
||||
String msg = (String)message;
|
||||
if (msg.equals("Hello")) {
|
||||
// Reply to original sender of message using the 'replyUnsafe' method
|
||||
getContext().replyUnsafe(msg + " from " + getContext().getUuid());
|
||||
// Reply to original sender of message using the 'reply' method
|
||||
getContext().reply(msg + " from " + getContext().getUuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
In this case we will a reply back to the Actor that sent the message.
|
||||
|
||||
The 'replyUnsafe' method throws an 'IllegalStateException' if unable to determine what to reply to, e.g. the sender has not been passed along with the message when invoking one of 'send*' methods. You can also use the more forgiving 'replySafe' method which returns 'true' if reply was sent, and 'false' if unable to determine what to reply to.
|
||||
The 'reply' method throws an 'IllegalStateException' if unable to determine what to reply to, e.g. the sender has not been passed along with the message when invoking one of 'send*' methods. You can also use the more forgiving 'tryReply' method which returns 'true' if reply was sent, and 'false' if unable to determine what to reply to.
|
||||
|
||||
.. code-block:: java
|
||||
|
||||
|
|
@ -274,8 +274,8 @@ The 'replyUnsafe' method throws an 'IllegalStateException' if unable to determin
|
|||
if (message instanceof String) {
|
||||
String msg = (String)message;
|
||||
if (msg.equals("Hello")) {
|
||||
// Reply to original sender of message using the 'replyUnsafe' method
|
||||
if (getContext().replySafe(msg + " from " + getContext().getUuid())) ... // success
|
||||
// Reply to original sender of message using the 'reply' method
|
||||
if (getContext().tryReply(msg + " from " + getContext().getUuid())) ... // success
|
||||
else ... // handle failure
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue