diff --git a/akka-actor/src/main/scala/akka/actor/Actor.scala b/akka-actor/src/main/scala/akka/actor/Actor.scala index 3fa5ea9d91..2b6232e060 100644 --- a/akka-actor/src/main/scala/akka/actor/Actor.scala +++ b/akka-actor/src/main/scala/akka/actor/Actor.scala @@ -205,10 +205,31 @@ object Actor extends ListenerManagement { // FIXME handle 'router' in 'Local' actors newLocalActorRef(clazz, address) - case Deploy(_, router, Clustered(Home(hostname, port), Replicate(nrOfReplicas), state)) => - RemoteActorRef( - address, clazz.getName, - Actor.TIMEOUT, None, ActorType.ScalaActor) + case Deploy(_, router, Clustered(Home(hostname, port), replication , state)) => + /* + 1. Check ZK for deployment config + 2. Check Home(..) + a) If home is same as Actor.remote.address then: + - check if actor is stored in ZK, if not; node.store(..) + - checkout actor using node.use(..) + b) If not the same + - check out actor using node.ref(..) + + Misc stuff: + - Manage deployment in ZK + - How to define a single ClusterNode to use? Where should it be booted up? How should it be configured? + - Deployer should: + 1. Check if deployment exists in ZK + 2. If not, upload it + - ClusterNode API and Actor.remote API should be made private[akka] + - Rewrite ClusterSpec or remove it + - Actor.stop on home node (actor checked out with node.use(..)) should do node.remove(..) of actor + - Should we allow configuring of session-scoped remote actors? How? + + + */ + + RemoteActorRef(address, Actor.TIMEOUT, None, ActorType.ScalaActor) case invalid => throw new IllegalActorStateException( "Could not create actor [" + clazz.getName + diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala index 2c66d0c276..f2a5b3dc57 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala @@ -295,8 +295,7 @@ trait ActorRef extends ActorRefShared with java.lang.Comparable[ActorRef] { scal def sendRequestReply(message: AnyRef, timeout: Long, sender: ActorRef): AnyRef = { !!(message, timeout)(Option(sender)).getOrElse(throw new ActorTimeoutException( "Message [" + message + - "]\n\tsent to [" + actorClassName + - "]\n\tfrom [" + (if (sender ne null) sender.actorClassName else "nowhere") + + "]\n\tfrom [" + (if (sender ne null) sender.address else "nowhere") + "]\n\twith timeout [" + timeout + "]\n\ttimed out.")) .asInstanceOf[AnyRef] @@ -355,32 +354,6 @@ trait ActorRef extends ActorRefShared with java.lang.Comparable[ActorRef] { scal */ def replySafe(message: AnyRef): Boolean = reply_?(message) - /** - * Returns the class for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def actorClass: Class[_ <: Actor] - - /** - * Akka Java API.

- * Returns the class for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def getActorClass(): Class[_ <: Actor] = actorClass - - /** - * Returns the class name for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def actorClassName: String - - /** - * Akka Java API.

- * Returns the class name for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def getActorClassName(): String = actorClassName - /** * Sets the dispatcher for this actor. Needs to be invoked before the actor is started. */ @@ -573,20 +546,6 @@ class LocalActorRef private[akka] (private[this] val actorFactory: () => Actor, // ========= PUBLIC FUNCTIONS ========= - /** - * Returns the class for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def actorClass: Class[_ <: Actor] = actor.getClass.asInstanceOf[Class[_ <: Actor]] - - /** - * Returns the class name for the Actor instance that is managed by the ActorRef. - */ - @deprecated("Will be removed without replacement, doesn't make any sense to have in the face of `become` and `unbecome`") - def actorClassName: String = actorClass.getName - - final def homeAddress: Option[InetSocketAddress] = None - /** * Sets the dispatcher for this actor. Needs to be invoked before the actor is started. */ @@ -996,7 +955,6 @@ object RemoteActorSystemMessage { */ private[akka] case class RemoteActorRef private[akka] ( val address: String, - val actorClassName: String, _timeout: Long, loader: Option[ClassLoader], val actorType: ActorType = ActorType.ScalaActor) @@ -1008,10 +966,11 @@ private[akka] case class RemoteActorRef private[akka] ( // FIXME BAD, we should not have different ActorRefs import DeploymentConfig._ + println("--------- " + Deployer.deploymentFor(address)) val remoteAddress = Deployer.deploymentFor(address) match { case Deploy(_, _, Clustered(Home(hostname, port), _, _)) => new InetSocketAddress(hostname, port) case _ => throw new IllegalStateException( - "Actor [" + actorClassName + "] with Address [" + address + "] is not bound to a Clustered Deployment") + "Actor with Address [" + address + "] is not bound to a Clustered Deployment") } start diff --git a/akka-actor/src/main/scala/akka/actor/Deployer.scala b/akka-actor/src/main/scala/akka/actor/Deployer.scala index c31090b520..278e6f8a24 100644 --- a/akka-actor/src/main/scala/akka/actor/Deployer.scala +++ b/akka-actor/src/main/scala/akka/actor/Deployer.scala @@ -9,9 +9,10 @@ import collection.immutable.Seq import java.util.concurrent.ConcurrentHashMap import akka.event.EventHandler -import akka.AkkaException import akka.actor.DeploymentConfig._ import akka.config.{ConfigurationException, Config} +import akka.util.ReflectiveAccess +import akka.AkkaException /** * Programatic deployment configuration classes. Most values have defaults and can be left out. @@ -138,9 +139,9 @@ object DeploymentConfig { * @author Jonas Bonér */ object Deployer { - // FIXME create clustered version of this when we have clustering in place - - private val deployments = new ConcurrentHashMap[String, Deploy] + lazy val useClusterDeployer = ReflectiveAccess.ClusterModule.isEnabled + lazy val cluster = ReflectiveAccess.ClusterModule.clusterDeployer + lazy val local = new LocalDeployer def deploy(deployment: Seq[Deploy]) { deployment foreach (deploy(_)) @@ -150,13 +151,8 @@ object Deployer { if (deployment eq null) throw new IllegalArgumentException("Deploy can not be null") val address = deployment.address Address.validate(address) - - if (deployments.putIfAbsent(address, deployment) != deployment) { - // FIXME do automatic 'undeploy' and redeploy (perhaps have it configurable if redeploy should be done or exception thrown) - // throwDeploymentBoundException(deployment) - } - - deployLocally(deployment) + if (useClusterDeployer) cluster.deploy(deployment) + else local.deploy(deployment) } private def deployLocally(deployment: Deploy) { @@ -185,11 +181,13 @@ object Deployer { * Undeploy is idemponent. E.g. safe to invoke multiple times. */ def undeploy(deployment: Deploy) { - deployments.remove(deployment.address) + if (useClusterDeployer) cluster.undeploy(deployment) + else local.undeploy(deployment) } def undeployAll() { - deployments.clear() + if (useClusterDeployer) cluster.undeployAll() + else local.undeployAll() } /** @@ -203,10 +201,12 @@ object Deployer { } def lookupDeploymentFor(address: String): Option[Deploy] = { - val deployment = deployments.get(address) - if (deployment ne null) Some(deployment) + val deployment_? = + if (useClusterDeployer) cluster.lookupDeploymentFor(address) + else local.lookupDeploymentFor(address) + if (deployment_?.isDefined && (deployment_?.get ne null)) deployment_? else { - val deployment = + val newDeployment = try { lookupInConfig(address) } catch { @@ -214,15 +214,15 @@ object Deployer { EventHandler.error(e, this, e.getMessage) throw e } - deployment foreach { d => + newDeployment foreach { d => if (d eq null) { val e = new IllegalStateException("Deployment for address [" + address + "] is null") EventHandler.error(e, this, e.getMessage) throw e } - deploy(d) + deploy(d) // deploy and cache it } - deployment + newDeployment } } @@ -319,15 +319,19 @@ object Deployer { } } - def isLocal(address: String): Boolean = lookupDeploymentFor(address) match { - case Some(Deploy(_, _, Local)) => true - case _ => false + def isLocal(deployment: Deploy): Boolean = deployment match { + case Deploy(_, _, Local) => true + case _ => false } + def isClustered(deployment: Deploy): Boolean = isLocal(deployment) + + def isLocal(address: String): Boolean = isLocal(deploymentFor(address)) + def isClustered(address: String): Boolean = !isLocal(address) private def throwDeploymentBoundException(deployment: Deploy): Nothing = { - val e = new DeploymentBoundException( + val e = new DeploymentAlreadyBoundException( "Address [" + deployment.address + "] already bound to [" + deployment + "]. You have to invoke 'undeploy(deployment) first.") @@ -342,6 +346,35 @@ object Deployer { } } +/** + * @author Jonas Bonér + */ +class LocalDeployer { + private val deployments = new ConcurrentHashMap[String, Deploy] + + def deploy(deployment: Deploy) { + if (deployments.putIfAbsent(deployment.address, deployment) != deployment) { + println("----- DEPLOYING " + deployment) + // FIXME do automatic 'undeploy' and redeploy (perhaps have it configurable if redeploy should be done or exception thrown) + // throwDeploymentBoundException(deployment) + } + } + + def undeploy(deployment: Deploy) { + deployments.remove(deployment.address) + } + + def undeployAll() { + deployments.clear() + } + + def lookupDeploymentFor(address: String): Option[Deploy] = { + val deployment = deployments.get(address) + if (deployment eq null) None + else Some(deployment) + } +} + /** * @author Jonas Bonér */ @@ -358,6 +391,6 @@ object Address { } } -class DeploymentBoundException private[akka](message: String) extends AkkaException(message) +class DeploymentException private[akka](message: String) extends AkkaException(message) +class DeploymentAlreadyBoundException private[akka](message: String) extends AkkaException(message) class NoDeploymentBoundException private[akka](message: String) extends AkkaException(message) - diff --git a/akka-actor/src/main/scala/akka/event/EventHandler.scala b/akka-actor/src/main/scala/akka/event/EventHandler.scala index 78314557d4..12a88201c8 100644 --- a/akka-actor/src/main/scala/akka/event/EventHandler.scala +++ b/akka-actor/src/main/scala/akka/event/EventHandler.scala @@ -226,7 +226,7 @@ object EventHandler extends ListenerManagement { addListener(Actor.actorOf(clazz, listenerName).start) } } catch { - case e: akka.actor.DeploymentBoundException => // do nothing + case e: akka.actor.DeploymentAlreadyBoundException => // do nothing case e: Exception => throw new ConfigurationException( "Event Handler specified in config can't be loaded [" + listenerName + diff --git a/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala b/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala index 032fb2da68..21ebbe2213 100644 --- a/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala +++ b/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala @@ -336,38 +336,26 @@ trait RemoteServerModule extends RemoteModule { trait RemoteClientModule extends RemoteModule { self: RemoteModule => - def actorFor(classNameOrServiceAddress: String, hostname: String, port: Int): ActorRef = - actorFor(classNameOrServiceAddress, classNameOrServiceAddress, Actor.TIMEOUT, hostname, port, None) + def actorFor(address: String, hostname: String, port: Int): ActorRef = + actorFor(address, Actor.TIMEOUT, hostname, port, None) - def actorFor(classNameOrServiceAddress: String, hostname: String, port: Int, loader: ClassLoader): ActorRef = - actorFor(classNameOrServiceAddress, classNameOrServiceAddress, Actor.TIMEOUT, hostname, port, Some(loader)) + def actorFor(address: String, hostname: String, port: Int, loader: ClassLoader): ActorRef = + actorFor(address, Actor.TIMEOUT, hostname, port, Some(loader)) - def actorFor(address: String, className: String, hostname: String, port: Int): ActorRef = - actorFor(address, className, Actor.TIMEOUT, hostname, port, None) + def actorFor(address: String, timeout: Long, hostname: String, port: Int): ActorRef = + actorFor(address, timeout, hostname, port, None) - def actorFor(address: String, className: String, hostname: String, port: Int, loader: ClassLoader): ActorRef = - actorFor(address, className, Actor.TIMEOUT, hostname, port, Some(loader)) - - def actorFor(classNameOrServiceAddress: String, timeout: Long, hostname: String, port: Int): ActorRef = - actorFor(classNameOrServiceAddress, classNameOrServiceAddress, timeout, hostname, port, None) - - def actorFor(classNameOrServiceAddress: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): ActorRef = - actorFor(classNameOrServiceAddress, classNameOrServiceAddress, timeout, hostname, port, Some(loader)) - - def actorFor(address: String, className: String, timeout: Long, hostname: String, port: Int): ActorRef = - actorFor(address, className, timeout, hostname, port, None) + def actorFor(address: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): ActorRef = + actorFor(address, timeout, hostname, port, Some(loader)) def typedActorFor[T](intfClass: Class[T], serviceIdOrClassName: String, hostname: String, port: Int): T = - typedActorFor(intfClass, serviceIdOrClassName, serviceIdOrClassName, Actor.TIMEOUT, hostname, port, None) + typedActorFor(intfClass, serviceIdOrClassName, Actor.TIMEOUT, hostname, port, None) def typedActorFor[T](intfClass: Class[T], serviceIdOrClassName: String, timeout: Long, hostname: String, port: Int): T = - typedActorFor(intfClass, serviceIdOrClassName, serviceIdOrClassName, timeout, hostname, port, None) + typedActorFor(intfClass, serviceIdOrClassName, timeout, hostname, port, None) def typedActorFor[T](intfClass: Class[T], serviceIdOrClassName: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): T = - typedActorFor(intfClass, serviceIdOrClassName, serviceIdOrClassName, timeout, hostname, port, Some(loader)) - - def typedActorFor[T](intfClass: Class[T], address: String, implClassName: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): T = - typedActorFor(intfClass, address, implClassName, timeout, hostname, port, Some(loader)) + typedActorFor(intfClass, serviceIdOrClassName, timeout, hostname, port, Some(loader)) /** * Clean-up all open connections. @@ -386,9 +374,9 @@ trait RemoteClientModule extends RemoteModule { self: RemoteModule => /** Methods that needs to be implemented by a transport **/ - protected[akka] def typedActorFor[T](intfClass: Class[T], serviceaddress: String, implClassName: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): T + protected[akka] def typedActorFor[T](intfClass: Class[T], serviceaddress: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): T - protected[akka] def actorFor(serviceaddress: String, className: String, timeout: Long, hostname: String, port: Int, loader: Option[ClassLoader]): ActorRef + protected[akka] def actorFor(address: String, timeout: Long, hostname: String, port: Int, loader: Option[ClassLoader]): ActorRef protected[akka] def send[T](message: Any, senderOption: Option[ActorRef], diff --git a/akka-actor/src/main/scala/akka/util/ReflectiveAccess.scala b/akka-actor/src/main/scala/akka/util/ReflectiveAccess.scala index a2e95a20d1..5e3f582fee 100644 --- a/akka-actor/src/main/scala/akka/util/ReflectiveAccess.scala +++ b/akka-actor/src/main/scala/akka/util/ReflectiveAccess.scala @@ -11,6 +11,7 @@ import java.net.InetSocketAddress import akka.remoteinterface.RemoteSupport import akka.actor._ import akka.event.EventHandler +import akka.actor.DeploymentConfig.Deploy /** * Helper class for reflective access to different modules in order to allow optional loading of modules. @@ -21,13 +22,13 @@ object ReflectiveAccess { val loader = getClass.getClassLoader - lazy val isRemotingEnabled = RemoteModule.isEnabled - lazy val isTypedActorEnabled = TypedActorModule.isEnabled - lazy val isClusterEnabled = ClusterModule.isEnabled + lazy val isRemotingEnabled: Boolean = RemoteModule.isEnabled + lazy val isTypedActorEnabled: Boolean = TypedActorModule.isEnabled + lazy val isClusterEnabled: Boolean = ClusterModule.isEnabled - def ensureClusterEnabled = ClusterModule.ensureEnabled - def ensureRemotingEnabled = RemoteModule.ensureEnabled - def ensureTypedActorEnabled = TypedActorModule.ensureEnabled + def ensureClusterEnabled() { ClusterModule.ensureEnabled() } + def ensureRemotingEnabled() { RemoteModule.ensureEnabled() } + def ensureTypedActorEnabled() { TypedActorModule.ensureEnabled() } /** * Reflective access to the Cluster module. @@ -35,32 +36,48 @@ object ReflectiveAccess { * @author Jonas Bonér */ object ClusterModule { - lazy val isEnabled = clusterObjectInstance.isDefined + lazy val isEnabled = clusterInstance.isDefined - def ensureEnabled = if (!isEnabled) { - val e = new ModuleNotAvailableException( - "Can't load the cluster module, make sure that akka-cluster.jar is on the classpath") - EventHandler.debug(this, e.toString) - throw e + def ensureEnabled() { + if (!isEnabled) { + val e = new ModuleNotAvailableException( + "Can't load the cluster module, make sure that akka-cluster.jar is on the classpath") + EventHandler.debug(this, e.toString) + throw e + } } - lazy val clusterObjectInstance: Option[Cluster] = getObjectFor("akka.cloud.cluster.Cluster$") + lazy val clusterInstance: Option[Cluster] = getObjectFor("akka.cluster.Cluster$") + + lazy val clusterDeployerInstance: Option[ClusterDeployer] = getObjectFor("akka.cluster.ClusterDeployer$") lazy val serializerClass: Option[Class[_]] = getClassFor("akka.serialization.Serializer") lazy val node: ClusterNode = { - ensureEnabled - clusterObjectInstance.get.newNode() + ensureEnabled() + clusterInstance.get.newNode() + } + + lazy val clusterDeployer: ClusterDeployer = { + ensureEnabled() + clusterDeployerInstance.get } type ClusterNode = { def nrOfActors: Int - def store[T <: Actor](address: String, actorRef: ActorRef): Unit + def store[T <: Actor](address: String, actorRef: ActorRef) // (implicit format: Format[T]) - def remove(address: String): Unit + def remove(address: String) def use(address: String): Option[ActorRef] } + type ClusterDeployer = { + def deploy(deployment: Deploy) + def undeploy(deployment: Deploy) + def undeployAll() + def lookupDeploymentFor(address: String): Option[Deploy] + } + type Cluster = { def newNode( //nodeAddress: NodeAddress, @@ -94,11 +111,13 @@ object ReflectiveAccess { lazy val isEnabled = remoteSupportClass.isDefined - def ensureEnabled = if (!isEnabled) { - val e = new ModuleNotAvailableException( - "Can't load the remoting module, make sure that akka-remote.jar is on the classpath") - EventHandler.debug(this, e.toString) - throw e + def ensureEnabled() { + if (!isEnabled) { + val e = new ModuleNotAvailableException( + "Can't load the remoting module, make sure that akka-remote.jar is on the classpath") + EventHandler.debug(this, e.toString) + throw e + } } val remoteSupportClass: Option[Class[_ <: RemoteSupport]] = getClassFor(TRANSPORT) @@ -130,19 +149,21 @@ object ReflectiveAccess { def isJoinPointAndOneWay(message: Any): Boolean def actorFor(proxy: AnyRef): Option[ActorRef] def proxyFor(actorRef: ActorRef): Option[AnyRef] - def stop(anyRef: AnyRef) : Unit + def stop(anyRef: AnyRef) } lazy val isEnabled = typedActorObjectInstance.isDefined - def ensureEnabled = if (!isTypedActorEnabled) throw new ModuleNotAvailableException( - "Can't load the typed actor module, make sure that akka-typed-actor.jar is on the classpath") + def ensureEnabled() { + if (!isTypedActorEnabled) throw new ModuleNotAvailableException( + "Can't load the typed actor module, make sure that akka-typed-actor.jar is on the classpath") + } val typedActorObjectInstance: Option[TypedActorObject] = getObjectFor("akka.actor.TypedActor$") def resolveFutureIfMessageIsJoinPoint(message: Any, future: Future[_]): Boolean = { - ensureEnabled + ensureEnabled() if (typedActorObjectInstance.get.isJoinPointAndOneWay(message)) { future.asInstanceOf[CompletableFuture[Option[_]]].completeWithResult(None) } diff --git a/akka-cluster/src/main/java/akka/cluster/ClusterProtocol.java b/akka-cluster/src/main/java/akka/cluster/ClusterProtocol.java index ff4ab448ed..ebf240b200 100644 --- a/akka-cluster/src/main/java/akka/cluster/ClusterProtocol.java +++ b/akka-cluster/src/main/java/akka/cluster/ClusterProtocol.java @@ -147,13 +147,6 @@ public final class ClusterProtocol { public boolean hasActorAddress() { return hasActorAddress; } public java.lang.String getActorAddress() { return actorAddress_; } - // optional string actorClassName = 4; - public static final int ACTORCLASSNAME_FIELD_NUMBER = 4; - private boolean hasActorClassName; - private java.lang.String actorClassName_ = ""; - public boolean hasActorClassName() { return hasActorClassName; } - public java.lang.String getActorClassName() { return actorClassName_; } - // optional bytes payload = 5; public static final int PAYLOAD_FIELD_NUMBER = 5; private boolean hasPayload; @@ -185,9 +178,6 @@ public final class ClusterProtocol { if (hasActorAddress()) { output.writeString(3, getActorAddress()); } - if (hasActorClassName()) { - output.writeString(4, getActorClassName()); - } if (hasPayload()) { output.writeBytes(5, getPayload()); } @@ -212,10 +202,6 @@ public final class ClusterProtocol { size += com.google.protobuf.CodedOutputStream .computeStringSize(3, getActorAddress()); } - if (hasActorClassName()) { - size += com.google.protobuf.CodedOutputStream - .computeStringSize(4, getActorClassName()); - } if (hasPayload()) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(5, getPayload()); @@ -387,9 +373,6 @@ public final class ClusterProtocol { if (other.hasActorAddress()) { setActorAddress(other.getActorAddress()); } - if (other.hasActorClassName()) { - setActorClassName(other.getActorClassName()); - } if (other.hasPayload()) { setPayload(other.getPayload()); } @@ -441,10 +424,6 @@ public final class ClusterProtocol { setActorAddress(input.readString()); break; } - case 34: { - setActorClassName(input.readString()); - break; - } case 42: { setPayload(input.readBytes()); break; @@ -533,27 +512,6 @@ public final class ClusterProtocol { return this; } - // optional string actorClassName = 4; - public boolean hasActorClassName() { - return result.hasActorClassName(); - } - public java.lang.String getActorClassName() { - return result.getActorClassName(); - } - public Builder setActorClassName(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - result.hasActorClassName = true; - result.actorClassName_ = value; - return this; - } - public Builder clearActorClassName() { - result.hasActorClassName = false; - result.actorClassName_ = getDefaultInstance().getActorClassName(); - return this; - } - // optional bytes payload = 5; public boolean hasPayload() { return result.hasPayload(); @@ -1376,24 +1334,23 @@ public final class ClusterProtocol { descriptor; static { java.lang.String[] descriptorData = { - "\n\025ClusterProtocol.proto\"\255\001\n\033RemoteDaemon" + + "\n\025ClusterProtocol.proto\"\225\001\n\033RemoteDaemon" + "MessageProtocol\022-\n\013messageType\030\001 \002(\0162\030.R" + "emoteDaemonMessageType\022 \n\tactorUuid\030\002 \001(" + - "\0132\r.UuidProtocol\022\024\n\014actorAddress\030\003 \001(\t\022\026" + - "\n\016actorClassName\030\004 \001(\t\022\017\n\007payload\030\005 \001(\014\"" + - "\212\001\n\035DurableMailboxMessageProtocol\022\031\n\021own" + - "erActorAddress\030\001 \002(\t\022\032\n\022senderActorAddre" + - "ss\030\002 \001(\t\022!\n\nfutureUuid\030\003 \001(\0132\r.UuidProto" + - "col\022\017\n\007message\030\004 \002(\014\")\n\014UuidProtocol\022\014\n\004" + - "high\030\001 \002(\004\022\013\n\003low\030\002 \002(\004*\232\002\n\027RemoteDaemon", - "MessageType\022\t\n\005START\020\001\022\010\n\004STOP\020\002\022\007\n\003USE\020" + - "\003\022\013\n\007RELEASE\020\004\022\022\n\016MAKE_AVAILABLE\020\005\022\024\n\020MA" + - "KE_UNAVAILABLE\020\006\022\016\n\nDISCONNECT\020\007\022\r\n\tRECO" + - "NNECT\020\010\022\n\n\006RESIGN\020\t\022\031\n\025FAIL_OVER_CONNECT" + - "IONS\020\n\022\026\n\022FUNCTION_FUN0_UNIT\020\013\022\025\n\021FUNCTI" + - "ON_FUN0_ANY\020\014\022\032\n\026FUNCTION_FUN1_ARG_UNIT\020" + - "\r\022\031\n\025FUNCTION_FUN1_ARG_ANY\020\016B\020\n\014akka.clu" + - "sterH\001" + "\0132\r.UuidProtocol\022\024\n\014actorAddress\030\003 \001(\t\022\017" + + "\n\007payload\030\005 \001(\014\"\212\001\n\035DurableMailboxMessag" + + "eProtocol\022\031\n\021ownerActorAddress\030\001 \002(\t\022\032\n\022" + + "senderActorAddress\030\002 \001(\t\022!\n\nfutureUuid\030\003" + + " \001(\0132\r.UuidProtocol\022\017\n\007message\030\004 \002(\014\")\n\014" + + "UuidProtocol\022\014\n\004high\030\001 \002(\004\022\013\n\003low\030\002 \002(\004*" + + "\232\002\n\027RemoteDaemonMessageType\022\t\n\005START\020\001\022\010", + "\n\004STOP\020\002\022\007\n\003USE\020\003\022\013\n\007RELEASE\020\004\022\022\n\016MAKE_A" + + "VAILABLE\020\005\022\024\n\020MAKE_UNAVAILABLE\020\006\022\016\n\nDISC" + + "ONNECT\020\007\022\r\n\tRECONNECT\020\010\022\n\n\006RESIGN\020\t\022\031\n\025F" + + "AIL_OVER_CONNECTIONS\020\n\022\026\n\022FUNCTION_FUN0_" + + "UNIT\020\013\022\025\n\021FUNCTION_FUN0_ANY\020\014\022\032\n\026FUNCTIO" + + "N_FUN1_ARG_UNIT\020\r\022\031\n\025FUNCTION_FUN1_ARG_A" + + "NY\020\016B\020\n\014akka.clusterH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -1405,7 +1362,7 @@ public final class ClusterProtocol { internal_static_RemoteDaemonMessageProtocol_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_RemoteDaemonMessageProtocol_descriptor, - new java.lang.String[] { "MessageType", "ActorUuid", "ActorAddress", "ActorClassName", "Payload", }, + new java.lang.String[] { "MessageType", "ActorUuid", "ActorAddress", "Payload", }, akka.cluster.ClusterProtocol.RemoteDaemonMessageProtocol.class, akka.cluster.ClusterProtocol.RemoteDaemonMessageProtocol.Builder.class); internal_static_DurableMailboxMessageProtocol_descriptor = diff --git a/akka-cluster/src/main/protocol/ClusterProtocol.proto b/akka-cluster/src/main/protocol/ClusterProtocol.proto index aa626fee3b..1287c1d9f0 100644 --- a/akka-cluster/src/main/protocol/ClusterProtocol.proto +++ b/akka-cluster/src/main/protocol/ClusterProtocol.proto @@ -18,7 +18,6 @@ message RemoteDaemonMessageProtocol { required RemoteDaemonMessageType messageType = 1; optional UuidProtocol actorUuid = 2; optional string actorAddress = 3; - optional string actorClassName = 4; optional bytes payload = 5; } diff --git a/akka-cluster/src/main/scala/akka/cluster/Cluster.scala b/akka-cluster/src/main/scala/akka/cluster/Cluster.scala index f6f35f0496..af8876815e 100644 --- a/akka-cluster/src/main/scala/akka/cluster/Cluster.scala +++ b/akka-cluster/src/main/scala/akka/cluster/Cluster.scala @@ -37,7 +37,7 @@ import akka.serialization.{Format, Serializer} import akka.serialization.Compression.LZF import akka.AkkaException -//import akka.cloud.monitoring.Monitoring +//import akka.monitoring.Monitoring import akka.cluster.zookeeper._ import com.eaio.uuid.UUID @@ -75,20 +75,16 @@ trait ClusterNodeMBean { def getLeader: String def getUuidsForClusteredActors: Array[String] - def getIdsForClusteredActors: Array[String] - def getClassNamesForClusteredActors: Array[String] + def getAddressesForClusteredActors: Array[String] def getUuidsForActorsInUse: Array[String] - def getIdsForActorsInUse: Array[String] - def getClassNamesForActorsInUse: Array[String] + def getAddressesForActorsInUse: Array[String] def getNodesForActorInUseWithUuid(uuid: String): Array[String] - def getNodesForActorInUseWithId(id: String): Array[String] - def getNodesForActorInUseWithClassName(className: String): Array[String] + def getNodesForActorInUseWithAddress(address: String): Array[String] def getUuidsForActorsInUseOnNode(nodeName: String): Array[String] - def getIdsForActorsInUseOnNode(nodeName: String): Array[String] - def getClassNamesForActorsInUseOnNode(nodeName: String): Array[String] + def getAddressesForActorsInUseOnNode(nodeName: String): Array[String] def setConfigElement(key: String, value: String): Unit def getConfigElement(key: String): AnyRef @@ -111,17 +107,6 @@ final case class NodeAddress( override def toString = "%s:%s:%s:%s".format(clusterName, nodeName, hostname, port) } -case class ActorAddress( - uuid: UUID = null, - address: String = Cluster.EMPTY_STRING, - className: String = Cluster.EMPTY_STRING) - -object ActorAddress { - def forUuid(uuid: UUID) = ActorAddress(uuid, Cluster.EMPTY_STRING, Cluster.EMPTY_STRING) - def forAddress(address: String) = ActorAddress(null, address, Cluster.EMPTY_STRING) - def forClassName(className: String) = ActorAddress(null, className, Cluster.EMPTY_STRING) -} - /** * Factory object for ClusterNode. Also holds global state such as configuration data etc. * @@ -379,7 +364,6 @@ object Cluster { .setHigh(uuid.getTime) .setLow(uuid.getClockSeqAndNode) .build - } /** @@ -411,6 +395,10 @@ class ClusterNode private[akka] ( }, "akka.cluster.remoteClientLifeCycleListener").start val remoteDaemon = actorOf(new RemoteClusterDaemon(this), RemoteClusterDaemon.ADDRESS).start + import DeploymentConfig._ + Deployer.deploy(Deploy( + RemoteClusterDaemon.ADDRESS, Direct, + Clustered(Home(nodeAddress.hostname, nodeAddress.port), NoReplicas, Stateless))) val remoteService: RemoteSupport = { val remote = new akka.remote.netty.NettyRemoteSupport @@ -424,23 +412,21 @@ class ClusterNode private[akka] ( val clusterJmxObjectName = JMX.nameFor(nodeAddress.hostname, "monitoring", "cluster") // static nodes - val CLUSTER_NODE = "/" + nodeAddress.clusterName - val MEMBERSHIP_NODE = CLUSTER_NODE + "/members" - val CONFIGURATION_NODE = CLUSTER_NODE + "/config" - val PROVISIONING_NODE = CLUSTER_NODE + "/provisioning" - val ACTOR_REGISTRY_NODE = CLUSTER_NODE + "/actor-registry" - val ACTOR_LOCATIONS_NODE = CLUSTER_NODE + "/actor-locations" - val ACTOR_ID_TO_UUIDS_NODE = CLUSTER_NODE + "/actor-id-to-uuids" - val ACTOR_CLASS_TO_UUIDS_NODE = CLUSTER_NODE + "/actor-class-to-uuids" - val ACTORS_AT_ADDRESS_NODE = CLUSTER_NODE + "/actors-at-address" + val CLUSTER_NODE = "/" + nodeAddress.clusterName + val MEMBERSHIP_NODE = CLUSTER_NODE + "/members" + val CONFIGURATION_NODE = CLUSTER_NODE + "/config" + val PROVISIONING_NODE = CLUSTER_NODE + "/provisioning" + val ACTOR_REGISTRY_NODE = CLUSTER_NODE + "/actor-registry" + val ACTOR_LOCATIONS_NODE = CLUSTER_NODE + "/actor-locations" + val ACTOR_ADDRESS_TO_UUIDS_NODE = CLUSTER_NODE + "/actor-address-to-uuids" + val ACTORS_AT_NODE_NODE = CLUSTER_NODE + "/actors-at-address" val baseNodes = List( CLUSTER_NODE, MEMBERSHIP_NODE, ACTOR_REGISTRY_NODE, ACTOR_LOCATIONS_NODE, - ACTORS_AT_ADDRESS_NODE, - ACTOR_ID_TO_UUIDS_NODE, - ACTOR_CLASS_TO_UUIDS_NODE, + ACTORS_AT_NODE_NODE, + ACTOR_ADDRESS_TO_UUIDS_NODE, CONFIGURATION_NODE, PROVISIONING_NODE) @@ -450,7 +436,7 @@ class ClusterNode private[akka] ( val isLeader = new AtomicBoolean(false) val electionNumber = new AtomicInteger(Integer.MAX_VALUE) - private val membershipNodePath = membershipNodePathFor(nodeAddress.nodeName) + private val membershipNodePath = membershipPathFor(nodeAddress.nodeName) // local caches of ZK data private[akka] val locallyCachedMembershipNodes = new ConcurrentSkipListSet[String]() @@ -587,8 +573,8 @@ class ClusterNode private[akka] ( * available durable store. */ def store[T <: Actor] - (actorClass: Class[T]) - (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass).start, 0, false) + (actorClass: Class[T], address: String) + (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass, address).start, 0, false) /** * Clusters an actor of a specific type. If the actor is already clustered then the clustered version will be updated @@ -596,8 +582,8 @@ class ClusterNode private[akka] ( * available durable store. */ def store[T <: Actor] - (actorClass: Class[T], replicationFactor: Int) - (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass).start, replicationFactor, false) + (actorClass: Class[T], address: String, replicationFactor: Int) + (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass, address).start, replicationFactor, false) /** * Clusters an actor of a specific type. If the actor is already clustered then the clustered version will be updated @@ -605,8 +591,8 @@ class ClusterNode private[akka] ( * available durable store. */ def store[T <: Actor] - (actorClass: Class[T], serializeMailbox: Boolean) - (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass).start, 0, serializeMailbox) + (actorClass: Class[T], address: String, serializeMailbox: Boolean) + (implicit format: Format[T]): ClusterNode = store(Actor.actorOf(actorClass, address).start, 0, serializeMailbox) /** * Clusters an actor of a specific type. If the actor is already clustered then the clustered version will be updated @@ -614,9 +600,9 @@ class ClusterNode private[akka] ( * available durable store. */ def store[T <: Actor] - (actorClass: Class[T], replicationFactor: Int, serializeMailbox: Boolean) + (actorClass: Class[T], address: String, replicationFactor: Int, serializeMailbox: Boolean) (implicit format: Format[T]): ClusterNode = - store(Actor.actorOf(actorClass).start, replicationFactor, serializeMailbox) + store(Actor.actorOf(actorClass, address).start, replicationFactor, serializeMailbox) /** * Clusters an actor with UUID. If the actor is already clustered then the clustered version will be updated @@ -661,11 +647,11 @@ class ClusterNode private[akka] ( val uuid = actorRef.uuid EventHandler.debug(this, - "Clustering actor [%s] with UUID [%s]".format( actorRef.actorClassName, uuid)) + "Clustering actor [%s] with UUID [%s]".format(actorRef.address, uuid)) val actorBytes = if (shouldCompressData) LZF.compress(toBinary(actorRef, serializeMailbox)(format)) else toBinary(actorRef)(format) - val actorRegistryPath = actorRegistryNodePathFor(uuid) + val actorRegistryPath = actorRegistryPathFor(uuid) // create UUID -> Array[Byte] for actor registry if (zkClient.exists(actorRegistryPath)) zkClient.writeData(actorRegistryPath, actorBytes) // FIXME check for size and warn if too big @@ -683,38 +669,27 @@ class ClusterNode private[akka] ( // create UUID -> Format registry try { - zkClient.createPersistent(actorRegistryFormatNodePathFor(uuid), format) + zkClient.createPersistent(actorRegistryFormatPathFor(uuid), format) } catch { - case e: ZkNodeExistsException => zkClient.writeData(actorRegistryFormatNodePathFor(uuid), format) + case e: ZkNodeExistsException => zkClient.writeData(actorRegistryFormatPathFor(uuid), format) } // create UUID -> ADDRESS registry try { - zkClient.createPersistent(actorRegistryactorAddressNodePathFor(uuid), actorRef.address) + zkClient.createPersistent(actorRegistryActorAddressPathFor(uuid), actorRef.address) } catch { - case e: ZkNodeExistsException => zkClient.writeData(actorRegistryactorAddressNodePathFor(uuid), actorRef.address) - } - - // create UUID -> class name registry - try { - zkClient.createPersistent(actorRegistryActorClassNameNodePathFor(uuid), actorRef.actorClassName) - } catch { - case e: ZkNodeExistsException => zkClient.writeData(actorRegistryActorClassNameNodePathFor(uuid), actorRef.actorClassName) + case e: ZkNodeExistsException => zkClient.writeData(actorRegistryActorAddressPathFor(uuid), actorRef.address) } // create UUID -> Address registry - ignore[ZkNodeExistsException]( zkClient.createPersistent(actorRegistryAddressNodePathFor(uuid)) ) + ignore[ZkNodeExistsException]( zkClient.createPersistent(actorRegistryNodePathFor(uuid)) ) // create UUID -> Node registry - ignore[ZkNodeExistsException]( zkClient.createPersistent(actorLocationsNodePathFor(uuid)) ) + ignore[ZkNodeExistsException]( zkClient.createPersistent(actorLocationsPathFor(uuid)) ) - // create ID -> UUIDs registry - ignore[ZkNodeExistsException]( zkClient.createPersistent(actorAddressToUuidsNodePathFor(actorRef.address)) ) - ignore[ZkNodeExistsException]( zkClient.createPersistent("%s/%s".format(actorAddressToUuidsNodePathFor(actorRef.address), uuid)) ) - - // create class name -> UUIDs registry - ignore[ZkNodeExistsException]( zkClient.createPersistent(actorClassNameToUuidsNodePathFor(actorRef.actorClassName)) ) - ignore[ZkNodeExistsException]( zkClient.createPersistent("%s/%s".format(actorClassNameToUuidsNodePathFor(actorRef.actorClassName), uuid)) ) + // create ADDRESS -> UUIDs registry + ignore[ZkNodeExistsException]( zkClient.createPersistent(actorAddressToUuidsPathFor(actorRef.address)) ) + ignore[ZkNodeExistsException]( zkClient.createPersistent("%s/%s".format(actorAddressToUuidsPathFor(actorRef.address), uuid)) ) } val command = RemoteDaemonMessageProtocol.newBuilder @@ -729,51 +704,27 @@ class ClusterNode private[akka] ( } else throw new ClusterException("Not connected to cluster") /** - * Removes actor by type from the cluster. - *

-   *   clusterNode remove classOf[MyActor]
-   * 
+ * Removes actor with uuid from the cluster. */ - def remove[T <: Actor](actorClass: Class[T]): ClusterNode = remove(ActorAddress(className = actorClass.getName)) + def remove(uuid: UUID) = { + releaseActorOnAllNodes(uuid) + + locallyCheckedOutActors.remove(uuid) + // warning: ordering matters here + ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAddressToUuidsPathFor(actorAddressForUuid(uuid)))) // remove ADDRESS to UUID mapping + ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAtNodePathFor(nodeAddress.nodeName, uuid))) + ignore[ZkNoNodeException](zkClient.deleteRecursive(actorRegistryPathFor(uuid))) + ignore[ZkNoNodeException](zkClient.deleteRecursive(actorLocationsPathFor(uuid))) + } /** - * Removes actor with UUID from the cluster. + * Removes actor with address from the cluster. */ - def remove(actorAddress: ActorAddress): ClusterNode = { - - def removeByUuid(uuid: UUID) = { - releaseActorOnAllNodes(uuid) - - locallyCheckedOutActors.remove(uuid) - // warning: ordering matters here - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAddressToUuidsNodePathFor(actorAddressForUuid(uuid)))) // remove ID to UUID mapping - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorClassNameToUuidsNodePathFor(actorClassNameForUuid(uuid)))) // remove class name to UUID mapping - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAtAddressNodePathFor(nodeAddress.nodeName, uuid))) - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorRegistryNodePathFor(uuid))) - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorLocationsNodePathFor(uuid))) - } - + def remove(address: String): ClusterNode = { isConnected ifOn { - // remove by UUID - if (actorAddress.uuid ne null) { - EventHandler.debug(this, - "Removing actor with UUID [%s] from cluster".format(actorAddress.uuid)) - removeByUuid(actorAddress.uuid) - - // remove by ID - } else if (actorAddress.address != EMPTY_STRING) { - EventHandler.debug(this, - "Removing actor(s) with ID [%s] from cluster".format(actorAddress.address)) - uuidsForActorAddress(actorAddress.address) foreach (uuid => removeByUuid(uuid)) - - // remove by class name - } else if (actorAddress.className != EMPTY_STRING) { - EventHandler.debug(this, - "Removing actor(s) with class name [%s] from cluster".format(actorAddress.className)) - uuidsForActorClassName(actorAddress.className) foreach (uuid => removeByUuid(uuid)) - - } else throw new IllegalArgumentException( - "You need to pass in at least one of 'uuid' or 'actorAddress' or 'className' to 'ClusterNode.remove(..)'") + EventHandler.debug(this, + "Removing actor(s) with ADDRESS [%s] from cluster".format(address)) + uuidsForActorAddress(address) foreach (uuid => remove(uuid)) } this } @@ -781,23 +732,23 @@ class ClusterNode private[akka] ( /** * Is the actor with uuid clustered or not? */ - def isClustered(actorAddress: ActorAddress): Boolean = if (isConnected.isOn) { + def isClustered(actorAddress: String): Boolean = if (isConnected.isOn) { actorUuidsForActorAddress(actorAddress) map { uuid => - zkClient.exists(actorRegistryNodePathFor(uuid)) + zkClient.exists(actorRegistryPathFor(uuid)) } exists (_ == true) } else false /** * Is the actor with uuid in use on 'this' node or not? */ - def isInUseOnNode(actorAddress: ActorAddress): Boolean = isInUseOnNode(actorAddress, nodeAddress) + def isInUseOnNode(actorAddress: String): Boolean = isInUseOnNode(actorAddress, nodeAddress) /** * Is the actor with uuid in use or not? */ - def isInUseOnNode(actorAddress: ActorAddress, node: NodeAddress): Boolean = if (isConnected.isOn) { + def isInUseOnNode(actorAddress: String, node: NodeAddress): Boolean = if (isConnected.isOn) { actorUuidsForActorAddress(actorAddress) map { uuid => - zkClient.exists(actorLocationsNodePathFor(uuid, node)) + zkClient.exists(actorLocationsPathFor(uuid, node)) } exists (_ == true) } else false @@ -805,7 +756,7 @@ class ClusterNode private[akka] ( * Checks out an actor for use on this node, e.g. checked out as a 'LocalActorRef' but it makes it available * for remote access through lookup by its UUID. */ - def use[T <: Actor](actorAddress: ActorAddress)( + def use[T <: Actor](actorAddress: String)( implicit format: Format[T] = formatForActor(actorAddress)): Array[LocalActorRef] = if (isConnected.isOn) { import akka.serialization.ActorSerialization._ @@ -814,14 +765,14 @@ class ClusterNode private[akka] ( EventHandler.debug(this, "Checking out actor with UUID [%s] to be used on node [%s]".format(uuid, nodeAddress.nodeName)) - ignore[ZkNodeExistsException](zkClient.createPersistent(actorAtAddressNodePathFor(nodeAddress.nodeName, uuid), true)) - ignore[ZkNodeExistsException](zkClient.createEphemeral(actorLocationsNodePathFor(uuid, nodeAddress))) + ignore[ZkNodeExistsException](zkClient.createPersistent(actorAtNodePathFor(nodeAddress.nodeName, uuid), true)) + ignore[ZkNodeExistsException](zkClient.createEphemeral(actorLocationsPathFor(uuid, nodeAddress))) // set home address - ignore[ZkNodeExistsException](zkClient.createPersistent(actorRegistryAddressNodePathFor(uuid))) - ignore[ZkNodeExistsException](zkClient.createEphemeral(actorRegistryAddressNodePathFor(uuid, remoteServerAddress))) + ignore[ZkNodeExistsException](zkClient.createPersistent(actorRegistryNodePathFor(uuid))) + ignore[ZkNodeExistsException](zkClient.createEphemeral(actorRegistryNodePathFor(uuid, remoteServerAddress))) - val actorPath = actorRegistryNodePathFor(uuid) + val actorPath = actorRegistryPathFor(uuid) zkClient.retryUntilConnected(new Callable[Either[Array[Byte], Exception]]() { def call: Either[Array[Byte], Exception] = { try { @@ -875,15 +826,15 @@ class ClusterNode private[akka] ( /** * Checks in an actor after done using it on this node. */ - def release(actorAddress: ActorAddress): Unit = isConnected ifOn { + def release(actorAddress: String): Unit = isConnected ifOn { actorUuidsForActorAddress(actorAddress) foreach { uuid => EventHandler.debug(this, "Releasing actor with UUID [%s] after usage".format(uuid)) locallyCheckedOutActors.remove(uuid) - ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAtAddressNodePathFor(nodeAddress.nodeName, uuid))) - ignore[ZkNoNodeException](zkClient.delete(actorAtAddressNodePathFor(nodeAddress.nodeName, uuid))) - ignore[ZkNoNodeException](zkClient.delete(actorLocationsNodePathFor(uuid, nodeAddress))) - ignore[ZkNoNodeException](zkClient.delete(actorRegistryAddressNodePathFor(uuid, remoteServerAddress))) + ignore[ZkNoNodeException](zkClient.deleteRecursive(actorAtNodePathFor(nodeAddress.nodeName, uuid))) + ignore[ZkNoNodeException](zkClient.delete(actorAtNodePathFor(nodeAddress.nodeName, uuid))) + ignore[ZkNoNodeException](zkClient.delete(actorLocationsPathFor(uuid, nodeAddress))) + ignore[ZkNoNodeException](zkClient.delete(actorRegistryNodePathFor(uuid, remoteServerAddress))) } } @@ -907,7 +858,7 @@ class ClusterNode private[akka] ( /** * Creates an ActorRef with a Router to a set of clustered actors. */ - def ref(actorAddress: ActorAddress, router: Router.RouterType): ActorRef = if (isConnected.isOn) { + def ref(actorAddress: String, router: Router.RouterType): ActorRef = if (isConnected.isOn) { val addresses = addressesForActor(actorAddress) val actorType = ActorType.ScalaActor // FIXME later we also want to suppot TypedActor, then 'actorType' needs to be configurable @@ -918,60 +869,39 @@ class ClusterNode private[akka] ( def registerClusterActorRefForAddress(actorRef: ClusterActorRef, addresses: Array[(UUID, InetSocketAddress)]) = addresses foreach { case (_, address) => clusterActorRefs.put(address, actorRef) } + // FIXME remove? def refByUuid(uuid: UUID): ActorRef = { - val className = actorClassNameForUuid(uuid) val actor = Router newRouter ( router, addresses, - uuidToString(uuid), className, - Cluster.lookupLocalhostName, Cluster.remoteServerPort, // set it to local hostname:port + uuidToString(uuid), Actor.TIMEOUT, actorType) registerClusterActorRefForAddress(actor, addresses) actor } - def refById(actorAddress: String): ActorRef = { - val uuids = uuidsForActorAddress(actorAddress) - val className = uuids.map(uuid => actorClassNameForUuid(uuid)).head - if (className eq null) throw new IllegalStateException( - "Actor class name for actor with UUID [" + uuids.head + "] could not be retrieved") + def refByAddress(actorAddress: String): ActorRef = { + val uuids = uuidsForActorAddress(actorAddress) val actor = Router newRouter ( router, addresses, - actorAddress, className, - Cluster.lookupLocalhostName, Cluster.remoteServerPort, // set it to local hostname:port + actorAddress, Actor.TIMEOUT, actorType) registerClusterActorRefForAddress(actor, addresses) actor } - def refByClassName(className: String): ActorRef = { - val actor = Router newRouter ( - router, addresses, - className, className, - Cluster.lookupLocalhostName, Cluster.remoteServerPort, // set it to local hostname:port - Actor.TIMEOUT, actorType) - registerClusterActorRefForAddress(actor, addresses) - actor - } - - val uuid = actorAddress.uuid - val address = actorAddress.address - val className = actorAddress.className - if ((uuid ne null) && address == EMPTY_STRING && className == EMPTY_STRING) refByUuid(uuid) - else if (address != EMPTY_STRING && (uuid eq null) && className == EMPTY_STRING) refById(address) - else if (className != EMPTY_STRING && (uuid eq null) && address == EMPTY_STRING) refByClassName(className) - else throw new IllegalArgumentException("You need to pass in either 'uuid' or 'actorAddress' or 'className' and only one of them") + refByAddress(actorAddress) } else throw new ClusterException("Not connected to cluster") /** * Migrate the actor from 'this' node to node 'to'. */ - def migrate(to: NodeAddress, actorAddress: ActorAddress): Unit = migrate(nodeAddress, to, actorAddress) + def migrate(to: NodeAddress, actorAddress: String): Unit = migrate(nodeAddress, to, actorAddress) /** * Migrate the actor from node 'from' to node 'to'. */ def migrate( - from: NodeAddress, to: NodeAddress, actorAddress: ActorAddress): Unit = isConnected ifOn { + from: NodeAddress, to: NodeAddress, actorAddress: String): Unit = isConnected ifOn { if (from eq null) throw new IllegalArgumentException("NodeAddress 'from' can not be 'null'") if (to eq null) throw new IllegalArgumentException("NodeAddress 'to' can not be 'null'") if (isInUseOnNode(actorAddress, from)) { @@ -987,14 +917,9 @@ class ClusterNode private[akka] ( def uuidsForActorsInUse: Array[UUID] = uuidsForActorsInUseOnNode(nodeAddress.nodeName) /** - * Returns the IDs of all actors checked out on this node. + * Returns the addresses of all actors checked out on this node. */ - def idsForActorsInUse: Array[String] = actorAddresssForUuids(uuidsForActorsInUse) - - /** - * Returns the class names of all actors checked out on this node. - */ - def classNamesForActorsInUse: Array[String] = actorClassNamesForUuids(uuidsForActorsInUse) + def addressesForActorsInUse: Array[String] = actorAddressForUuids(uuidsForActorsInUse) /** * Returns the UUIDs of all actors registered in this cluster. @@ -1004,54 +929,28 @@ class ClusterNode private[akka] ( } else Array.empty[UUID] /** - * Returns the IDs of all actors registered in this cluster. + * Returns the addresses of all actors registered in this cluster. */ - def idsForClusteredActors: Array[String] = actorAddresssForUuids(uuidsForClusteredActors) - - /** - * Returns the class names of all actors registered in this cluster. - */ - def classNamesForClusteredActors: Array[String] = actorClassNamesForUuids(uuidsForClusteredActors) + def addressesForClusteredActors: Array[String] = actorAddressForUuids(uuidsForClusteredActors) /** * Returns the actor id for the actor with a specific UUID. */ def actorAddressForUuid(uuid: UUID): String = if (isConnected.isOn) { - try { zkClient.readData(actorRegistryactorAddressNodePathFor(uuid)).asInstanceOf[String] } + try { zkClient.readData(actorRegistryActorAddressPathFor(uuid)).asInstanceOf[String] } catch { case e: ZkNoNodeException => "" } } else "" /** * Returns the actor ids for all the actors with a specific UUID. */ - def actorAddresssForUuids(uuids: Array[UUID]): Array[String] = uuids map (actorAddressForUuid(_)) filter (_ != "") - - /** - * Returns the actor class name for the actor with a specific UUID. - */ - def actorClassNameForUuid(uuid: UUID): String = if (isConnected.isOn) { - try { zkClient.readData(actorRegistryActorClassNameNodePathFor(uuid)).asInstanceOf[String] } - catch { case e: ZkNoNodeException => "" } - } else "" - - /** - * Returns the actor class names for all the actors with a specific UUID. - */ - def actorClassNamesForUuids(uuids: Array[UUID]): Array[String] = uuids map (actorClassNameForUuid(_)) filter (_ != "") + def actorAddressForUuids(uuids: Array[UUID]): Array[String] = uuids map (actorAddressForUuid(_)) filter (_ != "") /** * Returns the actor UUIDs for actor ID. */ def uuidsForActorAddress(actorAddress: String): Array[UUID] = if (isConnected.isOn) { - try { zkClient.getChildren(actorAddressToUuidsNodePathFor(actorAddress)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } - catch { case e: ZkNoNodeException => Array[UUID]() } - } else Array.empty[UUID] - - /** - * Returns the actor UUIDs for actor class name. - */ - def uuidsForActorClassName(className: String): Array[UUID] = if (isConnected.isOn) { - try { zkClient.getChildren(actorClassNameToUuidsNodePathFor(className)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } + try { zkClient.getChildren(actorAddressToUuidsPathFor(actorAddress)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } catch { case e: ZkNoNodeException => Array[UUID]() } } else Array.empty[UUID] @@ -1059,29 +958,17 @@ class ClusterNode private[akka] ( * Returns the node names of all actors in use with UUID. */ def nodesForActorsInUseWithUuid(uuid: UUID): Array[String] = if (isConnected.isOn) { - try { zkClient.getChildren(actorLocationsNodePathFor(uuid)).toList.toArray.asInstanceOf[Array[String]] } + try { zkClient.getChildren(actorLocationsPathFor(uuid)).toList.toArray.asInstanceOf[Array[String]] } catch { case e: ZkNoNodeException => Array[String]() } } else Array.empty[String] /** - * Returns the node names of all actors in use with id. + * Returns the node names of all actors in use with address. */ - def nodesForActorsInUseWithId(id: String): Array[String] = if (isConnected.isOn) { + def nodesForActorsInUseWithAddress(address: String): Array[String] = if (isConnected.isOn) { flatten { - actorUuidsForActorAddress(ActorAddress(null, id, EMPTY_STRING)) map { uuid => - try { zkClient.getChildren(actorLocationsNodePathFor(uuid)).toList.toArray.asInstanceOf[Array[String]] } - catch { case e: ZkNoNodeException => Array[String]() } - } - } - } else Array.empty[String] - - /** - * Returns the node names of all actors in use with class name. - */ - def nodesForActorsInUseWithClassName(className: String): Array[String] = if (isConnected.isOn) { - flatten { - actorUuidsForActorAddress(ActorAddress(null, EMPTY_STRING, className)) map { uuid => - try { zkClient.getChildren(actorLocationsNodePathFor(uuid)).toList.toArray.asInstanceOf[Array[String]] } + actorUuidsForActorAddress(address) map { uuid => + try { zkClient.getChildren(actorLocationsPathFor(uuid)).toList.toArray.asInstanceOf[Array[String]] } catch { case e: ZkNoNodeException => Array[String]() } } } @@ -1091,37 +978,27 @@ class ClusterNode private[akka] ( * Returns the UUIDs of all actors in use registered on a specific node. */ def uuidsForActorsInUseOnNode(nodeName: String): Array[UUID] = if (isConnected.isOn) { - try { zkClient.getChildren(actorsAtAddressNodePathFor(nodeName)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } + try { zkClient.getChildren(actorsAtNodePathFor(nodeName)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } catch { case e: ZkNoNodeException => Array[UUID]() } } else Array.empty[UUID] /** - * Returns the IDs of all actors in use registered on a specific node. + * Returns the addresses of all actors in use registered on a specific node. */ - def idsForActorsInUseOnNode(nodeName: String): Array[String] = if (isConnected.isOn) { + def addressesForActorsInUseOnNode(nodeName: String): Array[String] = if (isConnected.isOn) { val uuids = - try { zkClient.getChildren(actorsAtAddressNodePathFor(nodeName)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } + try { zkClient.getChildren(actorsAtNodePathFor(nodeName)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } catch { case e: ZkNoNodeException => Array[UUID]() } - actorAddresssForUuids(uuids) - } else Array.empty[String] - - /** - * Returns the class namess of all actors in use registered on a specific node. - */ - def classNamesForActorsInUseOnNode(nodeName: String): Array[String] = if (isConnected.isOn) { - val uuids = - try { zkClient.getChildren(actorsAtAddressNodePathFor(nodeName)).toList.map(new UUID(_)).toArray.asInstanceOf[Array[UUID]] } - catch { case e: ZkNoNodeException => Array[UUID]() } - actorClassNamesForUuids(uuids) + actorAddressForUuids(uuids) } else Array.empty[String] /** * Returns Format for actor with UUID. */ - def formatForActor[T <: Actor](actorAddress: ActorAddress): Format[T] = { + def formatForActor[T <: Actor](actorAddress: String): Format[T] = { val formats = actorUuidsForActorAddress(actorAddress) map { uuid => - zkClient.readData(actorRegistryFormatNodePathFor(uuid), new Stat).asInstanceOf[Format[T]] + zkClient.readData(actorRegistryFormatPathFor(uuid), new Stat).asInstanceOf[Format[T]] } val format = formats.head @@ -1134,11 +1011,11 @@ class ClusterNode private[akka] ( /** * Returns home address for actor with UUID. */ - def addressesForActor(actorAddress: ActorAddress): Array[(UUID, InetSocketAddress)] = { + def addressesForActor(actorAddress: String): Array[(UUID, InetSocketAddress)] = { try { for { uuid <- actorUuidsForActorAddress(actorAddress) - address <- zkClient.getChildren(actorRegistryAddressNodePathFor(uuid)).toList + address <- zkClient.getChildren(actorRegistryNodePathFor(uuid)).toList } yield { val tokenizer = new java.util.StringTokenizer(address, ":") val hostname = tokenizer.nextToken // hostname @@ -1215,10 +1092,10 @@ class ClusterNode private[akka] ( zkClient.retryUntilConnected(new Callable[Either[Unit, Exception]]() { def call: Either[Unit, Exception] = { try { - Left(zkClient.connection.create(configurationNodePathFor(key), compressedBytes, CreateMode.PERSISTENT)) + Left(zkClient.connection.create(configurationPathFor(key), compressedBytes, CreateMode.PERSISTENT)) } catch { case e: KeeperException.NodeExistsException => try { - Left(zkClient.connection.writeData(configurationNodePathFor(key), compressedBytes)) + Left(zkClient.connection.writeData(configurationPathFor(key), compressedBytes)) } catch { case e: Exception => Right(e) } } } @@ -1232,7 +1109,7 @@ class ClusterNode private[akka] ( * Returns the config element for the key or NULL if no element exists under the key. */ def getConfigElement(key: String): Array[Byte] = try { - zkClient.connection.readData(configurationNodePathFor(key), new Stat, true) + zkClient.connection.readData(configurationPathFor(key), new Stat, true) } catch { case e: KeeperException.NoNodeException => null } @@ -1240,7 +1117,7 @@ class ClusterNode private[akka] ( def removeConfigElement(key: String) = ignore[ZkNoNodeException]{ EventHandler.debug(this, "Removing config element with key [%s] from cluster registry".format(key)) - zkClient.deleteRecursive(configurationNodePathFor(key)) + zkClient.deleteRecursive(configurationPathFor(key)) } def getConfigElementKeys: Array[String] = zkClient.getChildren(CONFIGURATION_NODE).toList.toArray.asInstanceOf[Array[String]] @@ -1265,27 +1142,25 @@ class ClusterNode private[akka] ( // Private // ======================================= - private[cluster] def membershipNodePathFor(node: String) = "%s/%s".format(MEMBERSHIP_NODE, node) + private[cluster] def membershipPathFor(node: String) = "%s/%s".format(MEMBERSHIP_NODE, node) - private[cluster] def configurationNodePathFor(key: String) = "%s/%s".format(CONFIGURATION_NODE, key) + private[cluster] def configurationPathFor(key: String) = "%s/%s".format(CONFIGURATION_NODE, key) - private[cluster] def actorAddressToUuidsNodePathFor(actorAddress: String) = "%s/%s".format(ACTOR_ID_TO_UUIDS_NODE, actorAddress.replace('.', '_')) - private[cluster] def actorClassNameToUuidsNodePathFor(className: String) = "%s/%s".format(ACTOR_CLASS_TO_UUIDS_NODE, className) + private[cluster] def actorAddressToUuidsPathFor(actorAddress: String) = "%s/%s".format(ACTOR_ADDRESS_TO_UUIDS_NODE, actorAddress.replace('.', '_')) - private[cluster] def actorLocationsNodePathFor(uuid: UUID) = "%s/%s".format(ACTOR_LOCATIONS_NODE, uuid) - private[cluster] def actorLocationsNodePathFor(uuid: UUID, node: NodeAddress) = + private[cluster] def actorLocationsPathFor(uuid: UUID) = "%s/%s".format(ACTOR_LOCATIONS_NODE, uuid) + private[cluster] def actorLocationsPathFor(uuid: UUID, node: NodeAddress) = "%s/%s/%s".format(ACTOR_LOCATIONS_NODE, uuid, node.nodeName) - private[cluster] def actorsAtAddressNodePathFor(node: String) = "%s/%s".format(ACTORS_AT_ADDRESS_NODE, node) - private[cluster] def actorAtAddressNodePathFor(node: String, uuid: UUID) = "%s/%s/%s".format(ACTORS_AT_ADDRESS_NODE, node, uuid) + private[cluster] def actorsAtNodePathFor(node: String) = "%s/%s".format(ACTORS_AT_NODE_NODE, node) + private[cluster] def actorAtNodePathFor(node: String, uuid: UUID) = "%s/%s/%s".format(ACTORS_AT_NODE_NODE, node, uuid) - private[cluster] def actorRegistryNodePathFor(uuid: UUID) = "%s/%s".format(ACTOR_REGISTRY_NODE, uuid) - private[cluster] def actorRegistryFormatNodePathFor(uuid: UUID) = "%s/%s".format(actorRegistryNodePathFor(uuid), "format") - private[cluster] def actorRegistryactorAddressNodePathFor(uuid: UUID) = "%s/%s".format(actorRegistryNodePathFor(uuid), "id") - private[cluster] def actorRegistryActorClassNameNodePathFor(uuid: UUID) = "%s/%s".format(actorRegistryNodePathFor(uuid), "class") - private[cluster] def actorRegistryAddressNodePathFor(uuid: UUID): String = "%s/%s".format(actorRegistryNodePathFor(uuid), "address") - private[cluster] def actorRegistryAddressNodePathFor(uuid: UUID, address: InetSocketAddress): String = - "%s/%s:%s".format(actorRegistryAddressNodePathFor(uuid), address.getHostName, address.getPort) + private[cluster] def actorRegistryPathFor(uuid: UUID) = "%s/%s".format(ACTOR_REGISTRY_NODE, uuid) + private[cluster] def actorRegistryFormatPathFor(uuid: UUID) = "%s/%s".format(actorRegistryPathFor(uuid), "format") + private[cluster] def actorRegistryActorAddressPathFor(uuid: UUID) = "%s/%s".format(actorRegistryPathFor(uuid), "address") + private[cluster] def actorRegistryNodePathFor(uuid: UUID): String = "%s/%s".format(actorRegistryPathFor(uuid), "node") + private[cluster] def actorRegistryNodePathFor(uuid: UUID, address: InetSocketAddress): String = + "%s/%s:%s".format(actorRegistryNodePathFor(uuid), address.getHostName, address.getPort) private[cluster] def initializeNode = { EventHandler.info(this, "Initializing cluster node [%s]".format(nodeAddress)) @@ -1300,7 +1175,7 @@ class ClusterNode private[akka] ( } private[cluster] def addressForNode(node: String): InetSocketAddress = { - val address = zkClient.readData(membershipNodePathFor(node)).asInstanceOf[String] + val address = zkClient.readData(membershipPathFor(node)).asInstanceOf[String] val tokenizer = new java.util.StringTokenizer(address, ":") tokenizer.nextToken // cluster name tokenizer.nextToken // node name @@ -1309,15 +1184,7 @@ class ClusterNode private[akka] ( new InetSocketAddress(hostname, port) } - private def actorUuidsForActorAddress(actorAddress: ActorAddress): Array[UUID] = { - val uuid = actorAddress.uuid - val address = actorAddress.address - val className = actorAddress.className - if ((uuid ne null) && address == EMPTY_STRING && className == EMPTY_STRING) Array(uuid) - else if (address != EMPTY_STRING && (uuid eq null) && className == EMPTY_STRING) uuidsForActorAddress(address) - else if (className != EMPTY_STRING && (uuid eq null) && address == EMPTY_STRING) uuidsForActorClassName(className) - else throw new IllegalArgumentException("You need to pass in either 'uuid' or 'actorAddress' or 'className' and only one of them") - } filter (_ ne null) + private def actorUuidsForActorAddress(actorAddress: String): Array[UUID] = uuidsForActorAddress(actorAddress) filter (_ ne null) /** * Returns a random set with replica connections of size 'replicationFactor'. @@ -1375,7 +1242,7 @@ class ClusterNode private[akka] ( } private[cluster] def joinActorsAtAddressNode = - ignore[ZkNodeExistsException](zkClient.createPersistent(actorsAtAddressNodePathFor(nodeAddress.nodeName))) + ignore[ZkNodeExistsException](zkClient.createPersistent(actorsAtNodePathFor(nodeAddress.nodeName))) private[cluster] def joinLeaderElection: Boolean = { EventHandler.info(this, "Node [%s] is joining leader election".format(nodeAddress.nodeName)) @@ -1398,7 +1265,7 @@ class ClusterNode private[akka] ( (failedNodeIndex == myIndex + 1)) { // Am I the leftmost successor? // Yes I am the node to migrate the actor to (can only be one in the cluster) - val actorUuidsForFailedNode = zkClient.getChildren(actorsAtAddressNodePathFor(failedNodeName)) + val actorUuidsForFailedNode = zkClient.getChildren(actorsAtNodePathFor(failedNodeName)) EventHandler.debug(this, "Migrating actors from failed node [%s] to node [%s]: Actor UUIDs [%s]" .format(failedNodeName, nodeAddress.nodeName, actorUuidsForFailedNode)) @@ -1408,7 +1275,7 @@ class ClusterNode private[akka] ( "Cluster node [%s] has failed, migrating actor with UUID [%s] to [%s]" .format(failedNodeName, uuid, nodeAddress.nodeName)) - val actorAddress = ActorAddress(uuid = stringToUuid(uuid)) + val actorAddress = actorAddressForUuid(uuidFrom(uuid)) migrateWithoutCheckingThatActorResidesOnItsHomeNode( // since the ephemeral node is already gone, so can't check NodeAddress(nodeAddress.clusterName, failedNodeName), nodeAddress, actorAddress) @@ -1444,22 +1311,22 @@ class ClusterNode private[akka] ( * Used when the ephemeral "home" node is already gone, so we can't check. */ private def migrateWithoutCheckingThatActorResidesOnItsHomeNode( - from: NodeAddress, to: NodeAddress, actorAddress: ActorAddress) { + from: NodeAddress, to: NodeAddress, actorAddress: String) { actorUuidsForActorAddress(actorAddress) map { uuid => - val actorAddress = ActorAddress(uuid = uuid) + val actorAddress = actorAddressForUuid(uuid) if (!isInUseOnNode(actorAddress, to)) { release(actorAddress) val newAddress = new InetSocketAddress(to.hostname, to.port) - ignore[ZkNodeExistsException](zkClient.createPersistent(actorRegistryAddressNodePathFor(uuid))) - ignore[ZkNodeExistsException](zkClient.createEphemeral(actorRegistryAddressNodePathFor(uuid, newAddress))) - ignore[ZkNodeExistsException](zkClient.createEphemeral(actorLocationsNodePathFor(uuid, to))) - ignore[ZkNodeExistsException](zkClient.createPersistent(actorAtAddressNodePathFor(nodeAddress.nodeName, uuid))) + ignore[ZkNodeExistsException](zkClient.createPersistent(actorRegistryNodePathFor(uuid))) + ignore[ZkNodeExistsException](zkClient.createEphemeral(actorRegistryNodePathFor(uuid, newAddress))) + ignore[ZkNodeExistsException](zkClient.createEphemeral(actorLocationsPathFor(uuid, to))) + ignore[ZkNodeExistsException](zkClient.createPersistent(actorAtNodePathFor(nodeAddress.nodeName, uuid))) - ignore[ZkNoNodeException](zkClient.delete(actorLocationsNodePathFor(uuid, from))) - ignore[ZkNoNodeException](zkClient.delete(actorAtAddressNodePathFor(from.nodeName, uuid))) + ignore[ZkNoNodeException](zkClient.delete(actorLocationsPathFor(uuid, from))) + ignore[ZkNoNodeException](zkClient.delete(actorAtNodePathFor(from.nodeName, uuid))) // 'use' (check out) actor on the remote 'to' node useActorOnNode(to.nodeName, uuid) @@ -1537,20 +1404,16 @@ class ClusterNode private[akka] ( def getLeader = self.leader.toString def getUuidsForActorsInUse = self.uuidsForActorsInUse.map(_.toString).toArray - def getIdsForActorsInUse = self.idsForActorsInUse.map(_.toString).toArray - def getClassNamesForActorsInUse = self.classNamesForActorsInUse.map(_.toString).toArray + def getAddressesForActorsInUse = self.addressesForActorsInUse.map(_.toString).toArray def getUuidsForClusteredActors = self.uuidsForClusteredActors.map(_.toString).toArray - def getIdsForClusteredActors = self.idsForClusteredActors.map(_.toString).toArray - def getClassNamesForClusteredActors = self.classNamesForClusteredActors.map(_.toString).toArray + def getAddressesForClusteredActors = self.addressesForClusteredActors.map(_.toString).toArray def getNodesForActorInUseWithUuid(uuid: String) = self.nodesForActorsInUseWithUuid(stringToUuid(uuid)) - def getNodesForActorInUseWithId(id: String) = self.nodesForActorsInUseWithId(id) - def getNodesForActorInUseWithClassName(className: String) = self.nodesForActorsInUseWithClassName(className) + def getNodesForActorInUseWithAddress(id: String) = self.nodesForActorsInUseWithAddress(id) def getUuidsForActorsInUseOnNode(nodeName: String) = self.uuidsForActorsInUseOnNode(nodeName).map(_.toString).toArray - def getIdsForActorsInUseOnNode(nodeName: String) = self.idsForActorsInUseOnNode(nodeName).map(_.toString).toArray - def getClassNamesForActorsInUseOnNode(nodeName: String) = self.classNamesForActorsInUseOnNode(nodeName).map(_.toString).toArray + def getAddressesForActorsInUseOnNode(nodeName: String) = self.addressesForActorsInUseOnNode(nodeName).map(_.toString).toArray def setConfigElement(key: String, value: String) = self.setConfigElement(key, value.getBytes("UTF-8")) def getConfigElement(key: String) = new String(self.getConfigElement(key), "UTF-8") @@ -1640,7 +1503,7 @@ trait ErrorHandler { * @author Jonas Bonér */ object RemoteClusterDaemon { - val ADDRESS = "akka:cloud:cluster:daemon" + val ADDRESS = "akka-cluster-daemon" // FIXME configure functionServerDispatcher to what? val functionServerDispatcher = Dispatchers.newExecutorBasedEventDrivenDispatcher("akka:cloud:cluster:function:server").build @@ -1663,28 +1526,21 @@ class RemoteClusterDaemon(cluster: ClusterNode) extends Actor { case USE => if (message.hasActorUuid) { val uuid = uuidProtocolToUuid(message.getActorUuid) - val address = ActorAddress(uuid = uuid) + val address = cluster.actorAddressForUuid(uuid) implicit val format: Format[Actor] = cluster formatForActor address val actors = cluster use address } else if (message.hasActorAddress) { - val id = message.getActorAddress - val address = ActorAddress(address = id) - implicit val format: Format[Actor] = cluster formatForActor address - val actors = cluster use address - } else if (message.hasActorClassName) { - val actorClassName = message.getActorClassName - val address = ActorAddress(className = actorClassName) + val address = message.getActorAddress implicit val format: Format[Actor] = cluster formatForActor address val actors = cluster use address } else EventHandler.warning(this, - "None of 'uuid', 'actorAddress' or 'className' is specified, ignoring remote cluster daemon command [%s]".format(message)) + "None of 'uuid', or 'address' is specified, ignoring remote cluster daemon command [%s]".format(message)) case RELEASE => - if (message.hasActorUuid) { cluster release ActorAddress(uuid = uuidProtocolToUuid(message.getActorUuid)) } - else if (message.hasActorAddress) { cluster release ActorAddress(address = message.getActorAddress) } - else if (message.hasActorClassName) { cluster release ActorAddress(className = message.getActorClassName) } + if (message.hasActorUuid) { cluster release cluster.actorAddressForUuid(uuidProtocolToUuid(message.getActorUuid)) } + else if (message.hasActorAddress) { cluster release message.getActorAddress } else EventHandler.warning(this, - "None of 'uuid', 'actorAddress' or 'className' is specified, ignoring remote cluster daemon command [%s]".format(message)) + "None of 'uuid' or 'actorAddress'' is specified, ignoring remote cluster daemon command [%s]".format(message)) case START => cluster.start diff --git a/akka-cluster/src/main/scala/akka/cluster/ClusterActorRef.scala b/akka-cluster/src/main/scala/akka/cluster/ClusterActorRef.scala index 78a50925e4..fd4e91b513 100644 --- a/akka-cluster/src/main/scala/akka/cluster/ClusterActorRef.scala +++ b/akka-cluster/src/main/scala/akka/cluster/ClusterActorRef.scala @@ -20,18 +20,17 @@ import com.eaio.uuid.UUID */ class ClusterActorRef private[akka] ( actorAddresses: Array[Tuple2[UUID, InetSocketAddress]], - val serviceId: String, - actorClassName: String, + address: String, timeout: Long, actorType: ActorType, val replicationStrategy: ReplicationStrategy) - extends RemoteActorRef(serviceId, actorClassName, timeout, None, actorType) { + extends RemoteActorRef(address, timeout, None, actorType) { this: ClusterActorRef with Router.Router => - EventHandler.debug(this, "Creating a ClusterActorRef [%s] for Actor [%s]".format(serviceId, actorClassName)) + EventHandler.debug(this, "Creating a ClusterActorRef for actor with address [%s]".format(address)) private[akka] val addresses = new AtomicReference[Map[InetSocketAddress, ActorRef]]( - createConnections(actorAddresses, actorClassName)) + createConnections(actorAddresses)) def connections: Map[InetSocketAddress, ActorRef] = addresses.get.toMap @@ -56,9 +55,7 @@ class ClusterActorRef private[akka] ( ) } - private def createConnections( - addresses: Array[Tuple2[UUID, InetSocketAddress]], - actorClassName: String): Map[InetSocketAddress, ActorRef] = { + private def createConnections(addresses: Array[Tuple2[UUID, InetSocketAddress]]): Map[InetSocketAddress, ActorRef] = { var connections = Map.empty[InetSocketAddress, ActorRef] addresses foreach { case (uuid, address) => connections = connections + (address -> createRemoteActorRef(uuid, address)) @@ -68,7 +65,7 @@ class ClusterActorRef private[akka] ( private def createRemoteActorRef(uuid: UUID, address: InetSocketAddress) = { RemoteActorRef( - UUID_PREFIX + uuidToString(uuid), actorClassName, // clustered refs are always registered and looked up by UUID + UUID_PREFIX + uuidToString(uuid), // clustered refs are always registered and looked up by UUID Actor.TIMEOUT, None, actorType) } } diff --git a/akka-cluster/src/main/scala/akka/cluster/ClusterDeployer.scala b/akka-cluster/src/main/scala/akka/cluster/ClusterDeployer.scala new file mode 100644 index 0000000000..279c05bc3f --- /dev/null +++ b/akka-cluster/src/main/scala/akka/cluster/ClusterDeployer.scala @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2009-2011 Scalable Solutions AB + */ + +package akka.cluster + +import akka.actor.DeploymentConfig.Deploy +import akka.actor.DeploymentException +import akka.event.EventHandler +import akka.util.Switch +import akka.cluster.zookeeper.AkkaZkClient + +import org.apache.zookeeper.CreateMode + +import scala.collection.JavaConversions.collectionAsScalaIterable + +/** + * @author Jonas Bonér + */ +object ClusterDeployer { + val deploymentPath = "deployment" + val deploymentAddressPath = deploymentPath + "/%s" + + private val isConnected = new Switch(false) + + private lazy val zkClient = { + val zk = new AkkaZkClient( + Cluster.zooKeeperServers, + Cluster.sessionTimeout, + Cluster.connectionTimeout, + Cluster.defaultSerializer) + EventHandler.info(this, "ClusterDeployer started") + isConnected.switchOn + zk + } + + def shutdown() { + isConnected switchOff { + zkClient.close() + } + } + + def deploy(deployment: Deploy) { + try { + val path = deploymentAddressPath.format(deployment.address) + zkClient.create(path, null, CreateMode.PERSISTENT) + zkClient.writeData(path, deployment) + + // FIXME trigger some deploy action? + } catch { + case e => handleError(new DeploymentException("Could store deployment data [" + deployment + "] in ZooKeeper due to: " + e)) + } + } + + def undeploy(deployment: Deploy) { + try { + zkClient.delete(deploymentAddressPath.format(deployment.address)) + + // FIXME trigger some undeploy action? + } catch { + case e => handleError(new DeploymentException("Could undeploy deployment [" + deployment + "] in ZooKeeper due to: " + e)) + } + } + + def undeployAll() { + try { + for { + child <- collectionAsScalaIterable(zkClient.getChildren(deploymentPath)) + deployment <- lookupDeploymentFor(child) + } undeploy(deployment) + } catch { + case e => handleError(new DeploymentException("Could undeploy all deployment data in ZooKeeper due to: " + e)) + } + } + + def lookupDeploymentFor(address: String): Option[Deploy] = { + try { + Some(zkClient.readData(deploymentAddressPath.format(address)).asInstanceOf[Deploy]) + } catch { + case e: Exception => None + } + } + + private[akka] def handleError(e: Throwable): Nothing = { + EventHandler.error(e, this, e.toString) + throw e + } +} diff --git a/akka-cluster/src/main/scala/akka/cluster/Routing.scala b/akka-cluster/src/main/scala/akka/cluster/Routing.scala index a2e05e7062..d7777cf5f8 100644 --- a/akka-cluster/src/main/scala/akka/cluster/Routing.scala +++ b/akka-cluster/src/main/scala/akka/cluster/Routing.scala @@ -28,25 +28,22 @@ object Router { def newRouter( routerType: RouterType, addresses: Array[Tuple2[UUID, InetSocketAddress]], - serviceId: String, - actorClassName: String, - hostname: String, - port: Int, + address: String, timeout: Long, actorType: ActorType, replicationStrategy: ReplicationStrategy = ReplicationStrategy.WriteThrough): ClusterActorRef = { routerType match { case Direct => new ClusterActorRef( - addresses, serviceId, actorClassName, timeout, + addresses, address, timeout, actorType, replicationStrategy) with Direct case Random => new ClusterActorRef( - addresses, serviceId, actorClassName, timeout, + addresses, address, timeout, actorType, replicationStrategy) with Random case RoundRobin => new ClusterActorRef( - addresses, serviceId, actorClassName, timeout, + addresses, address, timeout, actorType, replicationStrategy) with RoundRobin } } diff --git a/akka-cluster/src/main/scala/akka/cluster/replication/ReplicatedClusterRef.scala b/akka-cluster/src/main/scala/akka/cluster/replication/ReplicatedClusterRef.scala index af395b8903..b28dea5a58 100644 --- a/akka-cluster/src/main/scala/akka/cluster/replication/ReplicatedClusterRef.scala +++ b/akka-cluster/src/main/scala/akka/cluster/replication/ReplicatedClusterRef.scala @@ -37,7 +37,7 @@ object ReplicationStrategy { class ReplicatedActorRef private[akka] (actorRef: ActorRef, val address: String) extends ActorRef with ScalaActorRef { private lazy val txLog = { - EventHandler.debug(this, "Creating a ReplicatedActorRef for Actor [%s]".format(actorClassName)) + EventHandler.debug(this, "Creating a ReplicatedActorRef for Actor [%s]".format(address)) TransactionLog.newLogFor(uuid.toString) } @@ -48,7 +48,7 @@ class ReplicatedActorRef private[akka] (actorRef: ActorRef, val address: String) def start(): ActorRef = { EventHandler.debug(this, "Starting ReplicatedActorRef for Actor [%s] with transaction log [%s]" - .format(actorClassName, txLog.logId)) + .format(address, txLog.logId)) actorRef.start } @@ -61,8 +61,6 @@ class ReplicatedActorRef private[akka] (actorRef: ActorRef, val address: String) override def getFaultHandler(): FaultHandlingStrategy = actorRef.getFaultHandler() override def setLifeCycle(lifeCycle: LifeCycle): Unit = actorRef.setLifeCycle(lifeCycle) override def getLifeCycle(): LifeCycle = actorRef.getLifeCycle - def actorClass: Class[_ <: Actor] = actorRef.actorClass - def actorClassName: String = actorRef.actorClassName def dispatcher_=(md: MessageDispatcher): Unit = actorRef.dispatcher_=(md) def dispatcher: MessageDispatcher = actorRef.dispatcher def link(actorRef: ActorRef): Unit = actorRef.link(actorRef) diff --git a/akka-cluster/src/main/scala/akka/cluster/replication/TransactionLog.scala b/akka-cluster/src/main/scala/akka/cluster/replication/TransactionLog.scala index a83abd461e..018b2c1726 100644 --- a/akka-cluster/src/main/scala/akka/cluster/replication/TransactionLog.scala +++ b/akka-cluster/src/main/scala/akka/cluster/replication/TransactionLog.scala @@ -270,15 +270,15 @@ class TransactionLog private ( */ object TransactionLog { - val digestType = config.getString("akka.cloud.cluster.replication.digest-type", "CRC32") match { + val digestType = config.getString("akka.cluster.replication.digest-type", "CRC32") match { case "CRC32" => BookKeeper.DigestType.CRC32 case "MAC" => BookKeeper.DigestType.MAC case unknown => throw new ConfigurationException( - "akka.cloud.cluster.replication.digest-type is invalid [" + unknown + "]") + "akka.cluster.replication.digest-type is invalid [" + unknown + "]") } - val password = config.getString("akka.cloud.cluster.replication.password", "secret").getBytes("UTF-8") - val ensembleSize = config.getInt("akka.cloud.cluster.replication.ensemble-size", 3) - val quorumSize = config.getInt("akka.cloud.cluster.replication.quorum-size", 2) + val password = config.getString("akka.cluster.replication.password", "secret").getBytes("UTF-8") + val ensembleSize = config.getInt("akka.cluster.replication.ensemble-size", 3) + val quorumSize = config.getInt("akka.cluster.replication.quorum-size", 2) val timeout = 5000 // FIXME make configurable private[akka] val transactionLogNode = "/transaction-log-ids" diff --git a/akka-cluster/src/test/scala/akka/cluster/ClusterMultiJvmSpec.scala b/akka-cluster/src/test/scala/akka/cluster/ClusterMultiJvmSpec.scala index 405d65d016..edf0b46ff7 100644 --- a/akka-cluster/src/test/scala/akka/cluster/ClusterMultiJvmSpec.scala +++ b/akka-cluster/src/test/scala/akka/cluster/ClusterMultiJvmSpec.scala @@ -8,7 +8,7 @@ import org.scalatest.WordSpec import org.scalatest.matchers.MustMatchers import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} -import akka.zookeeper._ +import akka.cluster.zookeeper._ import org.I0Itec.zkclient._ object MultiNodeTest { diff --git a/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala b/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala index 930444ea8a..8df23e9434 100644 --- a/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala +++ b/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala @@ -10,6 +10,7 @@ import akka.actor._ import akka.actor.Actor._ import akka.serialization.{Serializer, SerializerBasedActorFormat} import akka.util.Helpers._ +import akka.actor.DeploymentConfig._ import java.util.concurrent.{ CyclicBarrier, TimeUnit } @@ -42,6 +43,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var zkServer: ZkServer = _ "A ClusterNode" should { + /* "be able to start and stop - one node" in { val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "start-stop-1", port = 9001)) node.start() @@ -237,7 +239,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with "be able to cluster an actor by ActorRef" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "cluster-actor-1", port = 9001)) node.start @@ -247,29 +249,15 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true node.store(actorRef, serializeMailbox) - node.isClustered(ActorAddress(actorUuid = actorRef.uuid)) must be(true) + node.isClustered(actorRef.address) must be(true) node.uuidsForClusteredActors.exists(_ == actorRef.uuid) must be(true) node.stop } - "be able to cluster an actor by class" in { - // create actor - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "cluster-actor-1", port = 9001)) - node.start - - // register actor - import BinaryFormatMyJavaSerializableActor._ - node.store(classOf[MyJavaSerializableActor]) - - node.isClustered(ActorAddress(actorClassName = classOf[MyJavaSerializableActor].getName)) must be(true) - - node.stop - } - "be able to remove an actor by actor uuid" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-uuid", port = 9001)) node.start @@ -279,19 +267,18 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true node.store(actorRef, serializeMailbox) - node.isClustered(ActorAddress(actorUuid = actorRef.uuid)) must be(true) node.uuidsForClusteredActors.exists(_ == actorRef.uuid) must be(true) // deregister actor - node.remove(ActorAddress(actorUuid = actorRef.uuid)) + node.remove(actorRef.uuid) node.uuidsForClusteredActors.exists(_ == actorRef.uuid) must be(false) node.stop } - "be able to remove an actor by actor id" in { + "be able to remove an actor by actor address" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-id", port = 9001)) node.start @@ -301,71 +288,22 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true node.store(actorRef, serializeMailbox) - node.isClustered(ActorAddress(actorId = actorRef.id)) must be(true) - node.idsForClusteredActors.exists(_ == actorRef.id) must be(true) + node.isClustered(actorRef.address) must be(true) + node.addressesForClusteredActors.exists(_ == actorRef.address) must be(true) // deregister actor - node.remove(ActorAddress(actorId = actorRef.id)) - node.idsForClusteredActors.exists(_ == actorRef.id) must be(false) + node.remove(actorRef.address) + node.addressesForClusteredActors.exists(_ == actorRef.address) must be(false) node.stop } - "be able to remove an actor by actor class name" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-classname", port = 9001)) - node.start - - // register actor - import BinaryFormatMyJavaSerializableActor._ - var serializeMailbox = true - node.store(actorRef, serializeMailbox) - - node.isClustered(ActorAddress(actorClassName = actorRef.actorClassName)) must be(true) - node.classNamesForClusteredActors.exists(_ == actorRef.actorClassName) must be(true) - - // deregister actor - node.remove(ActorAddress(actorClassName = actorRef.actorClassName)) - node.classNamesForClusteredActors.exists(_ == actorRef.actorClassName) must be(false) - - node.stop - } - - "be able to use an actor by actor uuid" in { - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "use-actor-uuid", port = 9001)) - node.start - - // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start - (actorRef1 !! "hello").getOrElse("_") must equal("world 1") - (actorRef1 !! "hello").getOrElse("_") must equal("world 2") - - // register actor - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) - node.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) - - // check out actor - val actorRef2 = node.use(ActorAddress(actorUuid = actorRef1.uuid)).head - node.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "use-actor-uuid")) must be(true) - (actorRef2 !! "hello").getOrElse("_") must equal("world 3") - - actorRef1.stop - actorRef2.stop - - node.stop - } - - "be able to use an actor by actor id" in { + "be able to use an actor by actor address" in { val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "use-actor-id", port = 9001)) node.start // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start (actorRef1 !! "hello").getOrElse("_") must equal("world 1") (actorRef1 !! "hello").getOrElse("_") must equal("world 2") @@ -373,12 +311,12 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true import BinaryFormatMyJavaSerializableActor._ node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorId = actorRef1.id)) must be(true) - node.idsForClusteredActors.exists(_ == actorRef1.id) must be(true) + node.isClustered(actorRef1.address) must be(true) + node.addressesForClusteredActors.exists(_ == actorRef1.address) must be(true) // check out actor - val actorRef2 = node.use(ActorAddress(actorId = actorRef1.id)).head - node.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "use-actor-id")) must be(true) + val actorRef2 = node.use(actorRef1.address).head + node.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "use-actor-id")) must be(true) (actorRef2 !! "hello").getOrElse("_") must equal("world 3") actorRef1.stop @@ -387,70 +325,12 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node.stop } - "be able to use an actor by actor class name" in { - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "use-actor-classname", port = 9001)) - node.start - - // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start - (actorRef1 !! "hello").getOrElse("_") must equal("world 1") - (actorRef1 !! "hello").getOrElse("_") must equal("world 2") - - // register actor - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorClassName = actorRef1.actorClassName)) must be(true) - node.classNamesForClusteredActors.exists(_ == actorRef1.actorClassName) must be(true) - - // check out actor - val actorRef2 = node.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - node.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "use-actor-classname")) must be(true) - (actorRef2 !! "hello").getOrElse("_") must equal("world 3") - - actorRef1.stop - actorRef2.stop - - node.stop - } - - "be able to release an actor by uuid" in { - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "release-actor-uuid", port = 9001)) - node.start - - // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start - (actorRef1 !! "hello").getOrElse("_") must equal("world 1") - (actorRef1 !! "hello").getOrElse("_") must equal("world 2") - - // register actor - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) - node.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) - - // check out actor - val actorRef2 = node.use(ActorAddress(actorUuid = actorRef1.uuid)).head - node.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "release-actor-uuid")) must be(true) - (actorRef2 !! "hello").getOrElse("_") must equal("world 3") - - // check in actor - node.release(ActorAddress(actorUuid = actorRef2.uuid)) - node.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "release-actor-uuid")) must be(false) - - actorRef1.stop - actorRef2.stop - - node.stop - } - - "be able to release an actor by id" in { + "be able to release an actor by address" in { val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "release-actor-id", port = 9001)) node.start // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start (actorRef1 !! "hello").getOrElse("_") must equal("world 1") (actorRef1 !! "hello").getOrElse("_") must equal("world 2") @@ -458,17 +338,17 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true import BinaryFormatMyJavaSerializableActor._ node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorId = actorRef1.id)) must be(true) - node.idsForClusteredActors.exists(_ == actorRef1.id) must be(true) + node.isClustered(actorRef1.address) must be(true) + node.addressesForClusteredActors.exists(_ == actorRef1.address) must be(true) // check out actor - val actorRef2 = node.use(ActorAddress(actorId = actorRef1.id)).head - node.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "release-actor-id")) must be(true) + val actorRef2 = node.use(actorRef1.address).head + node.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "release-actor-id")) must be(true) (actorRef2 !! "hello").getOrElse("_") must equal("world 3") // check in actor - node.release(ActorAddress(actorId = actorRef2.id)) - node.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "release-actor-id")) must be(false) + node.release(actorRef2.address) + node.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "release-actor-id")) must be(false) actorRef1.stop actorRef2.stop @@ -476,65 +356,9 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node.stop } - "be able to release an actor by class name" in { - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "release-actor-classname", port = 9001)) - node.start - + "be able to release used actor on remove an actor by actor address" in { // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start - (actorRef1 !! "hello").getOrElse("_") must equal("world 1") - (actorRef1 !! "hello").getOrElse("_") must equal("world 2") - - // register actor - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorClassName = actorRef1.actorClassName)) must be(true) - node.classNamesForClusteredActors.exists(_ == actorRef1.actorClassName) must be(true) - - // check out actor - val actorRef2 = node.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - node.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "release-actor-classname")) must be(true) - (actorRef2 !! "hello").getOrElse("_") must equal("world 3") - - // check in actor - node.release(ActorAddress(actorClassName = actorRef2.actorClassName)) - node.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "release-actor-classname")) must be(false) - - actorRef1.stop - actorRef2.stop - - node.stop - } - - "be able to release used actor on remove an actor by actor uuid" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-uuid", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-uuid-2", port = 9002)).start - - // register actor - import BinaryFormatMyJavaSerializableActor._ - var serializeMailbox = true - node.store(actorRef, serializeMailbox) - val actorRef2 = node2.use(ActorAddress(actorUuid = actorRef.uuid)).head - - node2.isClustered(ActorAddress(actorUuid = actorRef.uuid)) must be(true) - node.uuidsForClusteredActors.exists(_ == actorRef.uuid) must be(true) - node.nodesForActorsInUseWithUuid(actorRef.uuid) must have length (1) - - // deregister actor - node.remove(ActorAddress(actorUuid = actorRef.uuid)) - node.uuidsForClusteredActors.exists(_ == actorRef.uuid) must be(false) - - node.nodesForActorsInUseWithUuid(actorRef.uuid) must have length (0) - node.stop - } - - "be able to release used actor on remove an actor by actor id" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-id", port = 9001)).start val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-uuid-2", port = 9002)).start @@ -543,43 +367,17 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with import BinaryFormatMyJavaSerializableActor._ var serializeMailbox = true node.store(actorRef, serializeMailbox) - val actorRef2 = node2.use(ActorAddress(actorId = actorRef.id)).head + val actorRef2 = node2.use(actorRef.address).head - node2.isClustered(ActorAddress(actorId = actorRef.id)) must be(true) - node.idsForClusteredActors.exists(_ == actorRef.id) must be(true) - node.nodesForActorsInUseWithId(actorRef.id) must have length (1) + node2.isClustered(actorRef.address) must be(true) + node.addressesForClusteredActors.exists(_ == actorRef.address) must be(true) + node.nodesForActorsInUseWithAddress(actorRef.address) must have length (1) // deregister actor - node.remove(ActorAddress(actorId = actorRef.id)) - node.idsForClusteredActors.exists(_ == actorRef.id) must be(false) - - node.nodesForActorsInUseWithId(actorRef.id) must have length (0) - node.stop - } - - "be able to release used actor on remove an actor by actor class name" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-classname", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "remove-actor-uuid-2", port = 9002)).start - node.start - - // register actor - import BinaryFormatMyJavaSerializableActor._ - var serializeMailbox = true - node.store(actorRef, serializeMailbox) - val actorRef2 = node2.use(ActorAddress(actorClassName = actorRef.actorClassName)).head - - node2.isClustered(ActorAddress(actorClassName = actorRef.actorClassName)) must be(true) - node.classNamesForClusteredActors.exists(_ == actorRef.actorClassName) must be(true) - node.nodesForActorsInUseWithClassName(actorRef.actorClassName) must have length (1) - - // deregister actor - node.remove(ActorAddress(actorClassName = actorRef.actorClassName)) - node.classNamesForClusteredActors.exists(_ == actorRef.actorClassName) must be(false) - node.nodesForActorsInUseWithClassName(actorRef.actorClassName) must have length (0) + node.remove(actorRef.address) + node.addressesForClusteredActors.exists(_ == actorRef.address) must be(false) + node.nodesForActorsInUseWithAddress(actorRef.address) must have length (0) node.stop } @@ -588,7 +386,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node.start // create actor - val actorRef1 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start (actorRef1 !! "hello").getOrElse("_") must equal("world 1") (actorRef1 !! "hello").getOrElse("_") must equal("world 2") @@ -596,15 +394,15 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with var serializeMailbox = true import BinaryFormatMyJavaSerializableActor._ node.store(actorRef1, serializeMailbox) - node.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) + node.isClustered(actorRef1.address) must be(true) node.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) // check out actor - val actorRef2 = node.use(ActorAddress(actorUuid = actorRef1.uuid)).head - node.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "get-home-address")) must be(true) + val actorRef2 = node.use(actorRef1.address).head + node.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "get-home-address")) must be(true) (actorRef2 !! "hello").getOrElse("_") must equal("world 3") - val addresses = node.addressesForActor(ActorAddress(actorUuid = actorRef1.uuid)) + val addresses = node.addressesForActor(actorRef1.address) addresses.length must be > (0) addresses(0)._2.getPort must equal(9001) @@ -614,89 +412,15 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node.stop } - "be able to migrate an actor between two nodes using uuid" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-uuid-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-uuid-2", port = 9002)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) - node1.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_2 = node1.use(ActorAddress(actorUuid = actorRef2.uuid)).head - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - - node1.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node1.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(true) - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(false) - - // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorUuid = actorRef1_2.uuid)) - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorUuid = actorRef2_2.uuid)) - - val actorRef1_3 = node2.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_3 = node2.use(ActorAddress(actorUuid = actorRef2.uuid)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node1.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node1.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-1")) must be(false) - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-uuid-2")) must be(true) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node1.stop - node2.stop - } - - "be able to migrate an actor between two nodes using id" in { + "be able to migrate an actor between two nodes using address" in { val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-id-1", port = 9001)) val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-id-2", port = 9002)) node1.start node2.start // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start + val actorRef2 = actorOf[MyJavaSerializableActor]("actor-address").start // register actors var serializeMailbox = true @@ -704,53 +428,53 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node1.store(actorRef1, serializeMailbox) node1.store(actorRef2, serializeMailbox) - node1.isClustered(ActorAddress(actorId = actorRef1.id)) must be(true) - node1.idsForClusteredActors.exists(_ == actorRef1.id) must be(true) + node1.isClustered(actorRef1.address) must be(true) + node1.addressesForClusteredActors.exists(_ == actorRef1.address) must be(true) // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_2 = node1.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_2 = node1.use(actorRef1.address).head + val actorRef2_2 = node1.use(actorRef2.address).head (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node1.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node1.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(false) // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorId = actorRef1_2.id)) + node1.migrate(node1.nodeAddress, node2.nodeAddress, actorRef1_2.address) - val actorRef1_3 = node2.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_3 = node2.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_3 = node2.use(actorRef1.address).head + val actorRef2_3 = node2.use(actorRef2.address).head (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - node1.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node1.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) + node1.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node1.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-1")) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-id-2")) must be(true) actorRef1.stop actorRef2.stop @@ -761,147 +485,15 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop } - "be able to migrate an actor between two nodes using actor class name" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-class-name-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-class-name-2", port = 9002)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorClassName = actorRef1.actorClassName)) must be(true) - node1.classNamesForClusteredActors.exists(_ == actorRef1.actorClassName) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_2 = node1.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(true) - - node1.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node1.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(true) - - node2.idsForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(false) - - // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorClassName = actorRef1_2.actorClassName)) - - val actorRef1_3 = node2.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_3 = node2.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node1.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node1.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(false) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-1")) must be(false) - - node2.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node2.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-class-name-2")) must be(true) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node1.stop - node2.stop - } - - "automatically migrate actors of a failed node in a cluster of two nodes using uuid" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-uuid-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-uuid-2", port = 9002)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) - node1.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_2 = node1.use(ActorAddress(actorUuid = actorRef2.uuid)).head - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node1.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-1")) must be(true) - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(false) - - // should migrate to node2 - node1.stop - node1.isRunning must be(false) - Thread.sleep(500) - - val actorRef1_3 = node2.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_3 = node2.use(ActorAddress(actorUuid = actorRef2.uuid)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-2-uuid-2")) must be(true) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node1.stop - } - - "automatically migrate actors of a failed node in a cluster of two nodes using id" in { + "automatically migrate actors of a failed node in a cluster of two nodes using address" in { val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-id-1", port = 9001)) val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-id-2", port = 9002)) node1.start node2.start // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start + val actorRef2 = actorOf[MyJavaSerializableActor]("actor-address").start // register actors var serializeMailbox = true @@ -909,46 +501,46 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node1.store(actorRef1, serializeMailbox) node1.store(actorRef2, serializeMailbox) - node1.isClustered(ActorAddress(actorClassName = actorRef1.id)) must be(true) - node1.idsForClusteredActors.exists(_ == actorRef1.id) must be(true) + node1.isClustered(actorRef1.address) must be(true) + node1.addressesForClusteredActors.exists(_ == actorRef1.address) must be(true) // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_2 = node1.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_2 = node1.use(actorRef1.address).head + val actorRef2_2 = node1.use(actorRef2.address).head (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - node1.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node1.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-1")) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(false) // should migrate to node2 node1.stop node1.isRunning must be(false) Thread.sleep(500) - val actorRef1_3 = node2.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_3 = node2.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_3 = node2.use(actorRef1.address).head + val actorRef2_3 = node2.use(actorRef2.address).head (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-2-id-2")) must be(true) actorRef1.stop actorRef2.stop @@ -958,153 +550,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop } - "automatically migrate actors of a failed node in a cluster of two nodes using class name" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-classname-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-2-classname-2", port = 9002)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorClassName = actorRef1.actorClassName)) must be(true) - node1.classNamesForClusteredActors.exists(_ == actorRef1.actorClassName) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_2 = node1.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node1.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-1")) must be(true) - - node2.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node2.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(false) - - // should migrate to node2 - node1.stop - node1.isRunning must be(false) - Thread.sleep(500) - - val actorRef1_3 = node2.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_3 = node2.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node2.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node2.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(true) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-2-classname-2")) must be(true) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node2.stop - } - - "automatically migrate actors of a failed node in a cluster of three nodes using uuid" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-uuid-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-uuid-2", port = 9002)) - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-uuid-3", port = 9003)) - node1.start - node2.start - node3.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorUuid = actorRef1.uuid)) must be(true) - node1.uuidsForClusteredActors.exists(_ == actorRef1.uuid) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_2 = node1.use(ActorAddress(actorUuid = actorRef2.uuid)).head - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node1.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-1")) must be(true) - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - - node3.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node3.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(false) - - // should migrate to node2 - node1.stop - node1.isRunning must be(false) - Thread.sleep(500) - - val actorRef1_3 = node3.use(ActorAddress(actorUuid = actorRef1.uuid)).head - val actorRef2_3 = node3.use(ActorAddress(actorUuid = actorRef2.uuid)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node3.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(true) - node3.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-3")) must be(true) - - node2.uuidsForActorsInUse.exists(_ == actorRef1.uuid) must be(false) - node2.uuidsForActorsInUse.exists(_ == actorRef2.uuid) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = NodeAddress("test-cluster", "migrate-3-uuid-2")) must be(false) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node2.stop - node3.stop - } - - "automatically migrate actors of a failed node in a cluster of three nodes using id" in { + "automatically migrate actors of a failed node in a cluster of three nodes using address" in { val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-id-1", port = 9001)) val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-id-2", port = 9002)) val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-id-3", port = 9003)) @@ -1113,8 +559,8 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node3.start // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start + val actorRef2 = actorOf[MyJavaSerializableActor]("actor-address").start // register actors var serializeMailbox = true @@ -1122,59 +568,59 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node1.store(actorRef1, serializeMailbox) node1.store(actorRef2, serializeMailbox) - node1.isClustered(ActorAddress(actorId = actorRef1.id)) must be(true) - node1.idsForClusteredActors.exists(_ == actorRef1.id) must be(true) + node1.isClustered(actorRef1.address) must be(true) + node1.addressesForClusteredActors.exists(_ == actorRef1.address) must be(true) // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_2 = node1.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_2 = node1.use(actorRef1.address).head + val actorRef2_2 = node1.use(actorRef2.address).head (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - node1.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node1.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node1.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) + node1.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) + node1.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-1")) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node3.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node3.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node3.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) + node3.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node3.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node3.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) + node3.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) + node3.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) + node3.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(false) // should migrate to node2 node1.stop node1.isRunning must be(false) Thread.sleep(500) - val actorRef1_3 = node3.use(ActorAddress(actorId = actorRef1.id)).head - val actorRef2_3 = node3.use(ActorAddress(actorId = actorRef2.id)).head + val actorRef1_3 = node3.use(actorRef1.address).head + val actorRef2_3 = node3.use(actorRef2.address).head (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - node3.idsForActorsInUse.exists(_ == actorRef1.id) must be(true) - node3.idsForActorsInUse.exists(_ == actorRef2.id) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) + node3.addressesForActorsInUse.exists(_ == actorRef1.address) must be(true) + node3.addressesForActorsInUse.exists(_ == actorRef2.address) must be(true) + node3.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) + node3.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) + node3.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) + node3.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-3")) must be(true) - node2.idsForActorsInUse.exists(_ == actorRef1.id) must be(false) - node2.idsForActorsInUse.exists(_ == actorRef2.id) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorId = actorRef2.id), node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef1.address) must be(false) + node2.addressesForActorsInUse.exists(_ == actorRef2.address) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef1.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) + node2.isInUseOnNode(actorRef2.address, node = NodeAddress("test-cluster", "migrate-3-id-2")) must be(false) actorRef1.stop actorRef2.stop @@ -1185,148 +631,17 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node3.stop } - "automatically migrate actors of a failed node in a cluster of three nodes using class name" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-classname-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-classname-2", port = 9002)) - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-3-classname-3", port = 9003)) - node1.start - node2.start - node3.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - // register actors - var serializeMailbox = true - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1, serializeMailbox) - node1.store(actorRef2, serializeMailbox) - - node1.isClustered(ActorAddress(actorClassName = actorRef1.actorClassName)) must be(true) - node1.classNamesForClusteredActors.exists(_ == actorRef1.actorClassName) must be(true) - - // check out actor - val actorRef1_2 = node1.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_2 = node1.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - node1.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node1.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-1")) must be(true) - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-1")) must be(true) - - node2.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node2.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - - node3.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node3.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(false) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(false) - - // should migrate to node2 - node1.stop - node1.isRunning must be(false) - Thread.sleep(500) - - val actorRef1_3 = node3.use(ActorAddress(actorClassName = actorRef1.actorClassName)).head - val actorRef2_3 = node3.use(ActorAddress(actorClassName = actorRef2.actorClassName)).head - (actorRef1_3 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_3 !! "hello").getOrElse("_") must equal("world 1") - - node3.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(true) - node3.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(true) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(true) - node3.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-3")) must be(true) - - node2.classNamesForActorsInUse.exists(_ == actorRef1.actorClassName) must be(false) - node2.classNamesForActorsInUse.exists(_ == actorRef2.actorClassName) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - node2.isInUseOnNode(ActorAddress(actorClassName = actorRef2.actorClassName), node = NodeAddress("test-cluster", "migrate-3-classname-2")) must be(false) - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node2.stop - node3.stop - } - - "be able to migrate an actor between two nodes using uuid and see that 'ref' to it is redirected and continue to work" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-uuid-and-see-ref-failover-1", port = 9001)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-uuid-and-see-ref-failover-2", port = 9002)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start - - Thread.sleep(500) - - // register actors - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1) - node1.store(actorRef2) - - Thread.sleep(500) - - // use on node1 - node1.use(ActorAddress(actorUuid = actorRef1.uuid)) - node1.use(ActorAddress(actorUuid = actorRef2.uuid)) - - Thread.sleep(500) - - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef1.uuid), node = node1.nodeAddress) must be(true) - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef2.uuid), node = node1.nodeAddress) must be(true) - - // check out actor ref on node2 - val actorRef1_2 = node2.ref(ActorAddress(actorUuid = actorRef1.uuid), router = Router.Direct) - val actorRef2_2 = node2.ref(ActorAddress(actorUuid = actorRef2.uuid), router = Router.Direct) - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 1") - - // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorUuid = actorRef1.uuid)) - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorUuid = actorRef2.uuid)) - - Thread.sleep(500) - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 2") - (actorRef2_2 !! "hello").getOrElse("_") must equal("world 2") - - actorRef1.stop - actorRef2.stop - actorRef1_2.stop - actorRef2_2.stop - - node1.stop - node2.stop - } - - "be able to migrate an actor between two nodes using id and see that 'ref' to it is redirected and continue to work" in { + "be able to migrate an actor between two nodes using address and see that 'ref' to it is redirected and continue to work" in { val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-id-and-see-ref-failover-1", port = 9001)) val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-id-and-see-ref-failover-2", port = 9002)) node1.start node2.start // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start + Deployer.deploy(Deploy( + "actor-address", Direct, + Clustered(Home("localhost", 2552), NoReplicas, Stateless))) + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start Thread.sleep(500) @@ -1337,17 +652,17 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with Thread.sleep(500) // use on node1 - node1.use(ActorAddress(actorId = actorRef1.id)) + node1.use(actorRef1.address) - node1.isInUseOnNode(ActorAddress(actorId = actorRef1.id), node = node1.nodeAddress) must be(true) + node1.isInUseOnNode(actorRef1.address, node = node1.nodeAddress) must be(true) // check out actor ref on node2 - val actorRef1_2 = node2.ref(ActorAddress(actorId = actorRef1.id), router = Router.Direct) + val actorRef1_2 = node2.ref(actorRef1.address, router = Router.Direct) (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorId = actorRef1.id)) + node1.migrate(node1.nodeAddress, node2.nodeAddress, actorRef1.address) Thread.sleep(500) @@ -1360,47 +675,6 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop } - "be able to migrate an actor between two nodes using class name and see that 'ref' to it is redirected and continue to work" in { - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-classname-and-see-ref-failover-1", port = 9011)) - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "migrate-classname-and-see-ref-failover-2", port = 9012)) - node1.start - node2.start - - // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - - Thread.sleep(500) - - // register actors - import BinaryFormatMyJavaSerializableActor._ - node1.store(actorRef1) - - Thread.sleep(500) - - // use on node1 - node1.use(ActorAddress(actorClassName = actorRef1.actorClassName)) - - node1.isInUseOnNode(ActorAddress(actorClassName = actorRef1.actorClassName), node = node1.nodeAddress) must be(true) - - Thread.sleep(500) - - // check out actor ref on node2 - val actorRef1_2 = node2.ref(ActorAddress(actorClassName = actorRef1.actorClassName), router = Router.Direct) - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 1") - - // migrate to node2 - node1.migrate(node1.nodeAddress, node2.nodeAddress, ActorAddress(actorClassName = actorRef1.actorClassName)) - - (actorRef1_2 !! "hello").getOrElse("_") must equal("world 2") - - actorRef1.stop - actorRef1_2.stop - - node1.stop - node2.stop - } - "be able to set and get config elements" in { val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "set-get-config-1", port = 9001)) val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "set-get-config-2", port = 9002)) @@ -1435,7 +709,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with "be able to replicate an actor" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "replicate-actor-1", port = 9001)).start val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "replicate-actor-2", port = 9002)).start @@ -1450,42 +724,20 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "replicate-actor-1", port = 9001)) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "replicate-actor-2", port = 9002)) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "replicate-actor-3", port = 9003)) must be(true) + node1.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "replicate-actor-1", port = 9001)) must be(true) + node2.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "replicate-actor-2", port = 9002)) must be(true) + node3.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "replicate-actor-3", port = 9003)) must be(true) node1.stop node2.stop node3.stop } - "be able to create a reference to a replicated actor by UUID using Router.Direct routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-uuid-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-uuid-2", port = 9002)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 1 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorUuid = actorRef.uuid), router = Router.Direct) - - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 2") - - node1.stop - node2.stop - } - - "be able to create a reference to a replicated actor by ID using Router.Direct routing" in { - val actorRef = actorOf[MyJavaSerializableActor].start + "be able to create a reference to a replicated actor by address using Router.Direct routing" in { + Deployer.deploy(Deploy( + "actor-address", Direct, + Clustered(Home("localhost", 2552), NoReplicas, Stateless))) + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-id-1", port = 9001)).start val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-id-2", port = 9002)).start @@ -1498,7 +750,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - val ref = node1.ref(ActorAddress(actorId = actorRef.id), router = Router.Direct) + val ref = node1.ref(actorRef.address, router = Router.Direct) (ref !! "hello").getOrElse("_") must equal("world 1") (ref !! "hello").getOrElse("_") must equal("world 2") @@ -1507,60 +759,12 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop } - "be able to create a reference to a replicated actor by ClassName using Router.Direct routing" in { + "be able to create a reference to a replicated actor by address using Router.Random routing" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-classname-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-direct-actor-by-classname-2", port = 9002)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 1 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorClassName = actorRef.actorClassName), router = Router.Direct) - - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 2") - - node1.stop - node2.stop - } - - "be able to create a reference to a replicated actor by UUID using Router.Random routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-uuid-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-uuid-2", port = 9002)).start - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-uuid-3", port = 9003)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 2 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorUuid = actorRef.uuid), router = Router.Random) - - (ref !! "hello").getOrElse("_") must equal("world 1") - - node1.stop - node2.stop - node3.stop - } - - "be able to create a reference to a replicated actor by ID using Router.Random routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + Deployer.deploy(Deploy( + "actor-address", Direct, + Clustered(Home("localhost", 2552), NoReplicas, Stateless))) + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-id-1", port = 9001)).start val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-id-2", port = 9002)).start @@ -1575,7 +779,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - val ref = node1.ref(ActorAddress(actorId = actorRef.id), router = Router.Random) + val ref = node1.ref(actorRef.address, router = Router.Random) (ref !! "hello").getOrElse("_") must equal("world 1") @@ -1583,79 +787,10 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop node3.stop } - - "be able to create a reference to a replicated actor by class name using Router.Random routing" in { +*/ + "be able to create a reference to a replicated actor by address using Router.RoundRobin routing" in { // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-classname-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-classname-2", port = 9002)).start - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-random-actor-by-classname-3", port = 9003)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 2 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorClassName = actorRef.actorClassName), router = Router.Random) - - (ref !! "hello").getOrElse("_") must equal("world 1") - - node1.stop - node2.stop - node3.stop - } - - "be able to create a reference to a replicated actor by UUID using Router.RoundRobin routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-2", port = 9002)).start - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-3", port = 9003)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 3 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorUuid = actorRef.uuid), router = Router.RoundRobin) - - node1.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-1", port = 9001)) must be(true) - node2.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-2", port = 9002)) must be(true) - node3.isInUseOnNode(ActorAddress(actorUuid = actorRef.uuid), node = NodeAddress("test-cluster", "router-round-robin-actor-by-uuid-3", port = 9003)) must be(true) - - val addresses = node1.addressesForActor(ActorAddress(actorUuid = actorRef.uuid)) - addresses.length must equal(3) - - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 1") - - (ref !! "hello").getOrElse("_") must equal("world 2") - (ref !! "hello").getOrElse("_") must equal("world 2") - (ref !! "hello").getOrElse("_") must equal("world 2") - - (ref !! "hello").getOrElse("_") must equal("world 3") - (ref !! "hello").getOrElse("_") must equal("world 3") - (ref !! "hello").getOrElse("_") must equal("world 3") - - node1.stop - node2.stop - node3.stop - } - - "be able to create a reference to a replicated actor by ID using Router.RoundRobin routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start + val actorRef = actorOf[MyJavaSerializableActor]("actor-address").start val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-id-1", port = 9001)).start val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-id-2", port = 9002)).start @@ -1670,13 +805,13 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - val ref = node1.ref(ActorAddress(actorId = actorRef.id), router = Router.RoundRobin) + val ref = node1.ref(actorRef.address, router = Router.RoundRobin) - node1.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-1", port = 9001)) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-2", port = 9002)) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-3", port = 9003)) must be(true) + node1.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-1", port = 9001)) must be(true) + node2.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-2", port = 9002)) must be(true) + node3.isInUseOnNode(actorRef.address, node = NodeAddress("test-cluster", "router-round-robin-actor-by-id-3", port = 9003)) must be(true) - val addresses = node1.addressesForActor(ActorAddress(actorId = actorRef.id)) + val addresses = node1.addressesForActor(actorRef.address) addresses.length must equal(3) (ref !! "hello").getOrElse("_") must equal("world 1") @@ -1695,57 +830,6 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.stop node3.stop } - - "be able to create a reference to a replicated actor by class name using Router.RoundRobin routing" in { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-1", port = 9001)).start - val node2 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-2", port = 9002)).start - val node3 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-3", port = 9003)).start - - Thread.sleep(500) - - // register actor - import BinaryFormatMyJavaSerializableActor._ - val replicationFactor = 3 - node1.store(actorRef, replicationFactor) - - Thread.sleep(500) // since deployment is async (daemon ! command), we have to wait some before checking - - val ref = node1.ref(ActorAddress(actorId = actorRef.id), router = Router.RoundRobin) - - node1.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-1", port = 9001)) must be(true) - node2.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-2", port = 9002)) must be(true) - node3.isInUseOnNode(ActorAddress(actorId = actorRef.id), node = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-3", port = 9003)) must be(true) - - val addresses = node1.addressesForActor(ActorAddress(actorId = actorRef.id)) - addresses.length must equal(3) - - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 1") - (ref !! "hello").getOrElse("_") must equal("world 1") - - (ref !! "hello").getOrElse("_") must equal("world 2") - (ref !! "hello").getOrElse("_") must equal("world 2") - (ref !! "hello").getOrElse("_") must equal("world 2") - - (ref !! "hello").getOrElse("_") must equal("world 3") - (ref !! "hello").getOrElse("_") must equal("world 3") - (ref !! "hello").getOrElse("_") must equal("world 3") - - node1.stop - node2.stop - node3.stop - } - - "last dummy test" in withPrintStackTraceOnError { - // create actor - val actorRef = actorOf[MyJavaSerializableActor].start - Thread.sleep(1000) - val node1 = Cluster.newNode(nodeAddress = NodeAddress("test-cluster", "router-round-robin-actor-by-classname-1", port = 9001)).start - node1.stop - } } override def beforeAll() = { @@ -1758,7 +842,7 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with override def afterAll() = { Cluster.shutdownLocalCluster - Actor.registry.shutdownAll + Actor.registry.local.shutdownAll } } @@ -1778,8 +862,8 @@ class ClusterSpec extends WordSpec with MustMatchers with BeforeAndAfterAll with node2.start // create actors - val actorRef1 = actorOf[MyJavaSerializableActor].start - val actorRef2 = actorOf[MyJavaSerializableActor].start + val actorRef1 = actorOf[MyJavaSerializableActor]("actor-address").start + val actorRef2 = actorOf[MyJavaSerializableActor]("actor-address").start // register actors var serializeMailbox = true diff --git a/akka-cluster/src/test/scala/akka/cluster/ClusteredPingPongSample.scala b/akka-cluster/src/test/scala/akka/cluster/ClusteredPingPongSample.scala index 77aff89707..a4b90e457f 100644 --- a/akka-cluster/src/test/scala/akka/cluster/ClusteredPingPongSample.scala +++ b/akka-cluster/src/test/scala/akka/cluster/ClusteredPingPongSample.scala @@ -13,6 +13,8 @@ import akka.serialization.{Serializer, SerializerBasedActorFormat} import java.util.concurrent.CountDownLatch object PingPong { + val PING_ADDRESS = "ping" + val PONG_ADDRESS = "pong" val NrOfPings = 5 @@ -79,8 +81,6 @@ object ClusteredPingPongSample { import BinaryFormats._ val CLUSTER_NAME = "test-cluster" - val PING_SERVICE = classOf[PingActor].getName - val PONG_SERVICE = classOf[PongActor].getName def main(args: Array[String]) = run @@ -102,11 +102,11 @@ object ClusteredPingPongSample { // ------------------------ // Store the PingActor in the cluster, but do not deploy it anywhere - localNode.store(classOf[PingActor]) + localNode.store(classOf[PingActor], PING_ADDRESS) // Store the PongActor in the cluster and deploy it // to 5 (replication factor) nodes in the cluster - localNode.store(classOf[PongActor], 5) + localNode.store(classOf[PongActor], PONG_ADDRESS, 5) Thread.sleep(1000) // let the deployment finish @@ -115,10 +115,10 @@ object ClusteredPingPongSample { // ------------------------ // Check out a local PingActor instance (not reference) - val ping = localNode.use[PingActor](ActorAddress(actorId = PING_SERVICE)).head + val ping = localNode.use[PingActor](PING_ADDRESS).head // Get a reference to all the pong actors through a round-robin router ActorRef - val pong = localNode.ref(ActorAddress(actorId = PONG_SERVICE), router = Router.RoundRobin) + val pong = localNode.ref(PONG_ADDRESS, router = Router.RoundRobin) // ------------------------ // Play the game diff --git a/akka-cluster/src/test/scala/akka/cluster/PingPongMultiJvmExample.scala b/akka-cluster/src/test/scala/akka/cluster/PingPongMultiJvmExample.scala index 3ea2fa221b..b93edb7bdf 100644 --- a/akka-cluster/src/test/scala/akka/cluster/PingPongMultiJvmExample.scala +++ b/akka-cluster/src/test/scala/akka/cluster/PingPongMultiJvmExample.scala @@ -11,6 +11,9 @@ import akka.serialization.{Serializer, SerializerBasedActorFormat} import akka.util.duration._ object PingPong { + val PING_ADDRESS = "ping" + val PONG_ADDRESS = "pong" + val ClusterName = "ping-pong-cluster" val NrOfNodes = 5 val Pause = true @@ -89,8 +92,8 @@ object PingPongMultiJvmNode1 { // Start monitoring // ----------------------------------------------- - MonitoringServer.start - Monitoring.startLocalDaemons + //MonitoringServer.start + //Monitoring.startLocalDaemons // ----------------------------------------------- // Start cluster @@ -128,10 +131,10 @@ object PingPongMultiJvmNode1 { println("Creating actors ...") // store the ping actor in the cluster, but do not deploy it anywhere - node.store(classOf[PingActor]) + node.store(classOf[PingActor], PING_ADDRESS) // store the pong actor in the cluster and replicate it on all nodes - node.store(classOf[PongActor], NrOfNodes) + node.store(classOf[PongActor], PONG_ADDRESS, NrOfNodes) // give some time for the deployment Thread.sleep(3000) @@ -141,10 +144,10 @@ object PingPongMultiJvmNode1 { // ----------------------------------------------- // check out a local ping actor - val ping = node.use[PingActor](ActorAddress(actorId = PingService)).head + val ping = node.use[PingActor](PING_ADDRESS).head // get a reference to all the pong actors through a round-robin router actor ref - val pong = node.ref(ActorAddress(actorId = PongService), router = Router.RoundRobin) + val pong = node.ref(PONG_ADDRESS, router = Router.RoundRobin) // ----------------------------------------------- // Play the game diff --git a/akka-remote/src/main/java/akka/remote/protocol/RemoteProtocol.java b/akka-remote/src/main/java/akka/remote/protocol/RemoteProtocol.java index 3bdbfa377b..817582f4ec 100644 --- a/akka-remote/src/main/java/akka/remote/protocol/RemoteProtocol.java +++ b/akka-remote/src/main/java/akka/remote/protocol/RemoteProtocol.java @@ -1848,15 +1848,8 @@ public final class RemoteProtocol { public boolean hasAddress() { return hasAddress; } public java.lang.String getAddress() { return address_; } - // required string actorClassname = 2; - public static final int ACTORCLASSNAME_FIELD_NUMBER = 2; - private boolean hasActorClassname; - private java.lang.String actorClassname_ = ""; - public boolean hasActorClassname() { return hasActorClassname; } - public java.lang.String getActorClassname() { return actorClassname_; } - - // optional uint64 timeout = 3; - public static final int TIMEOUT_FIELD_NUMBER = 3; + // optional uint64 timeout = 2; + public static final int TIMEOUT_FIELD_NUMBER = 2; private boolean hasTimeout; private long timeout_ = 0L; public boolean hasTimeout() { return hasTimeout; } @@ -1866,7 +1859,6 @@ public final class RemoteProtocol { } public final boolean isInitialized() { if (!hasAddress) return false; - if (!hasActorClassname) return false; return true; } @@ -1876,11 +1868,8 @@ public final class RemoteProtocol { if (hasAddress()) { output.writeString(1, getAddress()); } - if (hasActorClassname()) { - output.writeString(2, getActorClassname()); - } if (hasTimeout()) { - output.writeUInt64(3, getTimeout()); + output.writeUInt64(2, getTimeout()); } getUnknownFields().writeTo(output); } @@ -1895,13 +1884,9 @@ public final class RemoteProtocol { size += com.google.protobuf.CodedOutputStream .computeStringSize(1, getAddress()); } - if (hasActorClassname()) { - size += com.google.protobuf.CodedOutputStream - .computeStringSize(2, getActorClassname()); - } if (hasTimeout()) { size += com.google.protobuf.CodedOutputStream - .computeUInt64Size(3, getTimeout()); + .computeUInt64Size(2, getTimeout()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; @@ -2064,9 +2049,6 @@ public final class RemoteProtocol { if (other.hasAddress()) { setAddress(other.getAddress()); } - if (other.hasActorClassname()) { - setActorClassname(other.getActorClassname()); - } if (other.hasTimeout()) { setTimeout(other.getTimeout()); } @@ -2099,11 +2081,7 @@ public final class RemoteProtocol { setAddress(input.readString()); break; } - case 18: { - setActorClassname(input.readString()); - break; - } - case 24: { + case 16: { setTimeout(input.readUInt64()); break; } @@ -2133,28 +2111,7 @@ public final class RemoteProtocol { return this; } - // required string actorClassname = 2; - public boolean hasActorClassname() { - return result.hasActorClassname(); - } - public java.lang.String getActorClassname() { - return result.getActorClassname(); - } - public Builder setActorClassname(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - result.hasActorClassname = true; - result.actorClassname_ = value; - return this; - } - public Builder clearActorClassname() { - result.hasActorClassname = false; - result.actorClassname_ = getDefaultInstance().getActorClassname(); - return this; - } - - // optional uint64 timeout = 3; + // optional uint64 timeout = 2; public boolean hasTimeout() { return result.hasTimeout(); } @@ -4130,36 +4087,29 @@ public final class RemoteProtocol { public boolean hasUuid() { return hasUuid; } public akka.remote.protocol.RemoteProtocol.UuidProtocol getUuid() { return uuid_; } - // required string target = 2; - public static final int TARGET_FIELD_NUMBER = 2; - private boolean hasTarget; - private java.lang.String target_ = ""; - public boolean hasTarget() { return hasTarget; } - public java.lang.String getTarget() { return target_; } - - // required uint64 timeout = 3; - public static final int TIMEOUT_FIELD_NUMBER = 3; + // required uint64 timeout = 2; + public static final int TIMEOUT_FIELD_NUMBER = 2; private boolean hasTimeout; private long timeout_ = 0L; public boolean hasTimeout() { return hasTimeout; } public long getTimeout() { return timeout_; } - // required .ActorType actorType = 4; - public static final int ACTORTYPE_FIELD_NUMBER = 4; + // required .ActorType actorType = 3; + public static final int ACTORTYPE_FIELD_NUMBER = 3; private boolean hasActorType; private akka.remote.protocol.RemoteProtocol.ActorType actorType_; public boolean hasActorType() { return hasActorType; } public akka.remote.protocol.RemoteProtocol.ActorType getActorType() { return actorType_; } - // optional .TypedActorInfoProtocol typedActorInfo = 5; - public static final int TYPEDACTORINFO_FIELD_NUMBER = 5; + // optional .TypedActorInfoProtocol typedActorInfo = 4; + public static final int TYPEDACTORINFO_FIELD_NUMBER = 4; private boolean hasTypedActorInfo; private akka.remote.protocol.RemoteProtocol.TypedActorInfoProtocol typedActorInfo_; public boolean hasTypedActorInfo() { return hasTypedActorInfo; } public akka.remote.protocol.RemoteProtocol.TypedActorInfoProtocol getTypedActorInfo() { return typedActorInfo_; } - // optional string address = 6; - public static final int ADDRESS_FIELD_NUMBER = 6; + // optional string address = 5; + public static final int ADDRESS_FIELD_NUMBER = 5; private boolean hasAddress; private java.lang.String address_ = ""; public boolean hasAddress() { return hasAddress; } @@ -4172,7 +4122,6 @@ public final class RemoteProtocol { } public final boolean isInitialized() { if (!hasUuid) return false; - if (!hasTarget) return false; if (!hasTimeout) return false; if (!hasActorType) return false; if (!getUuid().isInitialized()) return false; @@ -4188,20 +4137,17 @@ public final class RemoteProtocol { if (hasUuid()) { output.writeMessage(1, getUuid()); } - if (hasTarget()) { - output.writeString(2, getTarget()); - } if (hasTimeout()) { - output.writeUInt64(3, getTimeout()); + output.writeUInt64(2, getTimeout()); } if (hasActorType()) { - output.writeEnum(4, getActorType().getNumber()); + output.writeEnum(3, getActorType().getNumber()); } if (hasTypedActorInfo()) { - output.writeMessage(5, getTypedActorInfo()); + output.writeMessage(4, getTypedActorInfo()); } if (hasAddress()) { - output.writeString(6, getAddress()); + output.writeString(5, getAddress()); } getUnknownFields().writeTo(output); } @@ -4216,25 +4162,21 @@ public final class RemoteProtocol { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getUuid()); } - if (hasTarget()) { - size += com.google.protobuf.CodedOutputStream - .computeStringSize(2, getTarget()); - } if (hasTimeout()) { size += com.google.protobuf.CodedOutputStream - .computeUInt64Size(3, getTimeout()); + .computeUInt64Size(2, getTimeout()); } if (hasActorType()) { size += com.google.protobuf.CodedOutputStream - .computeEnumSize(4, getActorType().getNumber()); + .computeEnumSize(3, getActorType().getNumber()); } if (hasTypedActorInfo()) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getTypedActorInfo()); + .computeMessageSize(4, getTypedActorInfo()); } if (hasAddress()) { size += com.google.protobuf.CodedOutputStream - .computeStringSize(6, getAddress()); + .computeStringSize(5, getAddress()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; @@ -4397,9 +4339,6 @@ public final class RemoteProtocol { if (other.hasUuid()) { mergeUuid(other.getUuid()); } - if (other.hasTarget()) { - setTarget(other.getTarget()); - } if (other.hasTimeout()) { setTimeout(other.getTimeout()); } @@ -4446,25 +4385,21 @@ public final class RemoteProtocol { setUuid(subBuilder.buildPartial()); break; } - case 18: { - setTarget(input.readString()); - break; - } - case 24: { + case 16: { setTimeout(input.readUInt64()); break; } - case 32: { + case 24: { int rawValue = input.readEnum(); akka.remote.protocol.RemoteProtocol.ActorType value = akka.remote.protocol.RemoteProtocol.ActorType.valueOf(rawValue); if (value == null) { - unknownFields.mergeVarintField(4, rawValue); + unknownFields.mergeVarintField(3, rawValue); } else { setActorType(value); } break; } - case 42: { + case 34: { akka.remote.protocol.RemoteProtocol.TypedActorInfoProtocol.Builder subBuilder = akka.remote.protocol.RemoteProtocol.TypedActorInfoProtocol.newBuilder(); if (hasTypedActorInfo()) { subBuilder.mergeFrom(getTypedActorInfo()); @@ -4473,7 +4408,7 @@ public final class RemoteProtocol { setTypedActorInfo(subBuilder.buildPartial()); break; } - case 50: { + case 42: { setAddress(input.readString()); break; } @@ -4519,28 +4454,7 @@ public final class RemoteProtocol { return this; } - // required string target = 2; - public boolean hasTarget() { - return result.hasTarget(); - } - public java.lang.String getTarget() { - return result.getTarget(); - } - public Builder setTarget(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - result.hasTarget = true; - result.target_ = value; - return this; - } - public Builder clearTarget() { - result.hasTarget = false; - result.target_ = getDefaultInstance().getTarget(); - return this; - } - - // required uint64 timeout = 3; + // required uint64 timeout = 2; public boolean hasTimeout() { return result.hasTimeout(); } @@ -4558,7 +4472,7 @@ public final class RemoteProtocol { return this; } - // required .ActorType actorType = 4; + // required .ActorType actorType = 3; public boolean hasActorType() { return result.hasActorType(); } @@ -4579,7 +4493,7 @@ public final class RemoteProtocol { return this; } - // optional .TypedActorInfoProtocol typedActorInfo = 5; + // optional .TypedActorInfoProtocol typedActorInfo = 4; public boolean hasTypedActorInfo() { return result.hasTypedActorInfo(); } @@ -4616,7 +4530,7 @@ public final class RemoteProtocol { return this; } - // optional string address = 6; + // optional string address = 5; public boolean hasAddress() { return result.hasAddress(); } @@ -6687,34 +6601,33 @@ public final class RemoteProtocol { "tadata\030\010 \003(\0132\026.MetadataEntryProtocol\022\016\n\006" + "cookie\030\t \001(\t\"J\n\025RemoteControlProtocol\022\016\n" + "\006cookie\030\001 \001(\t\022!\n\013commandType\030\002 \002(\0162\014.Com" + - "mandType\"R\n\026RemoteActorRefProtocol\022\017\n\007ad" + - "dress\030\001 \002(\t\022\026\n\016actorClassname\030\002 \002(\t\022\017\n\007t" + - "imeout\030\003 \001(\004\"_\n\033RemoteTypedActorRefProto" + - "col\022)\n\010actorRef\030\001 \002(\0132\027.RemoteActorRefPr" + - "otocol\022\025\n\rinterfaceName\030\002 \002(\t\"\323\002\n\032Serial" + - "izedActorRefProtocol\022\033\n\004uuid\030\001 \002(\0132\r.Uui" + - "dProtocol\022\017\n\007address\030\002 \002(\t\022\026\n\016actorClass", - "name\030\003 \002(\t\022\025\n\ractorInstance\030\004 \001(\014\022\033\n\023ser" + - "ializerClassname\030\005 \001(\t\022\017\n\007timeout\030\006 \001(\004\022" + - "\026\n\016receiveTimeout\030\007 \001(\004\022%\n\tlifeCycle\030\010 \001" + - "(\0132\022.LifeCycleProtocol\022+\n\nsupervisor\030\t \001" + - "(\0132\027.RemoteActorRefProtocol\022\024\n\014hotswapSt" + - "ack\030\n \001(\014\022(\n\010messages\030\013 \003(\0132\026.RemoteMess" + - "ageProtocol\"g\n\037SerializedTypedActorRefPr" + - "otocol\022-\n\010actorRef\030\001 \002(\0132\033.SerializedAct" + - "orRefProtocol\022\025\n\rinterfaceName\030\002 \002(\t\"r\n\017" + - "MessageProtocol\0225\n\023serializationScheme\030\001", - " \002(\0162\030.SerializationSchemeType\022\017\n\007messag" + - "e\030\002 \002(\014\022\027\n\017messageManifest\030\003 \001(\014\"\262\001\n\021Act" + - "orInfoProtocol\022\033\n\004uuid\030\001 \002(\0132\r.UuidProto" + - "col\022\016\n\006target\030\002 \002(\t\022\017\n\007timeout\030\003 \002(\004\022\035\n\t" + - "actorType\030\004 \002(\0162\n.ActorType\022/\n\016typedActo" + - "rInfo\030\005 \001(\0132\027.TypedActorInfoProtocol\022\017\n\007" + - "address\030\006 \001(\t\";\n\026TypedActorInfoProtocol\022" + + "mandType\":\n\026RemoteActorRefProtocol\022\017\n\007ad" + + "dress\030\001 \002(\t\022\017\n\007timeout\030\002 \001(\004\"_\n\033RemoteTy" + + "pedActorRefProtocol\022)\n\010actorRef\030\001 \002(\0132\027." + + "RemoteActorRefProtocol\022\025\n\rinterfaceName\030" + + "\002 \002(\t\"\323\002\n\032SerializedActorRefProtocol\022\033\n\004" + + "uuid\030\001 \002(\0132\r.UuidProtocol\022\017\n\007address\030\002 \002" + + "(\t\022\026\n\016actorClassname\030\003 \002(\t\022\025\n\ractorInsta", + "nce\030\004 \001(\014\022\033\n\023serializerClassname\030\005 \001(\t\022\017" + + "\n\007timeout\030\006 \001(\004\022\026\n\016receiveTimeout\030\007 \001(\004\022" + + "%\n\tlifeCycle\030\010 \001(\0132\022.LifeCycleProtocol\022+" + + "\n\nsupervisor\030\t \001(\0132\027.RemoteActorRefProto" + + "col\022\024\n\014hotswapStack\030\n \001(\014\022(\n\010messages\030\013 " + + "\003(\0132\026.RemoteMessageProtocol\"g\n\037Serialize" + + "dTypedActorRefProtocol\022-\n\010actorRef\030\001 \002(\013" + + "2\033.SerializedActorRefProtocol\022\025\n\rinterfa" + + "ceName\030\002 \002(\t\"r\n\017MessageProtocol\0225\n\023seria" + + "lizationScheme\030\001 \002(\0162\030.SerializationSche", + "meType\022\017\n\007message\030\002 \002(\014\022\027\n\017messageManife" + + "st\030\003 \001(\014\"\242\001\n\021ActorInfoProtocol\022\033\n\004uuid\030\001" + + " \002(\0132\r.UuidProtocol\022\017\n\007timeout\030\002 \002(\004\022\035\n\t" + + "actorType\030\003 \002(\0162\n.ActorType\022/\n\016typedActo" + + "rInfo\030\004 \001(\0132\027.TypedActorInfoProtocol\022\017\n\007" + + "address\030\005 \001(\t\";\n\026TypedActorInfoProtocol\022" + "\021\n\tinterface\030\001 \002(\t\022\016\n\006method\030\002 \002(\t\")\n\014Uu" + "idProtocol\022\014\n\004high\030\001 \002(\004\022\013\n\003low\030\002 \002(\004\"3\n" + - "\025MetadataEntryProtocol\022\013\n\003key\030\001 \002(\t\022\r\n\005v", - "alue\030\002 \002(\014\"6\n\021LifeCycleProtocol\022!\n\tlifeC" + + "\025MetadataEntryProtocol\022\013\n\003key\030\001 \002(\t\022\r\n\005v" + + "alue\030\002 \002(\014\"6\n\021LifeCycleProtocol\022!\n\tlifeC", "ycle\030\001 \002(\0162\016.LifeCycleType\"1\n\017AddressPro" + "tocol\022\020\n\010hostname\030\001 \002(\t\022\014\n\004port\030\002 \002(\r\"7\n" + "\021ExceptionProtocol\022\021\n\tclassname\030\001 \002(\t\022\017\n" + @@ -6723,7 +6636,7 @@ public final class RemoteProtocol { "A_ACTOR\020\002\022\017\n\013TYPED_ACTOR\020\003*]\n\027Serializat" + "ionSchemeType\022\010\n\004JAVA\020\001\022\013\n\007SBINARY\020\002\022\016\n\n" + "SCALA_JSON\020\003\022\r\n\tJAVA_JSON\020\004\022\014\n\010PROTOBUF\020" + - "\005*-\n\rLifeCycleType\022\r\n\tPERMANENT\020\001\022\r\n\tTEM", + "\005*-\n\rLifeCycleType\022\r\n\tPERMANENT\020\001\022\r\n\tTEM" + "PORARY\020\002B\030\n\024akka.remote.protocolH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = @@ -6760,7 +6673,7 @@ public final class RemoteProtocol { internal_static_RemoteActorRefProtocol_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_RemoteActorRefProtocol_descriptor, - new java.lang.String[] { "Address", "ActorClassname", "Timeout", }, + new java.lang.String[] { "Address", "Timeout", }, akka.remote.protocol.RemoteProtocol.RemoteActorRefProtocol.class, akka.remote.protocol.RemoteProtocol.RemoteActorRefProtocol.Builder.class); internal_static_RemoteTypedActorRefProtocol_descriptor = @@ -6800,7 +6713,7 @@ public final class RemoteProtocol { internal_static_ActorInfoProtocol_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_ActorInfoProtocol_descriptor, - new java.lang.String[] { "Uuid", "Target", "Timeout", "ActorType", "TypedActorInfo", "Address", }, + new java.lang.String[] { "Uuid", "Timeout", "ActorType", "TypedActorInfo", "Address", }, akka.remote.protocol.RemoteProtocol.ActorInfoProtocol.class, akka.remote.protocol.RemoteProtocol.ActorInfoProtocol.Builder.class); internal_static_TypedActorInfoProtocol_descriptor = diff --git a/akka-remote/src/main/protocol/RemoteProtocol.proto b/akka-remote/src/main/protocol/RemoteProtocol.proto index 85148b72cf..8680cb2305 100644 --- a/akka-remote/src/main/protocol/RemoteProtocol.proto +++ b/akka-remote/src/main/protocol/RemoteProtocol.proto @@ -52,8 +52,7 @@ enum CommandType { */ message RemoteActorRefProtocol { required string address = 1; - required string actorClassname = 2; - optional uint64 timeout = 3; + optional uint64 timeout = 2; } /** @@ -108,11 +107,10 @@ message MessageProtocol { */ message ActorInfoProtocol { required UuidProtocol uuid = 1; - required string target = 2; - required uint64 timeout = 3; - required ActorType actorType = 4; - optional TypedActorInfoProtocol typedActorInfo = 5; - optional string address = 6; + required uint64 timeout = 2; + required ActorType actorType = 3; + optional TypedActorInfoProtocol typedActorInfo = 4; + optional string address = 5; } /** diff --git a/akka-remote/src/main/scala/akka/remote/netty/NettyRemoteSupport.scala b/akka-remote/src/main/scala/akka/remote/netty/NettyRemoteSupport.scala index 2627747c91..84c66e5d79 100644 --- a/akka-remote/src/main/scala/akka/remote/netty/NettyRemoteSupport.scala +++ b/akka-remote/src/main/scala/akka/remote/netty/NettyRemoteSupport.scala @@ -62,8 +62,8 @@ trait NettyRemoteClientModule extends RemoteClientModule { self: ListenerManagem private val remoteActors = new Index[Address, Uuid] private val lock = new ReadWriteGuard - protected[akka] def typedActorFor[T](intfClass: Class[T], serviceId: String, implClassName: String, timeout: Long, hostname: String, port: Int, loader: Option[ClassLoader]): T = - TypedActor.createProxyForRemoteActorRef(intfClass, RemoteActorRef(serviceId, implClassName, timeout, loader, AkkaActorType.TypedActor)) + protected[akka] def typedActorFor[T](intfClass: Class[T], serviceId: String, timeout: Long, hostname: String, port: Int, loader: Option[ClassLoader]): T = + TypedActor.createProxyForRemoteActorRef(intfClass, RemoteActorRef(serviceId, timeout, loader, AkkaActorType.TypedActor)) protected[akka] def send[T](message: Any, senderOption: Option[ActorRef], @@ -200,7 +200,6 @@ abstract class RemoteClient private[akka] ( Some(actorRef), Left(actorRef.uuid), actorRef.address, - actorRef.actorClassName, actorRef.timeout, Right(message), isOneWay, @@ -536,16 +535,16 @@ class NettyRemoteSupport extends RemoteSupport with NettyRemoteServerModule with def optimizeLocalScoped_?() = optimizeLocal.get - protected[akka] def actorFor(serviceId: String, className: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): ActorRef = { + protected[akka] def actorFor(address: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): ActorRef = { if (optimizeLocalScoped_?) { val home = this.address if ((host == home.getAddress.getHostAddress || host == home.getHostName) && port == home.getPort) {//TODO: switch to InetSocketAddress.equals? - val localRef = findActorByAddressOrUuid(serviceId,serviceId) + val localRef = findActorByAddressOrUuid(address,address) if (localRef ne null) return localRef //Code significantly simpler with the return statement } } - RemoteActorRef(serviceId, className, timeout, loader) + RemoteActorRef(address, timeout, loader) } } @@ -934,7 +933,6 @@ class RemoteServerHandler( Some(actorRef), Right(request.getUuid), actorInfo.getAddress, - actorInfo.getTarget, actorInfo.getTimeout, r, true, @@ -1014,7 +1012,6 @@ class RemoteServerHandler( None, Right(request.getUuid), actorInfo.getAddress, - actorInfo.getTarget, actorInfo.getTimeout, result, true, @@ -1135,7 +1132,6 @@ class RemoteServerHandler( None, Right(request.getUuid), actorInfo.getAddress, - actorInfo.getTarget, actorInfo.getTimeout, Left(exception), true, diff --git a/akka-remote/src/main/scala/akka/serialization/SerializationProtocol.scala b/akka-remote/src/main/scala/akka/serialization/SerializationProtocol.scala index 50485beb41..adfd2f3bfd 100644 --- a/akka-remote/src/main/scala/akka/serialization/SerializationProtocol.scala +++ b/akka-remote/src/main/scala/akka/serialization/SerializationProtocol.scala @@ -67,7 +67,7 @@ trait StatelessActorFormat[T <: Actor] extends Format[T] with scala.Serializable trait SerializerBasedActorFormat[T <: Actor] extends Format[T] with scala.Serializable { val serializer: Serializer - def fromBinary(bytes: Array[Byte], act: T) = serializer.fromBinary(bytes, Some(act.self.actorClass)).asInstanceOf[T] + def fromBinary(bytes: Array[Byte], act: T) = serializer.fromBinary(bytes, Some(act.getClass)).asInstanceOf[T] def toBinary(ac: T) = serializer.toBinary(ac) } @@ -106,7 +106,7 @@ object ActorSerialization { val builder = SerializedActorRefProtocol.newBuilder .setUuid(UuidProtocol.newBuilder.setHigh(actorRef.uuid.getTime).setLow(actorRef.uuid.getClockSeqAndNode).build) .setAddress(actorRef.address) - .setActorClassname(actorRef.actorClass.getName) + .setActorClassname(actorRef.actorInstance.get.getClass.getName) .setTimeout(actorRef.timeout) if (serializeMailBox == true) { @@ -125,7 +125,6 @@ object ActorSerialization { Some(actorRef), Left(actorRef.uuid), actorRef.address, - actorRef.actorClassName, actorRef.timeout, Right(m.message), false, @@ -228,7 +227,6 @@ object RemoteActorSerialization { private[akka] def fromProtobufToRemoteActorRef(protocol: RemoteActorRefProtocol, loader: Option[ClassLoader]): ActorRef = { val ref = RemoteActorRef( protocol.getAddress, - protocol.getActorClassname, protocol.getTimeout, loader) ref @@ -244,7 +242,6 @@ object RemoteActorSerialization { RemoteActorRefProtocol.newBuilder .setAddress("uuid:" + uuid.toString) - .setActorClassname(actorClassName) .setTimeout(timeout) .build } @@ -253,7 +250,6 @@ object RemoteActorSerialization { actorRef: Option[ActorRef], replyUuid: Either[Uuid, UuidProtocol], actorAddress: String, - actorClassName: String, timeout: Long, message: Either[Throwable, Any], isOneWay: Boolean, @@ -270,7 +266,6 @@ object RemoteActorSerialization { val actorInfoBuilder = ActorInfoProtocol.newBuilder .setUuid(uuidProtocol) .setAddress(actorAddress) - .setTarget(actorClassName) .setTimeout(timeout) typedActorInfo.foreach { typedActor => diff --git a/akka-remote/src/test/scala/ticket/Ticket434Spec.scala b/akka-remote/src/test/scala/ticket/Ticket434Spec.scala index c03ae3cd3f..695f182c4f 100644 --- a/akka-remote/src/test/scala/ticket/Ticket434Spec.scala +++ b/akka-remote/src/test/scala/ticket/Ticket434Spec.scala @@ -30,7 +30,6 @@ class Ticket434Spec extends AkkaRemoteTest { val actorInfo = ActorInfoProtocol.newBuilder .setUuid(UuidProtocol.newBuilder.setHigh(uuid.getTime).setLow(uuid.getClockSeqAndNode).build) .setAddress("some-id") - .setTarget("actorClassName") .setTimeout(5000L) .setActorType(ActorType.SCALA_ACTOR).build