Package co.paralleluniverse.actors
Class ActorRegistry
- java.lang.Object
-
- co.paralleluniverse.actors.ActorRegistry
-
public class ActorRegistry extends java.lang.Object
A registry used to find registered actors by name. Actors are registered with theActor.register()
method.
-
-
Constructor Summary
Constructors Constructor Description ActorRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
clear()
Clears the registry (use only in tests!).static <T extends ActorRef<?>>
TgetActor(java.lang.String name)
Locates a registered actor by name, or blocks until one is registered.static <T extends ActorRef<?>>
TgetActor(java.lang.String name, long timeout, java.util.concurrent.TimeUnit unit)
Locates a registered actor by name, or blocks until one is registered, but no more than the given timeout.static <Message> ActorRef<Message>
getOrRegisterActor(java.lang.String name, java.util.concurrent.Callable<Actor<Message,?>> actorFactory)
Locates a registered actor by name, or, if not actor by that name is currently registered, spawns and registers it.static <Message> ActorRef<Message>
getOrRegisterActor(java.lang.String name, java.util.concurrent.Callable<Actor<Message,?>> actorFactory, FiberScheduler scheduler)
Locates a registered actor by name, or, if not actor by that name is currently registered, spawns and registers it.static boolean
hasGlobalRegistry()
Checks whether the registry is global to the entire cluster.static void
shutdown()
Shuts down the registry.static <T extends ActorRef<?>>
TtryGetActor(java.lang.String name)
Locates a registered actor by name.
-
-
-
Method Detail
-
tryGetActor
public static <T extends ActorRef<?>> T tryGetActor(java.lang.String name) throws SuspendExecution
Locates a registered actor by name.- Parameters:
name
- the actor's name.- Returns:
- the actor, or
null
if no actor by that name is currently registered. - Throws:
SuspendExecution
-
getActor
public static <T extends ActorRef<?>> T getActor(java.lang.String name, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, SuspendExecution
Locates a registered actor by name, or blocks until one is registered, but no more than the given timeout.- Parameters:
name
- the actor's name.timeout
- the timeoutunit
- the timeout's unit- Returns:
- the actor, or
null
if the timeout expires before one is registered. - Throws:
java.lang.InterruptedException
SuspendExecution
-
getActor
public static <T extends ActorRef<?>> T getActor(java.lang.String name) throws java.lang.InterruptedException, SuspendExecution
Locates a registered actor by name, or blocks until one is registered.- Parameters:
name
- the actor's name.- Returns:
- the actor.
- Throws:
java.lang.InterruptedException
SuspendExecution
-
getOrRegisterActor
public static <Message> ActorRef<Message> getOrRegisterActor(java.lang.String name, java.util.concurrent.Callable<Actor<Message,?>> actorFactory, FiberScheduler scheduler) throws SuspendExecution
Locates a registered actor by name, or, if not actor by that name is currently registered, spawns and registers it. This method atomically checks if an actor by the given name is registers, and if so, returns it; otherwise it spawns and registers the actor returned by the given factory.- Parameters:
name
- the actor's name.actorFactory
- returns an actor that will be registered if one isn't currently registered.scheduler
- theFiberScheduler
to use when spawning the actor, ornull
to spawn the fiber using the default scheduler.- Returns:
- the actor.
- Throws:
SuspendExecution
-
getOrRegisterActor
public static <Message> ActorRef<Message> getOrRegisterActor(java.lang.String name, java.util.concurrent.Callable<Actor<Message,?>> actorFactory) throws SuspendExecution
Locates a registered actor by name, or, if not actor by that name is currently registered, spawns and registers it. This method atomically checks if an actor by the given name is registers, and if so, returns it; otherwise it spawns the actor returned by the given factory using the default fiber scheduler, and registers it.- Parameters:
name
- the actor's name.actorFactory
- returns an actor that will be registered if one isn't currently registered.- Returns:
- the actor.
- Throws:
SuspendExecution
-
hasGlobalRegistry
public static boolean hasGlobalRegistry()
Checks whether the registry is global to the entire cluster.- Returns:
true
if the registry is global to the entire cluster, orfalse
if it is local to this JVM instance.
-
shutdown
public static void shutdown()
Shuts down the registry.
-
clear
public static void clear()
Clears the registry (use only in tests!).
-
-