From 4a6d4d65ea858fe8036df995f4412b02b5d4db1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bon=C3=A9r?= Date: Tue, 25 May 2010 16:11:18 +0200 Subject: [PATCH] Added option to specify class loader when deserializing RemoteActorRef --- akka-core/src/main/scala/actor/ActorRef.scala | 16 ++++--- .../src/main/scala/remote/RemoteClient.scala | 44 ++++++++++++++----- .../src/main/scala/remote/RemoteServer.scala | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/akka-core/src/main/scala/actor/ActorRef.scala b/akka-core/src/main/scala/actor/ActorRef.scala index c7473f46e3..8a432b64d9 100644 --- a/akka-core/src/main/scala/actor/ActorRef.scala +++ b/akka-core/src/main/scala/actor/ActorRef.scala @@ -51,18 +51,22 @@ object ActorRef { * Deserializes the ActorRef instance from a byte array (Array[Byte]) into an ActorRef instance. */ def fromBinary(bytes: Array[Byte]): ActorRef = - fromProtocol(ActorRefProtocol.newBuilder.mergeFrom(bytes).build) + fromProtocol(ActorRefProtocol.newBuilder.mergeFrom(bytes).build, None) + + def fromBinary(bytes: Array[Byte], loader: ClassLoader): ActorRef = + fromProtocol(ActorRefProtocol.newBuilder.mergeFrom(bytes).build, Some(loader)) /** * Deserializes the ActorRef instance from a Protocol Buffers (protobuf) Message into an ActorRef instance. */ - private[akka] def fromProtocol(protocol: ActorRefProtocol): ActorRef = + private[akka] def fromProtocol(protocol: ActorRefProtocol, loader: Option[ClassLoader]): ActorRef = RemoteActorRef( protocol.getUuid, protocol.getActorClassName, protocol.getSourceHostname, protocol.getSourcePort, - protocol.getTimeout) + protocol.getTimeout, + loader) } /** @@ -1217,13 +1221,13 @@ sealed class LocalActorRef private[akka]( */ private[akka] case class RemoteActorRef private[akka] ( // uuid: String, className: String, hostname: String, port: Int, timeOut: Long, isOnRemoteHost: Boolean) extends ActorRef { - uuuid: String, val className: String, val hostname: String, val port: Int, _timeout: Long) + uuuid: String, val className: String, val hostname: String, val port: Int, _timeout: Long, loader: Option[ClassLoader]) extends ActorRef { _uuid = uuuid timeout = _timeout - + start - lazy val remoteClient = RemoteClient.clientFor(hostname, port) + lazy val remoteClient = RemoteClient.clientFor(hostname, port, loader) def postMessageToMailbox(message: Any, senderOption: Option[ActorRef]): Unit = { val requestBuilder = RemoteRequestProtocol.newBuilder diff --git a/akka-core/src/main/scala/remote/RemoteClient.scala b/akka-core/src/main/scala/remote/RemoteClient.scala index 3af87fb7b5..50169922c3 100644 --- a/akka-core/src/main/scala/remote/RemoteClient.scala +++ b/akka-core/src/main/scala/remote/RemoteClient.scala @@ -56,26 +56,48 @@ object RemoteClient extends Logging { // FIXME: simplify overloaded methods when we have Scala 2.8 def actorFor(className: String, hostname: String, port: Int): ActorRef = - actorFor(className, className, 5000L, hostname, port) + actorFor(className, className, 5000L, hostname, port, None) - def actorFor(actorRef: String, className: String, hostname: String, port: Int): ActorRef = - actorFor(actorRef, className, 5000L, hostname, port) + def actorFor(className: String, hostname: String, port: Int, loader: ClassLoader): ActorRef = + actorFor(className, className, 5000L, hostname, port, Some(loader)) + + def actorFor(uuid: String, className: String, hostname: String, port: Int): ActorRef = + actorFor(uuid, className, 5000L, hostname, port, None) + + def actorFor(uuid: String, className: String, hostname: String, port: Int, loader: ClassLoader): ActorRef = + actorFor(uuid, className, 5000L, hostname, port, Some(loader)) def actorFor(className: String, timeout: Long, hostname: String, port: Int): ActorRef = - actorFor(className, className, timeout, hostname, port) + actorFor(className, className, timeout, hostname, port, None) - def actorFor(actorRef: String, className: String, timeout: Long, hostname: String, port: Int): ActorRef = - RemoteActorRef(actorRef, className, hostname, port, timeout) + def actorFor(className: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): ActorRef = + actorFor(className, className, timeout, hostname, port, Some(loader)) - def clientFor(hostname: String, port: Int): RemoteClient = clientFor(new InetSocketAddress(hostname, port), None) + def actorFor(uuid: String, className: String, timeout: Long, hostname: String, port: Int): ActorRef = + RemoteActorRef(uuid, className, hostname, port, timeout, None) - def clientFor(hostname: String, port: Int, loader: ClassLoader): RemoteClient = clientFor(new InetSocketAddress(hostname, port), Some(loader)) + private[akka] def actorFor(uuid: String, className: String, timeout: Long, hostname: String, port: Int, loader: ClassLoader): ActorRef = + RemoteActorRef(uuid, className, hostname, port, timeout, Some(loader)) - def clientFor(address: InetSocketAddress): RemoteClient = clientFor(address, None) + private[akka] def actorFor(uuid: String, className: String, timeout: Long, hostname: String, port: Int, loader: Option[ClassLoader]): ActorRef = + RemoteActorRef(uuid, className, hostname, port, timeout, loader) - def clientFor(address: InetSocketAddress, loader: ClassLoader): RemoteClient = clientFor(address, Some(loader)) + def clientFor(hostname: String, port: Int): RemoteClient = + clientFor(new InetSocketAddress(hostname, port), None) - private def clientFor(address: InetSocketAddress, loader: Option[ClassLoader]): RemoteClient = synchronized { + def clientFor(hostname: String, port: Int, loader: ClassLoader): RemoteClient = + clientFor(new InetSocketAddress(hostname, port), Some(loader)) + + def clientFor(address: InetSocketAddress): RemoteClient = + clientFor(address, None) + + def clientFor(address: InetSocketAddress, loader: ClassLoader): RemoteClient = + clientFor(address, Some(loader)) + + private[akka] def clientFor(hostname: String, port: Int, loader: Option[ClassLoader]): RemoteClient = + clientFor(new InetSocketAddress(hostname, port), loader) + + private[akka] def clientFor(address: InetSocketAddress, loader: Option[ClassLoader]): RemoteClient = synchronized { val hostname = address.getHostName val port = address.getPort val hash = hostname + ':' + port diff --git a/akka-core/src/main/scala/remote/RemoteServer.scala b/akka-core/src/main/scala/remote/RemoteServer.scala index a0b4810be3..782775e2a3 100644 --- a/akka-core/src/main/scala/remote/RemoteServer.scala +++ b/akka-core/src/main/scala/remote/RemoteServer.scala @@ -366,7 +366,7 @@ class RemoteServerHandler( val message = RemoteProtocolBuilder.getMessage(request) if (request.hasSender) { val sender = request.getSender - if (sender ne null) actorRef.!(message)(Some(ActorRef.fromProtocol(sender))) + if (sender ne null) actorRef.!(message)(Some(ActorRef.fromProtocol(sender, applicationLoader))) } else { try { val resultOrNone = actorRef !! message