From 3c61e593f2ba8d2a013179d083173f12a6228e4f Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 14 Nov 2011 18:18:08 +0100 Subject: [PATCH] remove app argument from Deployer --- .../main/scala/akka/actor/ActorRefProvider.scala | 11 ++++++++++- .../src/main/scala/akka/actor/ActorSystem.scala | 12 ++---------- akka-actor/src/main/scala/akka/actor/Deployer.scala | 13 ++++++------- .../main/scala/akka/actor/DeploymentConfig.scala | 6 +++--- .../main/scala/akka/cluster/ClusterInterface.scala | 2 +- akka-remote/src/main/scala/akka/remote/Remote.scala | 4 +--- .../scala/akka/remote/RemoteActorRefProvider.scala | 6 ++++-- .../DirectRoutedRemoteActorMultiJvmSpec.scala | 2 +- .../NewRemoteActorMultiJvmSpec.scala | 2 +- .../RandomRoutedRemoteActorMultiJvmSpec.scala | 2 +- .../RoundRobinRoutedRemoteActorMultiJvmSpec.scala | 2 +- ...ScatterGatherRoutedRemoteActorMultiJvmSpec.scala | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/akka-actor/src/main/scala/akka/actor/ActorRefProvider.scala b/akka-actor/src/main/scala/akka/actor/ActorRefProvider.scala index 95db57ce78..43043bfa91 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRefProvider.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRefProvider.scala @@ -15,6 +15,7 @@ import akka.event.{ Logging, DeathWatch, ActorClassification, EventStream } import akka.routing.{ ScatterGatherFirstCompletedRouter, Routing, RouterType, Router, RoutedProps, RoutedActorRef, RoundRobinRouter, RandomRouter, LocalConnectionManager, DirectRouter } import akka.util.Helpers import akka.AkkaException +import com.eaio.uuid.UUID /** * Interface for all ActorRef providers to implement. @@ -31,6 +32,8 @@ trait ActorRefProvider { def deathWatch: DeathWatch + def nodename: String + /** * What deployer will be used to resolve deployment configuration? */ @@ -116,6 +119,7 @@ class ActorRefProviderException(message: String) extends AkkaException(message) */ class LocalActorRefProvider( private val app: ActorSystem, + val AkkaConfig: ActorSystem.AkkaConfig, val root: ActorPath, val eventStream: EventStream, val dispatcher: MessageDispatcher, @@ -123,7 +127,12 @@ class LocalActorRefProvider( val log = Logging(eventStream, this) - private[akka] val deployer: Deployer = new Deployer(app) + val nodename: String = System.getProperty("akka.cluster.nodename") match { + case null | "" ⇒ new UUID().toString + case value ⇒ value + } + + private[akka] val deployer: Deployer = new Deployer(AkkaConfig, eventStream, nodename) val terminationFuture = new DefaultPromise[ActorSystem.ExitStatus](Timeout.never)(app.dispatcher) diff --git a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala index 65f6c6cf64..a07a2e74e2 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala @@ -142,11 +142,6 @@ class ActorSystem(val name: String, val config: Configuration) extends ActorRefF val startTime = System.currentTimeMillis def uptime = (System.currentTimeMillis - startTime) / 1000 - val nodename: String = System.getProperty("akka.cluster.nodename") match { - case null | "" ⇒ new UUID().toString - case value ⇒ value - } - val address = RemoteAddress(System.getProperty("akka.remote.hostname") match { case null | "" ⇒ InetAddress.getLocalHost.getHostAddress case value ⇒ value @@ -192,8 +187,8 @@ class ActorSystem(val name: String, val config: Configuration) extends ActorRefF case Left(e) ⇒ throw e case Right(b) ⇒ b } - val params: Array[Class[_]] = Array(classOf[ActorSystem], classOf[ActorPath], classOf[EventStream], classOf[MessageDispatcher], classOf[Scheduler]) - val args: Array[AnyRef] = Array(this, root, eventStream, dispatcher, scheduler) + val params: Array[Class[_]] = Array(classOf[ActorSystem], classOf[AkkaConfig], classOf[ActorPath], classOf[EventStream], classOf[MessageDispatcher], classOf[Scheduler]) + val args: Array[AnyRef] = Array(this, AkkaConfig, root, eventStream, dispatcher, scheduler) ReflectiveAccess.createInstance[ActorRefProvider](providerClass, params, args) match { case Left(e) ⇒ throw e @@ -213,9 +208,6 @@ class ActorSystem(val name: String, val config: Configuration) extends ActorRefF eventStream.start(provider) eventStream.startDefaultLoggers(provider, AkkaConfig) - // TODO think about memory consistency effects when doing funky stuff inside an ActorRefProvider's constructor - val deployer = new Deployer(this) - // TODO think about memory consistency effects when doing funky stuff inside constructor val typedActor = new TypedActor(this) diff --git a/akka-actor/src/main/scala/akka/actor/Deployer.scala b/akka-actor/src/main/scala/akka/actor/Deployer.scala index 3dc309f207..68b2d98d61 100644 --- a/akka-actor/src/main/scala/akka/actor/Deployer.scala +++ b/akka-actor/src/main/scala/akka/actor/Deployer.scala @@ -5,9 +5,7 @@ package akka.actor import collection.immutable.Seq - import java.util.concurrent.ConcurrentHashMap - import akka.event.Logging import akka.actor.DeploymentConfig._ import akka.AkkaException @@ -15,6 +13,7 @@ import akka.config.{ Configuration, ConfigurationException } import akka.util.Duration import java.net.InetSocketAddress import akka.remote.RemoteAddress +import akka.event.EventStream trait ActorDeployer { private[akka] def init(deployments: Seq[Deploy]): Unit @@ -34,10 +33,10 @@ trait ActorDeployer { * * @author Jonas Bonér */ -class Deployer(val app: ActorSystem) extends ActorDeployer { +class Deployer(val AkkaConfig: ActorSystem.AkkaConfig, val eventStream: EventStream, val nodename: String) extends ActorDeployer { - val deploymentConfig = new DeploymentConfig(app) - val log = Logging(app.eventStream, this) + val deploymentConfig = new DeploymentConfig(nodename) + val log = Logging(eventStream, this) val instance: ActorDeployer = { val deployer = new LocalDeployer() @@ -86,7 +85,7 @@ class Deployer(val app: ActorSystem) extends ActorDeployer { private[akka] def pathsInConfig: List[String] = { val deploymentPath = "akka.actor.deployment" - app.config.getSection(deploymentPath) match { + AkkaConfig.config.getSection(deploymentPath) match { case None ⇒ Nil case Some(pathConfig) ⇒ pathConfig.map.keySet @@ -98,7 +97,7 @@ class Deployer(val app: ActorSystem) extends ActorDeployer { /** * Lookup deployment in 'akka.conf' configuration file. */ - private[akka] def lookupInConfig(path: String, configuration: Configuration = app.config): Option[Deploy] = { + private[akka] def lookupInConfig(path: String, configuration: Configuration = AkkaConfig.config): Option[Deploy] = { import akka.util.ReflectiveAccess.{ createInstance, emptyArguments, emptyParams, getClassFor } // -------------------------------- diff --git a/akka-actor/src/main/scala/akka/actor/DeploymentConfig.scala b/akka-actor/src/main/scala/akka/actor/DeploymentConfig.scala index 0184ad9fef..d86bf7e142 100644 --- a/akka-actor/src/main/scala/akka/actor/DeploymentConfig.scala +++ b/akka-actor/src/main/scala/akka/actor/DeploymentConfig.scala @@ -217,13 +217,13 @@ object DeploymentConfig { * * @author Jonas Bonér */ -class DeploymentConfig(val app: ActorSystem) { +class DeploymentConfig(val nodename: String) { import DeploymentConfig._ - case class ClusterScope(preferredNodes: Iterable[Home] = Vector(Node(app.nodename)), replication: ReplicationScheme = Transient) extends Scope + case class ClusterScope(preferredNodes: Iterable[Home] = Vector(Node(nodename)), replication: ReplicationScheme = Transient) extends Scope - def isHomeNode(homes: Iterable[Home]): Boolean = homes exists (home ⇒ nodeNameFor(home) == app.nodename) + def isHomeNode(homes: Iterable[Home]): Boolean = homes exists (home ⇒ nodeNameFor(home) == nodename) def replicationSchemeFor(deployment: Deploy): Option[ReplicationScheme] = deployment match { case Deploy(_, _, _, _, ClusterScope(_, replicationScheme)) ⇒ Some(replicationScheme) diff --git a/akka-actor/src/main/scala/akka/cluster/ClusterInterface.scala b/akka-actor/src/main/scala/akka/cluster/ClusterInterface.scala index 37c75716d5..1f26ec29e3 100644 --- a/akka-actor/src/main/scala/akka/cluster/ClusterInterface.scala +++ b/akka-actor/src/main/scala/akka/cluster/ClusterInterface.scala @@ -103,7 +103,7 @@ class NodeAddress(val clusterName: String, val nodeName: String) { */ object NodeAddress { def apply(clusterName: String, nodeName: String): NodeAddress = new NodeAddress(clusterName, nodeName) - def apply(app: ActorSystem): NodeAddress = new NodeAddress(app.AkkaConfig.ClusterName, app.nodename) + def apply(app: ActorSystem): NodeAddress = new NodeAddress(app.AkkaConfig.ClusterName, app.provider.nodename) def unapply(other: Any) = other match { case address: NodeAddress ⇒ Some((address.clusterName, address.nodeName)) diff --git a/akka-remote/src/main/scala/akka/remote/Remote.scala b/akka-remote/src/main/scala/akka/remote/Remote.scala index ef29a8de00..01e461d4da 100644 --- a/akka-remote/src/main/scala/akka/remote/Remote.scala +++ b/akka-remote/src/main/scala/akka/remote/Remote.scala @@ -27,7 +27,7 @@ import akka.dispatch.{ Terminate, Dispatchers, Future, PinnedDispatcher } * * @author Jonas Bonér */ -class Remote(val app: ActorSystem) { +class Remote(val app: ActorSystem, val nodename: String) { val log = Logging(app, this) @@ -35,8 +35,6 @@ class Remote(val app: ActorSystem) { import app.config import app.AkkaConfig._ - val nodename = app.nodename - // TODO move to AkkaConfig? val shouldCompressData = config.getBool("akka.remote.use-compression", false) val remoteSystemDaemonAckTimeout = Duration(config.getInt("akka.remote.remote-daemon-ack-timeout", 30), DefaultTimeUnit).toMillis.toInt diff --git a/akka-remote/src/main/scala/akka/remote/RemoteActorRefProvider.scala b/akka-remote/src/main/scala/akka/remote/RemoteActorRefProvider.scala index 31d7b682ef..531730a51b 100644 --- a/akka-remote/src/main/scala/akka/remote/RemoteActorRefProvider.scala +++ b/akka-remote/src/main/scala/akka/remote/RemoteActorRefProvider.scala @@ -30,6 +30,7 @@ import akka.event.EventStream */ class RemoteActorRefProvider( val app: ActorSystem, + val AkkaConfig: ActorSystem.AkkaConfig, val root: ActorPath, val eventStream: EventStream, val dispatcher: MessageDispatcher, @@ -40,12 +41,13 @@ class RemoteActorRefProvider( import java.util.concurrent.ConcurrentHashMap import akka.dispatch.Promise - val local = new LocalActorRefProvider(app, root, eventStream, dispatcher, scheduler) + val local = new LocalActorRefProvider(app, AkkaConfig, root, eventStream, dispatcher, scheduler) def deathWatch = local.deathWatch def guardian = local.guardian def systemGuardian = local.systemGuardian + def nodename = local.nodename - val remote = new Remote(app) + val remote = new Remote(app, nodename) private val actors = new ConcurrentHashMap[String, AnyRef] diff --git a/akka-remote/src/multi-jvm/scala/akka/remote/direct_routed/DirectRoutedRemoteActorMultiJvmSpec.scala b/akka-remote/src/multi-jvm/scala/akka/remote/direct_routed/DirectRoutedRemoteActorMultiJvmSpec.scala index 1577066d67..37a33feb01 100644 --- a/akka-remote/src/multi-jvm/scala/akka/remote/direct_routed/DirectRoutedRemoteActorMultiJvmSpec.scala +++ b/akka-remote/src/multi-jvm/scala/akka/remote/direct_routed/DirectRoutedRemoteActorMultiJvmSpec.scala @@ -10,7 +10,7 @@ object DirectRoutedRemoteActorMultiJvmSpec { class SomeActor extends Actor with Serializable { def receive = { - case "identify" ⇒ sender ! app.nodename + case "identify" ⇒ sender ! app.provider.nodename } } } diff --git a/akka-remote/src/multi-jvm/scala/akka/remote/new_remote_actor/NewRemoteActorMultiJvmSpec.scala b/akka-remote/src/multi-jvm/scala/akka/remote/new_remote_actor/NewRemoteActorMultiJvmSpec.scala index b1e8f793b9..62ab22304b 100644 --- a/akka-remote/src/multi-jvm/scala/akka/remote/new_remote_actor/NewRemoteActorMultiJvmSpec.scala +++ b/akka-remote/src/multi-jvm/scala/akka/remote/new_remote_actor/NewRemoteActorMultiJvmSpec.scala @@ -8,7 +8,7 @@ object NewRemoteActorMultiJvmSpec { class SomeActor extends Actor with Serializable { def receive = { - case "identify" ⇒ sender ! app.nodename + case "identify" ⇒ sender ! app.provider.nodename } } } diff --git a/akka-remote/src/multi-jvm/scala/akka/remote/random_routed/RandomRoutedRemoteActorMultiJvmSpec.scala b/akka-remote/src/multi-jvm/scala/akka/remote/random_routed/RandomRoutedRemoteActorMultiJvmSpec.scala index 380f4d1712..a5b1eea333 100644 --- a/akka-remote/src/multi-jvm/scala/akka/remote/random_routed/RandomRoutedRemoteActorMultiJvmSpec.scala +++ b/akka-remote/src/multi-jvm/scala/akka/remote/random_routed/RandomRoutedRemoteActorMultiJvmSpec.scala @@ -9,7 +9,7 @@ object RandomRoutedRemoteActorMultiJvmSpec { val NrOfNodes = 4 class SomeActor extends Actor with Serializable { def receive = { - case "hit" ⇒ sender ! app.nodename + case "hit" ⇒ sender ! app.provider.nodename case "end" ⇒ self.stop() } } diff --git a/akka-remote/src/multi-jvm/scala/akka/remote/round_robin_routed/RoundRobinRoutedRemoteActorMultiJvmSpec.scala b/akka-remote/src/multi-jvm/scala/akka/remote/round_robin_routed/RoundRobinRoutedRemoteActorMultiJvmSpec.scala index a076a91786..472dd0afd8 100644 --- a/akka-remote/src/multi-jvm/scala/akka/remote/round_robin_routed/RoundRobinRoutedRemoteActorMultiJvmSpec.scala +++ b/akka-remote/src/multi-jvm/scala/akka/remote/round_robin_routed/RoundRobinRoutedRemoteActorMultiJvmSpec.scala @@ -9,7 +9,7 @@ object RoundRobinRoutedRemoteActorMultiJvmSpec { val NrOfNodes = 4 class SomeActor extends Actor with Serializable { def receive = { - case "hit" ⇒ sender ! app.nodename + case "hit" ⇒ sender ! app.provider.nodename case "end" ⇒ self.stop() } } diff --git a/akka-remote/src/multi-jvm/scala/akka/remote/scatter_gather_routed/ScatterGatherRoutedRemoteActorMultiJvmSpec.scala b/akka-remote/src/multi-jvm/scala/akka/remote/scatter_gather_routed/ScatterGatherRoutedRemoteActorMultiJvmSpec.scala index a73fc5b908..ac732f3656 100644 --- a/akka-remote/src/multi-jvm/scala/akka/remote/scatter_gather_routed/ScatterGatherRoutedRemoteActorMultiJvmSpec.scala +++ b/akka-remote/src/multi-jvm/scala/akka/remote/scatter_gather_routed/ScatterGatherRoutedRemoteActorMultiJvmSpec.scala @@ -9,7 +9,7 @@ object ScatterGatherRoutedRemoteActorMultiJvmSpec { val NrOfNodes = 4 class SomeActor extends Actor with Serializable { def receive = { - case "hit" ⇒ sender ! app.nodename + case "hit" ⇒ sender ! app.provider.nodename case "end" ⇒ self.stop() } }