From an actor (akka.actor.Actor) how can I execute a method twice simultaneously? Try to do it with Futures, but if the future does not respond, the actor does not take more requests ...
-
2How about to actually include some piece of code in your question that represents your current issue?– Branislav LazicMar 24, 2017 at 16:53
-
"if the future does not respond, the actor does not take more requests" - that doesn't seem right, i.e. that's not the case if you use Futures in the intended way. Could you post the code in question?– lutzhMar 25, 2017 at 15:56
-
Sorry.. I assumed it was very simple. :(– jamlhetMar 28, 2017 at 14:19
1 Answer
Generally, actors should not block. Dealing with actors, you should think in dataflow manner. Draw a dataflow diagram like this:
--> methodCall1 --> |----------|
actor1 / | actor2 |
\ --> methodCall2 --> |__________|
Actor2 can be inplemented as an Akka actor, which counts incoming messages and reacts when both messages has arrived. In this case, methodCall1
and methodCall
must know actor2 and send messages to it.
Or actor2 can be a CompletableFuture which is derived from the future of one of method calls using method thenCombine
.