Merge pull request #799 from akka/wip-2612-improve-receivetimeout-docs-√

#2612 - Clarifying ReceiveTimeout semantics in the documentation.
This commit is contained in:
Viktor Klang (√) 2012-10-15 04:50:38 -07:00
commit a1b8abbe6f
4 changed files with 40 additions and 14 deletions

View file

@ -11,13 +11,18 @@ import scala.concurrent.util.Duration;
public class MyReceivedTimeoutUntypedActor extends UntypedActor {
public MyReceivedTimeoutUntypedActor() {
// To set an initial delay
getContext().setReceiveTimeout(Duration.parse("30 seconds"));
}
public void onReceive(Object message) {
if (message.equals("Hello")) {
// To set in a response to a message
getContext().setReceiveTimeout(Duration.parse("10 seconds"));
getSender().tell("Hello world", getSelf());
} else if (message == ReceiveTimeout.getInstance()) {
// To turn it off
getContext().setReceiveTimeout(Duration.Undefined());
throw new RuntimeException("received timeout");
} else {
unhandled(message);