2011-12-19 11:07:59 +01:00
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
2011-12-19 11:07:59 +01:00
|
|
|
*/
|
2012-05-22 11:37:09 +02:00
|
|
|
package docs.dispatcher;
|
2011-12-13 16:18:51 +01:00
|
|
|
|
2014-03-11 17:03:05 +01:00
|
|
|
import akka.dispatch.ControlMessage;
|
2013-10-14 13:12:17 +02:00
|
|
|
import akka.dispatch.RequiresMessageQueue;
|
|
|
|
|
import akka.testkit.AkkaSpec;
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
2016-02-11 16:39:25 +01:00
|
|
|
import docs.AbstractJavaTest;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import docs.actorlambda.MyBoundedActor;
|
|
|
|
|
import docs.actorlambda.MyActor;
|
2013-10-14 13:12:17 +02:00
|
|
|
import org.junit.ClassRule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import scala.concurrent.ExecutionContext;
|
|
|
|
|
|
2011-12-13 16:18:51 +01:00
|
|
|
//#imports
|
2012-05-07 20:37:56 +02:00
|
|
|
import akka.actor.*;
|
2011-12-13 16:18:51 +01:00
|
|
|
//#imports
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import akka.actor.AbstractActor.Receive;
|
2011-12-13 16:18:51 +01:00
|
|
|
//#imports-prio
|
|
|
|
|
import akka.event.Logging;
|
|
|
|
|
import akka.event.LoggingAdapter;
|
|
|
|
|
|
|
|
|
|
//#imports-prio
|
|
|
|
|
|
2011-12-21 20:34:46 +01:00
|
|
|
//#imports-prio-mailbox
|
|
|
|
|
import akka.dispatch.PriorityGenerator;
|
2015-01-10 14:44:25 +00:00
|
|
|
import akka.dispatch.UnboundedStablePriorityMailbox;
|
2013-05-02 17:12:36 +02:00
|
|
|
import akka.testkit.AkkaJUnitActorSystemResource;
|
2013-03-31 03:04:12 +02:00
|
|
|
import akka.testkit.JavaTestKit;
|
2011-12-21 20:34:46 +01:00
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
|
|
|
|
|
//#imports-prio-mailbox
|
|
|
|
|
|
2013-04-18 13:35:36 +02:00
|
|
|
//#imports-required-mailbox
|
|
|
|
|
|
|
|
|
|
//#imports-required-mailbox
|
|
|
|
|
|
2016-02-11 16:39:25 +01:00
|
|
|
public class DispatcherDocTest extends AbstractJavaTest {
|
2011-12-13 16:18:51 +01:00
|
|
|
|
2013-05-02 17:12:36 +02:00
|
|
|
@ClassRule
|
|
|
|
|
public static AkkaJUnitActorSystemResource actorSystemResource =
|
|
|
|
|
new AkkaJUnitActorSystemResource("DispatcherDocTest", ConfigFactory.parseString(
|
|
|
|
|
DispatcherDocSpec.javaConfig()).withFallback(ConfigFactory.parseString(
|
|
|
|
|
DispatcherDocSpec.config())).withFallback(AkkaSpec.testConf()));
|
2011-12-13 16:18:51 +01:00
|
|
|
|
2013-05-02 17:12:36 +02:00
|
|
|
private final ActorSystem system = actorSystemResource.getSystem();
|
2011-12-13 16:18:51 +01:00
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
@SuppressWarnings("unused")
|
2011-12-13 16:18:51 +01:00
|
|
|
@Test
|
2013-04-05 16:12:45 +02:00
|
|
|
public void defineDispatcherInConfig() {
|
|
|
|
|
//#defining-dispatcher-in-config
|
|
|
|
|
ActorRef myActor =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
system.actorOf(Props.create(MyActor.class),
|
2013-04-05 16:12:45 +02:00
|
|
|
"myactor");
|
|
|
|
|
//#defining-dispatcher-in-config
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
@SuppressWarnings("unused")
|
2013-04-05 16:12:45 +02:00
|
|
|
@Test
|
|
|
|
|
public void defineDispatcherInCode() {
|
|
|
|
|
//#defining-dispatcher-in-code
|
2012-02-24 14:28:17 +01:00
|
|
|
ActorRef myActor =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
system.actorOf(Props.create(MyActor.class).withDispatcher("my-dispatcher"),
|
2012-02-24 14:28:17 +01:00
|
|
|
"myactor3");
|
2013-04-05 16:12:45 +02:00
|
|
|
//#defining-dispatcher-in-code
|
2011-12-13 16:18:51 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-17 09:40:03 +01:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
@Test
|
|
|
|
|
public void defineFixedPoolSizeDispatcher() {
|
|
|
|
|
//#defining-fixed-pool-size-dispatcher
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
ActorRef myActor = system.actorOf(Props.create(MyActor.class)
|
2015-12-17 09:40:03 +01:00
|
|
|
.withDispatcher("blocking-io-dispatcher"));
|
|
|
|
|
//#defining-fixed-pool-size-dispatcher
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
@SuppressWarnings("unused")
|
2011-12-13 16:18:51 +01:00
|
|
|
@Test
|
|
|
|
|
public void definePinnedDispatcher() {
|
|
|
|
|
//#defining-pinned-dispatcher
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
ActorRef myActor = system.actorOf(Props.create(MyActor.class)
|
2012-02-24 14:28:17 +01:00
|
|
|
.withDispatcher("my-pinned-dispatcher"));
|
2011-12-13 16:18:51 +01:00
|
|
|
//#defining-pinned-dispatcher
|
|
|
|
|
}
|
2015-01-10 14:44:25 +00:00
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
@SuppressWarnings("unused")
|
2012-10-15 21:34:31 +02:00
|
|
|
public void compileLookup() {
|
|
|
|
|
//#lookup
|
|
|
|
|
// this is scala.concurrent.ExecutionContext
|
|
|
|
|
// for use with Futures, Scheduler, etc.
|
|
|
|
|
final ExecutionContext ex = system.dispatchers().lookup("my-dispatcher");
|
|
|
|
|
//#lookup
|
|
|
|
|
}
|
2011-12-13 16:18:51 +01:00
|
|
|
|
2013-04-18 13:35:36 +02:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
@Test
|
|
|
|
|
public void defineMailboxInConfig() {
|
|
|
|
|
//#defining-mailbox-in-config
|
|
|
|
|
ActorRef myActor =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
system.actorOf(Props.create(MyActor.class),
|
2013-04-18 13:35:36 +02:00
|
|
|
"priomailboxactor");
|
|
|
|
|
//#defining-mailbox-in-config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
@Test
|
|
|
|
|
public void defineMailboxInCode() {
|
|
|
|
|
//#defining-mailbox-in-code
|
|
|
|
|
ActorRef myActor =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
system.actorOf(Props.create(MyActor.class)
|
2013-04-18 13:35:36 +02:00
|
|
|
.withMailbox("prio-mailbox"));
|
|
|
|
|
//#defining-mailbox-in-code
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
@Test
|
|
|
|
|
public void usingARequiredMailbox() {
|
|
|
|
|
ActorRef myActor =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
system.actorOf(Props.create(MyBoundedActor.class));
|
2013-04-18 13:35:36 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-13 16:18:51 +01:00
|
|
|
@Test
|
|
|
|
|
public void priorityDispatcher() throws Exception {
|
2013-03-31 03:04:12 +02:00
|
|
|
JavaTestKit probe = new JavaTestKit(system);
|
2011-12-13 16:18:51 +01:00
|
|
|
//#prio-dispatcher
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
class Demo extends AbstractActor {
|
2013-04-14 22:56:41 +02:00
|
|
|
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
|
|
|
|
{
|
|
|
|
|
for (Object msg : new Object[] { "lowpriority", "lowpriority",
|
|
|
|
|
"highpriority", "pigdog", "pigdog2", "pigdog3", "highpriority",
|
|
|
|
|
PoisonPill.getInstance() }) {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
self().tell(msg, self());
|
2013-04-14 22:56:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
@Override
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
return receiveBuilder().matchAny(message -> {
|
|
|
|
|
log.info(message.toString());
|
|
|
|
|
}).build();
|
2013-04-14 22:56:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:56:25 +02:00
|
|
|
// We create a new Actor that just prints out what it processes
|
2013-04-14 22:56:41 +02:00
|
|
|
ActorRef myActor = system.actorOf(Props.create(Demo.class, this)
|
|
|
|
|
.withDispatcher("prio-dispatcher"));
|
2011-12-13 16:18:51 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Logs:
|
|
|
|
|
'highpriority
|
|
|
|
|
'highpriority
|
|
|
|
|
'pigdog
|
|
|
|
|
'pigdog2
|
|
|
|
|
'pigdog3
|
|
|
|
|
'lowpriority
|
|
|
|
|
'lowpriority
|
|
|
|
|
*/
|
|
|
|
|
//#prio-dispatcher
|
|
|
|
|
|
2013-03-31 03:04:12 +02:00
|
|
|
probe.watch(myActor);
|
|
|
|
|
probe.expectMsgClass(Terminated.class);
|
2011-12-13 16:18:51 +01:00
|
|
|
}
|
2011-12-21 20:34:46 +01:00
|
|
|
|
2014-03-11 17:03:05 +01:00
|
|
|
@Test
|
|
|
|
|
public void controlAwareDispatcher() throws Exception {
|
|
|
|
|
JavaTestKit probe = new JavaTestKit(system);
|
|
|
|
|
//#control-aware-dispatcher
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
class Demo extends AbstractActor {
|
2014-03-11 17:03:05 +01:00
|
|
|
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
|
|
|
|
{
|
|
|
|
|
for (Object msg : new Object[] { "foo", "bar", new MyControlMessage(),
|
|
|
|
|
PoisonPill.getInstance() }) {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
self().tell(msg, self());
|
2014-03-11 17:03:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
@Override
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
return receiveBuilder().matchAny(message -> {
|
|
|
|
|
log.info(message.toString());
|
|
|
|
|
}).build();
|
2014-03-11 17:03:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We create a new Actor that just prints out what it processes
|
|
|
|
|
ActorRef myActor = system.actorOf(Props.create(Demo.class, this)
|
|
|
|
|
.withDispatcher("control-aware-dispatcher"));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Logs:
|
|
|
|
|
'MyControlMessage
|
|
|
|
|
'foo
|
|
|
|
|
'bar
|
|
|
|
|
*/
|
|
|
|
|
//#control-aware-dispatcher
|
|
|
|
|
|
|
|
|
|
probe.watch(myActor);
|
|
|
|
|
probe.expectMsgClass(Terminated.class);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:56:25 +02:00
|
|
|
static
|
2011-12-21 20:34:46 +01:00
|
|
|
//#prio-mailbox
|
2015-01-10 14:44:25 +00:00
|
|
|
public class MyPrioMailbox extends UnboundedStablePriorityMailbox {
|
2012-09-26 10:56:25 +02:00
|
|
|
// needed for reflective instantiation
|
|
|
|
|
public MyPrioMailbox(ActorSystem.Settings settings, Config config) {
|
2012-02-24 14:28:17 +01:00
|
|
|
// Create a new PriorityGenerator, lower prio means more important
|
|
|
|
|
super(new PriorityGenerator() {
|
2012-02-21 18:24:38 +01:00
|
|
|
@Override
|
|
|
|
|
public int gen(Object message) {
|
|
|
|
|
if (message.equals("highpriority"))
|
|
|
|
|
return 0; // 'highpriority messages should be treated first if possible
|
|
|
|
|
else if (message.equals("lowpriority"))
|
2012-02-24 14:28:17 +01:00
|
|
|
return 2; // 'lowpriority messages should be treated last if possible
|
2012-05-07 20:37:56 +02:00
|
|
|
else if (message.equals(PoisonPill.getInstance()))
|
2012-02-24 14:28:17 +01:00
|
|
|
return 3; // PoisonPill when no other left
|
2012-02-21 18:24:38 +01:00
|
|
|
else
|
2012-02-24 14:28:17 +01:00
|
|
|
return 1; // By default they go between high and low prio
|
2012-02-21 18:24:38 +01:00
|
|
|
}
|
|
|
|
|
});
|
2011-12-21 20:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#prio-mailbox
|
2012-09-26 10:56:25 +02:00
|
|
|
|
2014-03-11 17:03:05 +01:00
|
|
|
static
|
|
|
|
|
//#control-aware-mailbox-messages
|
|
|
|
|
public class MyControlMessage implements ControlMessage {}
|
|
|
|
|
//#control-aware-mailbox-messages
|
|
|
|
|
|
2013-10-14 13:12:17 +02:00
|
|
|
@Test
|
|
|
|
|
public void requiredMailboxDispatcher() throws Exception {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
ActorRef myActor = system.actorOf(Props.create(MyActor.class)
|
2013-10-14 13:12:17 +02:00
|
|
|
.withDispatcher("custom-dispatcher"));
|
|
|
|
|
}
|
2012-06-19 14:52:02 +02:00
|
|
|
|
2013-10-14 13:12:17 +02:00
|
|
|
static
|
|
|
|
|
//#require-mailbox-on-actor
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
public class MySpecialActor extends AbstractActor implements
|
2013-10-14 13:12:17 +02:00
|
|
|
RequiresMessageQueue<MyUnboundedJMessageQueueSemantics> {
|
|
|
|
|
//#require-mailbox-on-actor
|
|
|
|
|
@Override
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
public Receive createReceive() {
|
|
|
|
|
return AbstractActor.emptyBehavior();
|
2012-06-19 14:52:02 +02:00
|
|
|
}
|
2013-10-14 13:12:17 +02:00
|
|
|
//#require-mailbox-on-actor
|
|
|
|
|
// ...
|
|
|
|
|
}
|
|
|
|
|
//#require-mailbox-on-actor
|
2012-06-19 14:52:02 +02:00
|
|
|
|
2013-10-14 13:12:17 +02:00
|
|
|
@Test
|
|
|
|
|
public void requiredMailboxActor() throws Exception {
|
|
|
|
|
ActorRef myActor = system.actorOf(Props.create(MySpecialActor.class));
|
2012-06-19 14:52:02 +02:00
|
|
|
}
|
2013-10-14 13:12:17 +02:00
|
|
|
|
2011-12-13 16:18:51 +01:00
|
|
|
}
|