Class ActorRegistry


  • public class ActorRegistry
    extends java.lang.Object
    A registry used to find registered actors by name. Actors are registered with the Actor.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<?>>
      T
      getActor​(java.lang.String name)
      Locates a registered actor by name, or blocks until one is registered.
      static <T extends ActorRef<?>>
      T
      getActor​(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<?>>
      T
      tryGetActor​(java.lang.String name)
      Locates a registered actor by name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActorRegistry

        public ActorRegistry()
    • 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 timeout
        unit - 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 - the FiberScheduler to use when spawning the actor, or null 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, or false 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!).