Merged with master and fixed last issues
This commit is contained in:
commit
9aaad8c03c
66 changed files with 647 additions and 536 deletions
|
|
@ -95,7 +95,7 @@ object AMQP {
|
|||
returnListener: Option[ReturnListener],
|
||||
shutdownListener: Option[ShutdownListener],
|
||||
initReconnectDelay: Long): ActorRef = {
|
||||
val producer = newActor(() => new Producer(
|
||||
val producer = actorOf( new Producer(
|
||||
new ConnectionFactory(config),
|
||||
hostname, port,
|
||||
exchangeName,
|
||||
|
|
@ -118,7 +118,7 @@ object AMQP {
|
|||
durable: Boolean,
|
||||
autoDelete: Boolean,
|
||||
configurationArguments: Map[String, AnyRef]): ActorRef = {
|
||||
val consumer = newActor(() => new Consumer(
|
||||
val consumer = actorOf( new Consumer(
|
||||
new ConnectionFactory(config),
|
||||
hostname, port,
|
||||
exchangeName,
|
||||
|
|
|
|||
|
|
@ -23,9 +23,21 @@ case class Message(val body: Any, val headers: Map[String, Any] = Map.empty) {
|
|||
*
|
||||
* @see CamelContextManager.
|
||||
*/
|
||||
@deprecated("use bodyAs[T](implicit m: Manifest[T]): T instead")
|
||||
def bodyAs[T](clazz: Class[T]): T =
|
||||
CamelContextManager.context.getTypeConverter.mandatoryConvertTo[T](clazz, body)
|
||||
|
||||
/**
|
||||
* Returns the body of the message converted to the type <code>T</code>. Conversion is done
|
||||
* using Camel's type converter. The type converter is obtained from the CamelContext managed
|
||||
* by CamelContextManager. Applications have to ensure proper initialization of
|
||||
* CamelContextManager.
|
||||
*
|
||||
* @see CamelContextManager.
|
||||
*/
|
||||
def bodyAs[T](implicit m: Manifest[T]): T =
|
||||
CamelContextManager.context.getTypeConverter.mandatoryConvertTo[T](m.erasure.asInstanceOf[Class[T]], body)
|
||||
|
||||
/**
|
||||
* Returns those headers from this message whose name is contained in <code>names</code>.
|
||||
*/
|
||||
|
|
@ -41,8 +53,16 @@ case class Message(val body: Any, val headers: Map[String, Any] = Map.empty) {
|
|||
*
|
||||
* @see Message#bodyAs(Class)
|
||||
*/
|
||||
@deprecated("use setBodyAs[T](implicit m: Manifest[T]): Message instead")
|
||||
def setBodyAs[T](clazz: Class[T]): Message = setBody(bodyAs(clazz))
|
||||
|
||||
/**
|
||||
* Creates a Message with a new <code>body</code> converted to type <code>T</code>.
|
||||
*
|
||||
* @see Message#bodyAs(Class)
|
||||
*/
|
||||
def setBodyAs[T](implicit m: Manifest[T]): Message = setBody(bodyAs[T])
|
||||
|
||||
/**
|
||||
* Creates a Message with a new <code>body</code>.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ trait CamelService extends Bootable with Logging {
|
|||
|
||||
import CamelContextManager._
|
||||
|
||||
private[camel] val consumerPublisher = newActor[ConsumerPublisher]
|
||||
private[camel] val publishRequestor = newActor(() => new PublishRequestor(consumerPublisher))
|
||||
private[camel] val consumerPublisher = actorOf[ConsumerPublisher]
|
||||
private[camel] val publishRequestor = actorOf(new PublishRequestor(consumerPublisher))
|
||||
|
||||
/**
|
||||
* Starts the CamelService. Any started actor that is a consumer actor will be (asynchronously)
|
||||
|
|
@ -45,7 +45,7 @@ trait CamelService extends Bootable with Logging {
|
|||
ActorRegistry.addRegistrationListener(publishRequestor.start)
|
||||
|
||||
// publish already registered consumer actors
|
||||
for (publish <- Publish.forConsumers(ActorRegistry.actors)) consumerPublisher ! publish
|
||||
for (actor <- ActorRegistry.actors; event <- ConsumerRegistered.forConsumer(actor)) consumerPublisher ! event
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,36 +16,66 @@ import se.scalablesolutions.akka.util.Logging
|
|||
/**
|
||||
* Actor that publishes consumer actors as Camel endpoints at the CamelContext managed
|
||||
* by se.scalablesolutions.akka.camel.CamelContextManager. It accepts messages of type
|
||||
* se.scalablesolutions.akka.camel.service.Publish.
|
||||
* se.scalablesolutions.akka.camel.service.ConsumerRegistered and
|
||||
* se.scalablesolutions.akka.camel.service.ConsumerUnregistered.
|
||||
*
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
class ConsumerPublisher extends Actor with Logging {
|
||||
@volatile private var latch = new CountDownLatch(0)
|
||||
@volatile private var publishLatch = new CountDownLatch(0)
|
||||
@volatile private var unpublishLatch = new CountDownLatch(0)
|
||||
|
||||
/**
|
||||
* Adds a route to the actor identified by a Publish message to the global CamelContext.
|
||||
*/
|
||||
protected def receive = {
|
||||
case p: Publish => publish(new ConsumerRoute(p.endpointUri, p.id, p.uuid))
|
||||
case r: ConsumerRegistered => {
|
||||
handleConsumerRegistered(r)
|
||||
publishLatch.countDown // needed for testing only.
|
||||
}
|
||||
case u: ConsumerUnregistered => {
|
||||
handleConsumerUnregistered(u)
|
||||
unpublishLatch.countDown // needed for testing only.
|
||||
}
|
||||
case _ => { /* ignore */}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of expected Publish messages received by this actor. Used for testing
|
||||
* only.
|
||||
* Sets the expected number of actors to be published. Used for testing only.
|
||||
*/
|
||||
private[camel] def expectPublishCount(count: Int): Unit = latch = new CountDownLatch(count)
|
||||
private[camel] def expectPublishCount(count: Int): Unit =
|
||||
publishLatch = new CountDownLatch(count)
|
||||
|
||||
/**
|
||||
* Waits for the number of expected Publish messages to arrive. Used for testing only.
|
||||
* Sets the expected number of actors to be unpublished. Used for testing only.
|
||||
*/
|
||||
private[camel] def awaitPublish = latch.await
|
||||
private[camel] def expectUnpublishCount(count: Int): Unit =
|
||||
unpublishLatch = new CountDownLatch(count)
|
||||
|
||||
private def publish(route: ConsumerRoute) {
|
||||
CamelContextManager.context.addRoutes(route)
|
||||
log.info("published actor via endpoint %s" format route.endpointUri)
|
||||
latch.countDown // needed for testing only.
|
||||
/**
|
||||
* Waits for the expected number of actors to be published. Used for testing only.
|
||||
*/
|
||||
private[camel] def awaitPublish = publishLatch.await
|
||||
|
||||
/**
|
||||
* Waits for the expected number of actors to be unpublished. Used for testing only.
|
||||
*/
|
||||
private[camel] def awaitUnpublish = unpublishLatch.await
|
||||
|
||||
/**
|
||||
* Creates a route to the registered consumer actor.
|
||||
*/
|
||||
private def handleConsumerRegistered(event: ConsumerRegistered) {
|
||||
CamelContextManager.context.addRoutes(new ConsumerRoute(event.uri, event.id, event.uuid))
|
||||
log.info("published actor %s (%s) at endpoint %s" format (event.clazz, event.id, event.uri))
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops route to the already un-registered consumer actor.
|
||||
*/
|
||||
private def handleConsumerUnregistered(event: ConsumerUnregistered) {
|
||||
CamelContextManager.context.stopRoute(event.id)
|
||||
log.info("unpublished actor %s (%s) from endpoint %s" format (event.clazz, event.id, event.uri))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +98,8 @@ class ConsumerRoute(val endpointUri: String, id: String, uuid: Boolean) extends
|
|||
def configure = {
|
||||
val schema = endpointUri take endpointUri.indexOf(":") // e.g. "http" from "http://whatever/..."
|
||||
bodyConversions.get(schema) match {
|
||||
case Some(clazz) => from(endpointUri).convertBodyTo(clazz).to(actorUri)
|
||||
case None => from(endpointUri).to(actorUri)
|
||||
case Some(clazz) => from(endpointUri).routeId(id).convertBodyTo(clazz).to(actorUri)
|
||||
case None => from(endpointUri).routeId(id).to(actorUri)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,59 +107,104 @@ class ConsumerRoute(val endpointUri: String, id: String, uuid: Boolean) extends
|
|||
}
|
||||
|
||||
/**
|
||||
* A registration listener that publishes consumer actors (and ignores other actors).
|
||||
* A registration listener that triggers publication and un-publication of consumer actors.
|
||||
*
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
class PublishRequestor(consumerPublisher: ActorRef) extends Actor {
|
||||
protected def receive = {
|
||||
case ActorUnregistered(actor) => { /* ignore */ }
|
||||
case ActorRegistered(actor) => Publish.forConsumer(actor) match {
|
||||
case Some(publish) => consumerPublisher ! publish
|
||||
case None => { /* ignore */ }
|
||||
}
|
||||
case ActorRegistered(actor) => for (event <- ConsumerRegistered.forConsumer(actor)) consumerPublisher ! event
|
||||
case ActorUnregistered(actor) => for (event <- ConsumerUnregistered.forConsumer(actor)) consumerPublisher ! event
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request message for publishing a consumer actor.
|
||||
* Consumer actor lifecycle event.
|
||||
*
|
||||
* @param endpointUri endpoint URI of the consumer actor
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
sealed trait ConsumerEvent
|
||||
|
||||
/**
|
||||
* Event indicating that a consumer actor has been registered at the actor registry.
|
||||
*
|
||||
* @param clazz clazz name of the referenced actor
|
||||
* @param uri endpoint URI of the consumer actor
|
||||
* @param id actor identifier
|
||||
* @param uuid <code>true</code> if <code>id</code> refers to Actor.uuid, <code>false</code> if
|
||||
* <code>id</code> refers to Acotr.getId.
|
||||
* @param uuid <code>true</code> if <code>id</code> is the actor's uuid, <code>false</code> if
|
||||
* <code>id</code> is the actor's id.
|
||||
*
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
case class Publish(endpointUri: String, id: String, uuid: Boolean)
|
||||
case class ConsumerRegistered(clazz: String, uri: String, id: String, uuid: Boolean) extends ConsumerEvent
|
||||
|
||||
/**
|
||||
* Event indicating that a consumer actor has been unregistered from the actor registry.
|
||||
*
|
||||
* @param clazz clazz name of the referenced actor
|
||||
* @param uri endpoint URI of the consumer actor
|
||||
* @param id actor identifier
|
||||
* @param uuid <code>true</code> if <code>id</code> is the actor's uuid, <code>false</code> if
|
||||
* <code>id</code> is the actor's id.
|
||||
*
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
case class ConsumerUnregistered(clazz: String, uri: String, id: String, uuid: Boolean) extends ConsumerEvent
|
||||
|
||||
/**
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
object Publish {
|
||||
private[camel] object ConsumerRegistered {
|
||||
/**
|
||||
* Optionally creates an ConsumerRegistered event message for a consumer actor or None if
|
||||
* <code>actorRef</code> is not a consumer actor.
|
||||
*/
|
||||
def forConsumer(actorRef: ActorRef): Option[ConsumerRegistered] = actorRef match {
|
||||
case ConsumerDescriptor(clazz, uri, id, uuid) => Some(ConsumerRegistered(clazz, uri, id, uuid))
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of Publish request messages for all consumer actors in the <code>actors</code>
|
||||
* list.
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
def forConsumers(actors: List[ActorRef]): List[Publish] =
|
||||
for (actor <- actors; pub = forConsumer(actor); if pub.isDefined) yield pub.get
|
||||
private[camel] object ConsumerUnregistered {
|
||||
/**
|
||||
* Optionally creates an ConsumerUnregistered event message for a consumer actor or None if
|
||||
* <code>actorRef</code> is not a consumer actor.
|
||||
*/
|
||||
def forConsumer(actorRef: ActorRef): Option[ConsumerUnregistered] = actorRef match {
|
||||
case ConsumerDescriptor(clazz, uri, id, uuid) => Some(ConsumerUnregistered(clazz, uri, id, uuid))
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Publish request message if <code>actor</code> is a consumer actor.
|
||||
* Describes a consumer actor with elements that are relevant for publishing an actor at a
|
||||
* Camel endpoint (or unpublishing an actor from an endpoint).
|
||||
*
|
||||
* @author Martin Krasser
|
||||
*/
|
||||
def forConsumer(actor: ActorRef): Option[Publish] =
|
||||
forConsumeAnnotated(actor) orElse forConsumerType(actor)
|
||||
private[camel] object ConsumerDescriptor {
|
||||
|
||||
private def forConsumeAnnotated(actorRef: ActorRef): Option[Publish] = {
|
||||
/**
|
||||
* An extractor that optionally creates a 4-tuple from a consumer actor reference containing
|
||||
* the target actor's class name, endpoint URI, identifier and a hint whether the identifier
|
||||
* is the actor uuid or actor id. If <code>actorRef</code> doesn't reference a consumer actor,
|
||||
* None is returned.
|
||||
*/
|
||||
def unapply(actorRef: ActorRef): Option[(String, String, String, Boolean)] =
|
||||
unapplyConsumerInstance(actorRef) orElse unapplyConsumeAnnotated(actorRef)
|
||||
|
||||
private def unapplyConsumeAnnotated(actorRef: ActorRef): Option[(String, String, String, Boolean)] = {
|
||||
val annotation = actorRef.actorClass.getAnnotation(classOf[consume])
|
||||
if (annotation eq null) None
|
||||
else if (actorRef.remoteAddress.isDefined) None // do not publish proxies
|
||||
else Some(Publish(annotation.value, actorRef.id, false))
|
||||
else if (actorRef.remoteAddress.isDefined) None
|
||||
else Some((actorRef.actor.getClass.getName, annotation.value, actorRef.id, false))
|
||||
}
|
||||
|
||||
private def forConsumerType(actorRef: ActorRef): Option[Publish] =
|
||||
private def unapplyConsumerInstance(actorRef: ActorRef): Option[(String, String, String, Boolean)] =
|
||||
if (!actorRef.actor.isInstanceOf[Consumer]) None
|
||||
else if (actorRef.remoteAddress.isDefined) None
|
||||
else Some(Publish(actorRef.actor.asInstanceOf[Consumer].endpointUri, actorRef.uuid, true))
|
||||
else Some((actorRef.actor.getClass.getName, actorRef.actor.asInstanceOf[Consumer].endpointUri, actorRef.uuid, true))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ class MessageTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
override protected def beforeAll = CamelContextManager.init
|
||||
|
||||
@Test def shouldConvertDoubleBodyToString = {
|
||||
assertEquals("1.4", Message(1.4, null).bodyAs(classOf[String]))
|
||||
assertEquals("1.4", Message(1.4, null).bodyAs[String])
|
||||
}
|
||||
|
||||
@Test def shouldThrowExceptionWhenConvertingDoubleBodyToInputStream {
|
||||
intercept[NoTypeConversionAvailableException] {
|
||||
Message(1.4, null).bodyAs(classOf[InputStream])
|
||||
Message(1.4, null).bodyAs[InputStream]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ class MessageTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
@Test def shouldConvertBodyAndPreserveHeaders = {
|
||||
assertEquals(
|
||||
Message("1.4", Map("A" -> "1")),
|
||||
Message(1.4 , Map("A" -> "1")).setBodyAs(classOf[String]))
|
||||
Message(1.4 , Map("A" -> "1")).setBodyAs[String])
|
||||
}
|
||||
|
||||
@Test def shouldSetBodyAndPreserveHeaders = {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message sync and receive response") {
|
||||
given("a registered synchronous two-way producer for endpoint direct:producer-test-2")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-2") with Sync)
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-2") with Sync)
|
||||
producer.start
|
||||
|
||||
when("a test message is sent to the producer")
|
||||
|
|
@ -50,7 +50,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message async and receive response") {
|
||||
given("a registered asynchronous two-way producer for endpoint direct:producer-test-2")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-2"))
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-2"))
|
||||
producer.start
|
||||
|
||||
when("a test message is sent to the producer")
|
||||
|
|
@ -64,7 +64,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message sync and receive failure") {
|
||||
given("a registered synchronous two-way producer for endpoint direct:producer-test-2")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-2") with Sync)
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-2") with Sync)
|
||||
producer.start
|
||||
|
||||
when("a fail message is sent to the producer")
|
||||
|
|
@ -80,7 +80,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message async and receive failure") {
|
||||
given("a registered asynchronous two-way producer for endpoint direct:producer-test-2")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-2"))
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-2"))
|
||||
producer.start
|
||||
|
||||
when("a fail message is sent to the producer")
|
||||
|
|
@ -96,7 +96,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message sync oneway") {
|
||||
given("a registered synchronous one-way producer for endpoint direct:producer-test-1")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-1") with Sync with Oneway)
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-1") with Sync with Oneway)
|
||||
producer.start
|
||||
|
||||
when("a test message is sent to the producer")
|
||||
|
|
@ -109,7 +109,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
scenario("produce message async oneway") {
|
||||
given("a registered asynchronous one-way producer for endpoint direct:producer-test-1")
|
||||
val producer = newActor(() => new TestProducer("direct:producer-test-1") with Oneway)
|
||||
val producer = actorOf(new TestProducer("direct:producer-test-1") with Oneway)
|
||||
producer.start
|
||||
|
||||
when("a test message is sent to the producer")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
|
|||
import Actor._
|
||||
|
||||
scenario("one-way communication using actor id") {
|
||||
val actor = newActor(() => new Tester with Retain with Countdown[Message])
|
||||
val actor = actorOf(new Tester with Retain with Countdown[Message])
|
||||
actor.start
|
||||
template.sendBody("actor:%s" format actor.id, "Martin")
|
||||
assert(actor.actor.asInstanceOf[Countdown[Message]].waitFor)
|
||||
|
|
@ -31,7 +31,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
|
|||
}
|
||||
|
||||
scenario("one-way communication using actor uuid") {
|
||||
val actor = newActor(() => new Tester with Retain with Countdown[Message])
|
||||
val actor = actorOf(new Tester with Retain with Countdown[Message])
|
||||
actor.start
|
||||
template.sendBody("actor:uuid:%s" format actor.uuid, "Martin")
|
||||
assert(actor.actor.asInstanceOf[Countdown[Message]].waitFor)
|
||||
|
|
@ -39,19 +39,19 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
|
|||
}
|
||||
|
||||
scenario("two-way communication using actor id") {
|
||||
val actor = newActor(() => new Tester with Respond)
|
||||
val actor = actorOf(new Tester with Respond)
|
||||
actor.start
|
||||
assert(template.requestBody("actor:%s" format actor.id, "Martin") === "Hello Martin")
|
||||
}
|
||||
|
||||
scenario("two-way communication using actor uuid") {
|
||||
val actor = newActor(() => new Tester with Respond)
|
||||
val actor = actorOf(new Tester with Respond)
|
||||
actor.start
|
||||
assert(template.requestBody("actor:uuid:%s" format actor.uuid, "Martin") === "Hello Martin")
|
||||
}
|
||||
|
||||
scenario("two-way communication with timeout") {
|
||||
val actor = newActor(() => new Tester {
|
||||
val actor = actorOf(new Tester {
|
||||
self.timeout = 1
|
||||
})
|
||||
actor.start
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
@After def tearDown = ActorRegistry.shutdownAll
|
||||
|
||||
@Test def shouldSendMessageToActor = {
|
||||
val actor = newActor(() => new Tester with Retain with Countdown[Message])
|
||||
val actor = actorOf(new Tester with Retain with Countdown[Message])
|
||||
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
|
||||
val exchange = endpoint.createExchange(ExchangePattern.InOnly)
|
||||
actor.start
|
||||
|
|
@ -31,7 +31,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
@Test def shouldSendMessageToActorAndReceiveResponse = {
|
||||
val actor = newActor(() => new Tester with Respond {
|
||||
val actor = actorOf(new Tester with Respond {
|
||||
override def response(msg: Message) = Message(super.response(msg), Map("k2" -> "v2"))
|
||||
})
|
||||
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
|
||||
|
|
@ -45,7 +45,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
@Test def shouldSendMessageToActorAndReceiveFailure = {
|
||||
val actor = newActor(() => new Tester with Respond {
|
||||
val actor = actorOf(new Tester with Respond {
|
||||
override def response(msg: Message) = Failure(new Exception("testmsg"), Map("k3" -> "v3"))
|
||||
})
|
||||
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
|
||||
|
|
@ -60,7 +60,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
@Test def shouldSendMessageToActorAndTimeout: Unit = {
|
||||
val actor = newActor(() => new Tester {
|
||||
val actor = actorOf(new Tester {
|
||||
self.timeout = 1
|
||||
})
|
||||
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
override protected def beforeAll = {
|
||||
ActorRegistry.shutdownAll
|
||||
// register test consumer before starting the CamelService
|
||||
newActor(() => new TestConsumer("direct:publish-test-1")).start
|
||||
actorOf(new TestConsumer("direct:publish-test-1")).start
|
||||
// Consigure a custom camel route
|
||||
CamelContextManager.init
|
||||
CamelContextManager.context.addRoutes(new TestRoute)
|
||||
|
|
@ -61,10 +61,10 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
|
||||
given("two consumer actors registered before and after CamelService startup")
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].expectPublishCount(1)
|
||||
newActor(() => new TestConsumer("direct:publish-test-2")).start
|
||||
actorOf(new TestConsumer("direct:publish-test-2")).start
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].awaitPublish
|
||||
|
||||
when("requests are sent to these actors")
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].awaitPublish
|
||||
val response1 = CamelContextManager.template.requestBody("direct:publish-test-1", "msg1")
|
||||
val response2 = CamelContextManager.template.requestBody("direct:publish-test-2", "msg2")
|
||||
|
||||
|
|
@ -74,12 +74,38 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
}
|
||||
}
|
||||
|
||||
feature("Unpublish registered consumer actor from the global CamelContext") {
|
||||
|
||||
scenario("attempt access to unregistered consumer actor via Camel direct-endpoint") {
|
||||
val endpointUri = "direct:unpublish-test-1"
|
||||
|
||||
given("a consumer actor that has been stopped")
|
||||
assert(CamelContextManager.context.hasEndpoint(endpointUri) eq null)
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].expectPublishCount(1)
|
||||
val consumer = actorOf(new TestConsumer(endpointUri)).start
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].awaitPublish
|
||||
assert(CamelContextManager.context.hasEndpoint(endpointUri) ne null)
|
||||
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].expectUnpublishCount(1)
|
||||
consumer.stop
|
||||
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].awaitUnpublish
|
||||
// endpoint is still there but the route has been stopped
|
||||
assert(CamelContextManager.context.hasEndpoint(endpointUri) ne null)
|
||||
|
||||
when("a request is sent to this actor")
|
||||
val response1 = CamelContextManager.template.requestBody(endpointUri, "msg1")
|
||||
|
||||
then("the direct endpoint falls back to its default behaviour and returns the original message")
|
||||
assert(response1 === "msg1")
|
||||
}
|
||||
}
|
||||
|
||||
feature("Configure a custom Camel route for the global CamelContext") {
|
||||
|
||||
scenario("access an actor from the custom Camel route") {
|
||||
|
||||
given("a registered actor and a custom route to that actor")
|
||||
val actor = newActor[TestActor].start
|
||||
val actor = actorOf[TestActor].start
|
||||
|
||||
when("sending a a message to that route")
|
||||
val response = CamelContextManager.template.requestBody("direct:custom-route-test-1", "msg3")
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import se.scalablesolutions.akka.actor.Actor._
|
|||
import se.scalablesolutions.akka.actor.annotation.consume
|
||||
import se.scalablesolutions.akka.camel.Consumer
|
||||
|
||||
object PublishTest {
|
||||
object ConsumerRegisteredTest {
|
||||
@consume("mock:test1")
|
||||
class ConsumeAnnotatedActor extends Actor {
|
||||
self.id = "test"
|
||||
|
|
@ -25,27 +25,28 @@ object PublishTest {
|
|||
}
|
||||
}
|
||||
|
||||
class PublishTest extends JUnitSuite {
|
||||
import PublishTest._
|
||||
class ConsumerRegisteredTest extends JUnitSuite {
|
||||
import ConsumerRegisteredTest._
|
||||
|
||||
@Test def shouldCreatePublishRequestList = {
|
||||
val publish = Publish.forConsumers(List(newActor[ConsumeAnnotatedActor]))
|
||||
assert(publish === List(Publish("mock:test1", "test", false)))
|
||||
val as = List(actorOf[ConsumeAnnotatedActor])
|
||||
val events = for (a <- as; e <- ConsumerRegistered.forConsumer(a)) yield e
|
||||
assert(events === List(ConsumerRegistered(classOf[ConsumeAnnotatedActor].getName, "mock:test1", "test", false)))
|
||||
}
|
||||
|
||||
@Test def shouldCreateSomePublishRequestWithActorId = {
|
||||
val publish = Publish.forConsumer(newActor[ConsumeAnnotatedActor])
|
||||
assert(publish === Some(Publish("mock:test1", "test", false)))
|
||||
val event = ConsumerRegistered.forConsumer(actorOf[ConsumeAnnotatedActor])
|
||||
assert(event === Some(ConsumerRegistered(classOf[ConsumeAnnotatedActor].getName, "mock:test1", "test", false)))
|
||||
}
|
||||
|
||||
@Test def shouldCreateSomePublishRequestWithActorUuid = {
|
||||
val ca = newActor[ConsumerActor]
|
||||
val publish = Publish.forConsumer(ca)
|
||||
assert(publish === Some(Publish("mock:test2", ca.uuid, true)))
|
||||
val ca = actorOf[ConsumerActor]
|
||||
val event = ConsumerRegistered.forConsumer(ca)
|
||||
assert(event === Some(ConsumerRegistered(ca.actor.getClass.getName, "mock:test2", ca.uuid, true)))
|
||||
}
|
||||
|
||||
@Test def shouldCreateNone = {
|
||||
val publish = Publish.forConsumer(newActor[PlainActor])
|
||||
assert(publish === None)
|
||||
val event = ConsumerRegistered.forConsumer(actorOf[PlainActor])
|
||||
assert(event === None)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +1,55 @@
|
|||
package se.scalablesolutions.akka.camel.service
|
||||
|
||||
import org.junit.{After, Test}
|
||||
import _root_.org.junit.{Before, After, Test}
|
||||
import org.scalatest.junit.JUnitSuite
|
||||
|
||||
import se.scalablesolutions.akka.camel.Consumer
|
||||
import se.scalablesolutions.akka.camel.support.{Receive, Countdown}
|
||||
import se.scalablesolutions.akka.actor.{ActorRegistry, ActorRegistered, Actor}
|
||||
import se.scalablesolutions.akka.actor.{Actor, ActorRef, ActorRegistry, ActorRegistered, ActorUnregistered}
|
||||
import Actor._
|
||||
|
||||
object PublishRequestorTest {
|
||||
class PublisherMock extends Actor with Receive[Publish] {
|
||||
var received: Publish = _
|
||||
class PublisherMock extends Actor with Receive[ConsumerEvent] {
|
||||
var received: ConsumerEvent = _
|
||||
protected def receive = {
|
||||
case msg: Publish => onMessage(msg)
|
||||
case msg: ConsumerRegistered => onMessage(msg)
|
||||
case msg: ConsumerUnregistered => onMessage(msg)
|
||||
}
|
||||
def onMessage(msg: Publish) = received = msg
|
||||
def onMessage(msg: ConsumerEvent) = received = msg
|
||||
}
|
||||
}
|
||||
|
||||
class PublishRequestorTest extends JUnitSuite {
|
||||
import PublishRequestorTest._
|
||||
|
||||
@After def tearDown = ActorRegistry.shutdownAll
|
||||
var publisher: ActorRef = _
|
||||
var requestor: ActorRef = _
|
||||
var consumer: ActorRef = _
|
||||
|
||||
@Test def shouldReceivePublishRequestOnActorRegisteredEvent = {
|
||||
val consumer = newActor(() => new Actor with Consumer {
|
||||
@Before def setUp = {
|
||||
publisher = actorOf(new PublisherMock with Countdown[ConsumerEvent]).start
|
||||
requestor = actorOf(new PublishRequestor(publisher)).start
|
||||
consumer = actorOf(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
|
||||
requestor.start
|
||||
}
|
||||
|
||||
@After def tearDown = {
|
||||
ActorRegistry.shutdownAll
|
||||
}
|
||||
|
||||
@Test def shouldReceiveConsumerRegisteredEvent = {
|
||||
requestor.!(ActorRegistered(consumer))(None)
|
||||
publisher.actor.asInstanceOf[Countdown[Publish]].waitFor
|
||||
assert(publisher.actor.asInstanceOf[PublisherMock].received === Publish("mock:test", consumer.uuid, true))
|
||||
publisher.stop
|
||||
requestor.stop
|
||||
publisher.actor.asInstanceOf[Countdown[ConsumerEvent]].waitFor
|
||||
assert(publisher.actor.asInstanceOf[PublisherMock].received ===
|
||||
ConsumerRegistered(consumer.actor.getClass.getName, "mock:test", consumer.uuid, true))
|
||||
}
|
||||
|
||||
@Test def shouldReceiveConsumerUnregisteredEvent = {
|
||||
requestor.!(ActorUnregistered(consumer))(None)
|
||||
publisher.actor.asInstanceOf[Countdown[ConsumerRegistered]].waitFor
|
||||
assert(publisher.actor.asInstanceOf[PublisherMock].received ===
|
||||
ConsumerUnregistered(consumer.actor.getClass.getName, "mock:test", consumer.uuid, true))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,31 +73,31 @@ final class ActiveObjectConfiguration {
|
|||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||
*/
|
||||
object ActiveObject {
|
||||
import Actor.newActor
|
||||
import Actor.actorOf
|
||||
|
||||
val AKKA_CAMEL_ROUTING_SCHEME = "akka"
|
||||
private[actor] val AW_PROXY_PREFIX = "$$ProxiedByAW".intern
|
||||
|
||||
def newInstance[T](target: Class[T], timeout: Long): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(false, None)), None, timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(false, None)), None, timeout)
|
||||
|
||||
def newInstance[T](target: Class[T]): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(false, None)), None, Actor.TIMEOUT)
|
||||
newInstance(target, actorOf(new Dispatcher(false, None)), None, Actor.TIMEOUT)
|
||||
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(false, None)), None, timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(false, None)), None, timeout)
|
||||
|
||||
def newInstance[T](intf: Class[T], target: AnyRef): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(false, None)), None, Actor.TIMEOUT)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(false, None)), None, Actor.TIMEOUT)
|
||||
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, hostname: String, port: Int): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
def newRemoteInstance[T](target: Class[T], hostname: String, port: Int): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), Actor.TIMEOUT)
|
||||
newInstance(target, actorOf(new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), Actor.TIMEOUT)
|
||||
|
||||
def newInstance[T](target: Class[T], config: ActiveObjectConfiguration): T = {
|
||||
val actor = newActor(() => new Dispatcher(config._transactionRequired, config._restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(config._transactionRequired, config._restartCallbacks))
|
||||
if (config._messageDispatcher.isDefined) {
|
||||
actor.dispatcher = config._messageDispatcher.get
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ object ActiveObject {
|
|||
}
|
||||
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration): T = {
|
||||
val actor = newActor(() => new Dispatcher(config._transactionRequired, config._restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(config._transactionRequired, config._restartCallbacks))
|
||||
if (config._messageDispatcher.isDefined) {
|
||||
actor.dispatcher = config._messageDispatcher.get
|
||||
}
|
||||
|
|
@ -114,69 +114,69 @@ object ActiveObject {
|
|||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(false, restartCallbacks)), None, timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(false, restartCallbacks)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(false, restartCallbacks)), None, timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(false, restartCallbacks)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(transactionRequired, None)), None, timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(transactionRequired, None)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(transactionRequired, restartCallbacks)), None, timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(transactionRequired, restartCallbacks)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(transactionRequired, None)), None, timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(transactionRequired, None)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(transactionRequired, restartCallbacks)), None, timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(transactionRequired, restartCallbacks)), None, timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, hostname: String, port: Int): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(false, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(false, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(false, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean, hostname: String, port: Int): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(transactionRequired, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(transactionRequired, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean, hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(target, newActor(() => new Dispatcher(transactionRequired, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(target, actorOf(new Dispatcher(transactionRequired, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean, hostname: String, port: Int): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(transactionRequired, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(transactionRequired, None)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean, hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T =
|
||||
newInstance(intf, target, newActor(() => new Dispatcher(transactionRequired, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
newInstance(intf, target, actorOf(new Dispatcher(transactionRequired, restartCallbacks)), Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, dispatcher: MessageDispatcher): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, None))
|
||||
val actor = actorOf(new Dispatcher(false, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, None, timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, dispatcher: MessageDispatcher, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(false, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, None, timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, dispatcher: MessageDispatcher): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, None))
|
||||
val actor = actorOf(new Dispatcher(false, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, None, timeout)
|
||||
}
|
||||
|
|
@ -184,14 +184,14 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long,
|
||||
dispatcher: MessageDispatcher, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(false, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, None, timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean, dispatcher: MessageDispatcher): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, None))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, None, timeout)
|
||||
}
|
||||
|
|
@ -199,14 +199,14 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean,
|
||||
dispatcher: MessageDispatcher, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, None, timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean, dispatcher: MessageDispatcher): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, None))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, None, timeout)
|
||||
}
|
||||
|
|
@ -214,14 +214,14 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean,
|
||||
dispatcher: MessageDispatcher, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, None, timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, dispatcher: MessageDispatcher, hostname: String, port: Int): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, None))
|
||||
val actor = actorOf(new Dispatcher(false, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -229,14 +229,14 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, dispatcher: MessageDispatcher,
|
||||
hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(false, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
||||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, dispatcher: MessageDispatcher, hostname: String, port: Int): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, None))
|
||||
val actor = actorOf(new Dispatcher(false, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -244,7 +244,7 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, dispatcher: MessageDispatcher,
|
||||
hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(false, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(false, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean,
|
||||
dispatcher: MessageDispatcher, hostname: String, port: Int): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, None))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -260,7 +260,7 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(target: Class[T], config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](target: Class[T], timeout: Long, transactionRequired: Boolean, dispatcher: MessageDispatcher,
|
||||
hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean,
|
||||
dispatcher: MessageDispatcher, hostname: String, port: Int): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, None))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, None))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ object ActiveObject {
|
|||
@deprecated("use newInstance(intf: Class[T], target: AnyRef, config: ActiveObjectConfiguration) instead")
|
||||
def newRemoteInstance[T](intf: Class[T], target: AnyRef, timeout: Long, transactionRequired: Boolean,
|
||||
dispatcher: MessageDispatcher, hostname: String, port: Int, restartCallbacks: Option[RestartCallbacks]): T = {
|
||||
val actor = newActor(() => new Dispatcher(transactionRequired, restartCallbacks))
|
||||
val actor = actorOf(new Dispatcher(transactionRequired, restartCallbacks))
|
||||
actor.dispatcher = dispatcher
|
||||
newInstance(intf, target, actor, Some(new InetSocketAddress(hostname, port)), timeout)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.locks.{Lock, ReentrantLock}
|
|||
import java.util.{HashSet => JHashSet}
|
||||
|
||||
/*
|
||||
// FIXME add support for ActorWithNestedReceive
|
||||
trait ActorWithNestedReceive extends Actor {
|
||||
import Actor.actor
|
||||
private var nestedReactsProcessors: List[ActorRef] = Nil
|
||||
|
|
@ -90,32 +91,32 @@ object Actor extends Logging {
|
|||
private[actor] val actorRefInCreation = new scala.util.DynamicVariable[Option[ActorRef]](None)
|
||||
|
||||
/**
|
||||
* Creates a Actor.newActor out of the Actor with type T.
|
||||
* Creates a Actor.actorOf out of the Actor with type T.
|
||||
* <pre>
|
||||
* import Actor._
|
||||
* val actor = newActor[MyActor]
|
||||
* val actor = actorOf[MyActor]
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
* </pre>
|
||||
*/
|
||||
def newActor[T <: Actor: Manifest]: ActorRef = new LocalActorRef(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
|
||||
def actorOf[T <: Actor: Manifest]: ActorRef = new LocalActorRef(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
|
||||
|
||||
/**
|
||||
* Creates a Actor.newActor out of the Actor. Allows you to pass in a factory function
|
||||
* Creates a Actor.actorOf out of the Actor. Allows you to pass in a factory function
|
||||
* that creates the Actor. Please note that this function can be invoked multiple
|
||||
* times if for example the Actor is supervised and needs to be restarted.
|
||||
* <p/>
|
||||
* This function should <b>NOT</b> be used for remote actors.
|
||||
* <pre>
|
||||
* import Actor._
|
||||
* val actor = newActor(() => new MyActor)
|
||||
* val actor = actorOf(new MyActor)
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
* </pre>
|
||||
*/
|
||||
def newActor(factory: () => Actor): ActorRef = new LocalActorRef(factory)
|
||||
def actorOf(factory: => Actor): ActorRef = new LocalActorRef(() => factory)
|
||||
|
||||
/**
|
||||
* Use to create an anonymous event-driven actor.
|
||||
|
|
@ -134,7 +135,7 @@ object Actor extends Logging {
|
|||
* </pre>
|
||||
*/
|
||||
def actor(body: PartialFunction[Any, Unit]): ActorRef =
|
||||
newActor(() => new Actor() {
|
||||
actorOf(new Actor() {
|
||||
self.lifeCycle = Some(LifeCycle(Permanent))
|
||||
def receive: PartialFunction[Any, Unit] = body
|
||||
}).start
|
||||
|
|
@ -156,7 +157,7 @@ object Actor extends Logging {
|
|||
* </pre>
|
||||
*/
|
||||
def transactor(body: PartialFunction[Any, Unit]): ActorRef =
|
||||
newActor(() => new Transactor() {
|
||||
actorOf(new Transactor() {
|
||||
self.lifeCycle = Some(LifeCycle(Permanent))
|
||||
def receive: PartialFunction[Any, Unit] = body
|
||||
}).start
|
||||
|
|
@ -176,7 +177,7 @@ object Actor extends Logging {
|
|||
* </pre>
|
||||
*/
|
||||
def temporaryActor(body: PartialFunction[Any, Unit]): ActorRef =
|
||||
newActor(() => new Actor() {
|
||||
actorOf(new Actor() {
|
||||
self.lifeCycle = Some(LifeCycle(Temporary))
|
||||
def receive = body
|
||||
}).start
|
||||
|
|
@ -201,7 +202,7 @@ object Actor extends Logging {
|
|||
def init[A](body: => Unit) = {
|
||||
def handler[A](body: => Unit) = new {
|
||||
def receive(handler: PartialFunction[Any, Unit]) =
|
||||
newActor(() => new Actor() {
|
||||
actorOf(new Actor() {
|
||||
self.lifeCycle = Some(LifeCycle(Permanent))
|
||||
body
|
||||
def receive = handler
|
||||
|
|
@ -227,7 +228,7 @@ object Actor extends Logging {
|
|||
*/
|
||||
def spawn(body: => Unit): Unit = {
|
||||
case object Spawn
|
||||
newActor(() => new Actor() {
|
||||
actorOf(new Actor() {
|
||||
self ! Spawn
|
||||
def receive = {
|
||||
case Spawn => body; self.stop
|
||||
|
|
@ -236,6 +237,7 @@ object Actor extends Logging {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Actor base trait that should be extended by or mixed to create an Actor with the semantics of the 'Actor Model':
|
||||
* <a href="http://en.wikipedia.org/wiki/Actor_model">http://en.wikipedia.org/wiki/Actor_model</a>
|
||||
|
|
@ -263,8 +265,8 @@ trait Actor extends Logging {
|
|||
"\n\tYou can not create an instance of an actor explicitly using 'new MyActor'." +
|
||||
"\n\tYou have to use one of the factory methods in the 'Actor' object to create a new actor." +
|
||||
"\n\tEither use:" +
|
||||
"\n\t\t'val actor = Actor.newActor[MyActor]', or" +
|
||||
"\n\t\t'val actor = Actor.newActor(() => new MyActor(..))'")
|
||||
"\n\t\t'val actor = Actor.actorOf[MyActor]', or" +
|
||||
"\n\t\t'val actor = Actor.actorOf(new MyActor(..))'")
|
||||
else ref
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,26 +27,9 @@ import java.util.concurrent.atomic.AtomicReference
|
|||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.{Map => JMap}
|
||||
|
||||
/*
|
||||
trait ActorWithNestedReceive extends Actor {
|
||||
import Actor.actor
|
||||
private var nestedReactsProcessors: List[ActorRef] = Nil
|
||||
private val processNestedReacts: PartialFunction[Any, Unit] = {
|
||||
case message if !nestedReactsProcessors.isEmpty =>
|
||||
val processors = nestedReactsProcessors.reverse
|
||||
processors.head forward message
|
||||
nestedReactsProcessors = processors.tail.reverse
|
||||
}
|
||||
|
||||
protected def react: PartialFunction[Any, Unit]
|
||||
protected def reactAgain(pf: PartialFunction[Any, Unit]) = nestedReactsProcessors ::= actor(pf)
|
||||
protected def receive = processNestedReacts orElse react
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The ActorRef object can be used to deserialize ActorRef instances from of its binary representation
|
||||
* or its Protocol Buffers (protobuf) Message representation to a Actor.newActor instance.
|
||||
* or its Protocol Buffers (protobuf) Message representation to a Actor.actorOf instance.
|
||||
* <p/>
|
||||
* Binary -> ActorRef:
|
||||
* <pre>
|
||||
|
|
@ -90,16 +73,22 @@ object ActorRef {
|
|||
* <pre>
|
||||
* import Actor._
|
||||
*
|
||||
* val actor = newActor[MyActor]
|
||||
* val actor = actorOf[MyActor]
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
* </pre>
|
||||
*
|
||||
* You can also create and start actors like this:
|
||||
* <pre>
|
||||
* val actor = actorOf[MyActor].start
|
||||
* </pre>
|
||||
*
|
||||
* Here is an example on how to create an actor with a non-default constructor.
|
||||
* <pre>
|
||||
* import Actor._
|
||||
*
|
||||
* val actor = newActor(() => new MyActor(...))
|
||||
* val actor = actorOf(new MyActor(...))
|
||||
* actor.start
|
||||
* actor ! message
|
||||
* actor.stop
|
||||
|
|
@ -374,14 +363,9 @@ trait ActorRef extends TransactionManagement {
|
|||
* Returns true if reply was sent, and false if unable to determine what to reply to.
|
||||
*/
|
||||
def reply_?(message: Any): Boolean = replyTo match {
|
||||
case Some(Left(actor)) =>
|
||||
actor ! message
|
||||
true
|
||||
case Some(Right(future: Future[Any])) =>
|
||||
future completeWithResult message
|
||||
true
|
||||
case _ =>
|
||||
false
|
||||
case Some(Left(actor)) => actor ! message; true
|
||||
case Some(Right(future: Future[Any])) => future completeWithResult message; true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -714,8 +698,7 @@ sealed class LocalActorRef private[akka](
|
|||
* Returns the remote address for the actor, if any, else None.
|
||||
*/
|
||||
def remoteAddress: Option[InetSocketAddress] = guard.withGuard { _remoteAddress }
|
||||
protected[akka] def remoteAddress_=(addr: Option[InetSocketAddress]): Unit =
|
||||
guard.withGuard { _remoteAddress = addr }
|
||||
protected[akka] def remoteAddress_=(addr: Option[InetSocketAddress]): Unit = guard.withGuard { _remoteAddress = addr }
|
||||
|
||||
/**
|
||||
* Starts up the actor and its message queue.
|
||||
|
|
@ -878,11 +861,8 @@ sealed class LocalActorRef private[akka](
|
|||
protected[akka] def supervisor_=(sup: Option[ActorRef]): Unit = guard.withGuard { _supervisor = sup }
|
||||
|
||||
private def spawnButDoNotStart[T <: Actor: Manifest]: ActorRef = guard.withGuard {
|
||||
val actor = manifest[T].erasure.asInstanceOf[Class[T]].newInstance
|
||||
val actorRef = Actor.newActor(() => actor)
|
||||
if (!dispatcher.isInstanceOf[ThreadBasedDispatcher]) {
|
||||
actorRef.dispatcher = dispatcher
|
||||
}
|
||||
val actorRef = Actor.actorOf(manifest[T].erasure.asInstanceOf[Class[T]].newInstance)
|
||||
if (!dispatcher.isInstanceOf[ThreadBasedDispatcher]) actorRef.dispatcher = dispatcher
|
||||
actorRef
|
||||
}
|
||||
|
||||
|
|
@ -896,8 +876,9 @@ sealed class LocalActorRef private[akka](
|
|||
} catch {
|
||||
case e: InstantiationException => throw new ActorInitializationException(
|
||||
"Could not instantiate Actor due to:\n" + e +
|
||||
"\nMake sure Actor is defined inside a class/trait," +
|
||||
"\nif so put it outside the class/trait, f.e. in a companion object.")
|
||||
"\nMake sure Actor is NOT defined inside a class/trait," +
|
||||
"\nif so put it outside the class/trait, f.e. in a companion object," +
|
||||
"\nOR try to change: 'actorOf[MyActor]' to 'actorOf(new MyActor)'.")
|
||||
}
|
||||
case Right(Some(factory)) =>
|
||||
factory()
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ sealed class Agent[T] private (initialValue: T) {
|
|||
import Agent._
|
||||
import Actor._
|
||||
|
||||
private val dispatcher = newActor(() => new AgentDispatcher[T](initialValue)).start
|
||||
private val dispatcher = actorOf(new AgentDispatcher[T](initialValue)).start
|
||||
dispatcher ! Value(initialValue)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ object Scheduler extends Actor {
|
|||
|
||||
def schedule(receiver: ActorRef, message: AnyRef, initialDelay: Long, delay: Long, timeUnit: TimeUnit) = {
|
||||
try {
|
||||
self.startLink(newActor(() => new ScheduleActor(
|
||||
self.startLink(actorOf(new ScheduleActor(
|
||||
receiver,
|
||||
service.scheduleAtFixedRate(new java.lang.Runnable {
|
||||
def run = receiver ! message;
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ object Supervisor {
|
|||
object SupervisorActor {
|
||||
def apply(config: SupervisorConfig): ActorRef = {
|
||||
val (handler, trapExits) = SupervisorFactory.retrieveFaultHandlerAndTrapExitsFrom(config)
|
||||
newActor(() => new SupervisorActor(handler, trapExits)).start
|
||||
actorOf(new SupervisorActor(handler, trapExits)).start
|
||||
}
|
||||
|
||||
def apply(handler: FaultHandlingStrategy, trapExceptions: List[Class[_ <: Throwable]]): ActorRef =
|
||||
newActor(() => new SupervisorActor(handler, trapExceptions)).start
|
||||
actorOf(new SupervisorActor(handler, trapExceptions)).start
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ private[akka] class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurat
|
|||
|
||||
private def newSubclassingProxy(component: Component): DependencyBinding = {
|
||||
val targetClass = component.target
|
||||
val actorRef = Actor.newActor(() => new Dispatcher(component.transactionRequired, component.lifeCycle.callbacks))
|
||||
val actorRef = Actor.actorOf(new Dispatcher(component.transactionRequired, component.lifeCycle.callbacks))
|
||||
if (component.dispatcher.isDefined) actorRef.dispatcher = component.dispatcher.get
|
||||
val remoteAddress =
|
||||
if (component.remoteAddress.isDefined)
|
||||
|
|
@ -103,7 +103,7 @@ private[akka] class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurat
|
|||
val targetClass = component.intf.get
|
||||
val targetInstance = component.target.newInstance.asInstanceOf[AnyRef] // TODO: perhaps need to put in registry
|
||||
component.target.getConstructor(Array[Class[_]](): _*).setAccessible(true)
|
||||
val actorRef = Actor.newActor(() => new Dispatcher(component.transactionRequired, component.lifeCycle.callbacks))
|
||||
val actorRef = Actor.actorOf(new Dispatcher(component.transactionRequired, component.lifeCycle.callbacks))
|
||||
if (component.dispatcher.isDefined) actorRef.dispatcher = component.dispatcher.get
|
||||
val remoteAddress =
|
||||
if (component.remoteAddress.isDefined)
|
||||
|
|
|
|||
|
|
@ -28,17 +28,7 @@ object Config extends Logging {
|
|||
}
|
||||
|
||||
val config = {
|
||||
if (HOME.isDefined) {
|
||||
try {
|
||||
val configFile = HOME.get + "/config/akka.conf"
|
||||
Configgy.configure(configFile)
|
||||
log.info("AKKA_HOME is defined to [%s], config loaded from [%s].", HOME.get, configFile)
|
||||
} catch {
|
||||
case e: ParseException => throw new IllegalStateException(
|
||||
"'akka.conf' config file can not be found in [" + HOME + "/config/akka.conf] aborting." +
|
||||
"\n\tEither add it in the 'config' directory or add it to the classpath.")
|
||||
}
|
||||
} else if (System.getProperty("akka.config", "") != "") {
|
||||
if (System.getProperty("akka.config", "") != "") {
|
||||
val configFile = System.getProperty("akka.config", "")
|
||||
try {
|
||||
Configgy.configure(configFile)
|
||||
|
|
@ -47,21 +37,34 @@ object Config extends Logging {
|
|||
case e: ParseException => throw new IllegalStateException(
|
||||
"Config could not be loaded from -Dakka.config=" + configFile)
|
||||
}
|
||||
} else {
|
||||
} else if (getClass.getClassLoader.getResource("akka.conf") != null) {
|
||||
try {
|
||||
Configgy.configureFromResource("akka.conf", getClass.getClassLoader)
|
||||
log.info("Config loaded from the application classpath.")
|
||||
} catch {
|
||||
case e: ParseException => throw new IllegalStateException(
|
||||
"\nCan't find 'akka.conf' configuration file." +
|
||||
"Can't load 'akka.conf' config file from application classpath.")
|
||||
}
|
||||
} else if (HOME.isDefined) {
|
||||
try {
|
||||
val configFile = HOME.get + "/config/akka.conf"
|
||||
Configgy.configure(configFile)
|
||||
log.info("AKKA_HOME is defined as [%s], config loaded from [%s].", HOME.get, configFile)
|
||||
} catch {
|
||||
case e: ParseException => throw new IllegalStateException(
|
||||
"AKKA_HOME is defined as [" + HOME.get + "] " +
|
||||
"but the 'akka.conf' config file can not be found at [" + HOME.get + "/config/akka.conf].")
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"\nCan't load 'akka.conf'." +
|
||||
"\nOne of the three ways of locating the 'akka.conf' file needs to be defined:" +
|
||||
"\n\t1. Define 'AKKA_HOME' environment variable to the root of the Akka distribution." +
|
||||
"\n\t2. Define the '-Dakka.config=...' system property option." +
|
||||
"\n\t3. Put the 'akka.conf' file on the classpath." +
|
||||
"\n\t1. Define the '-Dakka.config=...' system property option." +
|
||||
"\n\t2. Put the 'akka.conf' file on the classpath." +
|
||||
"\n\t3. Define 'AKKA_HOME' environment variable pointing to the root of the Akka distribution." +
|
||||
"\nI have no way of finding the 'akka.conf' configuration file." +
|
||||
"\nAborting.")
|
||||
}
|
||||
}
|
||||
Configgy.config
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,12 +51,7 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
|
|||
if (!tryProcessMailbox(invocation.receiver)) {
|
||||
// we are not able to process our mailbox (another thread is busy with it), so lets donate some of our mailbox
|
||||
// to another actor and then process his mailbox in stead.
|
||||
findThief(invocation.receiver) match {
|
||||
case Some(thief) => {
|
||||
tryDonateAndProcessMessages(invocation.receiver, thief)
|
||||
}
|
||||
case None => { /* no other actor in the pool */ }
|
||||
}
|
||||
findThief(invocation.receiver).foreach( tryDonateAndProcessMessages(invocation.receiver,_) )
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -101,18 +96,13 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
|
|||
private def findThief(receiver: ActorRef): Option[ActorRef] = {
|
||||
// copy to prevent concurrent modifications having any impact
|
||||
val actors = pooledActors.toArray(new Array[ActorRef](pooledActors.size))
|
||||
var i = lastThiefIndex
|
||||
if (i > actors.size)
|
||||
i = 0
|
||||
val i = if ( lastThiefIndex > actors.size ) 0 else lastThiefIndex
|
||||
|
||||
// we risk to pick a thief which is unregistered from the dispatcher in the meantime, but that typically means
|
||||
// the dispatcher is being shut down...
|
||||
doFindThief(receiver, actors, i) match {
|
||||
case (thief: Option[ActorRef], index: Int) => {
|
||||
val (thief: Option[ActorRef], index: Int) = doFindThief(receiver, actors, i)
|
||||
lastThiefIndex = (index + 1) % actors.size
|
||||
return thief
|
||||
}
|
||||
}
|
||||
thief
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -127,13 +117,9 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
|
|||
for (i <- 0 to actors.length) {
|
||||
val index = (i + startIndex) % actors.length
|
||||
val actor = actors(index)
|
||||
if (actor != receiver) { // skip ourselves
|
||||
if (actor.mailbox.isEmpty) { // only pick actors that will most likely be able to process the messages
|
||||
return (Some(actor), index)
|
||||
if (actor != receiver && actor.mailbox.isEmpty) return (Some(actor), index)
|
||||
}
|
||||
}
|
||||
}
|
||||
return (None, startIndex) // nothing found, reuse same start index next time
|
||||
(None, startIndex) // nothing found, reuse same start index next time
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,38 +129,28 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
|
|||
private def tryDonateAndProcessMessages(receiver: ActorRef, thief: ActorRef) = {
|
||||
if (thief.dispatcherLock.tryLock) {
|
||||
try {
|
||||
donateAndProcessMessages(receiver, thief)
|
||||
while(donateMessage(receiver, thief))
|
||||
processMailbox(thief)
|
||||
} finally {
|
||||
thief.dispatcherLock.unlock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Donate messages to the thief and process them on the thief as long as the receiver has more messages.
|
||||
*/
|
||||
private def donateAndProcessMessages(receiver: ActorRef, thief: ActorRef): Unit = {
|
||||
donateMessage(receiver, thief) match {
|
||||
case None => {
|
||||
// no more messages to donate
|
||||
return
|
||||
}
|
||||
case Some(donatedInvocation) => {
|
||||
processMailbox(thief)
|
||||
return donateAndProcessMessages(receiver, thief)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Steal a message from the receiver and give it to the thief.
|
||||
*/
|
||||
private def donateMessage(receiver: ActorRef, thief: ActorRef): Option[MessageInvocation] = {
|
||||
private def donateMessage(receiver: ActorRef, thief: ActorRef): Boolean = {
|
||||
val donated = receiver.mailbox.pollLast
|
||||
if (donated != null) {
|
||||
thief.self ! donated.message
|
||||
return Some(donated)
|
||||
} else return None
|
||||
if (donated ne null) {
|
||||
donated.replyTo match {
|
||||
case None => thief.self.postMessageToMailbox(donated.message, None)
|
||||
case Some(Left(actor)) => thief.self.postMessageToMailbox(donated.message, Some(actor.asInstanceOf[ActorRef]))
|
||||
case Some(Right(future)) => thief.self.postMessageToMailboxAndCreateFutureResultWithTimeout[Any](
|
||||
donated.message, receiver.timeout, Some(future.asInstanceOf[CompletableFuture[Any]]))
|
||||
}
|
||||
true
|
||||
} else false
|
||||
}
|
||||
|
||||
def start = if (!active) {
|
||||
|
|
@ -206,16 +182,16 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
|
|||
|
||||
def usesActorMailbox = true
|
||||
|
||||
private def verifyActorsAreOfSameType(newActorId: ActorRef) = {
|
||||
private def verifyActorsAreOfSameType(actorOfId: ActorRef) = {
|
||||
actorType match {
|
||||
case None => {
|
||||
actorType = Some(newActorId.actor.getClass)
|
||||
actorType = Some(actorOfId.actor.getClass)
|
||||
}
|
||||
case Some(aType) => {
|
||||
if (aType != newActorId.actor.getClass)
|
||||
if (aType != actorOfId.actor.getClass)
|
||||
throw new IllegalStateException(
|
||||
String.format("Can't register actor %s in a work stealing dispatcher which already knows actors of type %s",
|
||||
newActorId.actor, aType))
|
||||
actorOfId.actor, aType))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ object Cluster extends Cluster with Logging {
|
|||
fqn =>
|
||||
val a = Class.forName(fqn).newInstance.asInstanceOf[ClusterActor]
|
||||
a setSerializer serializer
|
||||
Actor.newActor(() => a)
|
||||
Actor.actorOf(a)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
|
|
|||
|
|
@ -182,7 +182,6 @@ class RemoteClient(val hostname: String, val port: Int) extends Logging {
|
|||
futures.synchronized {
|
||||
val futureResult = if (senderFuture.isDefined) senderFuture.get
|
||||
else new DefaultCompletableFuture[T](request.getTimeout)
|
||||
println("------ SETTING ID: " + request.getId + " " + name)
|
||||
futures.put(request.getId, futureResult)
|
||||
connection.getChannel.write(request)
|
||||
Some(futureResult)
|
||||
|
|
@ -264,7 +263,6 @@ class RemoteClientHandler(val name: String,
|
|||
if (result.isInstanceOf[RemoteReplyProtocol]) {
|
||||
val reply = result.asInstanceOf[RemoteReplyProtocol]
|
||||
log.debug("Remote client received RemoteReplyProtocol[\n%s]", reply.toString)
|
||||
println("------ GETTING ID: " + reply.getId + " " + name)
|
||||
val future = futures.get(reply.getId).asInstanceOf[CompletableFuture[Any]]
|
||||
if (reply.getIsSuccessful) {
|
||||
val message = RemoteProtocolBuilder.getMessage(reply)
|
||||
|
|
|
|||
|
|
@ -210,10 +210,11 @@ class RemoteServer extends Logging {
|
|||
// TODO: register active object in RemoteServer as well
|
||||
|
||||
/**
|
||||
* Register Remote Actor by the Actor's 'id' field.
|
||||
* Register Remote Actor by the Actor's 'id' field. It starts the Actor if it is not started already.
|
||||
*/
|
||||
def register(actorRef: ActorRef) = synchronized {
|
||||
if (_isRunning) {
|
||||
if (!actorRef.isRunning) actorRef.start
|
||||
log.info("Registering server side remote actor [%s] with id [%s]", actorRef.actorClass.getName, actorRef.id)
|
||||
RemoteServer.actorsFor(RemoteServer.Address(hostname, port)).actors.put(actorRef.id, actorRef)
|
||||
}
|
||||
|
|
@ -226,6 +227,7 @@ class RemoteServer extends Logging {
|
|||
*/
|
||||
def register(id: String, actorRef: ActorRef) = synchronized {
|
||||
if (_isRunning) {
|
||||
if (!actorRef.isRunning) actorRef.start
|
||||
log.info("Registering server side remote actor [%s] with id [%s]", actorRef.actorClass.getName, id)
|
||||
RemoteServer.actorsFor(RemoteServer.Address(hostname, port)).actors.put(id, actorRef)
|
||||
}
|
||||
|
|
@ -477,7 +479,7 @@ class RemoteServerHandler(
|
|||
log.info("Creating a new remote actor [%s:%s]", name, uuid)
|
||||
val clazz = if (applicationLoader.isDefined) applicationLoader.get.loadClass(name)
|
||||
else Class.forName(name)
|
||||
val actorRef = Actor.newActor(() => clazz.newInstance.asInstanceOf[Actor])
|
||||
val actorRef = Actor.actorOf(clazz.newInstance.asInstanceOf[Actor])
|
||||
actorRef.uuid = uuid
|
||||
actorRef.timeout = timeout
|
||||
actorRef.remoteAddress = None
|
||||
|
|
|
|||
|
|
@ -27,21 +27,21 @@ object Patterns {
|
|||
/** Creates a LoadBalancer from the thunk-supplied InfiniteIterator
|
||||
*/
|
||||
def loadBalancerActor(actors: => InfiniteIterator[ActorRef]): ActorRef =
|
||||
newActor(() => new Actor with LoadBalancer {
|
||||
actorOf(new Actor with LoadBalancer {
|
||||
val seq = actors
|
||||
}).start
|
||||
|
||||
/** Creates a Dispatcher given a routing and a message-transforming function
|
||||
*/
|
||||
def dispatcherActor(routing: PF[Any, ActorRef], msgTransformer: (Any) => Any): ActorRef =
|
||||
newActor(() => new Actor with Dispatcher {
|
||||
actorOf(new Actor with Dispatcher {
|
||||
override def transform(msg: Any) = msgTransformer(msg)
|
||||
def routes = routing
|
||||
}).start
|
||||
|
||||
/** Creates a Dispatcher given a routing
|
||||
*/
|
||||
def dispatcherActor(routing: PF[Any, ActorRef]): ActorRef = newActor(() => new Actor with Dispatcher {
|
||||
def dispatcherActor(routing: PF[Any, ActorRef]): ActorRef = actorOf(new Actor with Dispatcher {
|
||||
def routes = routing
|
||||
}).start
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import se.scalablesolutions.akka.actor.Actor
|
|||
import se.scalablesolutions.akka.dispatch.CompletableFuture
|
||||
|
||||
def thread(body: => Unit) = {
|
||||
val thread = newActor(() => new IsolatedEventBasedThread(body)).start
|
||||
val thread = actorOf(new IsolatedEventBasedThread(body)).start
|
||||
thread ! Start
|
||||
thread
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
|
|||
}
|
||||
|
||||
def thread[A <: AnyRef, R <: AnyRef](body: A => R) =
|
||||
newActor(() => new ReactiveEventBasedThread(body)).start
|
||||
actorOf(new ReactiveEventBasedThread(body)).start
|
||||
|
||||
private class ReactiveEventBasedThread[A <: AnyRef, T <: AnyRef](body: A => T)
|
||||
extends Actor {
|
||||
|
|
@ -96,7 +96,7 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
|
|||
}
|
||||
}
|
||||
|
||||
private[this] val in = newActor(() => new In(this)).start
|
||||
private[this] val in = actorOf(new In(this)).start
|
||||
|
||||
def <<(ref: DataFlowVariable[T]) = in ! Set(ref())
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
|
|||
val ref = value.get
|
||||
if (ref.isDefined) ref.get
|
||||
else {
|
||||
val out = newActor(() => new Out(this)).start
|
||||
val out = actorOf(new Out(this)).start
|
||||
blockedReaders.offer(out)
|
||||
val result = out !! Get
|
||||
out ! Exit
|
||||
|
|
|
|||
|
|
@ -48,9 +48,8 @@ class ActorFireForgetRequestReplySpec extends JUnitSuite {
|
|||
@Test
|
||||
def shouldReplyToBangMessageUsingReply = {
|
||||
state.finished.reset
|
||||
val replyActor = newActor[ReplyActor].start
|
||||
val senderActor = newActor(() => new SenderActor(replyActor))
|
||||
senderActor.start
|
||||
val replyActor = actorOf[ReplyActor].start
|
||||
val senderActor = actorOf(new SenderActor(replyActor)).start
|
||||
senderActor ! "Init"
|
||||
try { state.finished.await(1L, TimeUnit.SECONDS) }
|
||||
catch { case e: TimeoutException => fail("Never got the message") }
|
||||
|
|
@ -60,8 +59,8 @@ class ActorFireForgetRequestReplySpec extends JUnitSuite {
|
|||
@Test
|
||||
def shouldReplyToBangMessageUsingImplicitSender = {
|
||||
state.finished.reset
|
||||
val replyActor = newActor[ReplyActor].start
|
||||
val senderActor = newActor(() => new SenderActor(replyActor)).start
|
||||
val replyActor = actorOf[ReplyActor].start
|
||||
val senderActor = actorOf(new SenderActor(replyActor)).start
|
||||
senderActor ! "InitImplicit"
|
||||
try { state.finished.await(1L, TimeUnit.SECONDS) }
|
||||
catch { case e: TimeoutException => fail("Never got the message") }
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ import org.scalatest.junit.JUnitRunner
|
|||
import org.scalatest.matchers.MustMatchers
|
||||
import org.junit.{Before, After, Test}
|
||||
import scala.collection.mutable.HashSet
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMatchers with Logging {
|
||||
import Patterns._
|
||||
@Test def testDispatcher = {
|
||||
val (testMsg1,testMsg2,testMsg3,testMsg4) = ("test1","test2","test3","test4")
|
||||
|
||||
val latch = new CountDownLatch(1)
|
||||
var targetOk = 0
|
||||
val t1 = actor {
|
||||
case `testMsg1` => targetOk += 2
|
||||
|
|
@ -26,7 +27,9 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
|
|||
}
|
||||
|
||||
val t2 = actor {
|
||||
case `testMsg3` => targetOk += 8
|
||||
case `testMsg3` =>
|
||||
targetOk += 8
|
||||
latch.countDown
|
||||
}
|
||||
|
||||
val d = dispatcherActor {
|
||||
|
|
@ -37,7 +40,8 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
|
|||
d ! testMsg1
|
||||
d ! testMsg2
|
||||
d ! testMsg3
|
||||
Thread.sleep(1000)
|
||||
val done = latch.await(5,TimeUnit.SECONDS)
|
||||
done must be (true)
|
||||
targetOk must be(14)
|
||||
t1.stop
|
||||
t2.stop
|
||||
|
|
@ -54,7 +58,6 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
|
|||
val bar : Any = "bar"
|
||||
l ! foo
|
||||
l ! bar
|
||||
Thread.sleep(1000)
|
||||
msgs must ( have size (2) and contain (foo) and contain (bar) )
|
||||
t1.stop
|
||||
l.stop
|
||||
|
|
@ -82,11 +85,9 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
|
|||
}
|
||||
|
||||
@Test def testListener = {
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
|
||||
val latch = new CountDownLatch(2)
|
||||
val num = new AtomicInteger(0)
|
||||
val i = newActor(() => new Actor with Listeners {
|
||||
val i = actorOf(new Actor with Listeners {
|
||||
def receive = listenerManagement orElse {
|
||||
case "foo" => gossip("bar")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorByIdFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor.start
|
||||
val actors = ActorRegistry.actorsFor("MyID")
|
||||
assert(actors.size === 1)
|
||||
|
|
@ -32,7 +32,7 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorByUUIDFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
val uuid = actor.uuid
|
||||
actor.start
|
||||
val actorOrNone = ActorRegistry.actorFor(uuid)
|
||||
|
|
@ -43,7 +43,7 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorByClassFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor.start
|
||||
val actors = ActorRegistry.actorsFor(classOf[TestActor])
|
||||
assert(actors.size === 1)
|
||||
|
|
@ -54,7 +54,7 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorByManifestFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor.start
|
||||
val actors = ActorRegistry.actorsFor[TestActor]
|
||||
assert(actors.size === 1)
|
||||
|
|
@ -65,9 +65,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorsByIdFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
val actors = ActorRegistry.actorsFor("MyID")
|
||||
assert(actors.size === 2)
|
||||
|
|
@ -81,9 +81,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorsByClassFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
val actors = ActorRegistry.actorsFor(classOf[TestActor])
|
||||
assert(actors.size === 2)
|
||||
|
|
@ -97,9 +97,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetActorsByManifestFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
val actors = ActorRegistry.actorsFor[TestActor]
|
||||
assert(actors.size === 2)
|
||||
|
|
@ -113,9 +113,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetAllActorsFromActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
val actors = ActorRegistry.actors
|
||||
assert(actors.size === 2)
|
||||
|
|
@ -129,9 +129,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldGetResponseByAllActorsInActorRegistryWhenInvokingForeach {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
record = ""
|
||||
ActorRegistry.foreach(actor => actor !! "ping")
|
||||
|
|
@ -142,9 +142,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldShutdownAllActorsInActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
ActorRegistry.shutdownAll
|
||||
assert(ActorRegistry.actors.size === 0)
|
||||
|
|
@ -152,9 +152,9 @@ class ActorRegistrySpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldRemoveUnregisterActorInActorRegistry {
|
||||
ActorRegistry.shutdownAll
|
||||
val actor1 = newActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
val actor2 = actorOf[TestActor]
|
||||
actor2.start
|
||||
assert(ActorRegistry.actors.size === 2)
|
||||
ActorRegistry.unregister(actor1)
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test
|
||||
def shouldSendOneWay {
|
||||
val actor = newActor[RemoteActorSpecActorUnidirectional]
|
||||
def shouldSendOneWay = {
|
||||
val actor = actorOf[RemoteActorSpecActorUnidirectional]
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
actor ! "OneWay"
|
||||
|
|
@ -94,11 +94,11 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test
|
||||
def shouldSendOneWayAndReceiveReply {
|
||||
val actor = newActor[SendOneWayAndReplyReceiverActor]
|
||||
def shouldSendOneWayAndReceiveReply = {
|
||||
val actor = actorOf[SendOneWayAndReplyReceiverActor]
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
val sender = newActor[SendOneWayAndReplySenderActor]
|
||||
val sender = actorOf[SendOneWayAndReplySenderActor]
|
||||
sender.homeAddress = (HOSTNAME, PORT2)
|
||||
sender.actor.asInstanceOf[SendOneWayAndReplySenderActor].sendTo = actor
|
||||
sender.start
|
||||
|
|
@ -111,8 +111,8 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test
|
||||
def shouldSendBangBangMessageAndReceiveReply {
|
||||
val actor = newActor[RemoteActorSpecActorBidirectional]
|
||||
def shouldSendBangBangMessageAndReceiveReply = {
|
||||
val actor = actorOf[RemoteActorSpecActorBidirectional]
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
val result = actor !! "Hello"
|
||||
|
|
@ -123,7 +123,7 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
@Test
|
||||
def shouldSendAndReceiveRemoteException {
|
||||
implicit val timeout = 500000000L
|
||||
val actor = newActor[RemoteActorSpecActorBidirectional]
|
||||
val actor = actorOf[RemoteActorSpecActorBidirectional]
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -32,33 +32,29 @@ class ExecutorBasedEventDrivenDispatcherActorSpec extends JUnitSuite {
|
|||
|
||||
private val unit = TimeUnit.MILLISECONDS
|
||||
|
||||
@Test def shouldSendOneWay {
|
||||
val actor = newActor[OneWayTestActor]
|
||||
actor.start
|
||||
@Test def shouldSendOneWay = {
|
||||
val actor = actorOf[OneWayTestActor].start
|
||||
val result = actor ! "OneWay"
|
||||
assert(OneWayTestActor.oneWay.await(1, TimeUnit.SECONDS))
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplySync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplyAsync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplyAsync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result = actor !! "Hello"
|
||||
assert("World" === result.get.asInstanceOf[String])
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReceiveException {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReceiveException = {
|
||||
val actor = actorOf[TestActor].start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
fail("Should have thrown an exception")
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ class ExecutorBasedEventDrivenDispatcherActorsSpec extends JUnitSuite with MustM
|
|||
@Test def slowActorShouldntBlockFastActor {
|
||||
val sFinished = new CountDownLatch(50)
|
||||
val fFinished = new CountDownLatch(10)
|
||||
val s = newActor(() => new SlowActor(sFinished)).start
|
||||
val f = newActor(() => new FastActor(fFinished)).start
|
||||
val s = actorOf(new SlowActor(sFinished)).start
|
||||
val f = actorOf(new FastActor(fFinished)).start
|
||||
|
||||
// send a lot of stuff to s
|
||||
for (i <- 1 to 50) {
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ class ExecutorBasedEventDrivenWorkStealingDispatcherSpec extends JUnitSuite with
|
|||
@Test def fastActorShouldStealWorkFromSlowActor {
|
||||
val finishedCounter = new CountDownLatch(110)
|
||||
|
||||
val slow = newActor(() => new DelayableActor("slow", 50, finishedCounter)).start
|
||||
val fast = newActor(() => new DelayableActor("fast", 10, finishedCounter)).start
|
||||
val slow = actorOf(new DelayableActor("slow", 50, finishedCounter)).start
|
||||
val fast = actorOf(new DelayableActor("fast", 10, finishedCounter)).start
|
||||
|
||||
for (i <- 1 to 100) {
|
||||
// send most work to slow actor
|
||||
|
|
@ -85,8 +85,8 @@ class ExecutorBasedEventDrivenWorkStealingDispatcherSpec extends JUnitSuite with
|
|||
}
|
||||
|
||||
@Test def canNotUseActorsOfDifferentTypesInSameDispatcher: Unit = {
|
||||
val first = newActor[FirstActor]
|
||||
val second = newActor[SecondActor]
|
||||
val first = actorOf[FirstActor]
|
||||
val second = actorOf[SecondActor]
|
||||
|
||||
first.start
|
||||
intercept[IllegalStateException] {
|
||||
|
|
@ -95,8 +95,8 @@ class ExecutorBasedEventDrivenWorkStealingDispatcherSpec extends JUnitSuite with
|
|||
}
|
||||
|
||||
@Test def canNotUseActorsOfDifferentSubTypesInSameDispatcher: Unit = {
|
||||
val parent = newActor[ParentActor]
|
||||
val child = newActor[ChildActor]
|
||||
val parent = actorOf[ParentActor]
|
||||
val child = actorOf[ChildActor]
|
||||
|
||||
parent.start
|
||||
intercept[IllegalStateException] {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ object ForwardActorSpec {
|
|||
|
||||
|
||||
class ForwardActor extends Actor {
|
||||
val receiverActor = newActor[ReceiverActor]
|
||||
val receiverActor = actorOf[ReceiverActor]
|
||||
receiverActor.start
|
||||
def receive = {
|
||||
case "SendBang" => receiverActor.forward("SendBang")
|
||||
|
|
@ -33,7 +33,7 @@ object ForwardActorSpec {
|
|||
}
|
||||
|
||||
class BangSenderActor extends Actor {
|
||||
val forwardActor = newActor[ForwardActor]
|
||||
val forwardActor = actorOf[ForwardActor]
|
||||
forwardActor.start
|
||||
forwardActor ! "SendBang"
|
||||
def receive = {
|
||||
|
|
@ -43,7 +43,7 @@ object ForwardActorSpec {
|
|||
|
||||
class BangBangSenderActor extends Actor {
|
||||
val latch = new CountDownLatch(1)
|
||||
val forwardActor = newActor[ForwardActor]
|
||||
val forwardActor = actorOf[ForwardActor]
|
||||
forwardActor.start
|
||||
(forwardActor !! "SendBangBang") match {
|
||||
case Some(_) => latch.countDown
|
||||
|
|
@ -60,7 +60,7 @@ class ForwardActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldForwardActorReferenceWhenInvokingForwardOnBang {
|
||||
val senderActor = newActor[BangSenderActor]
|
||||
val senderActor = actorOf[BangSenderActor]
|
||||
val latch = senderActor.actor.asInstanceOf[BangSenderActor]
|
||||
.forwardActor.actor.asInstanceOf[ForwardActor]
|
||||
.receiverActor.actor.asInstanceOf[ReceiverActor]
|
||||
|
|
@ -73,7 +73,7 @@ class ForwardActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldForwardActorReferenceWhenInvokingForwardOnBangBang {
|
||||
val senderActor = newActor[BangBangSenderActor]
|
||||
val senderActor = actorOf[BangBangSenderActor]
|
||||
senderActor.start
|
||||
val latch = senderActor.actor.asInstanceOf[BangBangSenderActor].latch
|
||||
assert(latch.await(1L, TimeUnit.SECONDS))
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class FutureSpec extends JUnitSuite {
|
|||
import FutureSpec._
|
||||
|
||||
@Test def shouldActorReplyResultThroughExplicitFuture {
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor.start
|
||||
val future = actor !!! "Hello"
|
||||
future.await
|
||||
|
|
@ -31,7 +31,7 @@ class FutureSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test def shouldActorReplyExceptionThroughExplicitFuture {
|
||||
val actor = newActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor.start
|
||||
val future = actor !!! "Failure"
|
||||
future.await
|
||||
|
|
@ -41,11 +41,10 @@ class FutureSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
/*
|
||||
@Test def shouldFutureAwaitEitherLeft {
|
||||
val actor1 = newActor[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
actor2.start
|
||||
// FIXME: implement Futures.awaitEither, and uncomment these two tests
|
||||
@Test def shouldFutureAwaitEitherLeft = {
|
||||
val actor1 = actorOf[TestActor].start
|
||||
val actor2 = actorOf[TestActor].start
|
||||
val future1 = actor1 !!! "Hello"
|
||||
val future2 = actor2 !!! "NoReply"
|
||||
val result = Futures.awaitEither(future1, future2)
|
||||
|
|
@ -55,11 +54,9 @@ class FutureSpec extends JUnitSuite {
|
|||
actor2.stop
|
||||
}
|
||||
|
||||
@Test def shouldFutureAwaitEitherRight {
|
||||
val actor1 = newActor[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
actor2.start
|
||||
@Test def shouldFutureAwaitEitherRight = {
|
||||
val actor1 = actorOf[TestActor].start
|
||||
val actor2 = actorOf[TestActor].start
|
||||
val future1 = actor1 !!! "NoReply"
|
||||
val future2 = actor2 !!! "Hello"
|
||||
val result = Futures.awaitEither(future1, future2)
|
||||
|
|
@ -69,11 +66,9 @@ class FutureSpec extends JUnitSuite {
|
|||
actor2.stop
|
||||
}
|
||||
*/
|
||||
@Test def shouldFutureAwaitOneLeft {
|
||||
val actor1 = newActor[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
actor2.start
|
||||
@Test def shouldFutureAwaitOneLeft = {
|
||||
val actor1 = actorOf[TestActor].start
|
||||
val actor2 = actorOf[TestActor].start
|
||||
val future1 = actor1 !!! "NoReply"
|
||||
val future2 = actor2 !!! "Hello"
|
||||
val result = Futures.awaitOne(List(future1, future2))
|
||||
|
|
@ -83,11 +78,9 @@ class FutureSpec extends JUnitSuite {
|
|||
actor2.stop
|
||||
}
|
||||
|
||||
@Test def shouldFutureAwaitOneRight {
|
||||
val actor1 = newActor[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
actor2.start
|
||||
@Test def shouldFutureAwaitOneRight = {
|
||||
val actor1 = actorOf[TestActor].start
|
||||
val actor2 = actorOf[TestActor].start
|
||||
val future1 = actor1 !!! "Hello"
|
||||
val future2 = actor2 !!! "NoReply"
|
||||
val result = Futures.awaitOne(List(future1, future2))
|
||||
|
|
@ -97,11 +90,9 @@ class FutureSpec extends JUnitSuite {
|
|||
actor2.stop
|
||||
}
|
||||
|
||||
@Test def shouldFutureAwaitAll {
|
||||
val actor1 = newActor[TestActor]
|
||||
actor1.start
|
||||
val actor2 = newActor[TestActor]
|
||||
actor2.start
|
||||
@Test def shouldFutureAwaitAll = {
|
||||
val actor1 = actorOf[TestActor].start
|
||||
val actor2 = actorOf[TestActor].start
|
||||
val future1 = actor1 !!! "Hello"
|
||||
val future2 = actor2 !!! "Hello"
|
||||
Futures.awaitAll(List(future1, future2))
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class InMemFailerActor extends Transactor {
|
|||
class InMemoryActorSpec extends JUnitSuite {
|
||||
@Test
|
||||
def shouldOneWayMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
stateful ! SetMapStateOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -120,7 +120,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -129,9 +129,9 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldOneWayMapShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
stateful ! SetMapStateOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
@ -142,10 +142,10 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldMapShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
@ -156,7 +156,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldOneWayVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
stateful ! SetVectorStateOneWay("init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -167,7 +167,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetVectorState("init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -176,11 +176,11 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldOneWayVectorShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
stateful ! SetVectorStateOneWay("init") // set init state
|
||||
Thread.sleep(1000)
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
|
|
@ -190,10 +190,10 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldVectorShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetVectorState("init") // set init state
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
@ -204,7 +204,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldOneWayRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
stateful ! SetRefStateOneWay("init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -215,7 +215,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetRefState("init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -224,11 +224,11 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldOneWayRefShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor(() => new InMemStatefulActor(2))
|
||||
val stateful = actorOf(new InMemStatefulActor(2))
|
||||
stateful.start
|
||||
stateful ! SetRefStateOneWay("init") // set init state
|
||||
Thread.sleep(1000)
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
|
|
@ -238,10 +238,10 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldRefShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[InMemStatefulActor]
|
||||
val stateful = actorOf[InMemStatefulActor]
|
||||
stateful.start
|
||||
stateful !! SetRefState("init") // set init state
|
||||
val failer = newActor[InMemFailerActor]
|
||||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ProtobufActorMessageSerializationSpec extends JUnitSuite {
|
|||
def init() {
|
||||
server = new RemoteServer
|
||||
server.start(HOSTNAME, PORT)
|
||||
server.register("RemoteActorSpecActorBidirectional", newActor[RemoteActorSpecActorBidirectional].start)
|
||||
server.register("RemoteActorSpecActorBidirectional", actorOf[RemoteActorSpecActorBidirectional])
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,33 +35,29 @@ class ReactorBasedSingleThreadEventDrivenDispatcherActorSpec extends JUnitSuite
|
|||
|
||||
private val unit = TimeUnit.MILLISECONDS
|
||||
|
||||
@Test def shouldSendOneWay {
|
||||
val actor = newActor[OneWayTestActor]
|
||||
actor.start
|
||||
@Test def shouldSendOneWay = {
|
||||
val actor = actorOf[OneWayTestActor].start
|
||||
val result = actor ! "OneWay"
|
||||
assert(OneWayTestActor.oneWay.await(1, TimeUnit.SECONDS))
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplySync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplyAsync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplyAsync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result = actor !! "Hello"
|
||||
assert("World" === result.get.asInstanceOf[String])
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReceiveException {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReceiveException = {
|
||||
val actor = actorOf[TestActor].start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
fail("Should have thrown an exception")
|
||||
|
|
|
|||
|
|
@ -26,37 +26,33 @@ class ReactorBasedThreadPoolEventDrivenDispatcherActorSpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldSendOneWay {
|
||||
val oneWay = new CountDownLatch(1)
|
||||
val actor = newActor(() => new Actor {
|
||||
val actor = actorOf(new Actor {
|
||||
self.dispatcher = Dispatchers.newReactorBasedThreadPoolEventDrivenDispatcher(self.uuid)
|
||||
def receive = {
|
||||
case "OneWay" => oneWay.countDown
|
||||
}
|
||||
})
|
||||
actor.start
|
||||
}).start
|
||||
val result = actor ! "OneWay"
|
||||
assert(oneWay.await(1, TimeUnit.SECONDS))
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplySync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplyAsync {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReplyAsync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result = actor !! "Hello"
|
||||
assert("World" === result.get.asInstanceOf[String])
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReceiveException {
|
||||
val actor = newActor[TestActor]
|
||||
actor.start
|
||||
@Test def shouldSendReceiveException = {
|
||||
val actor = actorOf[TestActor].start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
fail("Should have thrown an exception")
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ object Log {
|
|||
}
|
||||
|
||||
override def postRestart(reason: Throwable) {
|
||||
println("================= POST RESTART")
|
||||
Log.messageLog.put(reason.getMessage)
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +50,6 @@ object Log {
|
|||
}
|
||||
|
||||
override def postRestart(reason: Throwable) {
|
||||
println("================= POST RESTART")
|
||||
Log.messageLog.put(reason.getMessage)
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +65,6 @@ object Log {
|
|||
}
|
||||
|
||||
override def postRestart(reason: Throwable) {
|
||||
println("================= POST RESTART")
|
||||
Log.messageLog.put(reason.getMessage)
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +192,7 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Test def shouldKillMultipleActorsOneForOne2 = {
|
||||
Log.messageLog.clear
|
||||
val sup = getMultipleActorsOneForOneConf
|
||||
|
|
@ -207,7 +205,7 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
Log.messageLog.poll(5, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
def tesCallKillCallMultipleActorsOneForOne = {
|
||||
Log.messageLog.clear
|
||||
val sup = getMultipleActorsOneForOneConf
|
||||
|
|
@ -354,7 +352,7 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
// Then create a concrete container in which we mix in support for the specific
|
||||
// implementation of the Actors we want to use.
|
||||
|
||||
pingpong1 = newActor[RemotePingPong1Actor]
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong1.start
|
||||
|
||||
|
|
@ -370,7 +368,7 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getSingleActorOneForOneSupervisor: Supervisor = {
|
||||
pingpong1 = newActor[RemotePingPong1Actor]
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong1.start
|
||||
|
||||
|
|
@ -385,13 +383,13 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getMultipleActorsAllForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[RemotePingPong1Actor]
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong1.start
|
||||
pingpong2 = newActor[RemotePingPong2Actor]
|
||||
pingpong2 = actorOf[RemotePingPong2Actor]
|
||||
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong2.start
|
||||
pingpong3 = newActor[RemotePingPong3Actor]
|
||||
pingpong3 = actorOf[RemotePingPong3Actor]
|
||||
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong3.start
|
||||
|
||||
|
|
@ -414,13 +412,15 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getMultipleActorsOneForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[RemotePingPong1Actor]
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong1.start
|
||||
pingpong2 = newActor[RemotePingPong2Actor]
|
||||
pingpong2 = actorOf[RemotePingPong2Actor]
|
||||
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong2.start
|
||||
pingpong3 = newActor[RemotePingPong3Actor]
|
||||
pingpong3 = actorOf[RemotePingPong3Actor]
|
||||
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong3.start
|
||||
|
||||
|
|
@ -443,12 +443,15 @@ class RemoteSupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getNestedSupervisorsAllForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[RemotePingPong1Actor].start
|
||||
pingpong1 = actorOf[RemotePingPong1Actor]
|
||||
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong2 = newActor[RemotePingPong2Actor].start
|
||||
pingpong1.start
|
||||
pingpong2 = actorOf[RemotePingPong2Actor]
|
||||
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong3 = newActor[RemotePingPong3Actor].start
|
||||
pingpong2.start
|
||||
pingpong3 = actorOf[RemotePingPong3Actor]
|
||||
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
||||
pingpong3.start
|
||||
|
||||
val factory = SupervisorFactory(
|
||||
SupervisorConfig(
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ import org.junit.{Test, Before, After}
|
|||
|
||||
import scala.reflect.BeanInfo
|
||||
|
||||
//@BeanInfo
|
||||
@BeanInfo
|
||||
case class Foo(foo: String) {
|
||||
def this() = this(null)
|
||||
}
|
||||
|
||||
//@BeanInfo
|
||||
@BeanInfo
|
||||
case class MyMessage(val id: String, val value: Tuple2[String, Int]) {
|
||||
private def this() = this(null, null)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ object ServerInitiatedRemoteActorServer {
|
|||
|
||||
def run = {
|
||||
RemoteNode.start("localhost", 9999)
|
||||
RemoteNode.register("hello-service", newActor[HelloWorldActor])
|
||||
RemoteNode.register("hello-service", actorOf[HelloWorldActor])
|
||||
}
|
||||
|
||||
def main(args: Array[String]) = run
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ class ServerInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
|
||||
server.start(HOSTNAME, PORT)
|
||||
|
||||
server.register(newActor[RemoteActorSpecActorUnidirectional])
|
||||
server.register(newActor[RemoteActorSpecActorBidirectional])
|
||||
server.register(newActor[RemoteActorSpecActorAsyncSender])
|
||||
server.register(actorOf[RemoteActorSpecActorUnidirectional])
|
||||
server.register(actorOf[RemoteActorSpecActorBidirectional])
|
||||
server.register(actorOf[RemoteActorSpecActorAsyncSender])
|
||||
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ class ServerInitiatedRemoteActorSpec extends JUnitSuite {
|
|||
"se.scalablesolutions.akka.actor.ServerInitiatedRemoteActorSpec$RemoteActorSpecActorBidirectional",
|
||||
timeout,
|
||||
HOSTNAME, PORT)
|
||||
val sender = newActor[RemoteActorSpecActorAsyncSender]
|
||||
val sender = actorOf[RemoteActorSpecActorAsyncSender]
|
||||
sender.homeAddress = (HOSTNAME, PORT + 1)
|
||||
sender.start
|
||||
sender ! Send(actor)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ object ActorShutdownRunner {
|
|||
}
|
||||
}
|
||||
|
||||
val myActor = newActor[MyActor]
|
||||
val myActor = actorOf[MyActor]
|
||||
myActor.start
|
||||
myActor ! "test"
|
||||
myActor.stop
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ class SupervisorSpec extends JUnitSuite {
|
|||
messageLog.poll(1, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Test def shouldKillMultipleActorsOneForOne2 = {
|
||||
clearMessageLogs
|
||||
val sup = getMultipleActorsOneForOneConf
|
||||
|
|
@ -205,7 +205,7 @@ class SupervisorSpec extends JUnitSuite {
|
|||
messageLog.poll(1, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@Test def shouldKillCallMultipleActorsOneForOne = {
|
||||
clearMessageLogs
|
||||
val sup = getMultipleActorsOneForOneConf
|
||||
|
|
@ -440,20 +440,19 @@ class SupervisorSpec extends JUnitSuite {
|
|||
// Create some supervisors with different configurations
|
||||
|
||||
def getSingleActorAllForOneSupervisor: Supervisor = {
|
||||
pingpong1 = newActor[PingPong1Actor].start
|
||||
pingpong1 = actorOf[PingPong1Actor].start
|
||||
|
||||
val factory = SupervisorFactory(
|
||||
Supervisor(
|
||||
SupervisorConfig(
|
||||
RestartStrategy(AllForOne, 3, 100, List(classOf[Exception])),
|
||||
Supervise(
|
||||
pingpong1,
|
||||
LifeCycle(Permanent))
|
||||
:: Nil))
|
||||
factory.newInstance
|
||||
}
|
||||
|
||||
def getSingleActorOneForOneSupervisor: Supervisor = {
|
||||
pingpong1 = newActor[PingPong1Actor].start
|
||||
pingpong1 = actorOf[PingPong1Actor].start
|
||||
|
||||
Supervisor(
|
||||
SupervisorConfig(
|
||||
|
|
@ -465,9 +464,9 @@ class SupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getMultipleActorsAllForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[PingPong1Actor].start
|
||||
pingpong2 = newActor[PingPong2Actor].start
|
||||
pingpong3 = newActor[PingPong3Actor].start
|
||||
pingpong1 = actorOf[PingPong1Actor].start
|
||||
pingpong2 = actorOf[PingPong2Actor].start
|
||||
pingpong3 = actorOf[PingPong3Actor].start
|
||||
|
||||
Supervisor(
|
||||
SupervisorConfig(
|
||||
|
|
@ -487,9 +486,9 @@ class SupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getMultipleActorsOneForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[PingPong1Actor].start
|
||||
pingpong2 = newActor[PingPong2Actor].start
|
||||
pingpong3 = newActor[PingPong3Actor].start
|
||||
pingpong1 = actorOf[PingPong1Actor].start
|
||||
pingpong2 = actorOf[PingPong2Actor].start
|
||||
pingpong3 = actorOf[PingPong3Actor].start
|
||||
|
||||
Supervisor(
|
||||
SupervisorConfig(
|
||||
|
|
@ -509,9 +508,9 @@ class SupervisorSpec extends JUnitSuite {
|
|||
}
|
||||
|
||||
def getNestedSupervisorsAllForOneConf: Supervisor = {
|
||||
pingpong1 = newActor[PingPong1Actor].start
|
||||
pingpong2 = newActor[PingPong2Actor].start
|
||||
pingpong3 = newActor[PingPong3Actor].start
|
||||
pingpong1 = actorOf[PingPong1Actor].start
|
||||
pingpong2 = actorOf[PingPong2Actor].start
|
||||
pingpong3 = actorOf[PingPong3Actor].start
|
||||
|
||||
Supervisor(
|
||||
SupervisorConfig(
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class ThreadBasedActorSpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldSendOneWay {
|
||||
var oneWay = new CountDownLatch(1)
|
||||
val actor = newActor(() => new Actor {
|
||||
val actor = actorOf(new Actor {
|
||||
self.dispatcher = Dispatchers.newThreadBasedDispatcher(self)
|
||||
def receive = {
|
||||
case "OneWay" => oneWay.countDown
|
||||
|
|
@ -38,22 +38,22 @@ class ThreadBasedActorSpec extends JUnitSuite {
|
|||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplySync {
|
||||
val actor = newActor[TestActor].start
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReplyAsync {
|
||||
val actor = newActor[TestActor].start
|
||||
@Test def shouldSendReplyAsync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result = actor !! "Hello"
|
||||
assert("World" === result.get.asInstanceOf[String])
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test def shouldSendReceiveException {
|
||||
val actor = newActor[TestActor].start
|
||||
@Test def shouldSendReceiveException = {
|
||||
val actor = actorOf[TestActor].start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
fail("Should have thrown an exception")
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ import Actor._
|
|||
/*
|
||||
class ThreadBasedDispatcherSpec extends JUnitSuite {
|
||||
private var threadingIssueDetected: AtomicBoolean = null
|
||||
val key1 = newActor(() => new Actor { def receive = { case _ => {}} })
|
||||
val key2 = newActor(() => new Actor { def receive = { case _ => {}} })
|
||||
val key3 = newActor(() => new Actor { def receive = { case _ => {}} })
|
||||
val key1 = actorOf(new Actor { def receive = { case _ => {}} })
|
||||
val key2 = actorOf(new Actor { def receive = { case _ => {}} })
|
||||
val key3 = actorOf(new Actor { def receive = { case _ => {}} })
|
||||
|
||||
class TestMessageHandle(handleLatch: CountDownLatch) extends MessageInvoker {
|
||||
val guardLock: Lock = new ReentrantLock
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
|
|||
with Suite with MockitoSugar with MustMatchers {
|
||||
import BasicAuthenticatorSpec._
|
||||
|
||||
val authenticator = newActor[BasicAuthenticator]
|
||||
val authenticator = actorOf[BasicAuthenticator]
|
||||
authenticator.start
|
||||
|
||||
@Test def testChallenge = {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -86,10 +86,10 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testMapShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
@ -101,7 +101,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetVectorState("init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -110,10 +110,10 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testVectorShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetVectorState("init") // set init state
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
@ -124,7 +124,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetRefState("init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
|
|
@ -134,10 +134,10 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testRefShouldRollbackStateForStatefulServerInCaseOfFailure = {
|
||||
val stateful = newActor[CassandraPersistentActor]
|
||||
val stateful = actorOf[CassandraPersistentActor]
|
||||
stateful.start
|
||||
stateful !! SetRefState("init") // set init state
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
|
|
|
|||
|
|
@ -105,9 +105,9 @@ class BankAccountActor extends Transactor {
|
|||
class MongoPersistentActorSpec extends JUnitSuite {
|
||||
@Test
|
||||
def testSuccessfulDebit = {
|
||||
val bactor = newActor[BankAccountActor]
|
||||
val bactor = actorOf[BankAccountActor]
|
||||
bactor.start
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
bactor !! Debit("a-123", 3000, failer)
|
||||
|
|
@ -137,14 +137,14 @@ class MongoPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testUnsuccessfulDebit = {
|
||||
val bactor = newActor[BankAccountActor]
|
||||
val bactor = actorOf[BankAccountActor]
|
||||
bactor.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
|
||||
val JsNumber(b) = (bactor !! Balance("a-123")).get.asInstanceOf[JsValue]
|
||||
assertEquals(BigInt(5000), BigInt(b.intValue))
|
||||
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
bactor !! Debit("a-123", 7000, failer)
|
||||
|
|
@ -160,14 +160,14 @@ class MongoPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testUnsuccessfulMultiDebit = {
|
||||
val bactor = newActor[BankAccountActor]
|
||||
val bactor = actorOf[BankAccountActor]
|
||||
bactor.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
|
||||
val JsNumber(b) = (bactor !! Balance("a-123")).get.asInstanceOf[JsValue]
|
||||
assertEquals(BigInt(5000), BigInt(b.intValue))
|
||||
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
bactor !! MultiDebit("a-123", List(500, 2000, 1000, 3000), failer)
|
||||
|
|
|
|||
|
|
@ -101,9 +101,9 @@ import org.scalatest.junit.JUnitSuite
|
|||
class RedisPersistentActorSpec extends JUnitSuite {
|
||||
@Test
|
||||
def testSuccessfulDebit = {
|
||||
val bactor = newActor[AccountActor]
|
||||
val bactor = actorOf[AccountActor]
|
||||
bactor.start
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
bactor !! Debit("a-123", 3000, failer)
|
||||
|
|
@ -127,12 +127,12 @@ class RedisPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testUnsuccessfulDebit = {
|
||||
val bactor = newActor[AccountActor]
|
||||
val bactor = actorOf[AccountActor]
|
||||
bactor.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
assertEquals(BigInt(5000), (bactor !! Balance("a-123")).get)
|
||||
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
bactor !! Debit("a-123", 7000, failer)
|
||||
|
|
@ -148,13 +148,13 @@ class RedisPersistentActorSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testUnsuccessfulMultiDebit = {
|
||||
val bactor = newActor[AccountActor]
|
||||
val bactor = actorOf[AccountActor]
|
||||
bactor.start
|
||||
bactor !! Credit("a-123", 5000)
|
||||
|
||||
assertEquals(BigInt(5000), (bactor !! (Balance("a-123"), 5000)).get)
|
||||
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
try {
|
||||
bactor !! MultiDebit("a-123", List(500, 2000, 1000, 3000), failer)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ import org.scalatest.junit.JUnitSuite
|
|||
class RedisPersistentQSpec extends JUnitSuite {
|
||||
@Test
|
||||
def testSuccessfulNQ = {
|
||||
val qa = newActor[QueueActor]
|
||||
val qa = actorOf[QueueActor]
|
||||
qa.start
|
||||
qa !! NQ("a-123")
|
||||
qa !! NQ("a-124")
|
||||
|
|
@ -64,7 +64,7 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testSuccessfulDQ = {
|
||||
val qa = newActor[QueueActor]
|
||||
val qa = actorOf[QueueActor]
|
||||
qa.start
|
||||
qa !! NQ("a-123")
|
||||
qa !! NQ("a-124")
|
||||
|
|
@ -80,9 +80,9 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testSuccessfulMNDQ = {
|
||||
val qa = newActor[QueueActor]
|
||||
val qa = actorOf[QueueActor]
|
||||
qa.start
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
|
||||
qa !! NQ("a-123")
|
||||
|
|
@ -100,9 +100,9 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def testMixedMNDQ = {
|
||||
val qa = newActor[QueueActor]
|
||||
val qa = actorOf[QueueActor]
|
||||
qa.start
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
|
||||
// 3 enqueues
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class RedisPersistentSortedSetSpec extends
|
|||
val h6 = Hacker("Alan Turing", "1912")
|
||||
|
||||
describe("Add and report cardinality of the set") {
|
||||
val qa = newActor[SortedSetActor]
|
||||
val qa = actorOf[SortedSetActor]
|
||||
qa.start
|
||||
|
||||
it("should enter 6 hackers") {
|
||||
|
|
@ -167,10 +167,10 @@ class RedisPersistentSortedSetSpec extends
|
|||
|
||||
describe("Transaction semantics") {
|
||||
it("should rollback on exception") {
|
||||
val qa = newActor[SortedSetActor]
|
||||
val qa = actorOf[SortedSetActor]
|
||||
qa.start
|
||||
|
||||
val failer = newActor[PersistentFailerActor]
|
||||
val failer = actorOf[PersistentFailerActor]
|
||||
failer.start
|
||||
|
||||
(qa !! SIZE).get.asInstanceOf[Int] should equal(0)
|
||||
|
|
@ -195,7 +195,7 @@ class RedisPersistentSortedSetSpec extends
|
|||
|
||||
describe("zrange") {
|
||||
it ("should report proper range") {
|
||||
val qa = newActor[SortedSetActor]
|
||||
val qa = actorOf[SortedSetActor]
|
||||
qa.start
|
||||
qa !! ADD(h1)
|
||||
qa !! ADD(h2)
|
||||
|
|
@ -214,7 +214,7 @@ class RedisPersistentSortedSetSpec extends
|
|||
}
|
||||
|
||||
it ("should report proper rge") {
|
||||
val qa = newActor[SortedSetActor]
|
||||
val qa = actorOf[SortedSetActor]
|
||||
qa.start
|
||||
qa !! ADD(h1)
|
||||
qa !! ADD(h2)
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ class Consumer1 extends Actor with Consumer with Logging {
|
|||
def endpointUri = "file:data/input"
|
||||
|
||||
def receive = {
|
||||
case msg: Message => log.info("received %s" format msg.bodyAs(classOf[String]))
|
||||
case msg: Message => log.info("received %s" format msg.bodyAs[String])
|
||||
}
|
||||
}
|
||||
|
||||
@consume("jetty:http://0.0.0.0:8877/camel/test1")
|
||||
class Consumer2 extends Actor {
|
||||
def receive = {
|
||||
case msg: Message => self.reply("Hello %s" format msg.bodyAs(classOf[String]))
|
||||
case msg: Message => self.reply("Hello %s" format msg.bodyAs[String])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,32 @@ class Consumer3(transformer: ActorRef) extends Actor with Consumer {
|
|||
def endpointUri = "jetty:http://0.0.0.0:8877/camel/welcome"
|
||||
|
||||
def receive = {
|
||||
case msg: Message => transformer.forward(msg.setBodyAs(classOf[String]))
|
||||
case msg: Message => transformer.forward(msg.setBodyAs[String])
|
||||
}
|
||||
}
|
||||
|
||||
class Consumer4 extends Actor with Consumer with Logging {
|
||||
def endpointUri = "jetty:http://0.0.0.0:8877/camel/stop"
|
||||
|
||||
def receive = {
|
||||
case msg: Message => msg.bodyAs[String] match {
|
||||
case "stop" => {
|
||||
self.reply("Consumer4 stopped")
|
||||
self.stop
|
||||
}
|
||||
case body => self.reply(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Consumer5 extends Actor with Consumer with Logging {
|
||||
def endpointUri = "jetty:http://0.0.0.0:8877/camel/start"
|
||||
|
||||
def receive = {
|
||||
case _ => {
|
||||
Actor.actorOf[Consumer4].start
|
||||
self.reply("Consumer4 started")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +110,7 @@ class PublisherBridge(uri: String, publisher: ActorRef) extends Actor with Consu
|
|||
|
||||
protected def receive = {
|
||||
case msg: Message => {
|
||||
publisher ! msg.bodyAs(classOf[String])
|
||||
publisher ! msg.bodyAs[String]
|
||||
self.reply("message published")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ object Application1 {
|
|||
def main(args: Array[String]) {
|
||||
implicit val sender: Option[ActorRef] = None
|
||||
|
||||
val actor1 = newActor[RemoteActor1]
|
||||
val actor1 = actorOf[RemoteActor1]
|
||||
val actor2 = RemoteClient.actorFor("remote2", "localhost", 7777)
|
||||
|
||||
actor1.start
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ object Application2 {
|
|||
val camelService = CamelService.newInstance
|
||||
camelService.load
|
||||
RemoteNode.start("localhost", 7777)
|
||||
RemoteNode.register("remote2", newActor[RemoteActor2].start)
|
||||
RemoteNode.register("remote2", actorOf[RemoteActor2].start)
|
||||
}
|
||||
}
|
||||
|
|
@ -28,15 +28,15 @@ class Boot {
|
|||
val factory = SupervisorFactory(
|
||||
SupervisorConfig(
|
||||
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
|
||||
Supervise(newActor[Consumer1], LifeCycle(Permanent)) ::
|
||||
Supervise(newActor[Consumer2], LifeCycle(Permanent)) :: Nil))
|
||||
Supervise(actorOf[Consumer1], LifeCycle(Permanent)) ::
|
||||
Supervise(actorOf[Consumer2], LifeCycle(Permanent)) :: Nil))
|
||||
factory.newInstance.start
|
||||
|
||||
// Routing example
|
||||
|
||||
val producer = newActor[Producer1]
|
||||
val mediator = newActor(() => new Transformer(producer))
|
||||
val consumer = newActor(() => new Consumer3(mediator))
|
||||
val producer = actorOf[Producer1]
|
||||
val mediator = actorOf(new Transformer(producer))
|
||||
val consumer = actorOf(new Consumer3(mediator))
|
||||
|
||||
producer.start
|
||||
mediator.start
|
||||
|
|
@ -55,12 +55,15 @@ class Boot {
|
|||
//val cometdPublisher = new Publisher("cometd-publisher", cometdUri).start
|
||||
|
||||
val jmsUri = "jms:topic:test"
|
||||
val jmsSubscriber1 = newActor(() => new Subscriber("jms-subscriber-1", jmsUri)).start
|
||||
val jmsSubscriber2 = newActor(() => new Subscriber("jms-subscriber-2", jmsUri)).start
|
||||
val jmsPublisher = newActor(() => new Publisher("jms-publisher", jmsUri)).start
|
||||
val jmsSubscriber1 = actorOf(new Subscriber("jms-subscriber-1", jmsUri)).start
|
||||
val jmsSubscriber2 = actorOf(new Subscriber("jms-subscriber-2", jmsUri)).start
|
||||
val jmsPublisher = actorOf(new Publisher("jms-publisher", jmsUri)).start
|
||||
|
||||
//val cometdPublisherBridge = newActor(() => new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/cometd", cometdPublisher)).start
|
||||
val jmsPublisherBridge = newActor(() => new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/jms", jmsPublisher)).start
|
||||
//val cometdPublisherBridge = new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/cometd", cometdPublisher).start
|
||||
val jmsPublisherBridge = actorOf(new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/jms", jmsPublisher)).start
|
||||
|
||||
actorOf[Consumer4].start // POSTing "stop" to http://0.0.0.0:8877/camel/stop stops and unpublishes this actor
|
||||
actorOf[Consumer5].start // POSTing any msg to http://0.0.0.0:8877/camel/start starts and published Consumer4 again.
|
||||
}
|
||||
|
||||
class CustomRouteBuilder extends RouteBuilder {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Then to run the sample:
|
|||
4. In the first REPL you get execute:
|
||||
- scala> import sample.chat._
|
||||
- scala> import se.scalablesolutions.akka.actor.Actor._
|
||||
- scala> val chatService = newActor[ChatService].start
|
||||
- scala> val chatService = actorOf[ChatService].start
|
||||
5. In the second REPL you get execute:
|
||||
- scala> import sample.chat._
|
||||
- scala> Runner.run
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ Then to run the sample:
|
|||
2. In the first REPL you get execute:
|
||||
- scala> import sample.chat._
|
||||
- scala> import se.scalablesolutions.akka.actor.Actor._
|
||||
- scala> val chatService = newActor[ChatService].start
|
||||
- scala> val chatService = actorOf[ChatService].start
|
||||
3. In the second REPL you get execute:
|
||||
- scala> import sample.chat._
|
||||
- scala> Runner.run
|
||||
|
|
@ -130,7 +130,7 @@ trait SessionManagement { this: Actor =>
|
|||
protected def sessionManagement: PartialFunction[Any, Unit] = {
|
||||
case Login(username) =>
|
||||
log.info("User [%s] has logged in", username)
|
||||
val session = newActor(() => new Session(username, storage))
|
||||
val session = actorOf(new Session(username, storage))
|
||||
session.start
|
||||
sessions += (username -> session)
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ trait ChatServer extends Actor {
|
|||
* Class encapsulating the full Chat Service.
|
||||
* Start service by invoking:
|
||||
* <pre>
|
||||
* val chatService = Actor.newActor[ChatService].start
|
||||
* val chatService = Actor.actorOf[ChatService].start
|
||||
* </pre>
|
||||
*/
|
||||
class ChatService extends
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ class Boot extends Logging {
|
|||
SupervisorConfig(
|
||||
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
|
||||
Supervise(
|
||||
newActor[SimpleService],
|
||||
actorOf[SimpleService],
|
||||
LifeCycle(Permanent)) ::
|
||||
Supervise(
|
||||
newActor[PersistentSimpleService],
|
||||
actorOf[PersistentSimpleService],
|
||||
LifeCycle(Permanent)) ::
|
||||
Nil))
|
||||
factory.newInstance.start
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ import se.scalablesolutions.akka.actor.Actor._
|
|||
object Pub {
|
||||
println("starting publishing service ..")
|
||||
val r = new RedisClient("localhost", 6379)
|
||||
val p = newActor(() => new Publisher(r))
|
||||
val p = actorOf(new Publisher(r))
|
||||
p.start
|
||||
|
||||
def publish(channel: String, message: String) = {
|
||||
|
|
@ -63,7 +63,7 @@ object Pub {
|
|||
object Sub {
|
||||
println("starting subscription service ..")
|
||||
val r = new RedisClient("localhost", 6379)
|
||||
val s = newActor(() => new Subscriber(r))
|
||||
val s = actorOf(new Subscriber(r))
|
||||
s.start
|
||||
s ! Register(callback)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ To run the sample:
|
|||
- Step down into to the root of the Akka distribution.
|
||||
- Set 'export AKKA_HOME=<root of distribution>.
|
||||
- Run 'sbt'
|
||||
- Run 'update' followed by 'compile' if you have not done that before.
|
||||
- Run 'project akka-sample-remote'
|
||||
- Run 'console' to start up a REPL (interpreter).
|
||||
2. In the first REPL you get execute:
|
||||
|
|
@ -39,6 +40,7 @@ To run the sample:
|
|||
- Step down into to the root of the Akka distribution.
|
||||
- Set 'export AKKA_HOME=<root of distribution>.
|
||||
- Run 'sbt'
|
||||
- Run 'update' followed by 'compile' if you have not done that before.
|
||||
- Run 'project akka-sample-remote'
|
||||
- Run 'console' to start up a REPL (interpreter).
|
||||
2. In the first REPL you get execute:
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ object ClientManagedRemoteActorServer extends Logging {
|
|||
object ClientManagedRemoteActorClient extends Logging {
|
||||
|
||||
def run = {
|
||||
val actor = newActor[RemoteHelloWorldActor].start
|
||||
val actor = actorOf[RemoteHelloWorldActor].start
|
||||
log.info("Remote actor created, moved to the server")
|
||||
log.info("Sending 'Hello' to remote actor")
|
||||
val result = actor !! "Hello"
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ object ServerManagedRemoteActorServer extends Logging {
|
|||
def run = {
|
||||
RemoteNode.start("localhost", 9999)
|
||||
log.info("Remote node started")
|
||||
RemoteNode.register("hello-service", newActor[HelloWorldActor].start)
|
||||
RemoteNode.register("hello-service", actorOf[HelloWorldActor])
|
||||
log.info("Remote actor registered and started")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ class Boot {
|
|||
SupervisorConfig(
|
||||
RestartStrategy(OneForOne, 3, 100,List(classOf[Exception])),
|
||||
Supervise(
|
||||
newActor[SimpleService],
|
||||
actorOf[SimpleService],
|
||||
LifeCycle(Permanent)) ::
|
||||
Supervise(
|
||||
newActor[Chat],
|
||||
actorOf[Chat],
|
||||
LifeCycle(Permanent)) ::
|
||||
Supervise(
|
||||
newActor[PersistentSimpleService],
|
||||
actorOf[PersistentSimpleService],
|
||||
LifeCycle(Permanent)) ::
|
||||
Supervise(
|
||||
newActor[PubSub],
|
||||
actorOf[PubSub],
|
||||
LifeCycle(Permanent))
|
||||
:: Nil))
|
||||
factory.newInstance.start
|
||||
|
|
|
|||
|
|
@ -18,18 +18,18 @@ class Boot {
|
|||
// Dummy implementations of all authentication actors
|
||||
// see akka.conf to enable one of these for the AkkaSecurityFilterFactory
|
||||
Supervise(
|
||||
newActor[BasicAuthenticationService],
|
||||
actorOf[BasicAuthenticationService],
|
||||
LifeCycle(Permanent)) ::
|
||||
/**
|
||||
Supervise(
|
||||
newActor[DigestAuthenticationService],
|
||||
actorOf[DigestAuthenticationService],
|
||||
LifeCycle(Permanent)) ::
|
||||
Supervise(
|
||||
newActor[SpnegoAuthenticationService],
|
||||
actorOf[SpnegoAuthenticationService],
|
||||
LifeCycle(Permanent)) ::
|
||||
**/
|
||||
Supervise(
|
||||
newActor[SecureTickActor],
|
||||
actorOf[SecureTickActor],
|
||||
LifeCycle(Permanent)):: Nil))
|
||||
|
||||
val supervisor = factory.newInstance
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
|
|||
// val configgy = "Configgy" at "http://www.lag.net/repo"
|
||||
val codehaus = "Codehaus" at "http://repository.codehaus.org"
|
||||
val codehaus_snapshots = "Codehaus Snapshots" at "http://snapshots.repository.codehaus.org"
|
||||
val jboss = "jBoss" at "http://repository.jboss.org/maven2"
|
||||
val jboss = "jBoss" at "https://repository.jboss.org/nexus/content/groups/public/"
|
||||
val guiceyfruit = "GuiceyFruit" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
|
||||
val google = "Google" at "http://google-maven-repository.googlecode.com/svn/repository"
|
||||
val java_net = "java.net" at "http://download.java.net/maven/2"
|
||||
|
|
@ -136,7 +136,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
|
|||
// ------------------------------------------------------------
|
||||
// subprojects
|
||||
class AkkaCoreProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
|
||||
val netty = "org.jboss.netty" % "netty" % "3.2.0.BETA1" % "compile"
|
||||
val netty = "org.jboss.netty" % "netty" % "3.2.0.CR1" % "compile"
|
||||
val commons_io = "commons-io" % "commons-io" % "1.4" % "compile"
|
||||
val dispatch_json = "net.databinder" % "dispatch-json_2.8.0.Beta1" % "0.6.6" % "compile"
|
||||
val dispatch_http = "net.databinder" % "dispatch-http_2.8.0.Beta1" % "0.6.6" % "compile"
|
||||
|
|
@ -150,7 +150,8 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
|
|||
val werkz = "org.codehaus.aspectwerkz" % "aspectwerkz-nodeps-jdk5" % "2.1" % "compile"
|
||||
val werkz_core = "org.codehaus.aspectwerkz" % "aspectwerkz-jdk5" % "2.1" % "compile"
|
||||
val configgy = "net.lag" % "configgy" % "2.8.0.Beta1-1.5-SNAPSHOT" % "compile"
|
||||
val guicey = "org.guiceyfruit" % "guice-core" % "2.0-beta-4" % "compile"
|
||||
val guicey = "org.guiceyfruit" % "guice-all" % "2.0" % "compile"
|
||||
val aopalliance = "aopalliance" % "aopalliance" % "1.0" % "compile"
|
||||
val protobuf = "com.google.protobuf" % "protobuf-java" % "2.2.0" % "compile"
|
||||
val multiverse = "org.multiverse" % "multiverse-alpha" % "0.5" % "compile"
|
||||
|
||||
|
|
@ -209,8 +210,8 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
|
|||
|
||||
class AkkaCassandraProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
|
||||
val cassandra = "org.apache.cassandra" % "cassandra" % CASSANDRA_VERSION % "compile"
|
||||
val slf4j = "org.slf4j" % "slf4j-api" % "1.5.8" % "compile"
|
||||
val slf4j_log4j = "org.slf4j" % "slf4j-log4j12" % "1.5.8" % "compile"
|
||||
val slf4j = "org.slf4j" % "slf4j-api" % "1.6.0" % "compile"
|
||||
val slf4j_log4j = "org.slf4j" % "slf4j-log4j12" % "1.6.0" % "compile"
|
||||
val log4j = "log4j" % "log4j" % "1.2.15" % "compile"
|
||||
// testing
|
||||
val high_scale = "org.apache.cassandra" % "high-scale-lib" % CASSANDRA_VERSION % "test"
|
||||
|
|
@ -337,6 +338,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
|
|||
mainResources +++
|
||||
mainDependencies.scalaJars +++
|
||||
descendents(info.projectPath, "*.conf") +++
|
||||
descendents(info.projectPath / "scripts", "run_akka.sh") +++
|
||||
descendents(info.projectPath / "dist", "*.jar") +++
|
||||
descendents(info.projectPath / "deploy", "*.jar") +++
|
||||
descendents(path("lib") ##, "*.jar") +++
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue