ActorID: now all test pass, mission accomplished, ready for master
This commit is contained in:
parent
7b1e43c89e
commit
4f66e90aa0
10 changed files with 42 additions and 35 deletions
|
|
@ -121,15 +121,15 @@ object Publish {
|
|||
def forConsumer(actor: ActorID): Option[Publish] =
|
||||
forConsumeAnnotated(actor) orElse forConsumerType(actor)
|
||||
|
||||
private def forConsumeAnnotated(actor: ActorID): Option[Publish] = {
|
||||
val annotation = actor.getClass.getAnnotation(classOf[consume])
|
||||
private def forConsumeAnnotated(actorId: ActorID): Option[Publish] = {
|
||||
val annotation = actorId.actorInstanceClass.getAnnotation(classOf[consume])
|
||||
if (annotation eq null) None
|
||||
else if (actor.remoteAddress.isDefined) None // do not publish proxies
|
||||
else Some(Publish(annotation.value, actor.getId, false))
|
||||
else if (actorId.remoteAddress.isDefined) None // do not publish proxies
|
||||
else Some(Publish(annotation.value, actorId.id, false))
|
||||
}
|
||||
|
||||
private def forConsumerType(actor: ActorID): Option[Publish] =
|
||||
if (!actor.isInstanceOf[Consumer]) None
|
||||
else if (actor.remoteAddress.isDefined) None
|
||||
else Some(Publish(actor.asInstanceOf[Consumer].endpointUri, actor.uuid, true))
|
||||
private def forConsumerType(actorId: ActorID): Option[Publish] =
|
||||
if (!actorId.actor.isInstanceOf[Consumer]) None
|
||||
else if (actorId.remoteAddress.isDefined) None
|
||||
else Some(Publish(actorId.actor.asInstanceOf[Consumer].endpointUri, actorId.uuid, true))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
mockEndpoint.reset
|
||||
ActorRegistry.shutdownAll
|
||||
}
|
||||
/*
|
||||
|
||||
feature("Produce a message to a Camel endpoint") {
|
||||
|
||||
scenario("produce message sync and receive response") {
|
||||
|
|
@ -121,7 +121,6 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
private def mockEndpoint = CamelContextManager.context.getEndpoint("mock:mock", classOf[MockEndpoint])
|
||||
|
||||
class TestRoute extends RouteBuilder {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
|
||||
var service: CamelService = CamelService.newInstance
|
||||
|
||||
/*
|
||||
override protected def beforeAll = {
|
||||
ActorRegistry.shutdownAll
|
||||
// register test consumer before starting the CamelService
|
||||
|
|
@ -89,5 +88,4 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
assert(response === "received msg3")
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ object PublishRequestorTest {
|
|||
def onMessage(msg: Publish) = received = msg
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
class PublishRequestorTest extends JUnitSuite {
|
||||
import PublishRequestorTest._
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class PublishRequestorTest extends JUnitSuite {
|
|||
val consumer = newActor(() => new Actor with Consumer {
|
||||
def endpointUri = "mock:test"
|
||||
protected def receive = null
|
||||
})
|
||||
}).start
|
||||
val publisher = newActor(() => new PublisherMock with Countdown[Publish])
|
||||
val requestor = newActor(() => new PublishRequestor(publisher))
|
||||
publisher.start
|
||||
|
|
@ -39,4 +39,3 @@ class PublishRequestorTest extends JUnitSuite {
|
|||
requestor.stop
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -24,7 +24,7 @@ object PublishTest {
|
|||
protected def receive = null
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
class PublishTest extends JUnitSuite {
|
||||
import PublishTest._
|
||||
|
||||
|
|
@ -34,14 +34,13 @@ class PublishTest extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test def shouldCreateSomePublishRequestWithActorId = {
|
||||
val publish = Publish.forConsumers(List(newActor[ConsumeAnnotatedActor]))
|
||||
val publish = Publish.forConsumer(newActor[ConsumeAnnotatedActor])
|
||||
assert(publish === Some(Publish("mock:test1", "test", false)))
|
||||
}
|
||||
|
||||
@Test def shouldCreateSomePublishRequestWithActorUuid = {
|
||||
val ca = newActor[ConsumerActor]
|
||||
val publish = Publish.forConsumers(List(ca))
|
||||
assert(publish === Some(Publish("mock:test2", ca.uuid, true)))
|
||||
val publish = Publish.forConsumer(ca)
|
||||
assert(publish === Some(Publish("mock:test2", ca.uuid, true)))
|
||||
}
|
||||
|
||||
|
|
@ -50,4 +49,3 @@ class PublishTest extends JUnitSuite {
|
|||
assert(publish === None)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -260,12 +260,13 @@ final class ActorID private[akka] () {
|
|||
this()
|
||||
newActorFactory = Left(Some(clazz))
|
||||
}
|
||||
|
||||
private[akka] def this(factory: () => Actor) = {
|
||||
this()
|
||||
newActorFactory = Right(Some(factory))
|
||||
}
|
||||
|
||||
lazy val actor: Actor = {
|
||||
private[akka] lazy val actor: Actor = {
|
||||
val actor = newActorFactory match {
|
||||
case Left(Some(clazz)) =>
|
||||
try {
|
||||
|
|
@ -284,6 +285,12 @@ final class ActorID private[akka] () {
|
|||
if (actor eq null) throw new ActorInitializationException("Actor instance passed to ActorID can not be 'null'")
|
||||
actor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class for the Actor instance that is managed by the ActorID.
|
||||
*/
|
||||
def actorInstanceClass: Class[_ <: Actor] = actor.getClass.asInstanceOf[Class[_ <: Actor]]
|
||||
|
||||
/**
|
||||
* Starts up the actor and its message queue.
|
||||
*/
|
||||
|
|
@ -296,12 +303,12 @@ final class ActorID private[akka] () {
|
|||
* Shuts down the actor its dispatcher and message queue.
|
||||
* Alias for 'stop'.
|
||||
*/
|
||||
protected def exit = actor.stop
|
||||
protected def exit: Unit = actor.stop
|
||||
|
||||
/**
|
||||
* Shuts down the actor its dispatcher and message queue.
|
||||
*/
|
||||
def stop = actor.stop
|
||||
def stop: Unit = actor.stop
|
||||
|
||||
/**
|
||||
* Is the actor running?
|
||||
|
|
@ -456,7 +463,7 @@ final class ActorID private[akka] () {
|
|||
/**
|
||||
* Returns the id for the actor.
|
||||
*/
|
||||
def getId = actor.getId
|
||||
def id = actor.getId
|
||||
|
||||
/**
|
||||
* Returns the uuid for the actor.
|
||||
|
|
@ -1026,7 +1033,7 @@ trait Actor extends TransactionManagement with Logging {
|
|||
val server = new RemoteServer
|
||||
server.start(host, port)
|
||||
}
|
||||
RemoteServer.actorsFor(RemoteServer.Address(host, port)).actors.put(sender.get.getId, sender.get)
|
||||
RemoteServer.actorsFor(RemoteServer.Address(host, port)).actors.put(sender.get.id, sender.get)
|
||||
}
|
||||
RemoteProtocolBuilder.setMessage(message, requestBuilder)
|
||||
RemoteClient.clientFor(_remoteAddress.get).send[Any](requestBuilder.build, None)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ object ActorRegistry extends Logging {
|
|||
actorsByUUID.put(actorId.uuid, actorId)
|
||||
|
||||
// ID
|
||||
val id = actorId.getId
|
||||
val id = actorId.id
|
||||
if (id eq null) throw new IllegalStateException("Actor.id is null " + actorId)
|
||||
if (actorsById.containsKey(id)) actorsById.put(id, actorId :: actorsById.get(id))
|
||||
else actorsById.put(id, actorId :: Nil)
|
||||
|
|
@ -117,7 +117,7 @@ object ActorRegistry extends Logging {
|
|||
*/
|
||||
def unregister(actor: ActorID) = {
|
||||
actorsByUUID remove actor.uuid
|
||||
actorsById remove actor.getId
|
||||
actorsById remove actor.id
|
||||
actorsByClassName remove actor.getClass.getName
|
||||
// notify listeners
|
||||
foreachListener(_ ! ActorUnregistered(actor))
|
||||
|
|
@ -139,6 +139,7 @@ object ActorRegistry extends Logging {
|
|||
* Adds the registration <code>listener</code> this this registry's listener list.
|
||||
*/
|
||||
def addRegistrationListener(listener: ActorID) = {
|
||||
listener.start
|
||||
registrationListeners.add(listener)
|
||||
}
|
||||
|
||||
|
|
@ -146,11 +147,16 @@ object ActorRegistry extends Logging {
|
|||
* Removes the registration <code>listener</code> this this registry's listener list.
|
||||
*/
|
||||
def removeRegistrationListener(listener: ActorID) = {
|
||||
listener.stop
|
||||
registrationListeners.remove(listener)
|
||||
}
|
||||
|
||||
private def foreachListener(f: (ActorID) => Unit) {
|
||||
val iterator = registrationListeners.iterator
|
||||
while (iterator.hasNext) f(iterator.next)
|
||||
while (iterator.hasNext) {
|
||||
val listener = iterator.next
|
||||
if (listener.isRunning) f(listener)
|
||||
else log.warning("Can't send ActorRegistryEvent to [%s] since it is not running.", listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ sealed class Supervisor private[akka] (handler: FaultHandlingStrategy, trapExcep
|
|||
startLink(actorId)
|
||||
remoteAddress.foreach(address => RemoteServer.actorsFor(
|
||||
RemoteServer.Address(address.hostname, address.port))
|
||||
.actors.put(actorId.getId, actorId))
|
||||
.actors.put(actorId.id, actorId))
|
||||
|
||||
case supervisorConfig @ SupervisorConfig(_, _) => // recursive supervisor configuration
|
||||
val supervisor = {
|
||||
|
|
|
|||
|
|
@ -200,8 +200,8 @@ class RemoteServer extends Logging {
|
|||
*/
|
||||
def register(actor: ActorID) = synchronized {
|
||||
if (_isRunning) {
|
||||
log.info("Registering server side remote actor [%s] with id [%s]", actor.getClass.getName, actor.getId)
|
||||
RemoteServer.actorsFor(RemoteServer.Address(hostname, port)).actors.put(actor.getId, actor)
|
||||
log.info("Registering server side remote actor [%s] with id [%s]", actor.getClass.getName, actor.id)
|
||||
RemoteServer.actorsFor(RemoteServer.Address(hostname, port)).actors.put(actor.id, actor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue