In Akka 2.5.12 there is a method:
https://doc.akka.io/japi/akka/2.5.12/akka/actor/ActorSystem.html#getWhenTerminated--
And this works
CompletionStage<Terminated> stage = system.getWhenTerminated();
stage.thenRun(() ->System.out.println( "--Master Actor System Terminated"));
For legacy purposes I need to use 2.5.9, but am confused on the first parameter, I would like to do something the same like this:
Future<Terminated> fts = system.whenTerminated();
fts.onComplete(
() -> System.out.println( "--Master actor system terminated"),
, system.dispatcher());
Is this a viable option for 2.5.9
What do I pass i for the first parameter?
I think the nicest option is to transform the Future
into a CompletionStage
using the scala-java8-compat library (you likely have it as a transitive dependency via Akka already) and then use that as you are used to with a Java lambda.
There’s a Java example in the tests transforming a future to a completion stage here: https://github.com/scala/scala-java8-compat/blob/master/src/test/java/scala/compat/java8/FutureConvertersTest.java#L57
1 Like
So in essence is the only difference of getWhenTerminated
and whenTerminated
is one returns a future, and the other a completion stage?
ktoso
(Konrad `ktoso` Malawski)
July 17, 2018, 2:51pm
4
So in essence is the only difference of getWhenTerminated
and whenTerminated
is one returns a future, and the other a completion stage?
Correct, that’s the only difference; one is intended for Java users and the other for Scala users.
1 Like