DOC: Update Durable Mailboxes Chapter. See #1472

This commit is contained in:
Patrik Nordwall 2011-12-12 08:37:18 +01:00
parent 08af7684e5
commit eaafed69eb
9 changed files with 316 additions and 280 deletions

View file

@ -0,0 +1,31 @@
package akka.docs.actor.mailbox
//#imports
import akka.actor.Actor
import akka.actor.Props
import akka.actor.mailbox.FileDurableMailboxType
//#imports
import org.scalatest.{ BeforeAndAfterAll, WordSpec }
import org.scalatest.matchers.MustMatchers
import akka.testkit.AkkaSpec
class MyActor extends Actor {
def receive = {
case x
}
}
class DurableMailboxDocSpec extends AkkaSpec {
"define dispatcher with durable mailbox" in {
//#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
myActor ! "hello"
}
}

View file

@ -0,0 +1,5 @@
package akka.docs.actor.mailbox
import org.scalatest.junit.JUnitSuite
class DurableMailboxDocTest extends DurableMailboxDocTestBase with JUnitSuite

View file

@ -0,0 +1,41 @@
package akka.docs.actor.mailbox;
//#imports
import akka.actor.mailbox.DurableMailboxType;
import akka.dispatch.MessageDispatcher;
import akka.actor.UntypedActorFactory;
import akka.actor.UntypedActor;
import akka.actor.Props;
//#imports
import org.junit.Test;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import static org.junit.Assert.*;
public class DurableMailboxDocTestBase {
@Test
public void defineDispatcher() {
ActorSystem system = ActorSystem.create("MySystem");
//#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.tell("test");
system.stop();
}
public static class MyUntypedActor extends UntypedActor {
public void onReceive(Object message) {
}
}
}