Refactoring the use of !! to ?+.get for Akka internal code

This commit is contained in:
Viktor Klang 2011-06-13 15:29:35 +02:00
parent 6ddee70e0b
commit 9c1a50ba2c
11 changed files with 34 additions and 34 deletions

View file

@ -66,7 +66,7 @@ object SupervisorSpec {
} }
override def receive = { override def receive = {
case Die temp !! (Die, TimeoutMillis) case Die (temp ? (Die, TimeoutMillis)).get
} }
} }
@ -200,13 +200,13 @@ class SupervisorSpec extends WordSpec with MustMatchers with BeforeAndAfterEach
} }
def ping(pingPongActor: ActorRef) = { def ping(pingPongActor: ActorRef) = {
(pingPongActor !! (Ping, TimeoutMillis)).getOrElse("nil") must be(PongMessage) (pingPongActor ? (Ping, TimeoutMillis)).as[String].getOrElse("nil") must be === PongMessage
messageLogPoll must be(PingMessage) messageLogPoll must be === PingMessage
} }
def kill(pingPongActor: ActorRef) = { def kill(pingPongActor: ActorRef) = {
intercept[RuntimeException] { pingPongActor !! (Die, TimeoutMillis) } intercept[RuntimeException] { pingPongActor !! (Die, TimeoutMillis) }
messageLogPoll must be(ExceptionMessage) messageLogPoll must be === ExceptionMessage
} }
"A supervisor" must { "A supervisor" must {
@ -215,7 +215,7 @@ class SupervisorSpec extends WordSpec with MustMatchers with BeforeAndAfterEach
val master = actorOf[Master].start() val master = actorOf[Master].start()
intercept[RuntimeException] { intercept[RuntimeException] {
master !! (Die, TimeoutMillis) (master ? (Die, TimeoutMillis)).get
} }
sleepFor(1 second) sleepFor(1 second)
@ -226,7 +226,7 @@ class SupervisorSpec extends WordSpec with MustMatchers with BeforeAndAfterEach
val (temporaryActor, supervisor) = temporaryActorAllForOne val (temporaryActor, supervisor) = temporaryActorAllForOne
intercept[RuntimeException] { intercept[RuntimeException] {
temporaryActor !! (Die, TimeoutMillis) (temporaryActor ? (Die, TimeoutMillis)).get
} }
sleepFor(1 second) sleepFor(1 second)
@ -374,13 +374,13 @@ class SupervisorSpec extends WordSpec with MustMatchers with BeforeAndAfterEach
Supervise(dyingActor, Permanent) :: Nil)) Supervise(dyingActor, Permanent) :: Nil))
intercept[Exception] { intercept[Exception] {
dyingActor !! (Die, TimeoutMillis) (dyingActor ? (Die, TimeoutMillis)).get
} }
// give time for restart // give time for restart
sleepFor(3 seconds) sleepFor(3 seconds)
(dyingActor !! (Ping, TimeoutMillis)).getOrElse("nil") must be(PongMessage) (dyingActor ? (Ping, TimeoutMillis)).as[String].getOrElse("nil") must be === PongMessage
inits.get must be(3) inits.get must be(3)

View file

@ -53,8 +53,8 @@ class DispatcherActorSpec extends JUnitSuite {
@Test @Test
def shouldSendReplyAsync = { def shouldSendReplyAsync = {
val actor = actorOf[TestActor].start() val actor = actorOf[TestActor].start()
val result = actor !! "Hello" val result = (actor ? "Hello").as[String]
assert("World" === result.get.asInstanceOf[String]) assert("World" === result.get)
actor.stop() actor.stop()
} }
@ -62,7 +62,7 @@ class DispatcherActorSpec extends JUnitSuite {
def shouldSendReceiveException = { def shouldSendReceiveException = {
val actor = actorOf[TestActor].start() val actor = actorOf[TestActor].start()
try { try {
actor !! "Failure" (actor ? "Failure").get
fail("Should have thrown an exception") fail("Should have thrown an exception")
} catch { } catch {
case e case e

View file

@ -60,7 +60,7 @@ class PinnedActorSpec extends JUnitSuite {
def shouldSendReceiveException = { def shouldSendReceiveException = {
val actor = actorOf[TestActor].start() val actor = actorOf[TestActor].start()
try { try {
actor !! "Failure" (actor ? "Failure").get
fail("Should have thrown an exception") fail("Should have thrown an exception")
} catch { } catch {
case e case e

View file

@ -208,7 +208,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
count.get must be(2) count.get must be(2)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be(2) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be(2)
pool.stop() pool.stop()
} }
@ -276,7 +276,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
pool ! 1 pool ! 1
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be(2) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be(2)
var loops = 0 var loops = 0
def loop(t: Int) = { def loop(t: Int) = {
@ -296,7 +296,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
latch.await latch.await
count.get must be(loops) count.get must be(loops)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be(2) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be(2)
// a whole bunch should max it out // a whole bunch should max it out
@ -305,7 +305,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
latch.await latch.await
count.get must be(loops) count.get must be(loops)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be(4) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be(4)
pool.stop() pool.stop()
} }
@ -353,7 +353,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
latch.await latch.await
count.get must be(loops) count.get must be(loops)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be(2) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be(2)
// send a bunch over the theshold and observe an increment // send a bunch over the theshold and observe an increment
loops = 15 loops = 15
@ -362,7 +362,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
latch.await(10 seconds) latch.await(10 seconds)
count.get must be(loops) count.get must be(loops)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be >= (3) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be >= (3)
pool.stop() pool.stop()
} }
@ -458,7 +458,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
sleepFor(5 millis) sleepFor(5 millis)
val z = (pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size val z = (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size
z must be >= (2) z must be >= (2)
@ -469,7 +469,7 @@ class RoutingSpec extends WordSpec with MustMatchers {
sleepFor(500 millis) sleepFor(500 millis)
} }
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be <= (z) (pool ? ActorPool.Stat).as[ActorPool.Stats].get.size must be <= (z)
pool.stop() pool.stop()
} }

View file

@ -665,7 +665,7 @@ class DefaultClusterNode private[akka] (
.build .build
replicaConnectionsForReplicationFactor(replicationFactor) foreach { connection replicaConnectionsForReplicationFactor(replicationFactor) foreach { connection
(connection !! (command, remoteDaemonAckTimeout)) match { (connection ? (command, remoteDaemonAckTimeout)).as[Status] match {
case Some(Success) case Some(Success)
EventHandler.debug(this, "Replica for [%s] successfully created".format(actorRef.address)) EventHandler.debug(this, "Replica for [%s] successfully created".format(actorRef.address))

View file

@ -42,7 +42,7 @@ object PingPong {
count += 1 count += 1
self reply Ball self reply Ball
} else { } else {
self.sender.foreach(_ !! Stop) self.sender.foreach(s (s ? Stop).await)
gameOverLatch.countDown gameOverLatch.countDown
self.stop self.stop
} }

View file

@ -3,8 +3,8 @@
*/ */
package sample.osgi package sample.osgi
import akka.actor.{ Actor, ActorRegistry } import akka.actor.Actor
import Actor._ import akka.actor.Actor._
import org.osgi.framework.{ BundleActivator, BundleContext } import org.osgi.framework.{ BundleActivator, BundleContext }
@ -13,7 +13,7 @@ class Activator extends BundleActivator {
def start(context: BundleContext) { def start(context: BundleContext) {
println("Starting the OSGi example ...") println("Starting the OSGi example ...")
val echo = actorOf[EchoActor].start() val echo = actorOf[EchoActor].start()
val answer = (echo !! "OSGi example") val answer = (echo ? "OSGi example").as[String]
println(answer getOrElse "No answer!") println(answer getOrElse "No answer!")
} }

View file

@ -64,7 +64,7 @@ class CoordinatedIncrementSpec extends WordSpec with MustMatchers {
counters(0) ! coordinated(Increment(counters.tail)) counters(0) ! coordinated(Increment(counters.tail))
coordinated.await coordinated.await
for (counter counters) { for (counter counters) {
(counter !! GetCount).get must be === 1 (counter ? GetCount).as[Int].get must be === 1
} }
counters foreach (_.stop()) counters foreach (_.stop())
failer.stop() failer.stop()
@ -76,7 +76,7 @@ class CoordinatedIncrementSpec extends WordSpec with MustMatchers {
counters(0) ! Coordinated(Increment(counters.tail :+ failer)) counters(0) ! Coordinated(Increment(counters.tail :+ failer))
coordinated.await coordinated.await
for (counter counters) { for (counter counters) {
(counter !! GetCount).get must be === 0 (counter ? GetCount).as[Int].get must be === 0
} }
counters foreach (_.stop()) counters foreach (_.stop())
failer.stop() failer.stop()

View file

@ -109,9 +109,9 @@ class FickleFriendsSpec extends WordSpec with MustMatchers {
val latch = new CountDownLatch(1) val latch = new CountDownLatch(1)
coordinator ! FriendlyIncrement(counters, latch) coordinator ! FriendlyIncrement(counters, latch)
latch.await // this could take a while latch.await // this could take a while
(coordinator !! GetCount).get must be === 1 (coordinator ? GetCount).as[Int].get must be === 1
for (counter counters) { for (counter counters) {
(counter !! GetCount).get must be === 1 (counter ? GetCount).as[Int].get must be === 1
} }
counters foreach (_.stop()) counters foreach (_.stop())
coordinator.stop() coordinator.stop()

View file

@ -92,7 +92,7 @@ class TransactorSpec extends WordSpec with MustMatchers {
counters(0) ! Increment(counters.tail, incrementLatch) counters(0) ! Increment(counters.tail, incrementLatch)
incrementLatch.await(timeout.length, timeout.unit) incrementLatch.await(timeout.length, timeout.unit)
for (counter counters) { for (counter counters) {
(counter !! GetCount).get must be === 1 (counter ? GetCount).as[Int].get must be === 1
} }
counters foreach (_.stop()) counters foreach (_.stop())
failer.stop() failer.stop()
@ -104,7 +104,7 @@ class TransactorSpec extends WordSpec with MustMatchers {
counters(0) ! Increment(counters.tail :+ failer, failLatch) counters(0) ! Increment(counters.tail :+ failer, failLatch)
failLatch.await(timeout.length, timeout.unit) failLatch.await(timeout.length, timeout.unit)
for (counter counters) { for (counter counters) {
(counter !! GetCount).get must be === 0 (counter ? GetCount).as[Int].get must be === 0
} }
counters foreach (_.stop()) counters foreach (_.stop())
failer.stop() failer.stop()

View file

@ -114,7 +114,7 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac
def receive = { case _ self reply nested } def receive = { case _ self reply nested }
}).start() }).start()
a must not be (null) a must not be (null)
val nested = (a !! "any").get.asInstanceOf[ActorRef] val nested = (a ? "any").as[ActorRef].get
nested must not be (null) nested must not be (null)
a must not be theSameInstanceAs(nested) a must not be theSameInstanceAs(nested)
} }
@ -125,7 +125,7 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac
def receive = { case _ self reply nested } def receive = { case _ self reply nested }
}).start() }).start()
a must not be (null) a must not be (null)
val nested = (a !! "any").get.asInstanceOf[ActorRef] val nested = (a ? "any").as[ActorRef].get
nested must not be (null) nested must not be (null)
a must not be theSameInstanceAs(nested) a must not be theSameInstanceAs(nested)
} }
@ -160,7 +160,7 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac
"stop when sent a poison pill" in { "stop when sent a poison pill" in {
val a = TestActorRef[WorkerActor].start() val a = TestActorRef[WorkerActor].start()
intercept[ActorKilledException] { intercept[ActorKilledException] {
a !! PoisonPill (a ? PoisonPill).get
} }
a must not be ('running) a must not be ('running)
a must be('shutdown) a must be('shutdown)