ActorRegistry (Java)

Module stability: SOLID

Working with the underlying ActorRef

To be able to use the 'ActorRegistry' you need to work with the underlying (Scala) 'ActorRef'. In order to do that you need to know two things:
  • The first is how to create a Java friendly 'UntypedActorRef' from an 'ActorRef'. This is done by invoking 'UntypedActorRef.wrap(actorRef)'.
  • The second thing is how to get to underlying 'ActorRef' out of the 'UnypedActorRef'. This is done by invoking 'untypedActorRef.actorRef'.

When you know how to do this, then you can work with for example the 'ActorRegistry' which we will discuss next.

ActorRegistry: Finding Actors

Actors can be looked up using the '' object. Through this registry you can look up actors by:
  • uuid string – this uses the ‘uuid’ field in the Actor class, returns all actor instances with that uuid
  • id string – this uses the ‘id’ field in the Actor class, which can be set by the user (default is the class name), returns instances of a specific Actor
  • parameterized type - returns a 'ActorRef[]' with all actors that are a subtype of this specific type
  • specific actor class - returns a 'ActorRef[]' with all actors of this exact class

Actors are automatically registered in the ActorRegistry when they are started and removed when they are stopped. But you can explicitly register and unregister ActorRef's if you need to using the 'register' and 'unregister' methods.

Here is a summary of the API for finding actors:

Option<ActorRef> actorFor(String uuid);
Actor[] actors();
Actor[] actorsFor(String id);
Actor[] actorsFor(Class clazz);

You can shut down all Actors in the system by invoking:


If you want to know when a new Actor is added or to or removed from the registry, you can use the subscription API. You can register an Actor that should be notified when an event happens in the ActorRegistry:

void addRegistrationListener(ActorRef listener)
void removeRegistrationListener(ActorRef listener)

The messages sent to this Actor are:

class ActorRegistered {
  ActorRef actor();
class ActorUnregistered {
  ActorRef actor();

So your listener Actor needs to be able to handle these two messages.
Home Turn Off "Getting Started"