diff --git a/akka-camel/src/test/scala/CamelServiceFeatureTest.scala b/akka-camel/src/test/scala/CamelServiceFeatureTest.scala
index fd57d83457..771ed83af3 100644
--- a/akka-camel/src/test/scala/CamelServiceFeatureTest.scala
+++ b/akka-camel/src/test/scala/CamelServiceFeatureTest.scala
@@ -26,7 +26,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
// count expectations in the next step (needed for testing only).
service.consumerPublisher.start
// set expectations on publish count
- val latch = service.consumerPublisher.!).get
+ val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
// start the CamelService
service.load
// await publication of first test consumer
@@ -43,7 +43,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
scenario("access registered consumer actors via Camel direct-endpoints") {
given("two consumer actors registered before and after CamelService startup")
- val latch = service.consumerPublisher.!).get
+ val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
actorOf(new TestConsumer("direct:publish-test-2")).start
assert(latch.await(5000, TimeUnit.MILLISECONDS))
@@ -64,12 +64,12 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
given("a consumer actor that has been stopped")
assert(CamelContextManager.context.hasEndpoint(endpointUri) eq null)
- var latch = service.consumerPublisher.!).get
+ var latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
val consumer = actorOf(new TestConsumer(endpointUri)).start
assert(latch.await(5000, TimeUnit.MILLISECONDS))
assert(CamelContextManager.context.hasEndpoint(endpointUri) ne null)
- latch = service.consumerPublisher.!).get
+ latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
consumer.stop
assert(latch.await(5000, TimeUnit.MILLISECONDS))
// endpoint is still there but the route has been stopped
@@ -103,7 +103,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
scenario("access active object methods via Camel direct-endpoints") {
given("an active object registered after CamelService startup")
- val latch = service.consumerPublisher.!).get
+ val latch = (service.consumerPublisher !! SetExpectedMessageCount(3)).as[CountDownLatch].get
ActiveObject.newInstance(classOf[PojoBase])
assert(latch.await(5000, TimeUnit.MILLISECONDS))
diff --git a/akka-camel/src/test/scala/ProducerFeatureTest.scala b/akka-camel/src/test/scala/ProducerFeatureTest.scala
index eda866e064..96d1b9eeef 100644
--- a/akka-camel/src/test/scala/ProducerFeatureTest.scala
+++ b/akka-camel/src/test/scala/ProducerFeatureTest.scala
@@ -68,7 +68,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
when("a fail message is sent to the producer")
val message = Message("fail", Map(Message.MessageExchangeId -> "123"))
- val result = producer.!
+ val result = (producer !! message).as[Failure]
then("the expected failure message should be returned including a correlation identifier")
val expectedFailureText = result.get.cause.getMessage
@@ -84,7 +84,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
when("a fail message is sent to the producer")
val message = Message("fail", Map(Message.MessageExchangeId -> "123"))
- val result = producer.!
+ val result = (producer !! message).as[Failure]
then("the expected failure message should be returned including a correlation identifier")
val expectedFailureText = result.get.cause.getMessage
diff --git a/akka-camel/src/test/scala/PublishRequestorTest.scala b/akka-camel/src/test/scala/PublishRequestorTest.scala
index f3c9a899b2..7729e6eec6 100644
--- a/akka-camel/src/test/scala/PublishRequestorTest.scala
+++ b/akka-camel/src/test/scala/PublishRequestorTest.scala
@@ -34,7 +34,7 @@ class PublishRequestorTest extends JUnitSuite {
@Test def shouldReceiveConsumerMethodRegisteredEvent = {
val obj = ActiveObject.newInstance(classOf[PojoSingle])
val init = AspectInit(classOf[PojoSingle], null, None, 1000)
- val latch = publisher.!).get
+ val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
requestor ! AspectInitRegistered(obj, init)
assert(latch.await(5000, TimeUnit.MILLISECONDS))
val event = (publisher !! GetRetainedMessage).get.asInstanceOf[ConsumerMethodRegistered]
@@ -45,7 +45,7 @@ class PublishRequestorTest extends JUnitSuite {
}
@Test def shouldReceiveConsumerRegisteredEvent = {
- val latch = publisher.!).get
+ val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
requestor ! ActorRegistered(consumer)
assert(latch.await(5000, TimeUnit.MILLISECONDS))
assert((publisher !! GetRetainedMessage) ===
@@ -53,7 +53,7 @@ class PublishRequestorTest extends JUnitSuite {
}
@Test def shouldReceiveConsumerUnregisteredEvent = {
- val latch = publisher.!).get
+ val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
requestor ! ActorUnregistered(consumer)
assert(latch.await(5000, TimeUnit.MILLISECONDS))
assert((publisher !! GetRetainedMessage) ===
diff --git a/akka-camel/src/test/scala/RemoteConsumerTest.scala b/akka-camel/src/test/scala/RemoteConsumerTest.scala
index e1a7842e0d..4e2aa59b24 100644
--- a/akka-camel/src/test/scala/RemoteConsumerTest.scala
+++ b/akka-camel/src/test/scala/RemoteConsumerTest.scala
@@ -45,7 +45,7 @@ class RemoteConsumerTest extends FeatureSpec with BeforeAndAfterAll with GivenWh
val consumer = actorOf[RemoteConsumer].start
when("remote consumer publication is triggered")
- val latch = service.consumerPublisher.!).get
+ val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
consumer !! "init"
assert(latch.await(5000, TimeUnit.MILLISECONDS))
diff --git a/akka-camel/src/test/scala/component/ActorComponentFeatureTest.scala b/akka-camel/src/test/scala/component/ActorComponentFeatureTest.scala
index f73a2fcd3e..b7fd607f28 100644
--- a/akka-camel/src/test/scala/component/ActorComponentFeatureTest.scala
+++ b/akka-camel/src/test/scala/component/ActorComponentFeatureTest.scala
@@ -26,7 +26,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
scenario("one-way communication using actor id") {
val actor = actorOf[Tester1].start
- val latch = actor.!).get
+ val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
template.sendBody("actor:%s" format actor.id, "Martin")
assert(latch.await(5000, TimeUnit.MILLISECONDS))
val reply = (actor !! GetRetainedMessage).get.asInstanceOf[Message]
@@ -35,7 +35,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
scenario("one-way communication using actor uuid") {
val actor = actorOf[Tester1].start
- val latch = actor.!).get
+ val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
template.sendBody("actor:uuid:%s" format actor.uuid, "Martin")
assert(latch.await(5000, TimeUnit.MILLISECONDS))
val reply = (actor !! GetRetainedMessage).get.asInstanceOf[Message]
diff --git a/akka-camel/src/test/scala/component/ActorProducerTest.scala b/akka-camel/src/test/scala/component/ActorProducerTest.scala
index 419784681b..6840bf1c79 100644
--- a/akka-camel/src/test/scala/component/ActorProducerTest.scala
+++ b/akka-camel/src/test/scala/component/ActorProducerTest.scala
@@ -19,7 +19,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
@Test def shouldSendMessageToActor = {
val actor = actorOf[Tester1].start
- val latch = actor.!).get
+ val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
val exchange = endpoint.createExchange(ExchangePattern.InOnly)
exchange.getIn.setBody("Martin")
diff --git a/akka-core/src/main/scala/actor/ActiveObject.scala b/akka-core/src/main/scala/actor/ActiveObject.scala
index 5c113384b0..b66b4558d3 100644
--- a/akka-core/src/main/scala/actor/ActiveObject.scala
+++ b/akka-core/src/main/scala/actor/ActiveObject.scala
@@ -4,6 +4,7 @@
package se.scalablesolutions.akka.actor
+import Actor._
import se.scalablesolutions.akka.config.FaultHandlingStrategy
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol.RemoteRequestProtocol
import se.scalablesolutions.akka.remote.{RemoteProtocolBuilder, RemoteClient, RemoteRequestProtocolIdFactory}
@@ -548,7 +549,7 @@ private[akka] sealed class ActiveObjectAspect {
actorRef ! Invocation(joinPoint, true, true, sender, senderFuture)
null.asInstanceOf[AnyRef]
} else {
- val result = actorRef !! (Invocation(joinPoint, false, isOneWay, sender, senderFuture), timeout)
+ val result = (actorRef !! (Invocation(joinPoint, false, isOneWay, sender, senderFuture), timeout)).as[AnyRef]
if (result.isDefined) result.get
else throw new IllegalStateException("No result defined for invocation [" + joinPoint + "]")
}
diff --git a/akka-core/src/main/scala/actor/Actor.scala b/akka-core/src/main/scala/actor/Actor.scala
index 807355d95e..853ab79dd6 100644
--- a/akka-core/src/main/scala/actor/Actor.scala
+++ b/akka-core/src/main/scala/actor/Actor.scala
@@ -7,8 +7,9 @@ package se.scalablesolutions.akka.actor
import se.scalablesolutions.akka.dispatch._
import se.scalablesolutions.akka.config.Config._
import se.scalablesolutions.akka.config.ScalaConfig._
-import se.scalablesolutions.akka.util.Logging
import se.scalablesolutions.akka.serialization.Serializer
+import se.scalablesolutions.akka.util.Helpers.{ narrow, narrowSilently }
+import se.scalablesolutions.akka.util.Logging
import com.google.protobuf.Message
@@ -279,8 +280,13 @@ object Actor extends Logging {
case Spawn => body; self.stop
}
}).start ! Spawn
-
}
+
+ /**
+ * Implicitly converts the given Option[Any] to a AnyOptionAsTypedOption which offers the method as[T]
+ * to convert an Option[Any] to an Option[T].
+ */
+ implicit def toAnyOptionAsTypedOption(anyOption: Option[Any]) = new AnyOptionAsTypedOption(anyOption)
}
/**
@@ -496,3 +502,18 @@ trait Actor extends Logging {
case Kill => throw new ActorKilledException("Actor [" + toString + "] was killed by a Kill message")
}
}
+
+private[actor] class AnyOptionAsTypedOption(anyOption: Option[Any]) {
+
+ /**
+ * Convenience helper to cast the given Option of Any to an Option of the given type. Will throw a ClassCastException
+ * if the actual type is not assignable from the given one.
+ */
+ def as[T]: Option[T] = narrow[T](anyOption)
+
+ /**
+ * Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
+ * ClassCastException and return None in that case.
+ */
+ def asSilently[T: Manifest]: Option[T] = narrowSilently[T](anyOption)
+}
diff --git a/akka-core/src/main/scala/actor/ActorRef.scala b/akka-core/src/main/scala/actor/ActorRef.scala
index 42df4e1305..74fc3bc678 100644
--- a/akka-core/src/main/scala/actor/ActorRef.scala
+++ b/akka-core/src/main/scala/actor/ActorRef.scala
@@ -392,9 +392,9 @@ trait ActorRef extends TransactionManagement {
* If you are sending messages using !! then you have to use self.reply(..)
* to send a reply message to the original sender. If not then the sender will block until the timeout expires.
*/
- def !(implicit sender: Option[ActorRef] = None): Option[T] = {
+ def !!(message: Any, timeout: Long = this.timeout)(implicit sender: Option[ActorRef] = None): Option[Any] = {
if (isRunning) {
- val future = postMessageToMailboxAndCreateFutureResultWithTimeout[T](message, timeout, sender, None)
+ val future = postMessageToMailboxAndCreateFutureResultWithTimeout[Any](message, timeout, sender, None)
val isActiveObject = message.isInstanceOf[Invocation]
if (isActiveObject && message.asInstanceOf[Invocation].isVoid) {
future.asInstanceOf[CompletableFuture[Option[_]]].completeWithResult(None)
diff --git a/akka-core/src/main/scala/dataflow/DataFlowVariable.scala b/akka-core/src/main/scala/dataflow/DataFlowVariable.scala
index 8fa67e8269..baf3e33f6e 100644
--- a/akka-core/src/main/scala/dataflow/DataFlowVariable.scala
+++ b/akka-core/src/main/scala/dataflow/DataFlowVariable.scala
@@ -102,10 +102,10 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
else {
val out = actorOf(new Out(this)).start
blockedReaders.offer(out)
- val result = out !! Get
+ val result = (out !! Get).as[T]
out ! Exit
- result.getOrElse(throw new DataFlowVariableException(
- "Timed out (after " + TIME_OUT + " milliseconds) while waiting for result"))
+ if (result.isDefined) result.get
+ else throw new DataFlowVariableException("Timed out (after " + TIME_OUT + " milliseconds) while waiting for result")
}
}
diff --git a/akka-core/src/main/scala/remote/RemoteServer.scala b/akka-core/src/main/scala/remote/RemoteServer.scala
index 0d1540ab9a..54dfa4f075 100644
--- a/akka-core/src/main/scala/remote/RemoteServer.scala
+++ b/akka-core/src/main/scala/remote/RemoteServer.scala
@@ -10,6 +10,7 @@ import java.util.concurrent.{ConcurrentHashMap, Executors}
import java.util.{Map => JMap}
import se.scalablesolutions.akka.actor._
+import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.util._
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol._
import se.scalablesolutions.akka.config.Config.config
@@ -369,8 +370,8 @@ class RemoteServerHandler(
if (request.getIsOneWay) actorRef.!(message)(sender)
else {
try {
- val resultOrNone = actorRef.!!(message)(sender)
- val result: AnyRef = if (resultOrNone.isDefined) resultOrNone.get else null
+ val resultOrNone = (actorRef.!!(message)(sender)).as[AnyRef]
+ val result = if (resultOrNone.isDefined) resultOrNone.get else null
log.debug("Returning result from actor invocation [%s]", result)
val replyBuilder = RemoteReplyProtocol.newBuilder
.setId(request.getId)
diff --git a/akka-core/src/main/scala/util/Helpers.scala b/akka-core/src/main/scala/util/Helpers.scala
index 4835a4dd05..ccbd896610 100644
--- a/akka-core/src/main/scala/util/Helpers.scala
+++ b/akka-core/src/main/scala/util/Helpers.scala
@@ -37,5 +37,26 @@ object Helpers extends Logging {
})
sb.toString
}
-}
+ /**
+ * Convenience helper to cast the given Option of Any to an Option of the given type. Will throw a ClassCastException
+ * if the actual type is not assignable from the given one.
+ */
+ def narrow[T](o: Option[Any]): Option[T] = {
+ require(o != null, "Option to be narrowed must not be null!")
+ o.asInstanceOf[Option[T]]
+ }
+
+ /**
+ * Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
+ * ClassCastException and return None in that case.
+ */
+ def narrowSilently[T: Manifest](o: Option[Any]): Option[T] =
+ try {
+ narrow(o)
+ } catch {
+ case e: ClassCastException =>
+ log.warning(e, "Cannot narrow %s to expected type %s!", o, implicitly[Manifest[T]].erasure.getName)
+ None
+ }
+}
diff --git a/akka-core/src/test/scala/ActorPatternsTest.scala b/akka-core/src/test/scala/ActorPatternsTest.scala
index 0d4e9b6b08..f6205c2a91 100644
--- a/akka-core/src/test/scala/ActorPatternsTest.scala
+++ b/akka-core/src/test/scala/ActorPatternsTest.scala
@@ -39,9 +39,9 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
}.start
val result = for {
- a <- (d.!)
- b <- (d.!)
- c <- (d.!)
+ a <- (d !! (testMsg1,5000)).as[Int]
+ b <- (d !! (testMsg2,5000)).as[Int]
+ c <- (d !! (testMsg3,5000)).as[Int]
} yield a + b + c
result.get must be(21)
diff --git a/akka-core/src/test/scala/ExecutorBasedEventDrivenDispatcherActorSpec.scala b/akka-core/src/test/scala/ExecutorBasedEventDrivenDispatcherActorSpec.scala
index f876d59527..e679bc6b4f 100644
--- a/akka-core/src/test/scala/ExecutorBasedEventDrivenDispatcherActorSpec.scala
+++ b/akka-core/src/test/scala/ExecutorBasedEventDrivenDispatcherActorSpec.scala
@@ -41,8 +41,8 @@ class ExecutorBasedEventDrivenDispatcherActorSpec extends JUnitSuite {
@Test def shouldSendReplySync = {
val actor = actorOf[TestActor].start
- val result: String = (actor !! ("Hello", 10000)).get
- assert("World" === result)
+ val result = (actor !! ("Hello", 10000)).as[String]
+ assert("World" === result.get)
actor.stop
}
diff --git a/akka-core/src/test/scala/InMemoryActorSpec.scala b/akka-core/src/test/scala/InMemoryActorSpec.scala
index 3f9ec33cb3..fcc54399e2 100644
--- a/akka-core/src/test/scala/InMemoryActorSpec.scala
+++ b/akka-core/src/test/scala/InMemoryActorSpec.scala
@@ -116,7 +116,7 @@ class InMemoryActorSpec extends JUnitSuite {
stateful.start
stateful ! SetMapStateOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert("new state" === (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get)
}
@@ -138,7 +138,7 @@ class InMemoryActorSpec extends JUnitSuite {
failer.start
stateful ! SetMapStateOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert("init" === (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get) // check that state is == init state
}
@@ -163,7 +163,7 @@ class InMemoryActorSpec extends JUnitSuite {
stateful.start
stateful ! SetVectorStateOneWay("init") // set init state
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert(2 === (stateful !! GetVectorSize).get)
}
@@ -186,7 +186,7 @@ class InMemoryActorSpec extends JUnitSuite {
val failer = actorOf[InMemFailerActor]
failer.start
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert(1 === (stateful !! GetVectorSize).get)
}
@@ -211,7 +211,7 @@ class InMemoryActorSpec extends JUnitSuite {
stateful.start
stateful ! SetRefStateOneWay("init") // set init state
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert("new state" === (stateful !! GetRefState).get)
}
@@ -234,7 +234,7 @@ class InMemoryActorSpec extends JUnitSuite {
val failer = actorOf[InMemFailerActor]
failer.start
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
- val notifier: Option[CountDownLatch] = stateful !! GetNotifier
+ val notifier = (stateful !! GetNotifier).as[CountDownLatch]
assert(notifier.get.await(1, TimeUnit.SECONDS))
assert("init" === (stateful !! (GetRefState, 1000000)).get) // check that state is == init state
}
diff --git a/akka-core/src/test/scala/ReactorBasedSingleThreadEventDrivenDispatcherActorSpec.scala b/akka-core/src/test/scala/ReactorBasedSingleThreadEventDrivenDispatcherActorSpec.scala
index 726f79fa22..996c410977 100644
--- a/akka-core/src/test/scala/ReactorBasedSingleThreadEventDrivenDispatcherActorSpec.scala
+++ b/akka-core/src/test/scala/ReactorBasedSingleThreadEventDrivenDispatcherActorSpec.scala
@@ -44,7 +44,7 @@ class ReactorBasedSingleThreadEventDrivenDispatcherActorSpec extends JUnitSuite
@Test def shouldSendReplySync = {
val actor = actorOf[TestActor].start
- val result: String = (actor !! ("Hello", 10000)).get
+ val result = (actor !! ("Hello", 10000)).as[String].get
assert("World" === result)
actor.stop
}
diff --git a/akka-core/src/test/scala/ReactorBasedThreadPoolEventDrivenDispatcherActorSpec.scala b/akka-core/src/test/scala/ReactorBasedThreadPoolEventDrivenDispatcherActorSpec.scala
index b1f3dae678..b94a02a6fc 100644
--- a/akka-core/src/test/scala/ReactorBasedThreadPoolEventDrivenDispatcherActorSpec.scala
+++ b/akka-core/src/test/scala/ReactorBasedThreadPoolEventDrivenDispatcherActorSpec.scala
@@ -39,7 +39,7 @@ class ReactorBasedThreadPoolEventDrivenDispatcherActorSpec extends JUnitSuite {
@Test def shouldSendReplySync = {
val actor = actorOf[TestActor].start
- val result: String = (actor !! ("Hello", 10000)).get
+ val result = (actor !! ("Hello", 10000)).as[String].get
assert("World" === result)
actor.stop
}
diff --git a/akka-core/src/test/scala/StmSpec.scala b/akka-core/src/test/scala/StmSpec.scala
index e82d414800..1544936446 100644
--- a/akka-core/src/test/scala/StmSpec.scala
+++ b/akka-core/src/test/scala/StmSpec.scala
@@ -88,10 +88,10 @@ class StmSpec extends
try {
val actor = actorOf[GlobalTransactionVectorTestActor].start
actor !! Add(5)
- val size1: Int = (actor !! Size).getOrElse(fail("Could not get Vector::size"))
+ val size1 = (actor !! Size).as[Int].getOrElse(fail("Could not get Vector::size"))
size1 should equal(2)
actor !! Add(2)
- val size2: Int = (actor !! Size).getOrElse(fail("Could not get Vector::size"))
+ val size2 = (actor !! Size).as[Int].getOrElse(fail("Could not get Vector::size"))
size2 should equal(3)
} catch {
case e =>
@@ -107,18 +107,18 @@ class StmSpec extends
try {
val actor = actorOf[NestedTransactorLevelOneActor].start
actor !! Add(2)
- val size1: Int = (actor !! Size).getOrElse(fail("Could not get size"))
+ val size1 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
size1 should equal(2)
actor !! Add(7)
actor ! "HiLevelOne"
- val size2: Int = (actor !! Size).getOrElse(fail("Could not get size"))
+ val size2 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
size2 should equal(7)
actor !! Add(0)
actor ! "HiLevelTwo"
- val size3: Int = (actor !! Size).getOrElse(fail("Could not get size"))
+ val size3 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
size3 should equal(0)
actor !! Add(3)
- val size4: Int = (actor !! Size).getOrElse(fail("Could not get size"))
+ val size4 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
size4 should equal(3)
} catch {
case e =>
diff --git a/akka-core/src/test/scala/ThreadBasedActorSpec.scala b/akka-core/src/test/scala/ThreadBasedActorSpec.scala
index d10a39965b..eda6f4d52c 100644
--- a/akka-core/src/test/scala/ThreadBasedActorSpec.scala
+++ b/akka-core/src/test/scala/ThreadBasedActorSpec.scala
@@ -40,8 +40,8 @@ class ThreadBasedActorSpec extends JUnitSuite {
@Test def shouldSendReplySync = {
val actor = actorOf[TestActor].start
- val result: String = (actor !! ("Hello", 10000)).get
- assert("World" === result)
+ val result = (actor !! ("Hello", 10000)).as[String]
+ assert("World" === result.get)
actor.stop
}
diff --git a/akka-http/src/main/scala/Security.scala b/akka-http/src/main/scala/Security.scala
index 72d79db3d9..284d82d98e 100644
--- a/akka-http/src/main/scala/Security.scala
+++ b/akka-http/src/main/scala/Security.scala
@@ -23,8 +23,9 @@
package se.scalablesolutions.akka.security
import se.scalablesolutions.akka.actor.{Scheduler, Actor, ActorRef, ActorRegistry}
-import se.scalablesolutions.akka.util.Logging
+import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.config.Config
+import se.scalablesolutions.akka.util.Logging
import com.sun.jersey.api.model.AbstractMethod
import com.sun.jersey.spi.container.{ResourceFilterFactory, ContainerRequest, ContainerRequestFilter, ContainerResponse, ContainerResponseFilter, ResourceFilter}
@@ -87,7 +88,7 @@ class AkkaSecurityFilterFactory extends ResourceFilterFactory with Logging {
override def filter(request: ContainerRequest): ContainerRequest =
rolesAllowed match {
case Some(roles) => {
- val result : Option[AnyRef] = authenticator !! Authenticate(request, roles)
+ val result = (authenticator !! Authenticate(request, roles)).as[AnyRef]
result match {
case Some(OK) => request
case Some(r) if r.isInstanceOf[Response] =>
diff --git a/akka-http/src/test/scala/SecuritySpec.scala b/akka-http/src/test/scala/SecuritySpec.scala
index 2ee7596a25..6a3cf4f803 100644
--- a/akka-http/src/test/scala/SecuritySpec.scala
+++ b/akka-http/src/test/scala/SecuritySpec.scala
@@ -39,7 +39,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
@Test def testChallenge = {
val req = mock[ContainerRequest]
- val result: Response = (authenticator !! (Authenticate(req, List("foo")), 10000)).get
+ val result = (authenticator !! (Authenticate(req, List("foo")), 10000)).as[Response].get
// the actor replies with a challenge for the browser
result.getStatus must equal(Response.Status.UNAUTHORIZED.getStatusCode)
@@ -54,7 +54,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
// fake a request authorization -> this will authorize the user
when(req.isUserInRole("chef")).thenReturn(true)
- val result: AnyRef = (authenticator !! (Authenticate(req, List("chef")), 10000)).get
+ val result = (authenticator !! (Authenticate(req, List("chef")), 10000)).as[AnyRef].get
result must be(OK)
// the authenticator must have set a security context
@@ -68,7 +68,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
when(req.getHeaderValue("Authorization")).thenReturn("Basic " + new String(Base64.encode("foo:bar")))
when(req.isUserInRole("chef")).thenReturn(false) // this will deny access
- val result: Response = (authenticator !! (Authenticate(req, List("chef")), 10000)).get
+ val result = (authenticator !! (Authenticate(req, List("chef")), 10000)).as[Response].get
result.getStatus must equal(Response.Status.FORBIDDEN.getStatusCode)
diff --git a/akka-persistence/akka-persistence-cassandra/src/test/scala/CassandraPersistentActorSpec.scala b/akka-persistence/akka-persistence-cassandra/src/test/scala/CassandraPersistentActorSpec.scala
index 97419f3231..74673f2041 100644
--- a/akka-persistence/akka-persistence-cassandra/src/test/scala/CassandraPersistentActorSpec.scala
+++ b/akka-persistence/akka-persistence-cassandra/src/test/scala/CassandraPersistentActorSpec.scala
@@ -80,7 +80,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
stateful.start
stateful !! SetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
- val result: Array[Byte] = (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get
+ val result = (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).as[Array[Byte]].get
assertEquals("new state", new String(result, 0, result.length, "UTF-8"))
}
@@ -95,7 +95,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
fail("should have thrown an exception")
} catch {case e: RuntimeException => {}}
- val result: Array[Byte] = (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get
+ val result = (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).as[Array[Byte]].get
assertEquals("init", new String(result, 0, result.length, "UTF-8")) // check that state is == init state
}
@@ -128,7 +128,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
stateful.start
stateful !! SetRefState("init") // set init state
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
- val result: Array[Byte] = (stateful !! GetRefState).get
+ val result = (stateful !! GetRefState).as[Array[Byte]].get
assertEquals("new state", new String(result, 0, result.length, "UTF-8"))
}
@@ -143,7 +143,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
fail("should have thrown an exception")
} catch {case e: RuntimeException => {}}
- val result: Array[Byte] = (stateful !! GetRefState).get
+ val result = (stateful !! GetRefState).as[Array[Byte]].get
assertEquals("init", new String(result, 0, result.length, "UTF-8")) // check that state is == init state
}
diff --git a/akka-persistence/akka-persistence-redis/src/test/scala/RedisInconsistentSizeBugTest.scala b/akka-persistence/akka-persistence-redis/src/test/scala/RedisInconsistentSizeBugTest.scala
index dde431628a..74d1e95cc9 100644
--- a/akka-persistence/akka-persistence-redis/src/test/scala/RedisInconsistentSizeBugTest.scala
+++ b/akka-persistence/akka-persistence-redis/src/test/scala/RedisInconsistentSizeBugTest.scala
@@ -66,9 +66,9 @@ object Runner {
def run {
val proc = actorOf[RedisSampleStorage]
proc.start
- val i: Option[String] = proc !! SETFOO("debasish")
+ val i = (proc !! SETFOO("debasish")).as[String]
println("i = " + i)
- val ev: Option[Int] = proc !! GETFOO("debasish")
+ val ev = (proc !! GETFOO("debasish")).as[Int]
println(ev)
}
}
diff --git a/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentActorSpec.scala b/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentActorSpec.scala
index 18dd4ce94d..236519abd8 100644
--- a/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentActorSpec.scala
+++ b/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentActorSpec.scala
@@ -113,7 +113,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
bactor !! Debit("a-123", 8000, failer)
assertEquals(BigInt(1000), (bactor !! Balance("a-123")).get)
- val c: Int = (bactor !! LogSize).get
+ val c = (bactor !! LogSize).as[Int].get
assertTrue(7 == c)
}
@@ -134,7 +134,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
assertEquals(BigInt(5000), (bactor !! Balance("a-123")).get)
// should not count the failed one
- val c: Int = (bactor !! LogSize).get
+ val c = (bactor !! LogSize).as[Int].get
assertTrue(3 == c)
}
@@ -156,7 +156,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
assertEquals(BigInt(5000), (bactor !! (Balance("a-123"), 5000)).get)
// should not count the failed one
- val c: Int = (bactor !! LogSize).get
+ val c = (bactor !! LogSize).as[Int].get
assertTrue(3 == c)
}
}
diff --git a/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentQSpec.scala b/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentQSpec.scala
index 6cdd192593..5522b00d45 100644
--- a/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentQSpec.scala
+++ b/akka-persistence/akka-persistence-redis/src/test/scala/RedisPersistentQSpec.scala
@@ -58,7 +58,7 @@ class RedisPersistentQSpec extends JUnitSuite {
qa !! NQ("a-123")
qa !! NQ("a-124")
qa !! NQ("a-125")
- val t: Int = (qa !! SZ).get
+ val t = (qa !! SZ).as[Int].get
assertTrue(3 == t)
}
@@ -69,12 +69,12 @@ class RedisPersistentQSpec extends JUnitSuite {
qa !! NQ("a-123")
qa !! NQ("a-124")
qa !! NQ("a-125")
- val s: Int = (qa !! SZ).get
+ val s = (qa !! SZ).as[Int].get
assertTrue(3 == s)
assertEquals("a-123", (qa !! DQ).get)
assertEquals("a-124", (qa !! DQ).get)
assertEquals("a-125", (qa !! DQ).get)
- val t: Int = (qa !! SZ).get
+ val t = (qa !! SZ).as[Int].get
assertTrue(0 == t)
}
@@ -88,13 +88,13 @@ class RedisPersistentQSpec extends JUnitSuite {
qa !! NQ("a-123")
qa !! NQ("a-124")
qa !! NQ("a-125")
- val t: Int = (qa !! SZ).get
+ val t = (qa !! SZ).as[Int].get
assertTrue(3 == t)
assertEquals("a-123", (qa !! DQ).get)
- val s: Int = (qa !! SZ).get
+ val s = (qa !! SZ).as[Int].get
assertTrue(2 == s)
qa !! MNDQ(List("a-126", "a-127"), 2, failer)
- val u: Int = (qa !! SZ).get
+ val u = (qa !! SZ).as[Int].get
assertTrue(2 == u)
}
@@ -110,25 +110,25 @@ class RedisPersistentQSpec extends JUnitSuite {
qa !! NQ("a-124")
qa !! NQ("a-125")
- val t: Int = (qa !! SZ).get
+ val t = (qa !! SZ).as[Int].get
assertTrue(3 == t)
// dequeue 1
assertEquals("a-123", (qa !! DQ).get)
// size == 2
- val s: Int = (qa !! SZ).get
+ val s = (qa !! SZ).as[Int].get
assertTrue(2 == s)
// enqueue 2, dequeue 2 => size == 2
qa !! MNDQ(List("a-126", "a-127"), 2, failer)
- val u: Int = (qa !! SZ).get
+ val u = (qa !! SZ).as[Int].get
assertTrue(2 == u)
// enqueue 2 => size == 4
qa !! NQ("a-128")
qa !! NQ("a-129")
- val v: Int = (qa !! SZ).get
+ val v = (qa !! SZ).as[Int].get
assertTrue(4 == v)
// enqueue 1 => size 5
@@ -138,7 +138,7 @@ class RedisPersistentQSpec extends JUnitSuite {
qa !! MNDQ(List("a-130"), 6, failer)
} catch { case e: Exception => {} }
- val w: Int = (qa !! SZ).get
+ val w = (qa !! SZ).as[Int].get
assertTrue(4 == w)
}
}
diff --git a/akka-samples/akka-sample-chat/src/main/scala/ChatServer.scala b/akka-samples/akka-sample-chat/src/main/scala/ChatServer.scala
index abe76ebcfa..01e1738b87 100644
--- a/akka-samples/akka-sample-chat/src/main/scala/ChatServer.scala
+++ b/akka-samples/akka-sample-chat/src/main/scala/ChatServer.scala
@@ -63,10 +63,10 @@ case class ChatMessage(from: String, message: String) extends Event
class ChatClient(val name: String) {
val chat = RemoteClient.actorFor("chat:service", "localhost", 9999)
- def login = chat ! Login(name)
- def logout = chat ! Logout(name)
+ def login = chat ! Login(name)
+ def logout = chat ! Logout(name)
def post(message: String) = chat ! ChatMessage(name, name + ": " + message)
- def chatLog: ChatLog = (chat !! GetChatLog(name)).getOrElse(throw new Exception("Couldn't get the chat log from ChatServer"))
+ def chatLog = (chat !! GetChatLog(name)).as[ChatLog].getOrElse(throw new Exception("Couldn't get the chat log from ChatServer"))
}
/**
diff --git a/akka-samples/akka-sample-rest-scala/src/main/scala/SimpleService.scala b/akka-samples/akka-sample-rest-scala/src/main/scala/SimpleService.scala
index 0a5af80a57..870739bf8f 100644
--- a/akka-samples/akka-sample-rest-scala/src/main/scala/SimpleService.scala
+++ b/akka-samples/akka-sample-rest-scala/src/main/scala/SimpleService.scala
@@ -54,7 +54,7 @@ class SimpleService {
//Fetch the first actor of type SimpleServiceActor
//Send it the "Tick" message and expect a NodeSeq back
val result = for{a <- actorsFor(classOf[SimpleServiceActor]).headOption
- r <- a.!} yield r
+ r <- (a !! "Tick").as[NodeSeq]} yield r
//Return either the resulting NodeSeq or a default one
result getOrElse Error in counter
}
@@ -109,7 +109,7 @@ class PersistentSimpleService {
//Fetch the first actor of type PersistentSimpleServiceActor
//Send it the "Tick" message and expect a NodeSeq back
val result = for{a <- actorsFor(classOf[PersistentSimpleServiceActor]).headOption
- r <- a.!} yield r
+ r <- (a !! "Tick").as[NodeSeq]} yield r
//Return either the resulting NodeSeq or a default one
result getOrElse Error in counter
}
@@ -156,7 +156,7 @@ class Chat {
//Fetch the first actor of type ChatActor
//Send it the "Tick" message and expect a NodeSeq back
val result = for{a <- actorsFor(classOf[ChatActor]).headOption
- r <- a.!} yield r
+ r <- (a !! msg).as[String]} yield r
//Return either the resulting String or a default one
result getOrElse "System__error"
}
diff --git a/akka-samples/akka-sample-security/src/main/scala/SimpleService.scala b/akka-samples/akka-sample-security/src/main/scala/SimpleService.scala
index 061555ef05..e5c8029eb8 100644
--- a/akka-samples/akka-sample-security/src/main/scala/SimpleService.scala
+++ b/akka-samples/akka-sample-security/src/main/scala/SimpleService.scala
@@ -123,7 +123,7 @@ class SecureTickService {
//Fetch the first actor of type PersistentSimpleServiceActor
//Send it the "Tick" message and expect a NdeSeq back
val result = for{a <- actorsFor(classOf[SecureTickActor]).headOption
- r <- a.!} yield r
+ r <- (a !! "Tick").as[Integer]} yield r
//Return either the resulting NodeSeq or a default one
result match {
case (Some(counter)) => (Tick: {counter})