Full clustering circle now works, remote communication.

Added test for cluster communication.
Refactored deployment parsing.
Added InetSocketAddress to remote protocol.

Signed-off-by: Jonas Bonér <jonasremove@jonasboner.com>
This commit is contained in:
Jonas Bonér 2011-05-24 19:04:25 +02:00
parent 5fd10978d8
commit f75dcdbd15
18 changed files with 360 additions and 246 deletions

View file

@ -25,7 +25,8 @@ import akka.actor.{
LifeCycleMessage
}
import akka.actor.Actor._
import akka.config.Config._
import akka.config.Config
import Config._
import akka.util._
import akka.event.EventHandler
@ -206,7 +207,10 @@ abstract class RemoteClient private[akka] (
def send[T](
request: RemoteMessageProtocol,
senderFuture: Option[Promise[T]]): Option[Promise[T]] = {
if (isRunning) {
EventHandler.debug(this, "Sending remote message [%s]".format(request))
if (request.getOneWay) {
try {
val future = currentChannel.write(RemoteEncoder.encode(request))
@ -225,6 +229,7 @@ abstract class RemoteClient private[akka] (
} else throw e
}
None
} else {
val futureResult = if (senderFuture.isDefined) senderFuture.get
else new DefaultPromise[T](request.getActorInfo.getTimeout)
@ -254,6 +259,7 @@ abstract class RemoteClient private[akka] (
}
Some(futureResult)
}
} else {
val exception = new RemoteClientException("RemoteModule client is not running, make sure you have invoked 'RemoteClient.connect' before using it.", module, remoteAddress)
notifyListeners(RemoteClientError(exception, module, remoteAddress))
@ -544,16 +550,16 @@ class NettyRemoteSupport extends RemoteSupport with NettyRemoteServerModule with
def optimizeLocalScoped_?() = optimizeLocal.get
protected[akka] def actorFor(address: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): ActorRef = {
protected[akka] def actorFor(actorAddress: String, timeout: Long, host: String, port: Int, loader: Option[ClassLoader]): ActorRef = {
val inetSocketAddress = this.address
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(address, address)
if ((host == inetSocketAddress.getAddress.getHostAddress || host == inetSocketAddress.getHostName) && port == inetSocketAddress.getPort) { //TODO: switch to InetSocketAddress.equals?
val localRef = findActorByAddressOrUuid(actorAddress, actorAddress)
if (localRef ne null) return localRef //Code significantly simpler with the return statement
}
}
RemoteActorRef(address, timeout, loader)
RemoteActorRef(inetSocketAddress, actorAddress, timeout, loader)
}
}
@ -826,7 +832,7 @@ class RemoteServerHandler(
// stop all session actors
for (
map Option(sessionActors.remove(event.getChannel));
actor collectionAsScalaIterable(map.values)
actor collectionAsScalaIterable(map.values)gddd
) {
try { actor ! PoisonPill } catch { case e: Exception }
}
@ -839,11 +845,15 @@ class RemoteServerHandler(
server.notifyListeners(RemoteServerClientClosed(server, clientAddress))
}
override def messageReceived(ctx: ChannelHandlerContext, event: MessageEvent) = event.getMessage match {
case null throw new IllegalActorStateException("Message in remote MessageEvent is null: " + event)
case remote: AkkaRemoteProtocol if remote.hasMessage handleRemoteMessageProtocol(remote.getMessage, event.getChannel)
//case remote: AkkaRemoteProtocol if remote.hasInstruction => RemoteServer cannot receive control messages (yet)
case _ //ignore
override def messageReceived(ctx: ChannelHandlerContext, event: MessageEvent) = {
event.getMessage match {
case null
throw new IllegalActorStateException("Message in remote MessageEvent is null: " + event)
case remote: AkkaRemoteProtocol if remote.hasMessage
handleRemoteMessageProtocol(remote.getMessage, event.getChannel)
//case remote: AkkaRemoteProtocol if remote.hasInstruction => RemoteServer cannot receive control messages (yet)
case _ //ignore
}
}
override def exceptionCaught(ctx: ChannelHandlerContext, event: ExceptionEvent) = {
@ -857,12 +867,13 @@ class RemoteServerHandler(
case _ None
}
private def handleRemoteMessageProtocol(request: RemoteMessageProtocol, channel: Channel) =
private def handleRemoteMessageProtocol(request: RemoteMessageProtocol, channel: Channel) = {
EventHandler.debug(this, "Received remote message [%s]".format(request))
dispatchToActor(request, channel)
}
private def dispatchToActor(request: RemoteMessageProtocol, channel: Channel) {
val actorInfo = request.getActorInfo
val actorRef =
try { createActor(actorInfo, channel) } catch {
case e: SecurityException
@ -950,11 +961,16 @@ class RemoteServerHandler(
val uuid = actorInfo.getUuid
val address = actorInfo.getAddress
server.findActorByAddressOrUuid(address, parseUuid(uuid).toString) match {
EventHandler.debug(this, "Creating an remotely available actor for address [%s] on node [%s]".format(address, Config.nodename))
val actorRef = server.findActorByAddressOrUuid(address, parseUuid(uuid).toString) match {
// the actor has not been registered globally. See if we have it in the session
case null createSessionActor(actorInfo, channel)
case null createSessionActor(actorInfo, channel) // FIXME now session scoped actors are disabled, how to introduce them?
case actorRef actorRef
}
if (actorRef eq null) throw new IllegalActorStateException("Could not find a remote actor with address [" + address + "] or uuid [" + uuid + "]")
actorRef
}
private def createErrorReplyMessage(exception: Throwable, request: RemoteMessageProtocol): AkkaRemoteProtocol = {