From dfa637b090287edd4b8c54be112e9d98f0de8e29 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Sun, 19 Sep 2010 17:02:15 +0200 Subject: [PATCH] Its a wrap! --- akka-actor/src/main/scala/actor/Implicits.scala | 4 +++- akka-actor/src/main/scala/util/Logging.scala | 2 +- .../main/scala/component/ActorComponent.scala | 17 +++++++---------- .../scala/component/ActorComponentTest.scala | 11 +++++++---- .../src/main/scala/remote/RemoteServer.scala | 8 ++++---- .../serialization/SerializationProtocol.scala | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/akka-actor/src/main/scala/actor/Implicits.scala b/akka-actor/src/main/scala/actor/Implicits.scala index f228d45186..9992cd36a1 100644 --- a/akka-actor/src/main/scala/actor/Implicits.scala +++ b/akka-actor/src/main/scala/actor/Implicits.scala @@ -16,5 +16,7 @@ package object actor { type Uuid = com.eaio.uuid.UUID def newUuid(): Uuid = new Uuid() def uuidFrom(time: Long, clockSeqAndNode: Long): Uuid = new Uuid(time,clockSeqAndNode) - def uuidFrom(uuid: String) = new Uuid(uuid) + def uuidFrom(uuid: String): Uuid = { + new Uuid(uuid) + } } diff --git a/akka-actor/src/main/scala/util/Logging.scala b/akka-actor/src/main/scala/util/Logging.scala index b6ddaaa16a..8d2e64be58 100644 --- a/akka-actor/src/main/scala/util/Logging.scala +++ b/akka-actor/src/main/scala/util/Logging.scala @@ -111,7 +111,7 @@ class Logger(val logger: SLFLogger) { warning(message(fmt,arg,argN:_*)) } - def warn(fmt: => String, arg: Any, argN: Any*) = warning(fmt, arg, argN) + def warn(fmt: => String, arg: Any, argN: Any*) = warning(fmt, arg, argN:_*) def warning(msg: => String) { if (warning_?) logger warn msg diff --git a/akka-camel/src/main/scala/component/ActorComponent.scala b/akka-camel/src/main/scala/component/ActorComponent.scala index ccd4c63f0c..e0a70e255c 100644 --- a/akka-camel/src/main/scala/component/ActorComponent.scala +++ b/akka-camel/src/main/scala/component/ActorComponent.scala @@ -33,18 +33,15 @@ import scala.reflect.BeanProperty */ class ActorComponent extends DefaultComponent { def createEndpoint(uri: String, remaining: String, parameters: JavaMap[String, Object]): ActorEndpoint = { - val idAndUuid = idAndUuidPair(remaining) - new ActorEndpoint(uri, this, idAndUuid._1, idAndUuid._2) + val (id,uuid) = idAndUuidPair(remaining) + new ActorEndpoint(uri, this, id, uuid) } - private def idAndUuidPair(remaining: String): Tuple2[Option[String], Option[Uuid]] = { - remaining split ":" toList match { - case id :: Nil => (Some(id), None) - case "id" :: id :: Nil => (Some(id), None) - case "uuid" :: uuid :: Nil => (None, Some(uuidFrom(uuid))) - case _ => throw new IllegalArgumentException( - "invalid path format: %s - should be or id: or uuid:" format remaining) - } + private def idAndUuidPair(remaining: String): Tuple2[Option[String],Option[Uuid]] = remaining match { + case null | "" => throw new IllegalArgumentException("invalid path format: [%s] - should be or id: or uuid:" format remaining) + case id if id startsWith "id:" => (Some(id substring 3),None) + case uuid if uuid startsWith "uuid:" => (None,Some(uuidFrom(uuid substring 5))) + case id => (Some(id),None) } } diff --git a/akka-camel/src/test/scala/component/ActorComponentTest.scala b/akka-camel/src/test/scala/component/ActorComponentTest.scala index e27e8c5875..f35e8b3885 100644 --- a/akka-camel/src/test/scala/component/ActorComponentTest.scala +++ b/akka-camel/src/test/scala/component/ActorComponentTest.scala @@ -4,10 +4,13 @@ import org.apache.camel.{Endpoint, AsyncProcessor} import org.apache.camel.impl.DefaultCamelContext import org.junit._ import org.scalatest.junit.JUnitSuite +import se.scalablesolutions.akka.actor.uuidFrom class ActorComponentTest extends JUnitSuite { val component: ActorComponent = ActorComponentTest.actorComponent + def testUUID = uuidFrom("93da8c80-c3fd-11df-abed-60334b120057") + @Test def shouldCreateEndpointWithIdDefined = { val ep1: ActorEndpoint = component.createEndpoint("actor:abc").asInstanceOf[ActorEndpoint] val ep2: ActorEndpoint = component.createEndpoint("actor:id:abc").asInstanceOf[ActorEndpoint] @@ -20,15 +23,15 @@ class ActorComponentTest extends JUnitSuite { } @Test def shouldCreateEndpointWithUuidDefined = { - val ep: ActorEndpoint = component.createEndpoint("actor:uuid:abc").asInstanceOf[ActorEndpoint] - assert(ep.uuid === Some("abc")) + val ep: ActorEndpoint = component.createEndpoint("actor:uuid:" + testUUID).asInstanceOf[ActorEndpoint] + assert(ep.uuid === Some(testUUID)) assert(ep.id === None) assert(!ep.blocking) } @Test def shouldCreateEndpointWithBlockingSet = { - val ep: ActorEndpoint = component.createEndpoint("actor:uuid:abc?blocking=true").asInstanceOf[ActorEndpoint] - assert(ep.uuid === Some("abc")) + val ep: ActorEndpoint = component.createEndpoint("actor:uuid:"+testUUID+"?blocking=true").asInstanceOf[ActorEndpoint] + assert(ep.uuid === Some(testUUID)) assert(ep.id === None) assert(ep.blocking) } diff --git a/akka-remote/src/main/scala/remote/RemoteServer.scala b/akka-remote/src/main/scala/remote/RemoteServer.scala index a9841baf8c..bacaf22546 100644 --- a/akka-remote/src/main/scala/remote/RemoteServer.scala +++ b/akka-remote/src/main/scala/remote/RemoteServer.scala @@ -123,8 +123,8 @@ object RemoteServer { } private class RemoteActorSet { - private[RemoteServer] val actors = new ConcurrentHashMap[Object, ActorRef] - private[RemoteServer] val typedActors = new ConcurrentHashMap[Object, AnyRef] + private[RemoteServer] val actors = new ConcurrentHashMap[String, ActorRef] + private[RemoteServer] val typedActors = new ConcurrentHashMap[String, AnyRef] } private val guard = new ReadWriteGuard @@ -132,11 +132,11 @@ object RemoteServer { private val remoteServers = Map[Address, RemoteServer]() private[akka] def registerActor(address: InetSocketAddress, uuid: Uuid, actor: ActorRef) = guard.withWriteGuard { - actorsFor(RemoteServer.Address(address.getHostName, address.getPort)).actors.put(uuid, actor) + actorsFor(RemoteServer.Address(address.getHostName, address.getPort)).actors.put(uuid.toString, actor) } private[akka] def registerTypedActor(address: InetSocketAddress, uuid: Uuid, typedActor: AnyRef) = guard.withWriteGuard { - actorsFor(RemoteServer.Address(address.getHostName, address.getPort)).typedActors.put(uuid, typedActor) + actorsFor(RemoteServer.Address(address.getHostName, address.getPort)).typedActors.put(uuid.toString, typedActor) } private[akka] def getOrCreateServer(address: InetSocketAddress): RemoteServer = guard.withWriteGuard { diff --git a/akka-remote/src/main/scala/serialization/SerializationProtocol.scala b/akka-remote/src/main/scala/serialization/SerializationProtocol.scala index e94565ad97..7997be128b 100644 --- a/akka-remote/src/main/scala/serialization/SerializationProtocol.scala +++ b/akka-remote/src/main/scala/serialization/SerializationProtocol.scala @@ -231,7 +231,7 @@ object RemoteActorSerialization { } RemoteActorRefProtocol.newBuilder - .setClassOrServiceName(id) + .setClassOrServiceName(uuid.toString) .setActorClassname(actorClass.getName) .setHomeAddress(AddressProtocol.newBuilder.setHostname(host).setPort(port).build) .setTimeout(timeout)