Reputation: 8495
I am using AKKA 2.1 with Scala 2.10.
I need multiple machines to start actor systems and instantiate some number of actors. After this, each system needs to access all other systems and collect references to their actors using "actorFor(...)".
However, I need a way for an actor system to wait on the other systems to boot before it connects, otherwise I get errors.
If actor system A connects to B while B is offline, my program fails. However, if A connects to B and obtains a remote actor reference before it exists on B, the program continues fine once B actually instantiates the actor.
In a nutshell, I need somehow to await the creation event at B before I try connecting to it. Is there a good way to do this in Scala+AKKA?
Upvotes: 2
Views: 1512
Reputation: 26579
99% of the time solving the problems with people will let you solve it with actors. Imagine it being buildings (ActorSystems) and people (Actors).
You can create a "receptionist" actor that gets created on ActorSystem startup (Akka Extensions can be configured to be loaded when the ActorSystem starts) under a common path like "/user/receptionist" and then you tell the receptionist to hook you up with actor X/Y/Z when he/she comes online, and then have X/Y/Z register itself with the receptionist. So if X/Y/Z is not there when the external actor asks, it stores the request until some timeout or X/Y/Z "reports in".
Upvotes: 2
Reputation: 261
First off, actorSelection
is now the suggested mechanisms for obtaining references to actors, especially across the network. see: Akka Docs
This is a non-trivial problem in asynchronous and distributed systems. The akka cluster support uses all sorts of mechanisms adopted from their dynamo-like framework. If you imagine that each of your actors are people, and each actor system are people in the building, your task is akin to asking whether Bob has entered the building across the street. You can either:
actorRef
until successful and deal with the errorsUpvotes: 0
Reputation: 1863
You might want to look into the cluster support for Akka. It allows you to listen to events when other machines join the cluster and become available for communication.
Upvotes: 2