diff --git a/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala index 2af08fbe6f..59ce3d4952 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala @@ -276,14 +276,10 @@ class TypedActorSpec extends AkkaSpec with BeforeAndAfterEach with BeforeAndAfte t.failingFuturePigdog.await.exception.get.getMessage must be("expected") t.read() must be(1) //Make sure state is not reset after failure - (intercept[IllegalStateException] { - t.failingJOptionPigdog - }).getMessage must be("expected") + (intercept[IllegalStateException] { t.failingJOptionPigdog }).getMessage must be("expected") t.read() must be(1) //Make sure state is not reset after failure - (intercept[IllegalStateException] { - t.failingOptionPigdog - }).getMessage must be("expected") + (intercept[IllegalStateException] { t.failingOptionPigdog }).getMessage must be("expected") t.read() must be(1) //Make sure state is not reset after failure diff --git a/akka-actor/src/main/scala/akka/actor/TypedActor.scala b/akka-actor/src/main/scala/akka/actor/TypedActor.scala index c07cb7a128..fb3269249c 100644 --- a/akka-actor/src/main/scala/akka/actor/TypedActor.scala +++ b/akka-actor/src/main/scala/akka/actor/TypedActor.scala @@ -339,15 +339,23 @@ class TypedActor(val app: AkkaApplication) { TypedActor.appReference set app try { if (m.isOneWay) m(me) - else if (m.returnsFuture_?) { + else { val s = sender - m(me).asInstanceOf[Future[Any]] onComplete { - _.value.get match { - case Left(f) ⇒ s ! akka.actor.Status.Failure(f) - case Right(r) ⇒ s ! r + try { + if (m.returnsFuture_?) { + m(me).asInstanceOf[Future[Any]] onComplete { + _.value.get match { + case Left(f) ⇒ s ! akka.actor.Status.Failure(f) + case Right(r) ⇒ s ! r + } + } + } else { + s ! m(me) } + } catch { + case e: Exception ⇒ s ! akka.actor.Status.Failure(e) } - } else sender ! m(me) + } } finally { TypedActor.selfReference set null @@ -366,17 +374,18 @@ class TypedActor(val app: AkkaApplication) { case _ ⇒ MethodCall(app, method, args) match { case m if m.isOneWay ⇒ actor ! m; null //Null return value - case m if m.returnsFuture_? ⇒ actor ? m + case m if m.returnsFuture_? ⇒ actor.?(m, timeout) case m if m.returnsJOption_? || m.returnsOption_? ⇒ - val f = actor ? m + val f = actor.?(m, timeout) try { f.await } catch { case _: FutureTimeoutException ⇒ } + println("JOption result: " + f.value) f.value match { case None | Some(Right(null)) ⇒ if (m.returnsJOption_?) JOption.none[Any] else None case Some(Right(joption: AnyRef)) ⇒ joption case Some(Left(ex)) ⇒ throw ex } case m ⇒ - (actor ? m).get.asInstanceOf[AnyRef] + (actor.?(m, timeout)).get.asInstanceOf[AnyRef] } } }