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:
parent
6e3c2cb682
commit
61813c6635
10 changed files with 183 additions and 119 deletions
|
|
@ -4,15 +4,18 @@
|
|||
package akka.docs.actor.mailbox
|
||||
|
||||
//#imports
|
||||
import akka.actor.Actor
|
||||
import akka.actor.Props
|
||||
import akka.actor.mailbox.FileDurableMailboxType
|
||||
|
||||
//#imports
|
||||
|
||||
//#imports2
|
||||
import akka.actor.mailbox.FileDurableMailboxType
|
||||
//#imports2
|
||||
|
||||
import org.scalatest.{ BeforeAndAfterAll, WordSpec }
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.actor.Actor
|
||||
|
||||
class MyActor extends Actor {
|
||||
def receive = {
|
||||
|
|
@ -20,14 +23,31 @@ class MyActor extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
class DurableMailboxDocSpec extends AkkaSpec {
|
||||
object DurableMailboxDocSpec {
|
||||
val config = """
|
||||
//#dispatcher-config
|
||||
my-dispatcher {
|
||||
mailboxType = akka.actor.mailbox.FileBasedMailbox
|
||||
}
|
||||
//#dispatcher-config
|
||||
"""
|
||||
}
|
||||
|
||||
"define dispatcher with durable mailbox" in {
|
||||
//#define-dispatcher
|
||||
class DurableMailboxDocSpec extends AkkaSpec(DurableMailboxDocSpec.config) {
|
||||
|
||||
"configuration of dispatcher with durable mailbox" in {
|
||||
//#dispatcher-config-use
|
||||
val dispatcher = system.dispatcherFactory.lookup("my-dispatcher")
|
||||
val myActor = system.actorOf(Props[MyActor].withDispatcher(dispatcher), name = "myactor")
|
||||
//#dispatcher-config-use
|
||||
}
|
||||
|
||||
"programatically define dispatcher with durable mailbox" in {
|
||||
//#prog-define-dispatcher
|
||||
val dispatcher = system.dispatcherFactory.newDispatcher(
|
||||
"my-dispatcher", throughput = 1, mailboxType = FileDurableMailboxType).build
|
||||
val myActor = system.actorOf(Props[MyActor].withDispatcher(dispatcher), name = "myactor")
|
||||
//#define-dispatcher
|
||||
val myActor = system.actorOf(Props[MyActor].withDispatcher(dispatcher))
|
||||
//#prog-define-dispatcher
|
||||
myActor ! "hello"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue