Renaming createActor to actorOf
This commit is contained in:
parent
3f258f8b63
commit
474787a81d
68 changed files with 343 additions and 343 deletions
|
|
@ -12,12 +12,12 @@ public class JavaAPI {
|
|||
private AkkaApplication app = new AkkaApplication();
|
||||
|
||||
@Test void mustBeAbleToCreateActorRefFromClass() {
|
||||
ActorRef ref = app.createActor(JavaAPITestActor.class);
|
||||
ActorRef ref = app.actorOf(JavaAPITestActor.class);
|
||||
assertNotNull(ref);
|
||||
}
|
||||
|
||||
@Test void mustBeAbleToCreateActorRefFromFactory() {
|
||||
ActorRef ref = app.createActor(new Props().withCreator(new Creator<Actor>() {
|
||||
ActorRef ref = app.actorOf(new Props().withCreator(new Creator<Actor>() {
|
||||
public Actor create() {
|
||||
return new JavaAPITestActor();
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ public class JavaAPI {
|
|||
}
|
||||
|
||||
@Test void mustAcceptSingleArgTryTell() {
|
||||
ActorRef ref = app.createActor(JavaAPITestActor.class);
|
||||
ActorRef ref = app.actorOf(JavaAPITestActor.class);
|
||||
ref.tryTell("hallo");
|
||||
ref.tryTell("hallo", ref);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,16 +65,16 @@ class ActorFireForgetRequestReplySpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
"An Actor" must {
|
||||
|
||||
"reply to bang message using reply" in {
|
||||
val replyActor = createActor[ReplyActor]
|
||||
val senderActor = createActor(new SenderActor(replyActor))
|
||||
val replyActor = actorOf[ReplyActor]
|
||||
val senderActor = actorOf(new SenderActor(replyActor))
|
||||
senderActor ! "Init"
|
||||
state.finished.await
|
||||
state.s must be("Reply")
|
||||
}
|
||||
|
||||
"reply to bang message using implicit sender" in {
|
||||
val replyActor = createActor[ReplyActor]
|
||||
val senderActor = createActor(new SenderActor(replyActor))
|
||||
val replyActor = actorOf[ReplyActor]
|
||||
val senderActor = actorOf(new SenderActor(replyActor))
|
||||
senderActor ! "InitImplicit"
|
||||
state.finished.await
|
||||
state.s must be("ReplyImplicit")
|
||||
|
|
@ -82,8 +82,8 @@ class ActorFireForgetRequestReplySpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"should shutdown crashed temporary actor" in {
|
||||
filterEvents(EventFilter[Exception]("Expected")) {
|
||||
val supervisor = createActor(Props[Supervisor].withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
val actor = createActor(Props[CrashingActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props[Supervisor].withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
val actor = actorOf(Props[CrashingActor].withSupervisor(supervisor))
|
||||
actor.isShutdown must be(false)
|
||||
actor ! "Die"
|
||||
state.finished.await
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ class ActorLifeCycleSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitS
|
|||
"invoke preRestart, preStart, postRestart when using OneForOneStrategy" in {
|
||||
filterException[ActorKilledException] {
|
||||
val id = newUuid().toString
|
||||
val supervisor = createActor(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val supervisor = actorOf(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val gen = new AtomicInteger(0)
|
||||
val restarter = createActor(Props(new LifeCycleTestActor(id, gen) {
|
||||
val restarter = actorOf(Props(new LifeCycleTestActor(id, gen) {
|
||||
override def preRestart(reason: Throwable, message: Option[Any]) { report("preRestart") }
|
||||
override def postRestart(reason: Throwable) { report("postRestart") }
|
||||
}).withSupervisor(supervisor))
|
||||
|
|
@ -66,9 +66,9 @@ class ActorLifeCycleSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitS
|
|||
"default for preRestart and postRestart is to call postStop and preStart respectively" in {
|
||||
filterException[ActorKilledException] {
|
||||
val id = newUuid().toString
|
||||
val supervisor = createActor(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val supervisor = actorOf(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val gen = new AtomicInteger(0)
|
||||
val restarter = createActor(Props(new LifeCycleTestActor(id, gen)).withSupervisor(supervisor))
|
||||
val restarter = actorOf(Props(new LifeCycleTestActor(id, gen)).withSupervisor(supervisor))
|
||||
|
||||
expectMsg(("preStart", id, 0))
|
||||
restarter ! Kill
|
||||
|
|
@ -95,9 +95,9 @@ class ActorLifeCycleSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitS
|
|||
|
||||
"not invoke preRestart and postRestart when never restarted using OneForOneStrategy" in {
|
||||
val id = newUuid().toString
|
||||
val supervisor = createActor(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val supervisor = actorOf(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(3))))
|
||||
val gen = new AtomicInteger(0)
|
||||
val a = createActor(Props(new LifeCycleTestActor(id, gen)).withSupervisor(supervisor))
|
||||
val a = actorOf(Props(new LifeCycleTestActor(id, gen)).withSupervisor(supervisor))
|
||||
expectMsg(("preStart", id, 0))
|
||||
a ! "status"
|
||||
expectMsg(("OK", id, 0))
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ object ActorRefSpec {
|
|||
def receive = {
|
||||
case "complexRequest" ⇒ {
|
||||
replyTo = channel
|
||||
val worker = context.createActor(Props[WorkerActor])
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
worker ! "work"
|
||||
}
|
||||
case "complexRequest2" ⇒
|
||||
val worker = context.createActor(Props[WorkerActor])
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
worker ! ReplyTo(channel)
|
||||
case "workDone" ⇒ replyTo ! "complexReply"
|
||||
case "simpleRequest" ⇒ reply("simpleReply")
|
||||
|
|
@ -135,7 +135,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
|
||||
"An ActorRef" must {
|
||||
|
||||
"not allow Actors to be created outside of an createActor" in {
|
||||
"not allow Actors to be created outside of an actorOf" in {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
new Actor { def receive = { case _ ⇒ } }
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
filterException[akka.actor.ActorInitializationException] {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
val nested = promiseIntercept(new Actor { def receive = { case _ ⇒ } })(result)
|
||||
def receive = { case _ ⇒ }
|
||||
}))
|
||||
|
|
@ -155,49 +155,49 @@ class ActorRefSpec extends AkkaSpec {
|
|||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(promiseIntercept(new FailingOuterActor(createActor(new InnerActor)))(result)))
|
||||
actorOf(promiseIntercept(new FailingOuterActor(actorOf(new InnerActor)))(result)))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new OuterActor(createActor(promiseIntercept(new FailingInnerActor)(result)))))
|
||||
actorOf(new OuterActor(actorOf(promiseIntercept(new FailingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(promiseIntercept(new FailingInheritingOuterActor(createActor(new InnerActor)))(result)))
|
||||
actorOf(promiseIntercept(new FailingInheritingOuterActor(actorOf(new InnerActor)))(result)))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new FailingOuterActor(createActor(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
actorOf(new FailingOuterActor(actorOf(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new FailingInheritingOuterActor(createActor(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
actorOf(new FailingInheritingOuterActor(actorOf(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new FailingInheritingOuterActor(createActor(promiseIntercept(new FailingInnerActor)(result)))))
|
||||
actorOf(new FailingInheritingOuterActor(actorOf(promiseIntercept(new FailingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new OuterActor(createActor(new InnerActor {
|
||||
actorOf(new OuterActor(actorOf(new InnerActor {
|
||||
val a = promiseIntercept(new InnerActor)(result)
|
||||
}))))
|
||||
}
|
||||
|
|
@ -206,21 +206,21 @@ class ActorRefSpec extends AkkaSpec {
|
|||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new FailingOuterActor(createActor(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
actorOf(new FailingOuterActor(actorOf(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new OuterActor(createActor(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
actorOf(new OuterActor(actorOf(promiseIntercept(new FailingInheritingInnerActor)(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
createActor(new OuterActor(createActor(promiseIntercept({ new InnerActor; new InnerActor })(result)))))
|
||||
actorOf(new OuterActor(actorOf(promiseIntercept({ new InnerActor; new InnerActor })(result)))))
|
||||
}
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
|
@ -229,7 +229,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
filterException[java.lang.IllegalStateException] {
|
||||
(intercept[java.lang.IllegalStateException] {
|
||||
wrap(result ⇒
|
||||
createActor(new OuterActor(createActor(promiseIntercept({ throw new IllegalStateException("Ur state be b0rked"); new InnerActor })(result)))))
|
||||
actorOf(new OuterActor(actorOf(promiseIntercept({ throw new IllegalStateException("Ur state be b0rked"); new InnerActor })(result)))))
|
||||
}).getMessage must be === "Ur state be b0rked"
|
||||
|
||||
contextStackMustBeEmpty
|
||||
|
|
@ -237,7 +237,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"be serializable using Java Serialization on local node" in {
|
||||
val a = createActor[InnerActor]
|
||||
val a = actorOf[InnerActor]
|
||||
|
||||
import java.io._
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"throw an exception on deserialize if no app in scope" in {
|
||||
val a = createActor[InnerActor]
|
||||
val a = actorOf[InnerActor]
|
||||
|
||||
import java.io._
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
|
||||
"must throw exception on deserialize if not present in local registry and remoting is not enabled" in {
|
||||
val latch = new CountDownLatch(1)
|
||||
val a = createActor(new InnerActor {
|
||||
val a = actorOf(new InnerActor {
|
||||
override def postStop {
|
||||
// app.registry.unregister(self)
|
||||
latch.countDown
|
||||
|
|
@ -318,9 +318,9 @@ class ActorRefSpec extends AkkaSpec {
|
|||
}
|
||||
}
|
||||
|
||||
"support nested createActors" in {
|
||||
val a = createActor(new Actor {
|
||||
val nested = createActor(new Actor { def receive = { case _ ⇒ } })
|
||||
"support nested actorOfs" in {
|
||||
val a = actorOf(new Actor {
|
||||
val nested = actorOf(new Actor { def receive = { case _ ⇒ } })
|
||||
def receive = { case _ ⇒ reply(nested) }
|
||||
})
|
||||
|
||||
|
|
@ -330,8 +330,8 @@ class ActorRefSpec extends AkkaSpec {
|
|||
(a ne nested) must be === true
|
||||
}
|
||||
|
||||
"support advanced nested createActors" in {
|
||||
val a = createActor(Props(new OuterActor(createActor(Props(new InnerActor)))))
|
||||
"support advanced nested actorOfs" in {
|
||||
val a = actorOf(Props(new OuterActor(actorOf(Props(new InnerActor)))))
|
||||
val inner = (a ? "innerself").as[Any].get
|
||||
|
||||
(a ? a).as[ActorRef].get must be(a)
|
||||
|
|
@ -342,8 +342,8 @@ class ActorRefSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"support reply via channel" in {
|
||||
val serverRef = createActor(Props[ReplyActor])
|
||||
val clientRef = createActor(Props(new SenderActor(serverRef)))
|
||||
val serverRef = actorOf(Props[ReplyActor])
|
||||
val clientRef = actorOf(Props(new SenderActor(serverRef)))
|
||||
|
||||
clientRef ! "complex"
|
||||
clientRef ! "simple"
|
||||
|
|
@ -367,7 +367,7 @@ class ActorRefSpec extends AkkaSpec {
|
|||
|
||||
"stop when sent a poison pill" in {
|
||||
val timeout = Timeout(20000)
|
||||
val ref = createActor(Props(new Actor {
|
||||
val ref = actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case 5 ⇒ tryReply("five")
|
||||
case null ⇒ tryReply("null")
|
||||
|
|
@ -392,9 +392,9 @@ class ActorRefSpec extends AkkaSpec {
|
|||
filterException[ActorKilledException] {
|
||||
val latch = new CountDownLatch(2)
|
||||
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
|
||||
val ref = createActor(
|
||||
val ref = actorOf(
|
||||
Props(new Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
override def preRestart(reason: Throwable, msg: Option[Any]) = latch.countDown()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import akka.testkit.AkkaSpec
|
|||
|
||||
class ActorTimeoutSpec extends AkkaSpec with BeforeAndAfterAll {
|
||||
|
||||
def actorWithTimeout(t: Timeout): ActorRef = createActor(Props(creator = () ⇒ new Actor {
|
||||
def actorWithTimeout(t: Timeout): ActorRef = actorOf(Props(creator = () ⇒ new Actor {
|
||||
def receive = {
|
||||
case x ⇒
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ object Chameneos {
|
|||
var numFaded = 0
|
||||
|
||||
override def preStart() = {
|
||||
for (i ← 0 until numChameneos) context.createActor(new Chameneo(self, colours(i % 3), i))
|
||||
for (i ← 0 until numChameneos) context.actorOf(new Chameneo(self, colours(i % 3), i))
|
||||
}
|
||||
|
||||
def receive = {
|
||||
|
|
@ -109,7 +109,7 @@ object Chameneos {
|
|||
def run {
|
||||
// System.setProperty("akka.config", "akka.conf")
|
||||
Chameneos.start = System.currentTimeMillis
|
||||
AkkaApplication().createActor(new Mall(1000000, 4))
|
||||
AkkaApplication().actorOf(new Mall(1000000, 4))
|
||||
Thread.sleep(10000)
|
||||
println("Elapsed: " + (end - start))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
|
|||
}
|
||||
|
||||
"notify with one Terminated message when an Actor is stopped" in {
|
||||
val terminal = createActor(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
val terminal = actorOf(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
|
||||
testActor startsMonitoring terminal
|
||||
|
||||
|
|
@ -29,8 +29,8 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
|
|||
}
|
||||
|
||||
"notify with all monitors with one Terminated message when an Actor is stopped" in {
|
||||
val monitor1, monitor2 = createActor(Props(context ⇒ { case t: Terminated ⇒ testActor ! t }))
|
||||
val terminal = createActor(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
val monitor1, monitor2 = actorOf(Props(context ⇒ { case t: Terminated ⇒ testActor ! t }))
|
||||
val terminal = actorOf(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
|
||||
monitor1 startsMonitoring terminal
|
||||
monitor2 startsMonitoring terminal
|
||||
|
|
@ -48,8 +48,8 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
|
|||
}
|
||||
|
||||
"notify with _current_ monitors with one Terminated message when an Actor is stopped" in {
|
||||
val monitor1, monitor2 = createActor(Props(context ⇒ { case t: Terminated ⇒ testActor ! t }))
|
||||
val terminal = createActor(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
val monitor1, monitor2 = actorOf(Props(context ⇒ { case t: Terminated ⇒ testActor ! t }))
|
||||
val terminal = actorOf(Props(context ⇒ { case _ ⇒ context.self.stop() }))
|
||||
|
||||
monitor1 startsMonitoring terminal
|
||||
monitor2 startsMonitoring terminal
|
||||
|
|
@ -69,8 +69,8 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
|
|||
|
||||
"notify with a Terminated message once when an Actor is stopped but not when restarted" in {
|
||||
filterException[ActorKilledException] {
|
||||
val supervisor = createActor(Props(context ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(2))))
|
||||
val terminal = createActor(Props(context ⇒ { case x ⇒ context.channel ! x }).withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(context ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(2))))
|
||||
val terminal = actorOf(Props(context ⇒ { case x ⇒ context.channel ! x }).withSupervisor(supervisor))
|
||||
|
||||
testActor startsMonitoring terminal
|
||||
|
||||
|
|
|
|||
|
|
@ -107,9 +107,9 @@ class FSMActorSpec extends AkkaSpec(Configuration("akka.actor.debug.fsm" -> true
|
|||
"unlock the lock" in {
|
||||
|
||||
// lock that locked after being open for 1 sec
|
||||
val lock = createActor(new Lock("33221", 1 second))
|
||||
val lock = actorOf(new Lock("33221", 1 second))
|
||||
|
||||
val transitionTester = createActor(new Actor {
|
||||
val transitionTester = actorOf(new Actor {
|
||||
def receive = {
|
||||
case Transition(_, _, _) ⇒ transitionCallBackLatch.open
|
||||
case CurrentState(_, Locked) ⇒ initialStateLatch.open
|
||||
|
|
@ -141,7 +141,7 @@ class FSMActorSpec extends AkkaSpec(Configuration("akka.actor.debug.fsm" -> true
|
|||
val answerLatch = TestLatch()
|
||||
object Hello
|
||||
object Bye
|
||||
val tester = createActor(new Actor {
|
||||
val tester = actorOf(new Actor {
|
||||
protected def receive = {
|
||||
case Hello ⇒ lock ! "hello"
|
||||
case "world" ⇒ answerLatch.open
|
||||
|
|
@ -162,7 +162,7 @@ class FSMActorSpec extends AkkaSpec(Configuration("akka.actor.debug.fsm" -> true
|
|||
case Ev("go") ⇒ goto(2)
|
||||
}
|
||||
})
|
||||
val logger = createActor(new Actor {
|
||||
val logger = actorOf(new Actor {
|
||||
def receive = {
|
||||
case x ⇒ testActor forward x
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ class FSMActorSpec extends AkkaSpec(Configuration("akka.actor.debug.fsm" -> true
|
|||
case x ⇒ testActor ! x
|
||||
}
|
||||
}
|
||||
val ref = createActor(fsm)
|
||||
val ref = actorOf(fsm)
|
||||
started.await
|
||||
ref.stop()
|
||||
expectMsg(1 second, fsm.StopEvent(Shutdown, 1, null))
|
||||
|
|
@ -217,7 +217,7 @@ class FSMActorSpec extends AkkaSpec(Configuration("akka.actor.debug.fsm" -> true
|
|||
case StopEvent(r, _, _) ⇒ testActor ! r
|
||||
}
|
||||
})
|
||||
val logger = createActor(new Actor {
|
||||
val logger = actorOf(new Actor {
|
||||
def receive = {
|
||||
case x ⇒ testActor forward x
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
import FSMTimingSpec._
|
||||
import FSM._
|
||||
|
||||
val fsm = createActor(new StateMachine(testActor))
|
||||
val fsm = actorOf(new StateMachine(testActor))
|
||||
fsm ! SubscribeTransitionCallBack(testActor)
|
||||
expectMsg(200 millis, CurrentState(fsm, Initial))
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
|
|||
"A FSM transition notifier" must {
|
||||
|
||||
"notify listeners" in {
|
||||
val fsm = createActor(new MyFSM(testActor))
|
||||
val fsm = actorOf(new MyFSM(testActor))
|
||||
within(1 second) {
|
||||
fsm ! SubscribeTransitionCallBack(testActor)
|
||||
expectMsg(CurrentState(fsm, 0))
|
||||
|
|
@ -54,9 +54,9 @@ class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
|
|||
}
|
||||
|
||||
"not fail when listener goes away" in {
|
||||
val forward = createActor(new Forwarder(testActor))
|
||||
val sup = createActor(Props[Supervisor].withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, None)))
|
||||
val fsm = sup startsMonitoring createActor(new MyFSM(testActor))
|
||||
val forward = actorOf(new Forwarder(testActor))
|
||||
val sup = actorOf(Props[Supervisor].withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, None)))
|
||||
val fsm = sup startsMonitoring actorOf(new MyFSM(testActor))
|
||||
within(300 millis) {
|
||||
fsm ! SubscribeTransitionCallBack(forward)
|
||||
expectMsg(CurrentState(fsm, 0))
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ object ForwardActorSpec {
|
|||
val ExpectedMessage = "FOO"
|
||||
|
||||
def createForwardingChain(app: AkkaApplication): ActorRef = {
|
||||
val replier = app.createActor(new Actor {
|
||||
val replier = app.actorOf(new Actor {
|
||||
def receive = { case x ⇒ reply(x) }
|
||||
})
|
||||
|
||||
def mkforwarder(forwardTo: ActorRef) = app.createActor(
|
||||
def mkforwarder(forwardTo: ActorRef) = app.actorOf(
|
||||
new Actor {
|
||||
def receive = { case x ⇒ forwardTo forward x }
|
||||
})
|
||||
|
|
@ -35,7 +35,7 @@ class ForwardActorSpec extends AkkaSpec {
|
|||
"forward actor reference when invoking forward on bang" in {
|
||||
val latch = new TestLatch(1)
|
||||
|
||||
val replyTo = createActor(new Actor { def receive = { case ExpectedMessage ⇒ latch.countDown() } })
|
||||
val replyTo = actorOf(new Actor { def receive = { case ExpectedMessage ⇒ latch.countDown() } })
|
||||
|
||||
val chain = createForwardingChain(app)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class HotSwapSpec extends AkkaSpec {
|
|||
val barrier = TestBarrier(2)
|
||||
@volatile
|
||||
var _log = ""
|
||||
val a = createActor(new Actor {
|
||||
val a = actorOf(new Actor {
|
||||
def receive = { case _ ⇒ _log += "default" }
|
||||
})
|
||||
a ! HotSwap(self ⇒ {
|
||||
|
|
@ -31,7 +31,7 @@ class HotSwapSpec extends AkkaSpec {
|
|||
val barrier = TestBarrier(2)
|
||||
@volatile
|
||||
var _log = ""
|
||||
val a = createActor(new Actor {
|
||||
val a = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒
|
||||
_log += "init"
|
||||
|
|
@ -60,7 +60,7 @@ class HotSwapSpec extends AkkaSpec {
|
|||
val barrier = TestBarrier(2)
|
||||
@volatile
|
||||
var _log = ""
|
||||
val a = createActor(new Actor {
|
||||
val a = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒
|
||||
_log += "init"
|
||||
|
|
@ -106,7 +106,7 @@ class HotSwapSpec extends AkkaSpec {
|
|||
val barrier = TestBarrier(2)
|
||||
@volatile
|
||||
var _log = ""
|
||||
val a = createActor(new Actor {
|
||||
val a = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒
|
||||
_log += "init"
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ object IOActorSpec {
|
|||
started.open()
|
||||
}
|
||||
|
||||
def createWorker = context.createActor(Props(new Actor with IO {
|
||||
def createWorker = context.actorOf(Props(new Actor with IO {
|
||||
def receiveIO = {
|
||||
case NewClient(server) ⇒
|
||||
val socket = server.accept()
|
||||
|
|
@ -43,7 +43,7 @@ object IOActorSpec {
|
|||
class SimpleEchoClient(host: String, port: Int, ioManager: ActorRef) extends Actor with IO {
|
||||
|
||||
lazy val socket: SocketHandle = connect(ioManager, host, port, reader)
|
||||
lazy val reader: ActorRef = context.createActor {
|
||||
lazy val reader: ActorRef = context.actorOf {
|
||||
new Actor with IO {
|
||||
def receiveIO = {
|
||||
case length: Int ⇒
|
||||
|
|
@ -70,7 +70,7 @@ object IOActorSpec {
|
|||
started.open()
|
||||
}
|
||||
|
||||
def createWorker = context.createActor(Props(new Actor with IO {
|
||||
def createWorker = context.actorOf(Props(new Actor with IO {
|
||||
def receiveIO = {
|
||||
case NewClient(server) ⇒
|
||||
val socket = server.accept()
|
||||
|
|
@ -174,10 +174,10 @@ class IOActorSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
"an IO Actor" must {
|
||||
"run echo server" in {
|
||||
val started = TestLatch(1)
|
||||
val ioManager = createActor(new IOManager(2)) // teeny tiny buffer
|
||||
val server = createActor(new SimpleEchoServer("localhost", 8064, ioManager, started))
|
||||
val ioManager = actorOf(new IOManager(2)) // teeny tiny buffer
|
||||
val server = actorOf(new SimpleEchoServer("localhost", 8064, ioManager, started))
|
||||
started.await
|
||||
val client = createActor(new SimpleEchoClient("localhost", 8064, ioManager))
|
||||
val client = actorOf(new SimpleEchoClient("localhost", 8064, ioManager))
|
||||
val f1 = client ? ByteString("Hello World!1")
|
||||
val f2 = client ? ByteString("Hello World!2")
|
||||
val f3 = client ? ByteString("Hello World!3")
|
||||
|
|
@ -191,10 +191,10 @@ class IOActorSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"run echo server under high load" in {
|
||||
val started = TestLatch(1)
|
||||
val ioManager = createActor(new IOManager())
|
||||
val server = createActor(new SimpleEchoServer("localhost", 8065, ioManager, started))
|
||||
val ioManager = actorOf(new IOManager())
|
||||
val server = actorOf(new SimpleEchoServer("localhost", 8065, ioManager, started))
|
||||
started.await
|
||||
val client = createActor(new SimpleEchoClient("localhost", 8065, ioManager))
|
||||
val client = actorOf(new SimpleEchoClient("localhost", 8065, ioManager))
|
||||
val list = List.range(0, 1000)
|
||||
val f = Future.traverse(list)(i ⇒ client ? ByteString(i.toString))
|
||||
assert(f.get.size === 1000)
|
||||
|
|
@ -205,10 +205,10 @@ class IOActorSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"run echo server under high load with small buffer" in {
|
||||
val started = TestLatch(1)
|
||||
val ioManager = createActor(new IOManager(2))
|
||||
val server = createActor(new SimpleEchoServer("localhost", 8066, ioManager, started))
|
||||
val ioManager = actorOf(new IOManager(2))
|
||||
val server = actorOf(new SimpleEchoServer("localhost", 8066, ioManager, started))
|
||||
started.await
|
||||
val client = createActor(new SimpleEchoClient("localhost", 8066, ioManager))
|
||||
val client = actorOf(new SimpleEchoClient("localhost", 8066, ioManager))
|
||||
val list = List.range(0, 1000)
|
||||
val f = Future.traverse(list)(i ⇒ client ? ByteString(i.toString))
|
||||
assert(f.get.size === 1000)
|
||||
|
|
@ -219,11 +219,11 @@ class IOActorSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"run key-value store" in {
|
||||
val started = TestLatch(1)
|
||||
val ioManager = createActor(new IOManager(2)) // teeny tiny buffer
|
||||
val server = createActor(new KVStore("localhost", 8067, ioManager, started))
|
||||
val ioManager = actorOf(new IOManager(2)) // teeny tiny buffer
|
||||
val server = actorOf(new KVStore("localhost", 8067, ioManager, started))
|
||||
started.await
|
||||
val client1 = createActor(new KVClient("localhost", 8067, ioManager))
|
||||
val client2 = createActor(new KVClient("localhost", 8067, ioManager))
|
||||
val client1 = actorOf(new KVClient("localhost", 8067, ioManager))
|
||||
val client2 = actorOf(new KVClient("localhost", 8067, ioManager))
|
||||
val f1 = client1 ? (('set, "hello", ByteString("World")))
|
||||
val f2 = client1 ? (('set, "test", ByteString("No one will read me")))
|
||||
val f3 = client1 ? (('get, "hello"))
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
"get timeout" in {
|
||||
val timeoutLatch = TestLatch()
|
||||
|
||||
val timeoutActor = createActor(new Actor {
|
||||
val timeoutActor = actorOf(new Actor {
|
||||
receiveTimeout = Some(500L)
|
||||
|
||||
protected def receive = {
|
||||
|
|
@ -31,7 +31,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
"get timeout when swapped" in {
|
||||
val timeoutLatch = TestLatch()
|
||||
|
||||
val timeoutActor = createActor(new Actor {
|
||||
val timeoutActor = actorOf(new Actor {
|
||||
receiveTimeout = Some(500L)
|
||||
|
||||
protected def receive = {
|
||||
|
|
@ -55,7 +55,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
val timeoutLatch = TestLatch()
|
||||
case object Tick
|
||||
|
||||
val timeoutActor = createActor(new Actor {
|
||||
val timeoutActor = actorOf(new Actor {
|
||||
receiveTimeout = Some(500L)
|
||||
|
||||
protected def receive = {
|
||||
|
|
@ -75,7 +75,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
val timeoutLatch = TestLatch()
|
||||
case object Tick
|
||||
|
||||
val timeoutActor = createActor(new Actor {
|
||||
val timeoutActor = actorOf(new Actor {
|
||||
receiveTimeout = Some(500L)
|
||||
|
||||
protected def receive = {
|
||||
|
|
@ -97,7 +97,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
"not receive timeout message when not specified" in {
|
||||
val timeoutLatch = TestLatch()
|
||||
|
||||
val timeoutActor = createActor(new Actor {
|
||||
val timeoutActor = actorOf(new Actor {
|
||||
protected def receive = {
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
"A RestartStrategy" must {
|
||||
|
||||
"ensure that slave stays dead after max restarts within time range" in {
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
protected def receive = { case _ ⇒ () }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), 2, 1000)))
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
val countDownLatch = new CountDownLatch(3)
|
||||
val stopLatch = new StandardLatch
|
||||
|
||||
val slave = createActor(Props(new Actor {
|
||||
val slave = actorOf(Props(new Actor {
|
||||
|
||||
protected def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
|
|
@ -75,13 +75,13 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
"ensure that slave is immortal without max restarts and time range" in {
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
def receive = { case _ ⇒ () }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, None)))
|
||||
|
||||
val countDownLatch = new CountDownLatch(100)
|
||||
|
||||
val slave = createActor(Props(new Actor {
|
||||
val slave = actorOf(Props(new Actor {
|
||||
|
||||
protected def receive = {
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
|
|
@ -98,7 +98,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
"ensure that slave restarts after number of crashes not within time range" in {
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
def receive = { case _ ⇒ () }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), 2, 500)))
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
val pingLatch = new StandardLatch
|
||||
val secondPingLatch = new StandardLatch
|
||||
|
||||
val slave = createActor(Props(new Actor {
|
||||
val slave = actorOf(Props(new Actor {
|
||||
|
||||
protected def receive = {
|
||||
case Ping ⇒
|
||||
|
|
@ -156,7 +156,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
"ensure that slave is not restarted after max retries" in {
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
def receive = { case _ ⇒ () }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), Some(2), None)))
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
val countDownLatch = new CountDownLatch(3)
|
||||
val stopLatch = new StandardLatch
|
||||
|
||||
val slave = createActor(Props(new Actor {
|
||||
val slave = actorOf(Props(new Actor {
|
||||
|
||||
protected def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
|
|
@ -211,11 +211,11 @@ class RestartStrategySpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
val restartLatch, stopLatch, maxNoOfRestartsLatch = new StandardLatch
|
||||
val countDownLatch = new CountDownLatch(2)
|
||||
|
||||
val boss = createActor(Props(new Actor {
|
||||
val boss = actorOf(Props(new Actor {
|
||||
def receive = { case t: Terminated ⇒ maxNoOfRestartsLatch.open }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, Some(1000))))
|
||||
|
||||
val slave = createActor(Props(new Actor {
|
||||
val slave = actorOf(Props(new Actor {
|
||||
|
||||
protected def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
"schedule more than once" in {
|
||||
case object Tick
|
||||
val countDownLatch = new CountDownLatch(3)
|
||||
val tickActor = createActor(new Actor {
|
||||
val tickActor = actorOf(new Actor {
|
||||
def receive = { case Tick ⇒ countDownLatch.countDown() }
|
||||
})
|
||||
// run every 50 millisec
|
||||
|
|
@ -49,7 +49,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
"schedule once" in {
|
||||
case object Tick
|
||||
val countDownLatch = new CountDownLatch(3)
|
||||
val tickActor = createActor(new Actor {
|
||||
val tickActor = actorOf(new Actor {
|
||||
def receive = { case Tick ⇒ countDownLatch.countDown() }
|
||||
})
|
||||
// run every 50 millisec
|
||||
|
|
@ -69,7 +69,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
// "not create actors" in {
|
||||
// object Ping
|
||||
// val ticks = new CountDownLatch(1000)
|
||||
// val actor = createActor(new Actor {
|
||||
// val actor = actorOf(new Actor {
|
||||
// def receive = { case Ping ⇒ ticks.countDown }
|
||||
// })
|
||||
// val numActors = app.registry.local.actors.length
|
||||
|
|
@ -85,7 +85,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
object Ping
|
||||
val ticks = new CountDownLatch(1)
|
||||
|
||||
val actor = createActor(new Actor {
|
||||
val actor = actorOf(new Actor {
|
||||
def receive = { case Ping ⇒ ticks.countDown() }
|
||||
})
|
||||
|
||||
|
|
@ -106,8 +106,8 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
val restartLatch = new StandardLatch
|
||||
val pingLatch = new CountDownLatch(6)
|
||||
|
||||
val supervisor = createActor(Props(context ⇒ { case _ ⇒ }).withFaultHandler(AllForOneStrategy(List(classOf[Exception]), 3, 1000)))
|
||||
val actor = createActor(Props(new Actor {
|
||||
val supervisor = actorOf(Props(context ⇒ { case _ ⇒ }).withFaultHandler(AllForOneStrategy(List(classOf[Exception]), 3, 1000)))
|
||||
val actor = actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Ping ⇒ pingLatch.countDown()
|
||||
case Crash ⇒ throw new Exception("CRASH")
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ class SupervisorHierarchySpec extends AkkaSpec {
|
|||
"restart manager and workers in AllForOne" in {
|
||||
val countDown = new CountDownLatch(4)
|
||||
|
||||
val boss = createActor(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), None, None)))
|
||||
val boss = actorOf(Props(self ⇒ { case _ ⇒ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), None, None)))
|
||||
|
||||
val manager = createActor(Props(new CountDownActor(countDown)).withFaultHandler(AllForOneStrategy(List(), None, None)).withSupervisor(boss))
|
||||
val manager = actorOf(Props(new CountDownActor(countDown)).withFaultHandler(AllForOneStrategy(List(), None, None)).withSupervisor(boss))
|
||||
|
||||
val workerProps = Props(new CountDownActor(countDown)).withSupervisor(manager)
|
||||
val workerOne, workerTwo, workerThree = createActor(workerProps)
|
||||
val workerOne, workerTwo, workerThree = actorOf(workerProps)
|
||||
|
||||
filterException[ActorKilledException] {
|
||||
workerOne ! Kill
|
||||
|
|
@ -47,8 +47,8 @@ class SupervisorHierarchySpec extends AkkaSpec {
|
|||
"send notification to supervisor when permanent failure" in {
|
||||
val countDownMessages = new CountDownLatch(1)
|
||||
val countDownMax = new CountDownLatch(1)
|
||||
val boss = createActor(Props(new Actor {
|
||||
val crasher = self startsMonitoring createActor(Props(new CountDownActor(countDownMessages)).withSupervisor(self))
|
||||
val boss = actorOf(Props(new Actor {
|
||||
val crasher = self startsMonitoring actorOf(Props(new CountDownActor(countDownMessages)).withSupervisor(self))
|
||||
|
||||
protected def receive = {
|
||||
case "killCrasher" ⇒ crasher ! Kill
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class SupervisorMiscSpec extends AkkaSpec {
|
|||
filterEvents(EventFilter[Exception]("Kill")) {
|
||||
val countDownLatch = new CountDownLatch(4)
|
||||
|
||||
val supervisor = createActor(Props(new Actor {
|
||||
val supervisor = actorOf(Props(new Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), 3, 5000)))
|
||||
|
||||
|
|
@ -29,13 +29,13 @@ class SupervisorMiscSpec extends AkkaSpec {
|
|||
}
|
||||
}).withSupervisor(supervisor)
|
||||
|
||||
val actor1 = createActor(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
val actor1 = actorOf(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
|
||||
val actor2 = createActor(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
val actor2 = actorOf(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
|
||||
val actor3 = createActor(workerProps.withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val actor3 = actorOf(workerProps.withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
|
||||
val actor4 = createActor(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
val actor4 = actorOf(workerProps.withDispatcher(app.dispatcherFactory.newPinnedDispatcher("pinned")))
|
||||
|
||||
actor1 ! Kill
|
||||
actor2 ! Kill
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ object SupervisorSpec {
|
|||
|
||||
class Master extends Actor {
|
||||
|
||||
val temp = context.createActor(Props[PingPongActor].withSupervisor(self))
|
||||
val temp = context.actorOf(Props[PingPongActor].withSupervisor(self))
|
||||
|
||||
def receive = {
|
||||
case Die ⇒ (temp.?(Die, TimeoutMillis)).get
|
||||
|
|
@ -72,51 +72,51 @@ class SupervisorSpec extends AkkaSpec with BeforeAndAfterEach with BeforeAndAfte
|
|||
// =====================================================
|
||||
|
||||
def temporaryActorAllForOne = {
|
||||
val supervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
val temporaryActor = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
val temporaryActor = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
|
||||
(temporaryActor, supervisor)
|
||||
}
|
||||
|
||||
def singleActorAllForOne = {
|
||||
val supervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
|
||||
(pingpong, supervisor)
|
||||
}
|
||||
|
||||
def singleActorOneForOne = {
|
||||
val supervisor = createActor(Props(OneForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(OneForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
|
||||
(pingpong, supervisor)
|
||||
}
|
||||
|
||||
def multipleActorsAllForOne = {
|
||||
val supervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong2 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong3 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong2 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong3 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
|
||||
(pingpong1, pingpong2, pingpong3, supervisor)
|
||||
}
|
||||
|
||||
def multipleActorsOneForOne = {
|
||||
val supervisor = createActor(Props(OneForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong2 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong3 = createActor(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(OneForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong2 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
val pingpong3 = actorOf(Props[PingPongActor].withSupervisor(supervisor))
|
||||
|
||||
(pingpong1, pingpong2, pingpong3, supervisor)
|
||||
}
|
||||
|
||||
def nestedSupervisorsAllForOne = {
|
||||
val topSupervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = createActor(Props[PingPongActor].withSupervisor(topSupervisor))
|
||||
val topSupervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), 3, TimeoutMillis)))
|
||||
val pingpong1 = actorOf(Props[PingPongActor].withSupervisor(topSupervisor))
|
||||
|
||||
val middleSupervisor = createActor(Props(AllForOneStrategy(Nil, 3, TimeoutMillis)).withSupervisor(topSupervisor))
|
||||
val pingpong2 = createActor(Props[PingPongActor].withSupervisor(middleSupervisor))
|
||||
val pingpong3 = createActor(Props[PingPongActor].withSupervisor(middleSupervisor))
|
||||
val middleSupervisor = actorOf(Props(AllForOneStrategy(Nil, 3, TimeoutMillis)).withSupervisor(topSupervisor))
|
||||
val pingpong2 = actorOf(Props[PingPongActor].withSupervisor(middleSupervisor))
|
||||
val pingpong3 = actorOf(Props[PingPongActor].withSupervisor(middleSupervisor))
|
||||
|
||||
(pingpong1, pingpong2, pingpong3, topSupervisor)
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ class SupervisorSpec extends AkkaSpec with BeforeAndAfterEach with BeforeAndAfte
|
|||
"A supervisor" must {
|
||||
|
||||
"not restart programmatically linked temporary actor" in {
|
||||
val master = createActor(Props[Master].withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
val master = actorOf(Props[Master].withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(0))))
|
||||
|
||||
intercept[RuntimeException] {
|
||||
(master.?(Die, TimeoutMillis)).get
|
||||
|
|
@ -290,9 +290,9 @@ class SupervisorSpec extends AkkaSpec with BeforeAndAfterEach with BeforeAndAfte
|
|||
|
||||
"must attempt restart when exception during restart" in {
|
||||
val inits = new AtomicInteger(0)
|
||||
val supervisor = createActor(Props(OneForOneStrategy(classOf[Exception] :: Nil, 3, 10000)))
|
||||
val supervisor = actorOf(Props(OneForOneStrategy(classOf[Exception] :: Nil, 3, 10000)))
|
||||
|
||||
val dyingActor = createActor(Props(new Actor {
|
||||
val dyingActor = actorOf(Props(new Actor {
|
||||
inits.incrementAndGet
|
||||
|
||||
if (inits.get % 2 == 0) throw new IllegalStateException("Don't wanna!")
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ class SupervisorTreeSpec extends AkkaSpec with ImplicitSender {
|
|||
def receive = { case false ⇒ }
|
||||
override def preRestart(reason: Throwable, msg: Option[Any]) { testActor ! self.address }
|
||||
}).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), 3, 1000))
|
||||
val headActor = createActor(p)
|
||||
val middleActor = createActor(p.withSupervisor(headActor))
|
||||
val lastActor = createActor(p.withSupervisor(middleActor))
|
||||
val headActor = actorOf(p)
|
||||
val middleActor = actorOf(p.withSupervisor(headActor))
|
||||
val lastActor = actorOf(p.withSupervisor(middleActor))
|
||||
|
||||
middleActor ! Kill
|
||||
expectMsg(middleActor.address)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender
|
|||
"A supervised actor with lifecycle PERMANENT" should {
|
||||
"be able to reply on failure during preRestart" in {
|
||||
filterEvents(EventFilter[Exception]("test")) {
|
||||
val supervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), 5, 10000)))
|
||||
val supervised = createActor(Props[Supervised].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), 5, 10000)))
|
||||
val supervised = actorOf(Props[Supervised].withSupervisor(supervisor))
|
||||
|
||||
supervised.!("test")(Some(testActor))
|
||||
expectMsg("failure1")
|
||||
|
|
@ -29,8 +29,8 @@ class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender
|
|||
|
||||
"be able to reply on failure during postStop" in {
|
||||
filterEvents(EventFilter[Exception]("test")) {
|
||||
val supervisor = createActor(Props(AllForOneStrategy(List(classOf[Exception]), Some(0), None)))
|
||||
val supervised = createActor(Props[Supervised].withSupervisor(supervisor))
|
||||
val supervisor = actorOf(Props(AllForOneStrategy(List(classOf[Exception]), Some(0), None)))
|
||||
val supervised = actorOf(Props[Supervised].withSupervisor(supervisor))
|
||||
|
||||
supervised.!("test")(Some(testActor))
|
||||
expectMsg("failure2")
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ abstract class ActorModelSpec extends AkkaSpec {
|
|||
|
||||
import ActorModelSpec._
|
||||
|
||||
def newTestActor(dispatcher: MessageDispatcher) = app.createActor(Props[DispatcherActor].withDispatcher(dispatcher))
|
||||
def newTestActor(dispatcher: MessageDispatcher) = app.actorOf(Props[DispatcherActor].withDispatcher(dispatcher))
|
||||
|
||||
protected def newInterceptedDispatcher: MessageDispatcherInterceptor
|
||||
protected def dispatcherType: String
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ class BalancingDispatcherSpec extends AkkaSpec {
|
|||
"have fast actor stealing work from slow actor" in {
|
||||
val finishedCounter = new CountDownLatch(110)
|
||||
|
||||
val slow = createActor(Props(new DelayableActor(50, finishedCounter)).withDispatcher(delayableActorDispatcher)).asInstanceOf[LocalActorRef]
|
||||
val fast = createActor(Props(new DelayableActor(10, finishedCounter)).withDispatcher(delayableActorDispatcher)).asInstanceOf[LocalActorRef]
|
||||
val slow = actorOf(Props(new DelayableActor(50, finishedCounter)).withDispatcher(delayableActorDispatcher)).asInstanceOf[LocalActorRef]
|
||||
val fast = actorOf(Props(new DelayableActor(10, finishedCounter)).withDispatcher(delayableActorDispatcher)).asInstanceOf[LocalActorRef]
|
||||
|
||||
var sentToFast = 0
|
||||
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ class DispatcherActorSpec extends AkkaSpec {
|
|||
"A Dispatcher and an Actor" must {
|
||||
|
||||
"support tell" in {
|
||||
val actor = createActor(Props[OneWayTestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val actor = actorOf(Props[OneWayTestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val result = actor ! "OneWay"
|
||||
assert(OneWayTestActor.oneWay.await(1, TimeUnit.SECONDS))
|
||||
actor.stop()
|
||||
}
|
||||
|
||||
"support ask/reply" in {
|
||||
val actor = createActor(Props[TestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val actor = actorOf(Props[TestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val result = (actor ? "Hello").as[String]
|
||||
assert("World" === result.get)
|
||||
actor.stop()
|
||||
|
|
@ -47,7 +47,7 @@ class DispatcherActorSpec extends AkkaSpec {
|
|||
|
||||
"support ask/exception" in {
|
||||
filterEvents(EventFilter[RuntimeException]("Expected")) {
|
||||
val actor = createActor(Props[TestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
val actor = actorOf(Props[TestActor].withDispatcher(app.dispatcherFactory.newDispatcher("test").build))
|
||||
try {
|
||||
(actor ? "Failure").get
|
||||
fail("Should have thrown an exception")
|
||||
|
|
@ -68,10 +68,10 @@ class DispatcherActorSpec extends AkkaSpec {
|
|||
val works = new AtomicBoolean(true)
|
||||
val latch = new CountDownLatch(100)
|
||||
val start = new CountDownLatch(1)
|
||||
val fastOne = createActor(
|
||||
val fastOne = actorOf(
|
||||
Props(context ⇒ { case "sabotage" ⇒ works.set(false) }).withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = createActor(
|
||||
val slowOne = actorOf(
|
||||
Props(context ⇒ {
|
||||
case "hogexecutor" ⇒ start.await
|
||||
case "ping" ⇒ if (works.get) latch.countDown()
|
||||
|
|
@ -98,12 +98,12 @@ class DispatcherActorSpec extends AkkaSpec {
|
|||
val start = new CountDownLatch(1)
|
||||
val ready = new CountDownLatch(1)
|
||||
|
||||
val fastOne = createActor(
|
||||
val fastOne = actorOf(
|
||||
Props(context ⇒ {
|
||||
case "ping" ⇒ if (works.get) latch.countDown(); context.self.stop()
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = createActor(
|
||||
val slowOne = actorOf(
|
||||
Props(context ⇒ {
|
||||
case "hogexecutor" ⇒ ready.countDown(); start.await
|
||||
case "ping" ⇒ works.set(false); context.self.stop()
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ class DispatcherActorsSpec extends AkkaSpec {
|
|||
"not block fast actors by slow actors" in {
|
||||
val sFinished = new CountDownLatch(50)
|
||||
val fFinished = new CountDownLatch(10)
|
||||
val s = createActor(new SlowActor(sFinished))
|
||||
val f = createActor(new FastActor(fFinished))
|
||||
val s = actorOf(new SlowActor(sFinished))
|
||||
val f = actorOf(new FastActor(fFinished))
|
||||
|
||||
// send a lot of stuff to s
|
||||
for (i ← 1 to 50) {
|
||||
|
|
|
|||
|
|
@ -35,21 +35,21 @@ class PinnedActorSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"support tell" in {
|
||||
var oneWay = new CountDownLatch(1)
|
||||
val actor = createActor(Props(self ⇒ { case "OneWay" ⇒ oneWay.countDown() }).withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
val actor = actorOf(Props(self ⇒ { case "OneWay" ⇒ oneWay.countDown() }).withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
val result = actor ! "OneWay"
|
||||
assert(oneWay.await(1, TimeUnit.SECONDS))
|
||||
actor.stop()
|
||||
}
|
||||
|
||||
"support ask/reply" in {
|
||||
val actor = createActor(Props[TestActor].withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
val actor = actorOf(Props[TestActor].withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
val result = (actor ? "Hello").as[String]
|
||||
assert("World" === result.get)
|
||||
actor.stop()
|
||||
}
|
||||
|
||||
"support ask/exception" in {
|
||||
val actor = createActor(Props[TestActor].withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
val actor = actorOf(Props[TestActor].withDispatcher(app.dispatcherFactory.newPinnedDispatcher("test")))
|
||||
app.eventHandler.notify(Mute(EventFilter[RuntimeException]("Expected exception; to test fault-tolerance")))
|
||||
try {
|
||||
(actor ? "Failure").get
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ class ListenerSpec extends AkkaSpec {
|
|||
val barLatch = TestLatch(2)
|
||||
val barCount = new AtomicInteger(0)
|
||||
|
||||
val broadcast = createActor(new Actor with Listeners {
|
||||
val broadcast = actorOf(new Actor with Listeners {
|
||||
def receive = listenerManagement orElse {
|
||||
case "foo" ⇒ gossip("bar")
|
||||
}
|
||||
})
|
||||
|
||||
def newListener = createActor(new Actor {
|
||||
def newListener = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "bar" ⇒
|
||||
barCount.incrementAndGet
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"from an Actor" that {
|
||||
"returns a result" must {
|
||||
behave like futureWithResult { test ⇒
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
val future = actor ? "Hello"
|
||||
future.await
|
||||
test(future, "World")
|
||||
|
|
@ -126,7 +126,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"throws an exception" must {
|
||||
behave like futureWithException[RuntimeException] { test ⇒
|
||||
filterException[RuntimeException] {
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
val future = actor ? "Failure"
|
||||
future.await
|
||||
test(future, "Expected exception; to test fault-tolerance")
|
||||
|
|
@ -139,8 +139,8 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"using flatMap with an Actor" that {
|
||||
"will return a result" must {
|
||||
behave like futureWithResult { test ⇒
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor2 = createActor(new Actor { def receive = { case s: String ⇒ reply(s.toUpperCase) } })
|
||||
val actor1 = actorOf[TestActor]
|
||||
val actor2 = actorOf(new Actor { def receive = { case s: String ⇒ reply(s.toUpperCase) } })
|
||||
val future = actor1 ? "Hello" flatMap { case s: String ⇒ actor2 ? s }
|
||||
future.await
|
||||
test(future, "WORLD")
|
||||
|
|
@ -151,8 +151,8 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"will throw an exception" must {
|
||||
behave like futureWithException[ArithmeticException] { test ⇒
|
||||
filterException[ArithmeticException] {
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor2 = createActor(new Actor { def receive = { case s: String ⇒ reply(s.length / 0) } })
|
||||
val actor1 = actorOf[TestActor]
|
||||
val actor2 = actorOf(new Actor { def receive = { case s: String ⇒ reply(s.length / 0) } })
|
||||
val future = actor1 ? "Hello" flatMap { case s: String ⇒ actor2 ? s }
|
||||
future.await
|
||||
test(future, "/ by zero")
|
||||
|
|
@ -164,8 +164,8 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"will throw a MatchError when matching wrong type" must {
|
||||
behave like futureWithException[MatchError] { test ⇒
|
||||
filterException[MatchError] {
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor2 = createActor(new Actor { def receive = { case s: String ⇒ reply(s.toUpperCase) } })
|
||||
val actor1 = actorOf[TestActor]
|
||||
val actor2 = actorOf(new Actor { def receive = { case s: String ⇒ reply(s.toUpperCase) } })
|
||||
val future = actor1 ? "Hello" flatMap { case i: Int ⇒ actor2 ? i }
|
||||
future.await
|
||||
test(future, "World (of class java.lang.String)")
|
||||
|
|
@ -180,7 +180,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
"compose with for-comprehensions" in {
|
||||
filterException[ClassCastException] {
|
||||
val actor = createActor(new Actor {
|
||||
val actor = actorOf(new Actor {
|
||||
def receive = {
|
||||
case s: String ⇒ reply(s.length)
|
||||
case i: Int ⇒ reply((i * 2).toString)
|
||||
|
|
@ -212,7 +212,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
filterException[MatchError] {
|
||||
case class Req[T](req: T)
|
||||
case class Res[T](res: T)
|
||||
val actor = createActor(new Actor {
|
||||
val actor = actorOf(new Actor {
|
||||
def receive = {
|
||||
case Req(s: String) ⇒ reply(Res(s.length))
|
||||
case Req(i: Int) ⇒ reply(Res((i * 2).toString))
|
||||
|
|
@ -257,7 +257,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
val future7 = future3 recover { case e: ArithmeticException ⇒ "You got ERROR" }
|
||||
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
|
||||
val future8 = actor ? "Failure"
|
||||
val future9 = actor ? "Failure" recover {
|
||||
|
|
@ -300,7 +300,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
"fold" in {
|
||||
val actors = (1 to 10).toList map { _ ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
def receive = { case (add: Int, wait: Int) ⇒ Thread.sleep(wait); tryReply(add) }
|
||||
})
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
"fold by composing" in {
|
||||
val actors = (1 to 10).toList map { _ ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
def receive = { case (add: Int, wait: Int) ⇒ Thread.sleep(wait); tryReply(add) }
|
||||
})
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"fold with an exception" in {
|
||||
filterException[IllegalArgumentException] {
|
||||
val actors = (1 to 10).toList map { _ ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
def receive = {
|
||||
case (add: Int, wait: Int) ⇒
|
||||
Thread.sleep(wait)
|
||||
|
|
@ -358,7 +358,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
"shouldReduceResults" in {
|
||||
val actors = (1 to 10).toList map { _ ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
def receive = { case (add: Int, wait: Int) ⇒ Thread.sleep(wait); tryReply(add) }
|
||||
})
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"shouldReduceResultsWithException" in {
|
||||
filterException[IllegalArgumentException] {
|
||||
val actors = (1 to 10).toList map { _ ⇒
|
||||
createActor(new Actor {
|
||||
actorOf(new Actor {
|
||||
def receive = {
|
||||
case (add: Int, wait: Int) ⇒
|
||||
Thread.sleep(wait)
|
||||
|
|
@ -393,14 +393,14 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
|
||||
"receiveShouldExecuteOnComplete" in {
|
||||
val latch = new StandardLatch
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
actor ? "Hello" onResult { case "World" ⇒ latch.open }
|
||||
assert(latch.tryAwait(5, TimeUnit.SECONDS))
|
||||
actor.stop()
|
||||
}
|
||||
|
||||
"shouldTraverseFutures" in {
|
||||
val oddActor = createActor(new Actor {
|
||||
val oddActor = actorOf(new Actor {
|
||||
var counter = 1
|
||||
def receive = {
|
||||
case 'GetNext ⇒
|
||||
|
|
@ -467,7 +467,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
"futureComposingWithContinuations" in {
|
||||
import Future.flow
|
||||
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
|
||||
val x = Future("Hello")
|
||||
val y = x flatMap (actor ? _) mapTo manifest[String]
|
||||
|
|
@ -496,7 +496,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
filterException[ClassCastException] {
|
||||
import Future.flow
|
||||
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
|
||||
val x = Future(3)
|
||||
val y = (actor ? "Hello").mapTo[Int]
|
||||
|
|
@ -511,7 +511,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll {
|
|||
filterException[ClassCastException] {
|
||||
import Future.flow
|
||||
|
||||
val actor = createActor[TestActor]
|
||||
val actor = actorOf[TestActor]
|
||||
|
||||
val x = Future("Hello")
|
||||
val y = actor ? "Hello" mapTo manifest[Nothing]
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
|
||||
def createMessageInvocation(msg: Any): Envelope = {
|
||||
new Envelope(
|
||||
createActor(new Actor { //Dummy actor
|
||||
actorOf(new Actor { //Dummy actor
|
||||
def receive = { case _ ⇒ }
|
||||
}).asInstanceOf[LocalActorRef].underlying, msg, NullChannel)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class PriorityDispatcherSpec extends AkkaSpec {
|
|||
def testOrdering(mboxType: MailboxType) {
|
||||
val dispatcher = app.dispatcherFactory.newDispatcher("Test", 1, -1, mboxType).build
|
||||
|
||||
val actor = createActor(Props(new Actor {
|
||||
val actor = actorOf(Props(new Actor {
|
||||
var acc: List[Int] = Nil
|
||||
|
||||
def receive = {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class ActorEventBusSpec extends EventBusSpec("ActorEventBus") {
|
|||
|
||||
def createEvents(numberOfEvents: Int) = (0 until numberOfEvents)
|
||||
|
||||
def createSubscriber(pipeTo: ActorRef) = createActor(Props(new TestActorWrapperActor(pipeTo)))
|
||||
def createSubscriber(pipeTo: ActorRef) = actorOf(Props(new TestActorWrapperActor(pipeTo)))
|
||||
|
||||
def classifierFor(event: BusType#Event) = event.toString
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ abstract class AkkaPerformanceTest(val app: AkkaApplication) extends BenchmarkSc
|
|||
val clients = (for (i ← 0 until numberOfClients) yield {
|
||||
val receiver = receivers(i % receivers.size)
|
||||
Props(new Client(receiver, orders, latch, repeatsPerClient + (if (i < oddRepeats) 1 else 0), sampling, delayMs)).withDispatcher(clientDispatcher)
|
||||
}).toList.map(app.createActor(_))
|
||||
}).toList.map(app.actorOf(_))
|
||||
|
||||
clients.foreach(_ ! "run")
|
||||
val ok = latch.await((5000 + (2 + delayMs) * totalNumberOfRequests) * timeDilation, TimeUnit.MILLISECONDS)
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ class AkkaTradingSystem(val app: AkkaApplication) extends TradingSystem {
|
|||
|
||||
def createMatchingEngine(meId: String, orderbooks: List[Orderbook]) =
|
||||
meDispatcher match {
|
||||
case Some(d) ⇒ app.createActor(Props(new AkkaMatchingEngine(meId, orderbooks)).withDispatcher(d))
|
||||
case _ ⇒ app.createActor(Props(new AkkaMatchingEngine(meId, orderbooks)))
|
||||
case Some(d) ⇒ app.actorOf(Props(new AkkaMatchingEngine(meId, orderbooks)).withDispatcher(d))
|
||||
case _ ⇒ app.actorOf(Props(new AkkaMatchingEngine(meId, orderbooks)))
|
||||
}
|
||||
|
||||
override def createOrderReceivers: List[ActorRef] = {
|
||||
|
|
@ -91,8 +91,8 @@ class AkkaTradingSystem(val app: AkkaApplication) extends TradingSystem {
|
|||
}
|
||||
|
||||
def createOrderReceiver() = orDispatcher match {
|
||||
case Some(d) ⇒ app.createActor(Props(new AkkaOrderReceiver()).withDispatcher(d))
|
||||
case _ ⇒ app.createActor(Props(new AkkaOrderReceiver()))
|
||||
case Some(d) ⇒ app.actorOf(Props(new AkkaOrderReceiver()).withDispatcher(d))
|
||||
case _ ⇒ app.actorOf(Props(new AkkaOrderReceiver()))
|
||||
}
|
||||
|
||||
override def start() {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ class OneWayPerformanceTest extends AkkaPerformanceTest(AkkaApplication()) {
|
|||
|
||||
override def createTradingSystem: TS = new OneWayTradingSystem(app) {
|
||||
override def createMatchingEngine(meId: String, orderbooks: List[Orderbook]) = meDispatcher match {
|
||||
case Some(d) ⇒ app.createActor(Props(new OneWayMatchingEngine(meId, orderbooks) with LatchMessageCountDown).withDispatcher(d))
|
||||
case _ ⇒ app.createActor(new OneWayMatchingEngine(meId, orderbooks) with LatchMessageCountDown)
|
||||
case Some(d) ⇒ app.actorOf(Props(new OneWayMatchingEngine(meId, orderbooks) with LatchMessageCountDown).withDispatcher(d))
|
||||
case _ ⇒ app.actorOf(new OneWayMatchingEngine(meId, orderbooks) with LatchMessageCountDown)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import akka.AkkaApplication
|
|||
class OneWayTradingSystem(_app: AkkaApplication) extends AkkaTradingSystem(_app) {
|
||||
|
||||
override def createMatchingEngine(meId: String, orderbooks: List[Orderbook]) = meDispatcher match {
|
||||
case Some(d) ⇒ app.createActor(Props(new OneWayMatchingEngine(meId, orderbooks)).withDispatcher(d))
|
||||
case _ ⇒ app.createActor(Props(new OneWayMatchingEngine(meId, orderbooks)))
|
||||
case Some(d) ⇒ app.actorOf(Props(new OneWayMatchingEngine(meId, orderbooks)).withDispatcher(d))
|
||||
case _ ⇒ app.actorOf(Props(new OneWayMatchingEngine(meId, orderbooks)))
|
||||
}
|
||||
|
||||
override def createOrderReceiver() = orDispatcher match {
|
||||
case Some(d) ⇒ app.createActor(Props[OneWayOrderReceiver].withDispatcher(d))
|
||||
case _ ⇒ app.createActor(Props[OneWayOrderReceiver])
|
||||
case Some(d) ⇒ app.actorOf(Props[OneWayOrderReceiver].withDispatcher(d))
|
||||
case _ ⇒ app.actorOf(Props[OneWayOrderReceiver])
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
val latch = TestLatch(2)
|
||||
val count = new AtomicInteger(0)
|
||||
|
||||
val pool = createActor(
|
||||
val pool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with FixedCapacityStrategy with SmallestMailboxSelector {
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case _ ⇒
|
||||
count.incrementAndGet
|
||||
|
|
@ -52,7 +52,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
}).withFaultHandler(faultHandler))
|
||||
|
||||
val successes = TestLatch(2)
|
||||
val successCounter = createActor(new Actor {
|
||||
val successCounter = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "success" ⇒ successes.countDown()
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"pass ticket #705" in {
|
||||
val pool = createActor(
|
||||
val pool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with MailboxPressureCapacitor with SmallestMailboxSelector with BasicFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 20
|
||||
|
|
@ -84,7 +84,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case req: String ⇒ {
|
||||
sleepFor(10 millis)
|
||||
|
|
@ -110,9 +110,9 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
var latch = TestLatch(3)
|
||||
val count = new AtomicInteger(0)
|
||||
|
||||
val pool = createActor(
|
||||
val pool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with ActiveFuturesPressureCapacitor with SmallestMailboxSelector with BasicNoBackoffFilter {
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case n: Int ⇒
|
||||
sleepFor(n millis)
|
||||
|
|
@ -174,9 +174,9 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
var latch = TestLatch(3)
|
||||
val count = new AtomicInteger(0)
|
||||
|
||||
val pool = createActor(
|
||||
val pool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with MailboxPressureCapacitor with SmallestMailboxSelector with BasicNoBackoffFilter {
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case n: Int ⇒
|
||||
sleepFor(n millis)
|
||||
|
|
@ -227,10 +227,10 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
val latch1 = TestLatch(2)
|
||||
val delegates = new java.util.concurrent.ConcurrentHashMap[String, String]
|
||||
|
||||
val pool1 = createActor(
|
||||
val pool1 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with FixedCapacityStrategy with RoundRobinSelector with BasicNoBackoffFilter {
|
||||
|
||||
def instance(p: Props): ActorRef = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props): ActorRef = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case _ ⇒
|
||||
delegates put (self.uuid.toString, "")
|
||||
|
|
@ -256,9 +256,9 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
val latch2 = TestLatch(2)
|
||||
delegates.clear()
|
||||
|
||||
val pool2 = createActor(
|
||||
val pool2 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with FixedCapacityStrategy with RoundRobinSelector with BasicNoBackoffFilter {
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case _ ⇒
|
||||
delegates put (self.uuid.toString, "")
|
||||
|
|
@ -285,9 +285,9 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
"backoff" in {
|
||||
val latch = TestLatch(10)
|
||||
|
||||
val pool = createActor(
|
||||
val pool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with MailboxPressureCapacitor with SmallestMailboxSelector with Filter with RunningMeanBackoff with BasicRampup {
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case n: Int ⇒
|
||||
sleepFor(n millis)
|
||||
|
|
@ -357,7 +357,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
val deathCount = new AtomicInteger(0)
|
||||
val keepDying = new AtomicBoolean(false)
|
||||
|
||||
val pool1 = createActor(
|
||||
val pool1 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with ActiveFuturesPressureCapacitor with SmallestMailboxSelector with BasicFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 5
|
||||
|
|
@ -368,7 +368,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
if (deathCount.get > 5) deathCount.set(0)
|
||||
if (deathCount.get > 0) { deathCount.incrementAndGet; throw new IllegalStateException("keep dying") }
|
||||
def receive = {
|
||||
|
|
@ -380,7 +380,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
}))
|
||||
}).withFaultHandler(faultHandler))
|
||||
|
||||
val pool2 = createActor(
|
||||
val pool2 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with ActiveFuturesPressureCapacitor with SmallestMailboxSelector with BasicFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 5
|
||||
|
|
@ -391,7 +391,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
if (deathCount.get > 5) deathCount.set(0)
|
||||
if (deathCount.get > 0) { deathCount.incrementAndGet; throw new IllegalStateException("keep dying") }
|
||||
def receive = {
|
||||
|
|
@ -403,7 +403,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
}))
|
||||
}).withFaultHandler(faultHandler))
|
||||
|
||||
val pool3 = createActor(
|
||||
val pool3 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with ActiveFuturesPressureCapacitor with RoundRobinSelector with BasicFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 5
|
||||
|
|
@ -414,7 +414,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
|
||||
if (deathCount.get > 5) deathCount.set(0)
|
||||
if (deathCount.get > 0) { deathCount.incrementAndGet; throw new IllegalStateException("keep dying") }
|
||||
|
|
@ -501,7 +501,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
|
||||
object BadState
|
||||
|
||||
val pool1 = createActor(
|
||||
val pool1 = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with ActiveFuturesPressureCapacitor with SmallestMailboxSelector with BasicFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 5
|
||||
|
|
@ -512,7 +512,7 @@ class ActorPoolSpec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
if (deathCount.get > 5) deathCount.set(0)
|
||||
if (deathCount.get > 0) { deathCount.incrementAndGet; throw new IllegalStateException("keep dying") }
|
||||
def receive = {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
val helloLatch = new CountDownLatch(5)
|
||||
val stopLatch = new CountDownLatch(5)
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "hello" ⇒ helloLatch.countDown()
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
replies = replies + (i -> 0)
|
||||
}
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
lazy val id = counter.getAndIncrement()
|
||||
def receive = {
|
||||
case "hit" ⇒ reply(id)
|
||||
|
|
@ -108,7 +108,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
val helloLatch = new CountDownLatch(5)
|
||||
val stopLatch = new CountDownLatch(5)
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "hello" ⇒ helloLatch.countDown()
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
|
||||
val stopLatch = new CountDownLatch(7)
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "hello" ⇒ {}
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
replies = replies + (i -> 0)
|
||||
}
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
lazy val id = counter.getAndIncrement()
|
||||
def receive = {
|
||||
case "hit" ⇒ reply(id)
|
||||
|
|
@ -222,7 +222,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec {
|
|||
val helloLatch = new CountDownLatch(6)
|
||||
val stopLatch = new CountDownLatch(6)
|
||||
|
||||
val actor = app.createActor(Props(new Actor {
|
||||
val actor = app.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "hello" ⇒ helloLatch.countDown()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,17 +25,17 @@ class RoutingSpec extends AkkaSpec {
|
|||
|
||||
"direct router" must {
|
||||
"be started when constructed" in {
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
|
||||
val props = RoutedProps().withDirectRouter.withLocalConnections(List(actor1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
actor.isShutdown must be(false)
|
||||
}
|
||||
|
||||
"throw ConfigurationException at construction when no connections" in {
|
||||
try {
|
||||
val props = RoutedProps().withDirectRouter
|
||||
app.createActor(props, "foo")
|
||||
app.actorOf(props, "foo")
|
||||
fail()
|
||||
} catch {
|
||||
case e: ConfigurationException ⇒
|
||||
|
|
@ -46,7 +46,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(1)
|
||||
|
||||
val counter = new AtomicInteger(0)
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case _ ⇒ counter.incrementAndGet
|
||||
|
|
@ -54,7 +54,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withDirectRouter.withLocalConnections(List(connection1))
|
||||
val routedActor = app.createActor(props, "foo")
|
||||
val routedActor = app.actorOf(props, "foo")
|
||||
routedActor ! "hello"
|
||||
routedActor ! "end"
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(1)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter1.addAndGet(msg)
|
||||
|
|
@ -75,7 +75,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withDirectRouter.withLocalConnections(List(connection1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(1)
|
||||
actor ! "end"
|
||||
|
|
@ -89,17 +89,17 @@ class RoutingSpec extends AkkaSpec {
|
|||
"round robin router" must {
|
||||
|
||||
"be started when constructed" in {
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
|
||||
val props = RoutedProps().withRoundRobinRouter.withLocalConnections(List(actor1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
actor.isShutdown must be(false)
|
||||
}
|
||||
|
||||
"throw ConfigurationException at construction when no connections" in {
|
||||
try {
|
||||
val props = RoutedProps().withRoundRobinRouter
|
||||
app.createActor(props, "foo")
|
||||
app.actorOf(props, "foo")
|
||||
fail()
|
||||
} catch {
|
||||
case e: ConfigurationException ⇒
|
||||
|
|
@ -121,7 +121,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
for (i ← 0 until connectionCount) {
|
||||
counters = counters :+ new AtomicInteger()
|
||||
|
||||
val connection = createActor(new Actor {
|
||||
val connection = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counters.get(i).get.addAndGet(msg)
|
||||
|
|
@ -132,7 +132,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
|
||||
//create the routed actor.
|
||||
val props = RoutedProps().withRoundRobinRouter.withLocalConnections(connections)
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
//send messages to the actor.
|
||||
for (i ← 0 until iterationCount) {
|
||||
|
|
@ -155,7 +155,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(2)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter1.addAndGet(msg)
|
||||
|
|
@ -163,7 +163,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val counter2 = new AtomicInteger
|
||||
val connection2 = createActor(new Actor {
|
||||
val connection2 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter2.addAndGet(msg)
|
||||
|
|
@ -171,7 +171,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withRoundRobinRouter.withLocalConnections(List(connection1, connection2))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(1)
|
||||
actor ! Broadcast("end")
|
||||
|
|
@ -186,7 +186,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(1)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case _ ⇒ counter1.incrementAndGet()
|
||||
|
|
@ -194,7 +194,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withRoundRobinRouter.withLocalConnections(List(connection1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
try {
|
||||
actor ? Broadcast(1)
|
||||
|
|
@ -213,17 +213,17 @@ class RoutingSpec extends AkkaSpec {
|
|||
|
||||
"be started when constructed" in {
|
||||
|
||||
val actor1 = createActor[TestActor]
|
||||
val actor1 = actorOf[TestActor]
|
||||
|
||||
val props = RoutedProps().withRandomRouter.withLocalConnections(List(actor1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
actor.isShutdown must be(false)
|
||||
}
|
||||
|
||||
"throw ConfigurationException at construction when no connections" in {
|
||||
try {
|
||||
val props = RoutedProps().withRandomRouter
|
||||
app.createActor(props, "foo")
|
||||
app.actorOf(props, "foo")
|
||||
fail()
|
||||
} catch {
|
||||
case e: ConfigurationException ⇒
|
||||
|
|
@ -238,7 +238,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(2)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter1.addAndGet(msg)
|
||||
|
|
@ -246,7 +246,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val counter2 = new AtomicInteger
|
||||
val connection2 = createActor(new Actor {
|
||||
val connection2 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter2.addAndGet(msg)
|
||||
|
|
@ -254,7 +254,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withRandomRouter.withLocalConnections(List(connection1, connection2))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(1)
|
||||
actor ! Broadcast("end")
|
||||
|
|
@ -269,7 +269,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new CountDownLatch(1)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = createActor(new Actor {
|
||||
val connection1 = actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case _ ⇒ counter1.incrementAndGet()
|
||||
|
|
@ -277,7 +277,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val props = RoutedProps().withRandomRouter.withLocalConnections(List(connection1))
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
try {
|
||||
actor ? Broadcast(1)
|
||||
|
|
@ -302,7 +302,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(List(newActor(0, Some(shutdownLatch)), newActor(1, Some(shutdownLatch))))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(Stop(Some(0)))
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(List(newActor(0, Some(shutdownLatch)), newActor(1, Some(shutdownLatch))))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(Stop())
|
||||
|
||||
|
|
@ -337,7 +337,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(List(newActor(0), newActor(1)))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
(actor ? Broadcast("Hi!")).get.asInstanceOf[Int] must be(0)
|
||||
|
||||
|
|
@ -348,7 +348,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(List(newActor(0), newActor(1)))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
(actor ? Broadcast(0)).get.asInstanceOf[Int] must be(1)
|
||||
}
|
||||
|
|
@ -357,7 +357,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val props = RoutedProps()
|
||||
.withLocalConnections(List(newActor(0)))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor.isShutdown must be(false)
|
||||
|
||||
|
|
@ -369,7 +369,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
try {
|
||||
app.createActor(props, "foo")
|
||||
app.actorOf(props, "foo")
|
||||
fail()
|
||||
} catch {
|
||||
case e: ConfigurationException ⇒
|
||||
|
|
@ -386,7 +386,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
for (i ← 0 until connectionCount) {
|
||||
counters = counters :+ new AtomicInteger()
|
||||
|
||||
val connection = app.createActor(new Actor {
|
||||
val connection = app.actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counters.get(i).get.addAndGet(msg)
|
||||
|
|
@ -399,7 +399,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(connections)
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
for (i ← 0 until iterationCount) {
|
||||
for (k ← 0 until connectionCount) {
|
||||
|
|
@ -421,7 +421,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
val doneLatch = new TestLatch(2)
|
||||
|
||||
val counter1 = new AtomicInteger
|
||||
val connection1 = app.createActor(new Actor {
|
||||
val connection1 = app.actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter1.addAndGet(msg)
|
||||
|
|
@ -429,7 +429,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
})
|
||||
|
||||
val counter2 = new AtomicInteger
|
||||
val connection2 = app.createActor(new Actor {
|
||||
val connection2 = app.actorOf(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter2.addAndGet(msg)
|
||||
|
|
@ -440,7 +440,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
.withLocalConnections(List(connection1, connection2))
|
||||
.withRouter(() ⇒ new ScatterGatherFirstCompletedRouter())
|
||||
|
||||
val actor = app.createActor(props, "foo")
|
||||
val actor = app.actorOf(props, "foo")
|
||||
|
||||
actor ! Broadcast(1)
|
||||
actor ! Broadcast("end")
|
||||
|
|
@ -453,7 +453,7 @@ class RoutingSpec extends AkkaSpec {
|
|||
|
||||
case class Stop(id: Option[Int] = None)
|
||||
|
||||
def newActor(id: Int, shudownLatch: Option[TestLatch] = None) = app.createActor(new Actor {
|
||||
def newActor(id: Int, shudownLatch: Option[TestLatch] = None) = app.actorOf(new Actor {
|
||||
def receive = {
|
||||
case Stop(None) ⇒ self.stop()
|
||||
case Stop(Some(_id)) if (_id == id) ⇒ self.stop()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Ticket703Spec extends AkkaSpec {
|
|||
|
||||
"A ? call to an actor pool" should {
|
||||
"reuse the proper timeout" in {
|
||||
val actorPool = createActor(
|
||||
val actorPool = actorOf(
|
||||
Props(new Actor with DefaultActorPool with BoundedCapacityStrategy with MailboxPressureCapacitor with SmallestMailboxSelector with BasicNoBackoffFilter {
|
||||
def lowerBound = 2
|
||||
def upperBound = 20
|
||||
|
|
@ -17,7 +17,7 @@ class Ticket703Spec extends AkkaSpec {
|
|||
def selectionCount = 1
|
||||
def receive = _route
|
||||
def pressureThreshold = 1
|
||||
def instance(p: Props) = createActor(p.withCreator(new Actor {
|
||||
def instance(p: Props) = actorOf(p.withCreator(new Actor {
|
||||
def receive = {
|
||||
case req: String ⇒
|
||||
Thread.sleep(6000L)
|
||||
|
|
|
|||
|
|
@ -43,29 +43,29 @@ trait ActorRefFactory {
|
|||
|
||||
def dispatcher: MessageDispatcher
|
||||
|
||||
def createActor(props: Props): ActorRef = createActor(props, new UUID().toString)
|
||||
def actorOf(props: Props): ActorRef = actorOf(props, new UUID().toString)
|
||||
|
||||
/*
|
||||
* TODO this will have to go at some point, because creating two actors with
|
||||
* the same address can race on the cluster, and then you never know which
|
||||
* implementation wins
|
||||
*/
|
||||
def createActor(props: Props, address: String): ActorRef = provider.actorOf(props, address)
|
||||
def actorOf(props: Props, address: String): ActorRef = provider.actorOf(props, address)
|
||||
|
||||
def createActor[T <: Actor](implicit m: Manifest[T]): ActorRef = createActor(Props(m.erasure.asInstanceOf[Class[_ <: Actor]]))
|
||||
def actorOf[T <: Actor](implicit m: Manifest[T]): ActorRef = actorOf(Props(m.erasure.asInstanceOf[Class[_ <: Actor]]))
|
||||
|
||||
def createActor[T <: Actor](address: String)(implicit m: Manifest[T]): ActorRef =
|
||||
createActor(Props(m.erasure.asInstanceOf[Class[_ <: Actor]]), address)
|
||||
def actorOf[T <: Actor](address: String)(implicit m: Manifest[T]): ActorRef =
|
||||
actorOf(Props(m.erasure.asInstanceOf[Class[_ <: Actor]]), address)
|
||||
|
||||
def createActor[T <: Actor](clazz: Class[T]): ActorRef = createActor(Props(clazz))
|
||||
def actorOf[T <: Actor](clazz: Class[T]): ActorRef = actorOf(Props(clazz))
|
||||
|
||||
def createActor(factory: ⇒ Actor): ActorRef = createActor(Props(() ⇒ factory))
|
||||
def actorOf(factory: ⇒ Actor): ActorRef = actorOf(Props(() ⇒ factory))
|
||||
|
||||
def createActor(creator: UntypedActorFactory): ActorRef = createActor(Props(() ⇒ creator.create()))
|
||||
def actorOf(creator: UntypedActorFactory): ActorRef = actorOf(Props(() ⇒ creator.create()))
|
||||
|
||||
def createActor(props: RoutedProps): ActorRef = createActor(props, new UUID().toString)
|
||||
def actorOf(props: RoutedProps): ActorRef = actorOf(props, new UUID().toString)
|
||||
|
||||
def createActor(props: RoutedProps, address: String): ActorRef = provider.actorOf(props, address)
|
||||
def actorOf(props: RoutedProps, address: String): ActorRef = provider.actorOf(props, address)
|
||||
|
||||
def findActor(address: String): Option[ActorRef] = provider.actorFor(address)
|
||||
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ class TypedActor(val app: AkkaApplication) {
|
|||
}
|
||||
val proxy: T = Proxy.newProxyInstance(loader, interfaces, new TypedActorInvocationHandler(actorVar)(timeout)).asInstanceOf[T]
|
||||
proxyVar.set(proxy) // Chicken and egg situation we needed to solve, set the proxy so that we can set the self-reference inside each receive
|
||||
val ref = app.createActor(props)
|
||||
val ref = app.actorOf(props)
|
||||
actorVar.set(ref) //Make sure the InvocationHandler gets ahold of the actor reference, this is not a problem since the proxy hasn't escaped this method yet
|
||||
proxyVar.get
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1761,7 +1761,7 @@ class RemoteClusterDaemon(cluster: ClusterNode) extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
def createActorRefToUseForReplay(snapshotAsBytes: Option[Array[Byte]], actorAddress: String, newActorRef: LocalActorRef): ActorRef = {
|
||||
def actorOfRefToUseForReplay(snapshotAsBytes: Option[Array[Byte]], actorAddress: String, newActorRef: LocalActorRef): ActorRef = {
|
||||
snapshotAsBytes match {
|
||||
|
||||
// we have a new actor ref - the snapshot
|
||||
|
|
@ -1816,7 +1816,7 @@ class RemoteClusterDaemon(cluster: ClusterNode) extends Actor {
|
|||
val (snapshotAsBytes, entriesAsBytes) = readonlyTxLog.latestSnapshotAndSubsequentEntries
|
||||
|
||||
// deserialize and restore actor snapshot. This call will automatically recreate a transaction log.
|
||||
val actorRef = createActorRefToUseForReplay(snapshotAsBytes, actorAddress, newActorRef)
|
||||
val actorRef = actorOfRefToUseForReplay(snapshotAsBytes, actorAddress, newActorRef)
|
||||
|
||||
// deserialize the messages
|
||||
val messages: Vector[AnyRef] = deserializeMessages(entriesAsBytes)
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ object Pi extends App {
|
|||
|
||||
//#create-workers
|
||||
// create the workers
|
||||
val workers = Vector.fill(nrOfWorkers)(app.createActor[Worker])
|
||||
val workers = Vector.fill(nrOfWorkers)(app.actorOf[Worker])
|
||||
|
||||
// wrap them with a load-balancing router
|
||||
val router = app.createActor(RoutedProps().withRoundRobinRouter.withLocalConnections(workers), "pi")
|
||||
val router = app.actorOf(RoutedProps().withRoundRobinRouter.withLocalConnections(workers), "pi")
|
||||
//#create-workers
|
||||
|
||||
//#master-receive
|
||||
|
|
@ -121,7 +121,7 @@ object Pi extends App {
|
|||
val latch = new CountDownLatch(1)
|
||||
|
||||
// create the master
|
||||
val master = app.createActor(new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch))
|
||||
val master = app.actorOf(new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch))
|
||||
|
||||
// start the calculation
|
||||
master ! Calculate
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ class MyActor extends Actor {
|
|||
|
||||
class ActorDocSpec extends AkkaSpec {
|
||||
|
||||
"creating actor with AkkaSpec.createActor" in {
|
||||
"creating actor with AkkaSpec.actorOf" in {
|
||||
//#creating-actorOf
|
||||
val myActor = createActor[MyActor]
|
||||
val myActor = actorOf[MyActor]
|
||||
//#creating-actorOf
|
||||
|
||||
// testing the actor
|
||||
|
|
@ -58,7 +58,7 @@ class ActorDocSpec extends AkkaSpec {
|
|||
|
||||
//#creating-constructor
|
||||
// allows passing in arguments to the MyActor constructor
|
||||
val myActor = createActor(new MyActor("..."))
|
||||
val myActor = actorOf(new MyActor("..."))
|
||||
//#creating-constructor
|
||||
|
||||
myActor.stop()
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Remote(val app: AkkaApplication) extends RemoteService {
|
|||
// FIXME configure computeGridDispatcher to what?
|
||||
val computeGridDispatcher = app.dispatcherFactory.newDispatcher("akka:compute-grid").build
|
||||
|
||||
private[remote] lazy val remoteDaemonSupervisor = app.createActor(Props(
|
||||
private[remote] lazy val remoteDaemonSupervisor = app.actorOf(Props(
|
||||
OneForOneStrategy(List(classOf[Exception]), None, None))) // is infinite restart what we want?
|
||||
|
||||
private[remote] lazy val remoteDaemon =
|
||||
|
|
@ -51,7 +51,7 @@ class Remote(val app: AkkaApplication) extends RemoteService {
|
|||
givenAddress = remoteDaemonServiceName,
|
||||
systemService = true)
|
||||
|
||||
private[remote] lazy val remoteClientLifeCycleHandler = app.createActor(Props(new Actor {
|
||||
private[remote] lazy val remoteClientLifeCycleHandler = app.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case RemoteClientError(cause, client, address) ⇒ client.shutdownClientModule()
|
||||
case RemoteClientDisconnected(client, address) ⇒ client.shutdownClientModule()
|
||||
|
|
@ -141,7 +141,7 @@ class RemoteDaemon(val remote: Remote) extends Actor {
|
|||
}
|
||||
|
||||
val actorAddress = message.getActorAddress
|
||||
val newActorRef = app.createActor(Props(creator = actorFactory), actorAddress)
|
||||
val newActorRef = app.actorOf(Props(creator = actorFactory), actorAddress)
|
||||
|
||||
remote.server.register(actorAddress, newActorRef)
|
||||
|
||||
|
|
|
|||
|
|
@ -942,7 +942,7 @@ class RemoteServerHandler(
|
|||
|
||||
val actorRef =
|
||||
try {
|
||||
createActor(actorInfo, channel)
|
||||
actorOf(actorInfo, channel)
|
||||
} catch {
|
||||
case e: SecurityException ⇒
|
||||
app.eventHandler.error(e, this, e.getMessage)
|
||||
|
|
@ -998,7 +998,7 @@ class RemoteServerHandler(
|
|||
*
|
||||
* Does not start the actor.
|
||||
*/
|
||||
private def createActor(actorInfo: ActorInfoProtocol, channel: Channel): ActorRef = {
|
||||
private def actorOf(actorInfo: ActorInfoProtocol, channel: Channel): ActorRef = {
|
||||
val uuid = actorInfo.getUuid
|
||||
val address = actorInfo.getAddress
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class DirectRoutedRemoteActorMultiJvmNode2 extends AkkaRemoteSpec {
|
|||
|
||||
barrier("start")
|
||||
|
||||
val actor = app.createActor[SomeActor]("service-hello")
|
||||
val actor = app.actorOf[SomeActor]("service-hello")
|
||||
actor.isInstanceOf[RoutedActorRef] must be(true)
|
||||
|
||||
val result = (actor ? "identify").get
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class NewRemoteActorMultiJvmNode2 extends AkkaRemoteSpec {
|
|||
|
||||
barrier("start")
|
||||
|
||||
val actor = app.createActor[SomeActor]("service-hello")
|
||||
val actor = app.actorOf[SomeActor]("service-hello")
|
||||
val result = (actor ? "identify").get
|
||||
result must equal("node1")
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class RandomRoutedRemoteActorMultiJvmNode4 extends AkkaRemoteSpec {
|
|||
remote.start()
|
||||
|
||||
barrier("start")
|
||||
val actor = app.createActor[SomeActor]("service-hello")
|
||||
val actor = app.actorOf[SomeActor]("service-hello")
|
||||
actor.isInstanceOf[RoutedActorRef] must be(true)
|
||||
|
||||
val connectionCount = NrOfNodes - 1
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class RoundRobinRoutedRemoteActorMultiJvmNode4 extends AkkaRemoteSpec {
|
|||
remote.start()
|
||||
|
||||
barrier("start")
|
||||
val actor = app.createActor[SomeActor]("service-hello")
|
||||
val actor = app.actorOf[SomeActor]("service-hello")
|
||||
actor.isInstanceOf[RoutedActorRef] must be(true)
|
||||
|
||||
val connectionCount = NrOfNodes - 1
|
||||
|
|
|
|||
|
|
@ -126,11 +126,11 @@ object DiningHakkers {
|
|||
val app = AkkaApplication()
|
||||
def run {
|
||||
//Create 5 chopsticks
|
||||
val chopsticks = for (i ← 1 to 5) yield app.createActor(new Chopstick("Chopstick " + i))
|
||||
val chopsticks = for (i ← 1 to 5) yield app.actorOf(new Chopstick("Chopstick " + i))
|
||||
//Create 5 awesome hakkers and assign them their left and right chopstick
|
||||
val hakkers = for {
|
||||
(name, i) ← List("Ghosh", "Bonér", "Klang", "Krasser", "Manie").zipWithIndex
|
||||
} yield app.createActor(new Hakker(name, chopsticks(i), chopsticks((i + 1) % 5)))
|
||||
} yield app.actorOf(new Hakker(name, chopsticks(i), chopsticks((i + 1) % 5)))
|
||||
|
||||
//Signal all hakkers that they should start thinking, and watch the show
|
||||
hakkers.foreach(_ ! Think)
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ object DiningHakkersOnFsm {
|
|||
|
||||
def run = {
|
||||
// Create 5 chopsticks
|
||||
val chopsticks = for (i ← 1 to 5) yield app.createActor(new Chopstick("Chopstick " + i))
|
||||
val chopsticks = for (i ← 1 to 5) yield app.actorOf(new Chopstick("Chopstick " + i))
|
||||
// Create 5 awesome fsm hakkers and assign them their left and right chopstick
|
||||
val hakkers = for {
|
||||
(name, i) ← List("Ghosh", "Bonér", "Klang", "Krasser", "Manie").zipWithIndex
|
||||
} yield app.createActor(new FSMHakker(name, chopsticks(i), chopsticks((i + 1) % 5)))
|
||||
} yield app.actorOf(new FSMHakker(name, chopsticks(i), chopsticks((i + 1) % 5)))
|
||||
|
||||
hakkers.foreach(_ ! Think)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ object Agent {
|
|||
*/
|
||||
class Agent[T](initialValue: T, app: AkkaApplication) {
|
||||
private[akka] val ref = Ref(initialValue)
|
||||
private[akka] val updater = app.createActor(Props(new AgentUpdater(this))).asInstanceOf[LocalActorRef] //TODO can we avoid this somehow?
|
||||
private[akka] val updater = app.actorOf(Props(new AgentUpdater(this))).asInstanceOf[LocalActorRef] //TODO can we avoid this somehow?
|
||||
|
||||
/**
|
||||
* Read the internal state of the agent.
|
||||
|
|
@ -154,7 +154,7 @@ class Agent[T](initialValue: T, app: AkkaApplication) {
|
|||
send((value: T) ⇒ {
|
||||
suspend()
|
||||
val pinnedDispatcher = new PinnedDispatcher(app, null, "agent-send-off", UnboundedMailbox(), app.AkkaConfig.ActorTimeoutMillis)
|
||||
val threadBased = app.createActor(Props(new ThreadBasedAgentUpdater(this)).withDispatcher(pinnedDispatcher))
|
||||
val threadBased = app.actorOf(Props(new ThreadBasedAgentUpdater(this)).withDispatcher(pinnedDispatcher))
|
||||
threadBased ! Update(f)
|
||||
value
|
||||
})
|
||||
|
|
@ -172,7 +172,7 @@ class Agent[T](initialValue: T, app: AkkaApplication) {
|
|||
send((value: T) ⇒ {
|
||||
suspend()
|
||||
val pinnedDispatcher = new PinnedDispatcher(app, null, "agent-alter-off", UnboundedMailbox(), app.AkkaConfig.ActorTimeoutMillis)
|
||||
val threadBased = app.createActor(Props(new ThreadBasedAgentUpdater(this)).withDispatcher(pinnedDispatcher))
|
||||
val threadBased = app.actorOf(Props(new ThreadBasedAgentUpdater(this)).withDispatcher(pinnedDispatcher))
|
||||
result completeWith threadBased.?(Update(f), timeout).asInstanceOf[Future[T]]
|
||||
value
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class EitherOrElseExample {
|
|||
final Ref<Integer> left = new Ref<Integer>(100);
|
||||
final Ref<Integer> right = new Ref<Integer>(100);
|
||||
|
||||
ActorRef brancher = application.createActor(new Props().withCreator(Brancher.class));
|
||||
ActorRef brancher = application.actorOf(new Props().withCreator(Brancher.class));
|
||||
|
||||
brancher.tell(new Branch(left, right, 500));
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class RetryExample {
|
|||
final Ref<Double> account1 = new Ref<Double>(100.0);
|
||||
final Ref<Double> account2 = new Ref<Double>(100.0);
|
||||
|
||||
ActorRef transferer = application.createActor(new Props().withCreator(Transferer.class));
|
||||
ActorRef transferer = application.actorOf(new Props().withCreator(Transferer.class));
|
||||
|
||||
transferer.tell(new Transfer(account1, account2, 500.0));
|
||||
// Transferer: not enough money - retrying
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ public class UntypedCoordinatedExample {
|
|||
|
||||
AkkaApplication application = new AkkaApplication("UntypedCoordinatedExample");
|
||||
|
||||
ActorRef counter1 = application.createActor(new Props().withCreator(UntypedCoordinatedCounter.class));
|
||||
ActorRef counter2 = application.createActor(new Props().withCreator(UntypedCoordinatedCounter.class));
|
||||
ActorRef counter1 = application.actorOf(new Props().withCreator(UntypedCoordinatedCounter.class));
|
||||
ActorRef counter2 = application.actorOf(new Props().withCreator(UntypedCoordinatedCounter.class));
|
||||
|
||||
counter1.tell(new Coordinated(new Increment(counter2)));
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ public class UntypedTransactorExample {
|
|||
|
||||
AkkaApplication application = new AkkaApplication("UntypedTransactorExample");
|
||||
|
||||
ActorRef counter1 = application.createActor(new Props().withCreator(UntypedCounter.class));
|
||||
ActorRef counter2 = application.createActor(new Props().withCreator(UntypedCounter.class));
|
||||
ActorRef counter1 = application.actorOf(new Props().withCreator(UntypedCounter.class));
|
||||
ActorRef counter2 = application.actorOf(new Props().withCreator(UntypedCounter.class));
|
||||
|
||||
counter1.tell(new Increment(counter2));
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ public class UntypedCoordinatedIncrementTest {
|
|||
counters = new ArrayList<ActorRef>();
|
||||
for (int i = 1; i <= numCounters; i++) {
|
||||
final String name = "counter" + i;
|
||||
ActorRef counter = application.createActor(new Props().withCreator(new UntypedActorFactory() {
|
||||
ActorRef counter = application.actorOf(new Props().withCreator(new UntypedActorFactory() {
|
||||
public UntypedActor create() {
|
||||
return new UntypedCoordinatedCounter(name);
|
||||
}
|
||||
}));
|
||||
counters.add(counter);
|
||||
}
|
||||
failer = application.createActor(new Props().withCreator(UntypedFailer.class));
|
||||
failer = application.actorOf(new Props().withCreator(UntypedFailer.class));
|
||||
}
|
||||
|
||||
@Test public void incrementAllCountersWithSuccessfulTransaction() {
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ public class UntypedTransactorTest {
|
|||
counters = new ArrayList<ActorRef>();
|
||||
for (int i = 1; i <= numCounters; i++) {
|
||||
final String name = "counter" + i;
|
||||
ActorRef counter = application.createActor(new Props().withCreator(new UntypedActorFactory() {
|
||||
ActorRef counter = application.actorOf(new Props().withCreator(new UntypedActorFactory() {
|
||||
public UntypedActor create() {
|
||||
return new UntypedCounter(name);
|
||||
}
|
||||
}));
|
||||
counters.add(counter);
|
||||
}
|
||||
failer = application.createActor(new Props().withCreator(UntypedFailer.class));
|
||||
failer = application.actorOf(new Props().withCreator(UntypedFailer.class));
|
||||
}
|
||||
|
||||
@Test public void incrementAllCountersWithSuccessfulTransaction() {
|
||||
|
|
|
|||
|
|
@ -60,16 +60,16 @@ class CoordinatedIncrementSpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
|
||||
val numCounters = 5
|
||||
|
||||
def createActors = {
|
||||
def createCounter(i: Int) = app.createActor(Props(new Counter("counter" + i)))
|
||||
def actorOfs = {
|
||||
def createCounter(i: Int) = app.actorOf(Props(new Counter("counter" + i)))
|
||||
val counters = (1 to numCounters) map createCounter
|
||||
val failer = app.createActor(Props(new Failer))
|
||||
val failer = app.actorOf(Props(new Failer))
|
||||
(counters, failer)
|
||||
}
|
||||
|
||||
"Coordinated increment" should {
|
||||
"increment all counters by one with successful transactions" in {
|
||||
val (counters, failer) = createActors
|
||||
val (counters, failer) = actorOfs
|
||||
val coordinated = Coordinated()
|
||||
counters(0) ! coordinated(Increment(counters.tail))
|
||||
coordinated.await
|
||||
|
|
@ -86,7 +86,7 @@ class CoordinatedIncrementSpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
EventFilter[CoordinatedTransactionException],
|
||||
EventFilter[ActorTimeoutException])
|
||||
app.eventHandler.notify(TestEvent.Mute(ignoreExceptions))
|
||||
val (counters, failer) = createActors
|
||||
val (counters, failer) = actorOfs
|
||||
val coordinated = Coordinated()
|
||||
counters(0) ! Coordinated(Increment(counters.tail :+ failer))
|
||||
coordinated.await
|
||||
|
|
|
|||
|
|
@ -105,10 +105,10 @@ class FickleFriendsSpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
|
||||
val numCounters = 2
|
||||
|
||||
def createActors = {
|
||||
def createCounter(i: Int) = app.createActor(Props(new FickleCounter("counter" + i)))
|
||||
def actorOfs = {
|
||||
def createCounter(i: Int) = app.actorOf(Props(new FickleCounter("counter" + i)))
|
||||
val counters = (1 to numCounters) map createCounter
|
||||
val coordinator = app.createActor(Props(new Coordinator("coordinator")))
|
||||
val coordinator = app.actorOf(Props(new Coordinator("coordinator")))
|
||||
(counters, coordinator)
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ class FickleFriendsSpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
EventFilter[CoordinatedTransactionException],
|
||||
EventFilter[ActorTimeoutException])
|
||||
app.eventHandler.notify(TestEvent.Mute(ignoreExceptions))
|
||||
val (counters, coordinator) = createActors
|
||||
val (counters, coordinator) = actorOfs
|
||||
val latch = new CountDownLatch(1)
|
||||
coordinator ! FriendlyIncrement(counters, latch)
|
||||
latch.await // this could take a while
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ class TransactorSpec extends AkkaSpec {
|
|||
val numCounters = 5
|
||||
|
||||
def createTransactors = {
|
||||
def createCounter(i: Int) = app.createActor(Props(new Counter("counter" + i)))
|
||||
def createCounter(i: Int) = app.actorOf(Props(new Counter("counter" + i)))
|
||||
val counters = (1 to numCounters) map createCounter
|
||||
val failer = app.createActor(Props(new Failer))
|
||||
val failer = app.actorOf(Props(new Failer))
|
||||
(counters, failer)
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ class TransactorSpec extends AkkaSpec {
|
|||
|
||||
"Transactor" should {
|
||||
"be usable without overriding normally" in {
|
||||
val transactor = app.createActor(Props(new Setter))
|
||||
val transactor = app.actorOf(Props(new Setter))
|
||||
val ref = Ref(0)
|
||||
val latch = TestLatch(1)
|
||||
transactor ! Set(ref, 5, latch)
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ abstract class AkkaSpec(_application: AkkaApplication = AkkaApplication())
|
|||
|
||||
def this(config: Configuration) = this(new AkkaApplication(getClass.getSimpleName, AkkaApplication.defaultConfig ++ config))
|
||||
|
||||
def createActor(props: Props): ActorRef = app.createActor(props)
|
||||
def actorOf(props: Props): ActorRef = app.actorOf(props)
|
||||
|
||||
def createActor[T <: Actor](clazz: Class[T]): ActorRef = createActor(Props(clazz))
|
||||
def actorOf[T <: Actor](clazz: Class[T]): ActorRef = actorOf(Props(clazz))
|
||||
|
||||
def createActor[T <: Actor: Manifest]: ActorRef = createActor(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
|
||||
def actorOf[T <: Actor: Manifest]: ActorRef = actorOf(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
|
||||
|
||||
def createActor[T <: Actor](factory: ⇒ T): ActorRef = createActor(Props(factory))
|
||||
def actorOf[T <: Actor](factory: ⇒ T): ActorRef = actorOf(Props(factory))
|
||||
|
||||
def spawn(body: ⇒ Unit)(implicit dispatcher: MessageDispatcher) {
|
||||
createActor(Props(ctx ⇒ { case "go" ⇒ try body finally ctx.self.stop() }).withDispatcher(dispatcher)) ! "go"
|
||||
actorOf(Props(ctx ⇒ { case "go" ⇒ try body finally ctx.self.stop() }).withDispatcher(dispatcher)) ! "go"
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ class TestActorRefSpec extends AkkaSpec with BeforeAndAfterEach {
|
|||
|
||||
"used with ActorRef" in {
|
||||
val a = TestActorRef(Props(new Actor {
|
||||
val nested = context.createActor(Props(self ⇒ { case _ ⇒ }))
|
||||
val nested = context.actorOf(Props(self ⇒ { case _ ⇒ }))
|
||||
def receive = { case _ ⇒ reply(nested) }
|
||||
}))
|
||||
a must not be (null)
|
||||
|
|
|
|||
|
|
@ -110,11 +110,11 @@ public class Pi {
|
|||
|
||||
LinkedList<ActorRef> workers = new LinkedList<ActorRef>();
|
||||
for (int i = 0; i < nrOfWorkers; i++) {
|
||||
ActorRef worker = app.createActor(Worker.class);
|
||||
ActorRef worker = app.actorOf(Worker.class);
|
||||
workers.add(worker);
|
||||
}
|
||||
|
||||
router = app.createActor(new RoutedProps().withRoundRobinRouter().withLocalConnections(workers), "pi");
|
||||
router = app.actorOf(new RoutedProps().withRoundRobinRouter().withLocalConnections(workers), "pi");
|
||||
}
|
||||
|
||||
// message handler
|
||||
|
|
@ -168,7 +168,7 @@ public class Pi {
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
// create the master
|
||||
ActorRef master = app.createActor(new UntypedActorFactory() {
|
||||
ActorRef master = app.actorOf(new UntypedActorFactory() {
|
||||
public UntypedActor create() {
|
||||
return new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@ object Pi extends App {
|
|||
var start: Long = _
|
||||
|
||||
// create the workers
|
||||
val workers = Vector.fill(nrOfWorkers)(app.createActor[Worker])
|
||||
val workers = Vector.fill(nrOfWorkers)(app.actorOf[Worker])
|
||||
|
||||
// wrap them with a load-balancing router
|
||||
val router = app.createActor(RoutedProps().withRoundRobinRouter.withLocalConnections(workers), "pi")
|
||||
val router = app.actorOf(RoutedProps().withRoundRobinRouter.withLocalConnections(workers), "pi")
|
||||
|
||||
// message handler
|
||||
def receive = {
|
||||
|
|
@ -104,7 +104,7 @@ object Pi extends App {
|
|||
val latch = new CountDownLatch(1)
|
||||
|
||||
// create the master
|
||||
val master = app.createActor(new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch))
|
||||
val master = app.actorOf(new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch))
|
||||
|
||||
// start the calculation
|
||||
master ! Calculate
|
||||
|
|
|
|||
|
|
@ -103,11 +103,11 @@ public class Pi {
|
|||
|
||||
LinkedList<ActorRef> workers = new LinkedList<ActorRef>();
|
||||
for (int i = 0; i < nrOfWorkers; i++) {
|
||||
ActorRef worker = app.createActor(Worker.class);
|
||||
ActorRef worker = app.actorOf(Worker.class);
|
||||
workers.add(worker);
|
||||
}
|
||||
|
||||
router = app.createActor(new RoutedProps().withRoundRobinRouter().withLocalConnections(workers), "pi");
|
||||
router = app.actorOf(new RoutedProps().withRoundRobinRouter().withLocalConnections(workers), "pi");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -163,7 +163,7 @@ public class Pi {
|
|||
public void calculate(final int nrOfWorkers, final int nrOfElements, final int nrOfMessages) throws Exception {
|
||||
|
||||
// create the master
|
||||
ActorRef master = app.createActor(new UntypedActorFactory() {
|
||||
ActorRef master = app.actorOf(new UntypedActorFactory() {
|
||||
public UntypedActor create() {
|
||||
return new Master(nrOfWorkers, nrOfMessages, nrOfElements);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ object Pi extends App {
|
|||
var nrOfResults: Int = _
|
||||
|
||||
// create the workers
|
||||
val workers = Vector.fill(nrOfWorkers)(app.createActor[Worker])
|
||||
val workers = Vector.fill(nrOfWorkers)(app.actorOf[Worker])
|
||||
|
||||
// wrap them with a load-balancing router
|
||||
val router = app.createActor(RoutedProps(
|
||||
val router = app.actorOf(RoutedProps(
|
||||
routerFactory = () ⇒ new RoundRobinRouter,
|
||||
connectionManager = new LocalConnectionManager(workers)), "pi")
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ object Pi extends App {
|
|||
// ==================
|
||||
def calculate(nrOfWorkers: Int, nrOfElements: Int, nrOfMessages: Int) {
|
||||
// create the master
|
||||
val master = app.createActor(new Master(nrOfWorkers, nrOfElements, nrOfMessages))
|
||||
val master = app.actorOf(new Master(nrOfWorkers, nrOfElements, nrOfMessages))
|
||||
|
||||
//start the calculation
|
||||
val start = now
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue