Updated docs with changes to 'actorOf(Props(..))'
Signed-off-by: Jonas Bonér <jonas@jonasboner.com>
This commit is contained in:
parent
c9b787f029
commit
d725c9c681
21 changed files with 100 additions and 98 deletions
|
|
@ -73,13 +73,14 @@ So your listener Actor needs to be able to handle these two messages. Example:
|
|||
import akka.actor.TypedActorRegistered;
|
||||
import akka.actor.TypedActorUnregistered;
|
||||
import akka.actor.UntypedActor;
|
||||
import akka.actor.Props;
|
||||
import akka.event.EventHandler;
|
||||
|
||||
public class RegistryListener extends UntypedActor {
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof ActorRegistered) {
|
||||
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()));
|
||||
} else if (message instanceof ActorUnregistered) {
|
||||
|
|
@ -94,5 +95,5 @@ The above actor can be added as listener of registry events:
|
|||
|
||||
import static akka.actor.Actors.*;
|
||||
|
||||
ActorRef listener = actorOf(RegistryListener.class);
|
||||
ActorRef listener = actorOf(new Props(RegistryListener.class));
|
||||
registry().addListener(listener);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Dispatchers (Java)
|
|||
.. sidebar:: Contents
|
||||
|
||||
.. contents:: :local:
|
||||
|
||||
|
||||
Module stability: **SOLID**
|
||||
|
||||
The Dispatcher is an important piece that allows you to configure the right semantics and parameters for optimal performance, throughput and scalability. Different Actors have different needs.
|
||||
|
|
@ -129,7 +129,7 @@ should have, as shown above. This defines the number of messages for a specific
|
|||
Actor the dispatcher should process in one single sweep; in other words, the
|
||||
dispatcher will bunch up to ``throughput`` message invocations together when
|
||||
having elected an actor to run. Setting this to a higher number will increase
|
||||
throughput but lower fairness, and vice versa. If you don't specify it explicitly
|
||||
throughput but lower fairness, and vice versa. If you don't specify it explicitly
|
||||
then it uses the value (5) defined for ``default-dispatcher`` in the :ref:`configuration`.
|
||||
|
||||
Browse the :ref:`scaladoc` or look at the code for all the options available.
|
||||
|
|
@ -145,10 +145,10 @@ Creating a Dispatcher with a priority mailbox using PriorityGenerator:
|
|||
.. code-block:: java
|
||||
|
||||
package some.pkg;
|
||||
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.dispatch.*;
|
||||
|
||||
|
||||
public class Main {
|
||||
// A simple Actor that just prints the messages it processes
|
||||
public static class MyActor extends UntypedActor {
|
||||
|
|
@ -167,7 +167,7 @@ Creating a Dispatcher with a priority mailbox using PriorityGenerator:
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Create a new PriorityGenerator, lower prio means more important
|
||||
// Create a new PriorityGenerator, lower prio means more important
|
||||
PriorityGenerator gen = new PriorityGenerator() {
|
||||
public int gen(Object message) {
|
||||
if (message.equals("highpriority")) return 0; // "highpriority" messages should be treated first if possible
|
||||
|
|
@ -177,7 +177,7 @@ Creating a Dispatcher with a priority mailbox using PriorityGenerator:
|
|||
};
|
||||
// We create an instance of the actor that will print out the messages it processes
|
||||
// We create a new Priority dispatcher and seed it with the priority generator
|
||||
ActorRef ref = Actors.actorOf((new Props()).withCreator(MyActor.class).withDispatcher(new Dispatcher("foo", 5, new UnboundedPriorityMailbox(gen))));
|
||||
ActorRef ref = Actors.actorOf(new Props(MyActor.class).withDispatcher(new Dispatcher("foo", 5, new UnboundedPriorityMailbox(gen))));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ An UntypedDispatcher is an actor that routes incoming messages to outbound actor
|
|||
}
|
||||
|
||||
public class MyRouter extends UntypedRouter {
|
||||
private ActorRef pinger = actorOf(Pinger.class);
|
||||
private ActorRef ponger = actorOf(Ponger.class);
|
||||
private ActorRef pinger = actorOf(new Props(Pinger.class));
|
||||
private ActorRef ponger = actorOf(new Props(Ponger.class));
|
||||
|
||||
//Route Ping-messages to the pinger, and Pong-messages to the ponger
|
||||
public ActorRef route(Object message) {
|
||||
|
|
@ -38,7 +38,7 @@ An UntypedDispatcher is an actor that routes incoming messages to outbound actor
|
|||
}
|
||||
}
|
||||
|
||||
ActorRef router = actorOf(MyRouter.class);
|
||||
ActorRef router = actorOf(new Props(MyRouter.class));
|
||||
router.tell("Ping"); //Prints "Pinger: Ping"
|
||||
router.tell("Pong"); //Prints "Ponger: Pong"
|
||||
|
||||
|
|
@ -71,8 +71,8 @@ An UntypedLoadBalancer is an actor that forwards messages it receives to a bound
|
|||
//Our load balancer, sends messages to a pinger, then a ponger, rinse and repeat.
|
||||
public class MyLoadBalancer extends UntypedLoadBalancer {
|
||||
private InfiniteIterator<ActorRef> actors = new CyclicIterator<ActorRef>(asList(
|
||||
actorOf(Pinger.class),
|
||||
actorOf(Ponger.class)
|
||||
actorOf(new Props(Pinger.class)),
|
||||
actorOf(new Props(Ponger.class))
|
||||
));
|
||||
|
||||
public InfiniteIterator<ActorRef> seq() {
|
||||
|
|
@ -80,7 +80,7 @@ An UntypedLoadBalancer is an actor that forwards messages it receives to a bound
|
|||
}
|
||||
}
|
||||
|
||||
ActorRef balancer = actorOf(MyLoadBalancer.class);
|
||||
ActorRef balancer = actorOf(new Props(MyLoadBalancer.class));
|
||||
balancer.tell("Pong"); //Prints "Pinger: Pong"
|
||||
balancer.tell("Ping"); //Prints "Ponger: Ping"
|
||||
balancer.tell("Ping"); //Prints "Pinger: Ping"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Software Transactional Memory (Java)
|
|||
.. sidebar:: Contents
|
||||
|
||||
.. contents:: :local:
|
||||
|
||||
|
||||
Module stability: **SOLID**
|
||||
|
||||
Overview of STM
|
||||
|
|
@ -287,7 +287,7 @@ Here is an example of using ``retry`` to block until an account has enough money
|
|||
final Ref<Double> account1 = new Ref<Double>(100.0);
|
||||
final Ref<Double> account2 = new Ref<Double>(100.0);
|
||||
|
||||
ActorRef transferer = Actors.actorOf(Transferer.class);
|
||||
ActorRef transferer = Actors.actorOf(new Props(Transferer.class));
|
||||
|
||||
transferer.tell(new Transfer(account1, account2, 500.0));
|
||||
// Transferer: not enough money - retrying
|
||||
|
|
@ -410,7 +410,7 @@ You can also have two alternative blocking transactions, one of which can succee
|
|||
final Ref<Integer> left = new Ref<Integer>(100);
|
||||
final Ref<Integer> right = new Ref<Integer>(100);
|
||||
|
||||
ActorRef brancher = Actors.actorOf(Brancher.class);
|
||||
ActorRef brancher = Actors.actorOf(new Props(Brancher.class));
|
||||
|
||||
brancher.tell(new Branch(left, right, 500));
|
||||
// not enough on left - retrying
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ Here is an example of coordinating two simple counter UntypedActors so that they
|
|||
|
||||
.. code-block:: java
|
||||
|
||||
ActorRef counter1 = actorOf(Counter.class);
|
||||
ActorRef counter2 = actorOf(Counter.class);
|
||||
ActorRef counter1 = actorOf(new Props(Counter.class));
|
||||
ActorRef counter2 = actorOf(new Props(Counter.class));
|
||||
|
||||
counter1.tell(new Coordinated(new Increment(counter2)));
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Typed Actors (Java)
|
|||
.. sidebar:: Contents
|
||||
|
||||
.. contents:: :local:
|
||||
|
||||
|
||||
Module stability: **SOLID**
|
||||
|
||||
The Typed Actors are implemented through `Typed Actors <http://en.wikipedia.org/wiki/Active_object>`_. It uses AOP through `AspectWerkz <http://aspectwerkz.codehaus.org/>`_ to turn regular POJOs into asynchronous non-blocking Actors with semantics of the Actor Model. Each method dispatch is turned into a message that is put on a queue to be processed by the Typed Actor sequentially one by one.
|
||||
|
|
@ -36,7 +36,7 @@ If you have a POJO with an interface implementation separation like this:
|
|||
.. code-block:: java
|
||||
|
||||
import akka.actor.TypedActor;
|
||||
|
||||
|
||||
public class RegistrationServiceImpl extends TypedActor implements RegistrationService {
|
||||
public void register(User user, Credentials cred) {
|
||||
... // register user
|
||||
|
|
@ -137,7 +137,7 @@ Here is an example:
|
|||
}
|
||||
}
|
||||
|
||||
MathTypedActor math = TypedActor.actorOf(MathTypedActor .class, MathTypedActorImpl.class);
|
||||
MathTypedActor math = TypedActor.typedActorOf(MathTypedActor.class, MathTypedActorImpl.class);
|
||||
|
||||
// This method will return immediately when called, caller should wait on the Future for the result
|
||||
Future<Integer> future = math.square(10);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue