This commit is contained in:
Patrik Nordwall 2011-04-11 15:16:32 +02:00
commit 996fa5fbcf
4 changed files with 17 additions and 19 deletions

View file

@ -64,6 +64,7 @@ So your listener Actor needs to be able to handle these two messages. Example:
ActorRegistered event = (ActorRegistered) message; ActorRegistered event = (ActorRegistered) message;
EventHandler.info(this, String.format("Actor registered: %s - %s", EventHandler.info(this, String.format("Actor registered: %s - %s",
event.actor().actorClassName(), event.actor().getUuid())); event.actor().actorClassName(), event.actor().getUuid()));
event.actor().actorClassName(), event.actor().getUuid()));
} else if (message instanceof ActorUnregistered) { } else if (message instanceof ActorUnregistered) {
// ... // ...
} }

View file

@ -198,7 +198,7 @@ An Actor has to implement the receive method to receive messages:
protected def receive: PartialFunction[Any, Unit] protected def receive: PartialFunction[Any, Unit]
Note: Akka has an alias to the 'PartialFunction[Any, Unit]' type called 'Receive', so you can use this type instead for clarity. But most often you don't need to spell it out. Note: Akka has an alias to the 'PartialFunction[Any, Unit]' type called 'Receive' (akka.actor.Actor.Receive), so you can use this type instead for clarity. But most often you don't need to spell it out.
This method should return a PartialFunction, e.g. a match/case clause in which the message can be matched against the different case clauses using Scala pattern matching. Here is an example: This method should return a PartialFunction, e.g. a match/case clause in which the message can be matched against the different case clauses using Scala pattern matching. Here is an example:
@ -545,24 +545,28 @@ In generic base Actor:
.. code-block:: scala .. code-block:: scala
import akka.actor.Actor.Receive
abstract class GenericActor extends Actor { abstract class GenericActor extends Actor {
// to be defined in subclassing actor // to be defined in subclassing actor
def specificMessageHandler: PartialFunction[Any, Unit] def specificMessageHandler: Receive
// generic message handler // generic message handler
def genericMessageHandler = { def genericMessageHandler: Receive = {
... // generic message handler case event => printf("generic: %s\n", event)
} }
def receive = specificMessageHandler orElse genericMessageHandler def receive = specificMessageHandler orElse genericMessageHandler
} }
In subclassing Actor: In subclassing Actor:
`<code format="scala">`_ `<code format="scala">`_
class SpecificActor extends GenericActor { class SpecificActor extends GenericActor {
def specificMessageHandler = { def specificMessageHandler = {
... // specific message handler case event: MyMsg => printf("specific: %s\n", event.subject)
} }
} }
`<code>`_
case class MyMsg(subject: String)
`<code>`_

View file

@ -3,15 +3,10 @@ SLF4J
This module is available in the 'akka-slf4j.jar'. It has one single dependency; the slf4j-api jar. This module is available in the 'akka-slf4j.jar'. It has one single dependency; the slf4j-api jar.
Logging trait
-------------
You can use the 'akka.event.slf4j.Logging' trait to mix in logging behavior into your classes and use the 'log' Logger member variable. But the preferred way is to use the event handler (see below).
Event Handler Event Handler
------------- -------------
This module also includes an SLF4J Event Handler that works with Akka's standar Event Handler. You enabled it in the 'event-handlers' element in akka.conf. Here you can also define the log level. This module includes a SLF4J Event Handler that works with Akka's standard Event Handler. You enabled it in the 'event-handlers' element in akka.conf. Here you can also define the log level.
.. code-block:: ruby .. code-block:: ruby

View file

@ -26,8 +26,6 @@ Here is an example:
} }
} }
The 'UntypedActor' class inherits from the 'akka.util.Logging' class which defines a logger in the 'log' field that you can use to log. The logging uses SLF4j backed by logback - for more information on how to configure the logger see `Logging <logging>`_.
Creating Actors Creating Actors
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
@ -35,7 +33,7 @@ Creating an Actor is done using the 'akka.actor.Actors.actorOf' factory method.
.. code-block:: java .. code-block:: java
ActorRef actor = Actors.actorOf(SampleUntypedActor.class); ActorRef myActor = Actors.actorOf(SampleUntypedActor.class);
myActor.start(); myActor.start();
Normally you would want to import the 'actorOf' method like this: Normally you would want to import the 'actorOf' method like this:
@ -51,7 +49,7 @@ You can also create & start the actor in one statement:
.. code-block:: java .. code-block:: java
ActorRef actor = actorOf(SampleUntypedActor.class).start(); ActorRef myActor = actorOf(SampleUntypedActor.class).start();
The call to 'actorOf' returns an instance of 'ActorRef'. This is a handle to the 'UntypedActor' instance which you can use to interact with the Actor, like send messages to it etc. more on this shortly. The 'ActorRef' is immutble and has a one to one relationship with the Actor it represents. The 'ActorRef' is also serializable and network-aware. This means that you can serialize it, send it over the wire and use it on a remote host and it will still be representing the same Actor on the original node, across the network. The call to 'actorOf' returns an instance of 'ActorRef'. This is a handle to the 'UntypedActor' instance which you can use to interact with the Actor, like send messages to it etc. more on this shortly. The 'ActorRef' is immutble and has a one to one relationship with the Actor it represents. The 'ActorRef' is also serializable and network-aware. This means that you can serialize it, send it over the wire and use it on a remote host and it will still be representing the same Actor on the original node, across the network.