newActor(() => refactored

This commit is contained in:
Viktor Klang 2010-05-08 15:59:11 +02:00
parent 57e46e2ecc
commit ae6eb54ee9
20 changed files with 53 additions and 53 deletions

View file

@ -94,7 +94,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,
@ -117,7 +117,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,

View file

@ -21,7 +21,7 @@ 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 publishRequestor = actorOf(new PublishRequestor(consumerPublisher))
/**
* Starts the CamelService. Any started actor that is a consumer actor will be (asynchronously)

View file

@ -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")

View file

@ -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 {
timeout = 1
})
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)

View file

@ -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,7 +61,7 @@ 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
when("requests are sent to these actors")
service.consumerPublisher.actor.asInstanceOf[ConsumerPublisher].awaitPublish

View file

@ -24,12 +24,12 @@ class PublishRequestorTest extends JUnitSuite {
@After def tearDown = ActorRegistry.shutdownAll
@Test def shouldReceivePublishRequestOnActorRegisteredEvent = {
val consumer = newActor(() => new Actor with Consumer {
val 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))
val publisher = actorOf(new PublisherMock with Countdown[Publish])
val requestor = actorOf(new PublishRequestor(publisher))
publisher.start
requestor.start
requestor.!(ActorRegistered(consumer))(None)

View file

@ -97,13 +97,13 @@ object Actor extends Logging {
* 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 ActorRef(factory)
def actorOf(factory: => Actor): ActorRef = new ActorRef(() => factory)
/**
* Use to create an anonymous event-driven actor.
@ -288,7 +288,7 @@ object ActorRef {
* <pre>
* import Actor._
*
* val actor = newActor(() => new MyActor(...))
* val actor = actorOf(new MyActor(...))
* actor.start
* actor ! message
* actor.stop

View file

@ -27,7 +27,7 @@ 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 {
start
val seq = actors
})
@ -35,7 +35,7 @@ object Patterns {
/** 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 {
start
override def transform(msg: Any) = msgTransformer(msg)
def routes = routing
@ -43,7 +43,7 @@ object Patterns {
/** 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 {
start
def routes = routing
})

View file

@ -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
}
@ -98,7 +98,7 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
}
}
private[this] val in = newActor(() => new In(this))
private[this] val in = actorOf(new In(this))
def <<(ref: DataFlowVariable[T]) = in ! Set(ref())
@ -108,7 +108,7 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
val ref = value.get
if (ref.isDefined) ref.get
else {
val out = newActor(() => new Out(this))
val out = actorOf(new Out(this))
blockedReaders.offer(out)
val result = out !! Get
out ! Exit

View file

@ -48,7 +48,7 @@ class ActorFireForgetRequestReplySpec extends JUnitSuite {
state.finished.reset
val replyActor = newActor[ReplyActor]
replyActor.start
val senderActor = newActor(() => new SenderActor(replyActor))
val senderActor = actorOf(new SenderActor(replyActor))
senderActor.start
senderActor ! "Init"
try { state.finished.await(1L, TimeUnit.SECONDS) }
@ -61,7 +61,7 @@ class ActorFireForgetRequestReplySpec extends JUnitSuite {
state.finished.reset
val replyActor = newActor[ReplyActor]
replyActor.start
val senderActor = newActor(() => new SenderActor(replyActor))
val senderActor = actorOf(new SenderActor(replyActor))
senderActor.start
senderActor ! "InitImplicit"
try { state.finished.await(1L, TimeUnit.SECONDS) }

View file

@ -87,7 +87,7 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
@Test def testListener = {
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")
}

View file

@ -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) {

View file

@ -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

View file

@ -110,7 +110,7 @@ class InMemFailerActor extends Actor {
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
@ -130,7 +130,7 @@ 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]
failer.start
@ -157,7 +157,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
@ -177,7 +177,7 @@ 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)
@ -205,7 +205,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
@ -225,7 +225,7 @@ 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)

View file

@ -26,7 +26,7 @@ class ReactorBasedThreadPoolEventDrivenDispatcherActorSpec extends JUnitSuite {
@Test def shouldSendOneWay = {
val oneWay = new CountDownLatch(1)
val actor = newActor(() => new Actor {
val actor = actorOf(new Actor {
dispatcher = Dispatchers.newReactorBasedThreadPoolEventDrivenDispatcher(uuid)
def receive = {
case "OneWay" => oneWay.countDown

View file

@ -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 {
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
def receive = {
case "OneWay" => oneWay.countDown

View file

@ -14,9 +14,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

View file

@ -35,8 +35,8 @@ class Boot {
// Routing example
val producer = newActor[Producer1]
val mediator = newActor(() => new Transformer(producer))
val consumer = newActor(() => new Consumer3(mediator))
val mediator = actorOf(new Transformer(producer))
val consumer = actorOf(new Consumer3(mediator))
producer.start
mediator.start
@ -55,9 +55,9 @@ 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 = new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/cometd", cometdPublisher).start
val jmsPublisherBridge = new PublisherBridge("jetty:http://0.0.0.0:8877/camel/pub/jms", jmsPublisher).start

View file

@ -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)

View file

@ -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)