From a96317047fc049b2c926e95dcb272429bc4abada Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 24 Apr 2012 17:56:18 +0200 Subject: [PATCH 1/2] #2020 - Adding 'checkedApply' to Mapper to allow for binary compatible retrofit. And then @throws on the other Java Callbacks --- .../java/akka/dispatch/JavaFutureTests.java | 5 +++- .../src/main/scala/akka/dispatch/Future.scala | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) 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 5cb502cbf9f..e9ab0fccf15 100644 --- a/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java +++ b/akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java @@ -10,6 +10,8 @@ import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; + +import java.io.IOException; import java.util.concurrent.Callable; import java.util.LinkedList; import java.lang.Iterable; @@ -130,7 +132,8 @@ public void mustBeAbleToFlatMapAFuture() throws Throwable { cf.success("1000"); Future f = cf; Future r = f.flatMap(new Mapper>() { - public Future apply(String r) { + public Future checkedApply(String r) throws Throwable { + if (false) throw new IOException("Just here to make sure this compiles."); latch.countDown(); Promise cf = Futures.promise(system.dispatcher()); cf.success(Integer.parseInt(r)); diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 300d44f0bed..adc7cada44d 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -1015,6 +1015,7 @@ abstract class OnSuccess[-T] extends japi.CallbackBridge[T] { * This method will be invoked once when/if a Future that this callback is registered on * becomes successfully completed */ + @throws(classOf[Throwable]) def onSuccess(result: T): Unit } @@ -1031,6 +1032,7 @@ abstract class OnFailure extends japi.CallbackBridge[Throwable] { * This method will be invoked once when/if a Future that this callback is registered on * becomes completed with a failure */ + @throws(classOf[Throwable]) def onFailure(failure: Throwable): Unit } @@ -1051,6 +1053,7 @@ abstract class OnComplete[-T] extends japi.CallbackBridge[Either[Throwable, T]] * becomes completed with a failure or a success. * In the case of success then "failure" will be null, and in the case of failure the "success" will be null. */ + @throws(classOf[Throwable]) def onComplete(failure: Throwable, success: T): Unit } @@ -1121,6 +1124,7 @@ abstract class Foreach[-T] extends japi.UnitFunctionBridge[T] { * This method will be invoked once when/if a Future that this callback is registered on * becomes successfully completed */ + @throws(classOf[Throwable]) def each(result: T): Unit } @@ -1129,8 +1133,25 @@ abstract class Foreach[-T] extends japi.UnitFunctionBridge[T] { * if the Future that this callback is registered on becomes completed with a success. * This callback is the equivalent of an akka.japi.Function * + * Override "apply" normally, or "checkedApply" if you need to throw checked exceptions. + * * SAM (Single Abstract Method) class * * Java API */ -abstract class Mapper[-T, +R] extends scala.runtime.AbstractFunction1[T, R] +abstract class Mapper[-T, +R] extends scala.runtime.AbstractFunction1[T, R] { + + /** + * Override this method to perform the map operation, by default delegates to "checkedApply" + * which by default throws an UnsupportedOperationException. + */ + def apply(parameter: T): R = checkedApply(parameter) + + /** + * Override this method if you need to throw checked exceptions + * + * @throws UnsupportedOperation by default + */ + @throws(classOf[Throwable]) + def checkedApply(parameter: T): R = throw new UnsupportedOperationException("Mapper.checkedApply has not been implemented") +} From f089160aec8c26e0e7fb56d79b7694d50384af21 Mon Sep 17 00:00:00 2001 From: viktorklang Date: Fri, 27 Apr 2012 12:25:09 +0300 Subject: [PATCH 2/2] Adding warning about the Scala REPL context classloader bug --- akka-docs/general/configuration.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/akka-docs/general/configuration.rst b/akka-docs/general/configuration.rst index 20b3de7335f..621caa4f208 100644 --- a/akka-docs/general/configuration.rst +++ b/akka-docs/general/configuration.rst @@ -11,6 +11,14 @@ should have a look at its documentation (in particular about `ConfigFactory `_), which is only summarized in the following. +.. warning:: + + If you use Akka from the Scala REPL from the 2.9.x series, + and you do not provide your own ClassLoader to the ActorSystem, + start the REPL with "-Yrepl-sync" to work around a deficiency in + the REPLs provided Context ClassLoader. + + Where configuration is read from --------------------------------