diff --git a/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java b/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java index ad99a4af58..8ebee80595 100644 --- a/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java +++ b/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java @@ -60,7 +60,7 @@ public class JavaFutureTests { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(system.dispatcher()); Future f = cf; - f.onResult(new Procedure() { + f.onSuccess(new Procedure() { public void apply(String result) { if (result.equals("foo")) latch.countDown(); @@ -77,7 +77,7 @@ public class JavaFutureTests { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(system.dispatcher()); Future f = cf; - f.onException(new Procedure() { + f.onFailure(new Procedure() { public void apply(Throwable t) { if (t instanceof NullPointerException) latch.countDown(); diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala index 7109c804af..fdf5756973 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala @@ -394,7 +394,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "receiveShouldExecuteOnComplete" in { val latch = new StandardLatch val actor = system.actorOf[TestActor] - actor ? "Hello" onResult { case "World" ⇒ latch.open } + actor ? "Hello" onSuccess { case "World" ⇒ latch.open } assert(latch.tryAwait(5, TimeUnit.SECONDS)) actor.stop() } @@ -427,12 +427,12 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa val latch = new StandardLatch val f2 = Future { latch.tryAwait(5, TimeUnit.SECONDS); "success" } f2 foreach (_ ⇒ throw new ThrowableTest("dispatcher foreach")) - f2 onResult { case _ ⇒ throw new ThrowableTest("dispatcher receive") } + f2 onSuccess { case _ ⇒ throw new ThrowableTest("dispatcher receive") } val f3 = f2 map (s ⇒ s.toUpperCase) latch.open assert(Block.sync(f2, timeout.duration) === "success") f2 foreach (_ ⇒ throw new ThrowableTest("current thread foreach")) - f2 onResult { case _ ⇒ throw new ThrowableTest("current thread receive") } + f2 onSuccess { case _ ⇒ throw new ThrowableTest("current thread receive") } assert(Block.sync(f3, timeout.duration) === "SUCCESS") } } diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 785dc46703..ca558748c6 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -295,7 +295,7 @@ object Future { def flow[A](body: ⇒ A @cps[Future[Any]])(implicit dispatcher: MessageDispatcher): Future[A] = { val future = Promise[A] dispatchTask({ () ⇒ - (reify(body) foreachFull (future success, future failure): Future[Any]) onException { + (reify(body) foreachFull (future success, future failure): Future[Any]) onFailure { case e: Exception ⇒ future failure e } }, true) @@ -420,13 +420,13 @@ sealed trait Future[+T] extends japi.Future[T] with Block.Blockable[T] { * When the future is completed with a valid result, apply the provided * PartialFunction to the result. See `onComplete` for more details. *
-   *   future onResult {
+   *   future onSuccess {
    *     case Foo ⇒ target ! "foo"
    *     case Bar ⇒ target ! "bar"
    *   }
    * 
*/ - final def onResult(pf: PartialFunction[T, Unit]): this.type = onComplete { + final def onSuccess(pf: PartialFunction[T, Unit]): this.type = onComplete { _.value match { case Some(Right(r)) if pf isDefinedAt r ⇒ pf(r) case _ ⇒ @@ -437,12 +437,12 @@ sealed trait Future[+T] extends japi.Future[T] with Block.Blockable[T] { * When the future is completed with an exception, apply the provided * PartialFunction to the exception. See `onComplete` for more details. *
-   *   future onException {
+   *   future onFailure {
    *     case NumberFormatException ⇒ target ! "wrong format"
    *   }
    * 
*/ - final def onException(pf: PartialFunction[Throwable, Unit]): this.type = onComplete { + final def onFailure(pf: PartialFunction[Throwable, Unit]): this.type = onComplete { _.value match { case Some(Left(ex)) if pf isDefinedAt ex ⇒ pf(ex) case _ ⇒ diff --git a/akka-actor/src/main/scala/akka/dispatch/japi/Future.scala b/akka-actor/src/main/scala/akka/dispatch/japi/Future.scala index 8871050adb..a9b2b2482f 100644 --- a/akka-actor/src/main/scala/akka/dispatch/japi/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/japi/Future.scala @@ -8,8 +8,8 @@ import akka.actor.Timeout /* Java API */ trait Future[+T] { self: akka.dispatch.Future[T] ⇒ - private[japi] final def onResult[A >: T](proc: Procedure[A]): this.type = self.onResult({ case r ⇒ proc(r.asInstanceOf[A]) }: PartialFunction[T, Unit]) - private[japi] final def onException(proc: Procedure[Throwable]): this.type = self.onException({ case t: Throwable ⇒ proc(t) }: PartialFunction[Throwable, Unit]) + private[japi] final def onSuccess[A >: T](proc: Procedure[A]): this.type = self.onSuccess({ case r ⇒ proc(r.asInstanceOf[A]) }: PartialFunction[T, Unit]) + private[japi] final def onFailure(proc: Procedure[Throwable]): this.type = self.onFailure({ case t: Throwable ⇒ proc(t) }: PartialFunction[Throwable, Unit]) private[japi] final def onComplete[A >: T](proc: Procedure[akka.dispatch.Future[A]]): this.type = self.onComplete(proc(_)) private[japi] final def map[A >: T, B](f: JFunc[A, B]): akka.dispatch.Future[B] = self.map(f(_)) private[japi] final def flatMap[A >: T, B](f: JFunc[A, akka.dispatch.Future[B]]): akka.dispatch.Future[B] = self.flatMap(f(_)) diff --git a/akka-docs/general/jmm.rst b/akka-docs/general/jmm.rst index a84bad2dd2..d05a0e28a0 100644 --- a/akka-docs/general/jmm.rst +++ b/akka-docs/general/jmm.rst @@ -79,7 +79,7 @@ Since Akka runs on the JVM there are still some rules to be followed. // Very bad, shared mutable state, // will break your application in weird ways Future { state = NewState } - anotherActor ? message onResult { r => state = r } + anotherActor ? message onSuccess { r => state = r } // Very bad, "sender" changes for every message, // shared mutable state bug diff --git a/akka-docs/scala/actors.rst b/akka-docs/scala/actors.rst index b5cd58ef70..88a9c9df16 100644 --- a/akka-docs/scala/actors.rst +++ b/akka-docs/scala/actors.rst @@ -306,7 +306,7 @@ future. .. warning:: - When using future callbacks, such as ``onComplete``, ``onResult``, and ``onTimeout``, + When using future callbacks, such as ``onComplete``, ``onSuccess``, and ``onFailure``, inside actors you need to carefully avoid closing over the containing actor’s reference, i.e. do not call methods or access mutable state on the enclosing actor from within the callback. This would break the actor encapsulation and may