Make MailboxType implementation configurable. See #1484

* Added mailboxType property to dispatcher config
* Changed durable mailboxes to use this
* Updated docs for durable mailboxes
This commit is contained in:
Patrik Nordwall 2011-12-19 20:36:06 +01:00
parent 6e3c2cb682
commit 61813c6635
10 changed files with 183 additions and 119 deletions

View file

@ -4,7 +4,6 @@
package akka.docs.actor.mailbox;
//#imports
import akka.actor.mailbox.DurableMailboxType;
import akka.dispatch.MessageDispatcher;
import akka.actor.UntypedActorFactory;
import akka.actor.UntypedActor;
@ -12,8 +11,17 @@ import akka.actor.Props;
//#imports
//#imports2
import akka.actor.mailbox.DurableMailboxType;
//#imports2
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import akka.testkit.AkkaSpec;
import akka.docs.dispatcher.DispatcherDocSpec;
import com.typesafe.config.ConfigFactory;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
@ -21,20 +29,44 @@ import static org.junit.Assert.*;
public class DurableMailboxDocTestBase {
ActorSystem system;
@Before
public void setUp() {
system = ActorSystem.create("MySystem",
ConfigFactory.parseString(DurableMailboxDocSpec.config()).withFallback(AkkaSpec.testConf()));
}
@After
public void tearDown() {
system.shutdown();
}
@Test
public void defineDispatcher() {
ActorSystem system = ActorSystem.create("MySystem");
//#define-dispatcher
public void configDefinedDispatcher() {
//#dispatcher-config-use
MessageDispatcher dispatcher = system.dispatcherFactory().lookup("my-dispatcher");
ActorRef myActor = system.actorOf(new Props().withDispatcher(dispatcher).withCreator(new UntypedActorFactory() {
public UntypedActor create() {
return new MyUntypedActor();
}
}), "myactor");
//#dispatcher-config-use
myActor.tell("test");
}
@Test
public void programaticallyDefinedDispatcher() {
//#prog-define-dispatcher
MessageDispatcher dispatcher = system.dispatcherFactory()
.newDispatcher("my-dispatcher", 1, DurableMailboxType.fileDurableMailboxType()).build();
ActorRef myActor = system.actorOf(new Props().withDispatcher(dispatcher).withCreator(new UntypedActorFactory() {
public UntypedActor create() {
return new MyUntypedActor();
}
}));
//#define-dispatcher
}), "myactor");
//#prog-define-dispatcher
myActor.tell("test");
system.shutdown();
}
public static class MyUntypedActor extends UntypedActor {