From 6eb7e1d4383d57ebc92cce152040098a0a597511 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Wed, 21 Dec 2011 19:07:54 +0100 Subject: [PATCH] Rename dispatcherFactory to dispatchers in ActorSystem. See #1458 --- .../akka/actor/dispatch/ActorModelSpec.scala | 20 +++++++++---------- .../akka/actor/dispatch/DispatchersSpec.scala | 2 +- .../akka/dispatch/MailboxConfigSpec.scala | 2 +- .../dispatch/PriorityDispatcherSpec.scala | 12 +++++------ .../CallingThreadDispatcherModelSpec.scala | 6 +++--- .../src/main/scala/akka/actor/ActorCell.scala | 2 +- .../main/scala/akka/actor/ActorSystem.scala | 6 +++--- .../dispatcher/DispatcherDocTestBase.java | 8 ++++---- akka-docs/java/dispatchers.rst | 4 ++-- .../docs/dispatcher/DispatcherDocSpec.scala | 10 +++++----- .../akka/docs/testkit/TestkitDocSpec.scala | 4 ++-- akka-docs/scala/dispatchers.rst | 4 ++-- .../src/main/scala/akka/remote/Remote.scala | 2 +- .../scala/akka/testkit/TestActorRef.scala | 2 +- .../main/scala/akka/testkit/TestFSMRef.scala | 4 ++-- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala index 3536dcadcc..fabdf227cf 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala @@ -444,18 +444,18 @@ class DispatcherModelSpec extends ActorModelSpec(DispatcherModelSpec.config) { override def registerInterceptedDispatcher(): MessageDispatcherInterceptor = { // use new id for each invocation, since the MessageDispatcherInterceptor holds state val id = "dispatcher-" + dispatcherCount.incrementAndGet() - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.settings.config.getConfig("dispatcher"), system.dispatcherFactory.prerequisites) { + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.settings.config.getConfig("dispatcher"), system.dispatchers.prerequisites) { val instance = { ThreadPoolConfigDispatcherBuilder(config ⇒ - new Dispatcher(system.dispatcherFactory.prerequisites, id, id, system.settings.DispatcherThroughput, - system.settings.DispatcherThroughputDeadlineTime, system.dispatcherFactory.MailboxType, + new Dispatcher(system.dispatchers.prerequisites, id, id, system.settings.DispatcherThroughput, + system.settings.DispatcherThroughputDeadlineTime, system.dispatchers.MailboxType, config, system.settings.DispatcherDefaultShutdown) with MessageDispatcherInterceptor, ThreadPoolConfig()).build } override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(id, dispatcherConfigurator) - system.dispatcherFactory.lookup(id).asInstanceOf[MessageDispatcherInterceptor] + system.dispatchers.register(id, dispatcherConfigurator) + system.dispatchers.lookup(id).asInstanceOf[MessageDispatcherInterceptor] } override def dispatcherType = "Dispatcher" @@ -505,19 +505,19 @@ class BalancingDispatcherModelSpec extends ActorModelSpec(BalancingDispatcherMod override def registerInterceptedDispatcher(): MessageDispatcherInterceptor = { // use new id for each invocation, since the MessageDispatcherInterceptor holds state val id = "dispatcher-" + dispatcherCount.incrementAndGet() - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.settings.config.getConfig("dispatcher"), system.dispatcherFactory.prerequisites) { + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.settings.config.getConfig("dispatcher"), system.dispatchers.prerequisites) { val instance = { ThreadPoolConfigDispatcherBuilder(config ⇒ - new BalancingDispatcher(system.dispatcherFactory.prerequisites, id, id, 1, // TODO check why 1 here? (came from old test) - system.settings.DispatcherThroughputDeadlineTime, system.dispatcherFactory.MailboxType, + new BalancingDispatcher(system.dispatchers.prerequisites, id, id, 1, // TODO check why 1 here? (came from old test) + system.settings.DispatcherThroughputDeadlineTime, system.dispatchers.MailboxType, config, system.settings.DispatcherDefaultShutdown) with MessageDispatcherInterceptor, ThreadPoolConfig()).build } override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(id, dispatcherConfigurator) - system.dispatcherFactory.lookup(id).asInstanceOf[MessageDispatcherInterceptor] + system.dispatchers.register(id, dispatcherConfigurator) + system.dispatchers.lookup(id).asInstanceOf[MessageDispatcherInterceptor] } override def dispatcherType = "Balancing Dispatcher" diff --git a/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala index 3cc8c275e3..4ebf0d0de8 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala @@ -23,7 +23,7 @@ object DispatchersSpec { @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) { - val df = system.dispatcherFactory + val df = system.dispatchers import df._ val tipe = "type" diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala index 35e809100f..de3ec03fae 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala @@ -166,7 +166,7 @@ object CustomMailboxSpec { class CustomMailboxSpec extends AkkaSpec(CustomMailboxSpec.config) { "Dispatcher configuration" must { "support custom mailboxType" in { - val dispatcher = system.dispatcherFactory.lookup("my-dispatcher") + val dispatcher = system.dispatchers.lookup("my-dispatcher") dispatcher.createMailbox(null).getClass must be(classOf[CustomMailboxSpec.MyMailbox]) } } diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala index 4aacdb0e7e..cf8695d35f 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala @@ -13,19 +13,19 @@ class PriorityDispatcherSpec extends AkkaSpec with DefaultTimeout { // FIXME #1458: how should we make it easy to configure prio mailbox? val dispatcherKey = "unbounded-prio-dispatcher" - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory.defaultDispatcherConfig, system.dispatcherFactory.prerequisites) { + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers.defaultDispatcherConfig, system.dispatchers.prerequisites) { val instance = { val mailboxType = UnboundedPriorityMailbox(PriorityGenerator({ case i: Int ⇒ i //Reverse order case 'Result ⇒ Int.MaxValue }: Any ⇒ Int)) - system.dispatcherFactory.newDispatcher(dispatcherKey, 5, mailboxType).build + system.dispatchers.newDispatcher(dispatcherKey, 5, mailboxType).build } override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(dispatcherKey, dispatcherConfigurator) + system.dispatchers.register(dispatcherKey, dispatcherConfigurator) testOrdering(dispatcherKey) } @@ -34,19 +34,19 @@ class PriorityDispatcherSpec extends AkkaSpec with DefaultTimeout { // FIXME #1458: how should we make it easy to configure prio mailbox? val dispatcherKey = "bounded-prio-dispatcher" - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory.defaultDispatcherConfig, system.dispatcherFactory.prerequisites) { + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers.defaultDispatcherConfig, system.dispatchers.prerequisites) { val instance = { val mailboxType = BoundedPriorityMailbox(PriorityGenerator({ case i: Int ⇒ i //Reverse order case 'Result ⇒ Int.MaxValue }: Any ⇒ Int), 1000, system.settings.MailboxPushTimeout) - system.dispatcherFactory.newDispatcher(dispatcherKey, 5, mailboxType).build + system.dispatchers.newDispatcher(dispatcherKey, 5, mailboxType).build } override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(dispatcherKey, dispatcherConfigurator) + system.dispatchers.register(dispatcherKey, dispatcherConfigurator) testOrdering(dispatcherKey) } diff --git a/akka-actor-tests/src/test/scala/akka/testkit/CallingThreadDispatcherModelSpec.scala b/akka-actor-tests/src/test/scala/akka/testkit/CallingThreadDispatcherModelSpec.scala index 14c23d432a..efaf28aaf1 100644 --- a/akka-actor-tests/src/test/scala/akka/testkit/CallingThreadDispatcherModelSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/testkit/CallingThreadDispatcherModelSpec.scala @@ -29,14 +29,14 @@ class CallingThreadDispatcherModelSpec extends ActorModelSpec(CallingThreadDispa override def registerInterceptedDispatcher(): MessageDispatcherInterceptor = { // use new id for each invocation, since the MessageDispatcherInterceptor holds state val dispatcherId = "test-calling-thread" + dispatcherCount.incrementAndGet() - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory.defaultDispatcherConfig, system.dispatcherFactory.prerequisites) { + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers.defaultDispatcherConfig, system.dispatchers.prerequisites) { val instance = new CallingThreadDispatcher(prerequisites) with MessageDispatcherInterceptor { override def id: String = dispatcherId } override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(dispatcherId, dispatcherConfigurator) - system.dispatcherFactory.lookup(dispatcherId).asInstanceOf[MessageDispatcherInterceptor] + system.dispatchers.register(dispatcherId, dispatcherConfigurator) + system.dispatchers.lookup(dispatcherId).asInstanceOf[MessageDispatcherInterceptor] } override def dispatcherType = "Calling Thread Dispatcher" diff --git a/akka-actor/src/main/scala/akka/actor/ActorCell.scala b/akka-actor/src/main/scala/akka/actor/ActorCell.scala index 4ce727c420..6a532136b4 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorCell.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorCell.scala @@ -258,7 +258,7 @@ private[akka] class ActorCell( } @inline - final def dispatcher: MessageDispatcher = system.dispatcherFactory.lookup(props.dispatcher) + final def dispatcher: MessageDispatcher = system.dispatchers.lookup(props.dispatcher) /** * UntypedActorContext impl diff --git a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala index cbc3c47f09..129445775d 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala @@ -271,7 +271,7 @@ abstract class ActorSystem extends ActorRefFactory { /** * Helper object for looking up configured dispatchers. */ - def dispatcherFactory: Dispatchers + def dispatchers: Dispatchers /** * Default dispatcher as configured. This dispatcher is used for all actors @@ -412,8 +412,8 @@ class ActorSystemImpl(val name: String, applicationConfig: Config) extends Actor } } - val dispatcherFactory = new Dispatchers(settings, DefaultDispatcherPrerequisites(eventStream, deadLetterMailbox, scheduler)) - val dispatcher = dispatcherFactory.defaultGlobalDispatcher + val dispatchers = new Dispatchers(settings, DefaultDispatcherPrerequisites(eventStream, deadLetterMailbox, scheduler)) + val dispatcher = dispatchers.defaultGlobalDispatcher def terminationFuture: Future[Unit] = provider.terminationFuture def lookupRoot: InternalActorRef = provider.rootGuardian diff --git a/akka-docs/java/code/akka/docs/dispatcher/DispatcherDocTestBase.java b/akka-docs/java/code/akka/docs/dispatcher/DispatcherDocTestBase.java index 411bf01b5f..436c2b0677 100644 --- a/akka-docs/java/code/akka/docs/dispatcher/DispatcherDocTestBase.java +++ b/akka-docs/java/code/akka/docs/dispatcher/DispatcherDocTestBase.java @@ -90,9 +90,9 @@ public class DispatcherDocTestBase { // FIXME #1458: how should we make it easy to configure prio mailbox? // We create a new Priority dispatcher and seed it with the priority generator final String dispatcherKey = "prio-dispatcher"; - MessageDispatcherConfigurator dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory() - .defaultDispatcherConfig(), system.dispatcherFactory().prerequisites()) { - private final MessageDispatcher instance = system.dispatcherFactory() + MessageDispatcherConfigurator dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers() + .defaultDispatcherConfig(), system.dispatchers().prerequisites()) { + private final MessageDispatcher instance = system.dispatchers() .newDispatcher(dispatcherKey, 5, new UnboundedPriorityMailbox(generator)).build(); @Override @@ -100,7 +100,7 @@ public class DispatcherDocTestBase { return instance; } }; - system.dispatcherFactory().register(dispatcherKey, dispatcherConfigurator); + system.dispatchers().register(dispatcherKey, dispatcherConfigurator); ActorRef myActor = system.actorOf( // We create a new Actor that just prints out what it processes new Props().withCreator(new UntypedActorFactory() { diff --git a/akka-docs/java/dispatchers.rst b/akka-docs/java/dispatchers.rst index d053501d78..901cf6ff56 100644 --- a/akka-docs/java/dispatchers.rst +++ b/akka-docs/java/dispatchers.rst @@ -44,7 +44,7 @@ There are 4 different types of message dispatchers: It is recommended to define the dispatcher in :ref:`configuration` to allow for tuning for different environments. -Example of a custom event-based dispatcher, which can be fetched with ``system.dispatcherFactory().lookup("my-dispatcher")`` +Example of a custom event-based dispatcher, which can be fetched with ``system.dispatchers().lookup("my-dispatcher")`` as in the example above: .. includecode:: ../scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala#my-dispatcher-config @@ -54,7 +54,7 @@ Default values are taken from ``default-dispatcher``, i.e. all options doesn't n .. warning:: Factory methods for creating dispatchers programmatically are available in ``akka.dispatch.Dispatchers``, i.e. - ``dispatcherFactory`` of the ``ActorSystem``. These methods will probably be changed or removed before + ``dispatchers`` of the ``ActorSystem``. These methods will probably be changed or removed before 2.0 final release, because dispatchers need to be defined by configuration to work in a clustered setup. Let's now walk through the different dispatchers in more detail. diff --git a/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala b/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala index 86ee7f15bc..2ce292a882 100644 --- a/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala +++ b/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala @@ -78,7 +78,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) { } "defining dispatcher with bounded queue" in { - val dispatcher = system.dispatcherFactory.lookup("my-dispatcher-bounded-queue") + val dispatcher = system.dispatchers.lookup("my-dispatcher-bounded-queue") } "defining pinned dispatcher" in { @@ -100,11 +100,11 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) { // FIXME #1458: how should we make it easy to configure prio mailbox? // We create a new Priority dispatcher and seed it with the priority generator val dispatcherKey = "prio-dispatcher" - val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory.defaultDispatcherConfig, system.dispatcherFactory.prerequisites) { - val instance = system.dispatcherFactory.newDispatcher(dispatcherKey, 5, UnboundedPriorityMailbox(gen)).build + val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers.defaultDispatcherConfig, system.dispatchers.prerequisites) { + val instance = system.dispatchers.newDispatcher(dispatcherKey, 5, UnboundedPriorityMailbox(gen)).build override def dispatcher(): MessageDispatcher = instance } - system.dispatcherFactory.register(dispatcherKey, dispatcherConfigurator) + system.dispatchers.register(dispatcherKey, dispatcherConfigurator) val a = system.actorOf( // We create a new Actor that just prints out what it processes Props(new Actor { @@ -140,7 +140,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) { } "defining balancing dispatcher" in { - val dispatcher = system.dispatcherFactory.lookup("my-balancing-dispatcher") + val dispatcher = system.dispatchers.lookup("my-balancing-dispatcher") } } diff --git a/akka-docs/scala/code/akka/docs/testkit/TestkitDocSpec.scala b/akka-docs/scala/code/akka/docs/testkit/TestkitDocSpec.scala index 07c785df0c..8f16f83d1e 100644 --- a/akka-docs/scala/code/akka/docs/testkit/TestkitDocSpec.scala +++ b/akka-docs/scala/code/akka/docs/testkit/TestkitDocSpec.scala @@ -181,8 +181,8 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { val actor = system.actorOf(Props[MyDoubleEcho]) actor ! (probe1.ref, probe2.ref) actor ! "hello" - probe1.expectMsg(50 millis, "hello") - probe2.expectMsg(50 millis, "hello") + probe1.expectMsg(500 millis, "hello") + probe2.expectMsg(500 millis, "hello") //#test-probe //#test-special-probe diff --git a/akka-docs/scala/dispatchers.rst b/akka-docs/scala/dispatchers.rst index a5a4453e89..c33bc3e629 100644 --- a/akka-docs/scala/dispatchers.rst +++ b/akka-docs/scala/dispatchers.rst @@ -44,7 +44,7 @@ There are 4 different types of message dispatchers: It is recommended to define the dispatcher in :ref:`configuration` to allow for tuning for different environments. -Example of a custom event-based dispatcher, which can be fetched with ``system.dispatcherFactory.lookup("my-dispatcher")`` +Example of a custom event-based dispatcher, which can be fetched with ``system.dispatchers.lookup("my-dispatcher")`` as in the example above: .. includecode:: code/akka/docs/dispatcher/DispatcherDocSpec.scala#my-dispatcher-config @@ -54,7 +54,7 @@ Default values are taken from ``default-dispatcher``, i.e. all options doesn't n .. warning:: Factory methods for creating dispatchers programmatically are available in ``akka.dispatch.Dispatchers``, i.e. - ``dispatcherFactory`` of the ``ActorSystem``. These methods will probably be changed or removed before + ``dispatchers`` of the ``ActorSystem``. These methods will probably be changed or removed before 2.0 final release, because dispatchers need to be defined by configuration to work in a clustered setup. Let's now walk through the different dispatchers in more detail. diff --git a/akka-remote/src/main/scala/akka/remote/Remote.scala b/akka-remote/src/main/scala/akka/remote/Remote.scala index d04517cefc..b1425a2754 100644 --- a/akka-remote/src/main/scala/akka/remote/Remote.scala +++ b/akka-remote/src/main/scala/akka/remote/Remote.scala @@ -75,7 +75,7 @@ class Remote(val settings: ActorSystem.Settings, val remoteSettings: RemoteSetti _provider = provider _serialization = SerializationExtension(system) - _computeGridDispatcher = system.dispatcherFactory.lookup("akka.remote.compute-grid-dispatcher") + _computeGridDispatcher = system.dispatchers.lookup("akka.remote.compute-grid-dispatcher") _remoteDaemon = new RemoteSystemDaemon(system, this, system.provider.rootPath / "remote", system.provider.rootGuardian, log) _eventStream = new NetworkEventStream(system) _server = { diff --git a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala index c0ed2383d6..eaeecf7487 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala @@ -116,7 +116,7 @@ object TestActorRef { apply[T](props, system.asInstanceOf[ActorSystemImpl].guardian, name) def apply[T <: Actor](props: Props, supervisor: ActorRef, name: String)(implicit system: ActorSystem): TestActorRef[T] = - new TestActorRef(system.asInstanceOf[ActorSystemImpl], system.dispatcherFactory.prerequisites, props, supervisor.asInstanceOf[InternalActorRef], name) + new TestActorRef(system.asInstanceOf[ActorSystemImpl], system.dispatchers.prerequisites, props, supervisor.asInstanceOf[InternalActorRef], name) def apply[T <: Actor](implicit m: Manifest[T], system: ActorSystem): TestActorRef[T] = apply[T](randomName) diff --git a/akka-testkit/src/main/scala/akka/testkit/TestFSMRef.scala b/akka-testkit/src/main/scala/akka/testkit/TestFSMRef.scala index c37201cda5..d86bab2ea6 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestFSMRef.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestFSMRef.scala @@ -89,11 +89,11 @@ object TestFSMRef { def apply[S, D, T <: Actor](factory: ⇒ T)(implicit ev: T <:< FSM[S, D], system: ActorSystem): TestFSMRef[S, D, T] = { val impl = system.asInstanceOf[ActorSystemImpl] //FIXME should we rely on this cast to work here? - new TestFSMRef(impl, system.dispatcherFactory.prerequisites, Props(creator = () ⇒ factory), impl.guardian.asInstanceOf[InternalActorRef], TestActorRef.randomName) + new TestFSMRef(impl, system.dispatchers.prerequisites, Props(creator = () ⇒ factory), impl.guardian.asInstanceOf[InternalActorRef], TestActorRef.randomName) } def apply[S, D, T <: Actor](factory: ⇒ T, name: String)(implicit ev: T <:< FSM[S, D], system: ActorSystem): TestFSMRef[S, D, T] = { val impl = system.asInstanceOf[ActorSystemImpl] //FIXME should we rely on this cast to work here? - new TestFSMRef(impl, system.dispatcherFactory.prerequisites, Props(creator = () ⇒ factory), impl.guardian.asInstanceOf[InternalActorRef], name) + new TestFSMRef(impl, system.dispatchers.prerequisites, Props(creator = () ⇒ factory), impl.guardian.asInstanceOf[InternalActorRef], name) } }