From f878ee4c5d854c6ce1a4fce51c38f6d7588de4a0 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 11 Apr 2011 15:27:45 +0200 Subject: [PATCH] minor improvements --- akka-docs/pending/actors-scala.rst | 2 +- akka-docs/pending/untyped-actors-java.rst | 27 +++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/akka-docs/pending/actors-scala.rst b/akka-docs/pending/actors-scala.rst index fa24e91db3..f07dbb0ca4 100644 --- a/akka-docs/pending/actors-scala.rst +++ b/akka-docs/pending/actors-scala.rst @@ -263,7 +263,7 @@ If you want to send a message back to the original sender of the message you jus val result = process(request) self.reply(result) -In this case the 'result' will be send back to the Actor that send the 'request'. +In this case the 'result' will be send back to the Actor that sent the 'request'. The 'reply' method throws an 'IllegalStateException' if unable to determine what to reply to, e.g. the sender is not an actor. You can also use the more forgiving 'reply_?' method which returns 'true' if reply was sent, and 'false' if unable to determine what to reply to. diff --git a/akka-docs/pending/untyped-actors-java.rst b/akka-docs/pending/untyped-actors-java.rst index be6e35f2cd..760b5fd324 100644 --- a/akka-docs/pending/untyped-actors-java.rst +++ b/akka-docs/pending/untyped-actors-java.rst @@ -41,7 +41,7 @@ Normally you would want to import the 'actorOf' method like this: .. code-block:: java import static akka.actor.Actors.*; - ActorRef actor = actorOf(SampleUntypedActor.class); + ActorRef myActor = actorOf(SampleUntypedActor.class); To avoid prefix it with 'Actors' every time you use it. @@ -154,7 +154,7 @@ Using 'sendRequestReplyFuture' will send a message to the receiving Actor asynch .. code-block:: java - Future future= actorRef.sendRequestReplyFuture("Hello", getContext(), 1000); + Future future = actorRef.sendRequestReplyFuture("Hello", getContext(), 1000); The 'Future' interface looks like this: @@ -175,7 +175,7 @@ So the normal way of working with futures is something like this: .. code-block:: java - Future future= actorRef.sendRequestReplyFuture("Hello", getContext(), 1000); + Future future = actorRef.sendRequestReplyFuture("Hello", getContext(), 1000); future.await(); if (future.isCompleted()) { Option resultOption = future.result(); @@ -188,13 +188,6 @@ So the normal way of working with futures is something like this: The 'onComplete' callback can be used to register a callback to get a notification when the Future completes. Gives you a way to avoid blocking. -We also have a utility class 'Futures' that have a couple of convenience methods: - -.. code-block:: java - - void awaitAll(Future[] futures); - Future awaitOne(Future[] futures) - Forward message ^^^^^^^^^^^^^^^ @@ -207,7 +200,7 @@ You can forward a message from one actor to another. This means that the origina Receive messages ---------------- -When an actor receives a message is passed into the 'onReceive' method, this is an abstract method on the 'UntypedActor' base class that needs to be defined. +When an actor receives a message it is passed into the 'onReceive' method, this is an abstract method on the 'UntypedActor' base class that needs to be defined. Here is an example: @@ -216,8 +209,10 @@ Here is an example: public class SampleUntypedActor extends UntypedActor { public void onReceive(Object message) throws Exception { - if (message instanceof String) log.info("Received String message: %s", message); - else throw new IllegalArgumentException("Unknown message: " + message); + if (message instanceof String) + EventHandler.info(this, String.format("Received String message: %s", message)); + else + throw new IllegalArgumentException("Unknown message: " + message); } } @@ -241,7 +236,7 @@ If you want to send a message back to the original sender of the message you jus } } -In this case we will a reply back to the Actor that send the message. +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. @@ -391,6 +386,8 @@ Use it like this: .. code-block:: java + import static akka.actor.Actors.*; + actor.sendOneWay(poisonPill()); Killing an Actor @@ -402,6 +399,8 @@ Use it like this: .. code-block:: java + import static akka.actor.Actors.*; + // kill the actor called 'victim' victim.sendOneWay(kill());