Class ShardedDaemonProcess


  • public abstract class ShardedDaemonProcess
    extends java.lang.Object
    This extension runs a pre set number of actors in a cluster.

    The typical use case is when you have a task that can be divided in a number of workers, each doing a sharded part of the work, for example consuming the read side events from Akka Persistence through tagged events where each tag decides which consumer that should consume the event.

    Each named set needs to be started on all the nodes of the cluster on start up.

    The processes are spread out across the cluster, when the cluster topology changes the processes may be stopped and started anew on a new node to rebalance them.

    Not for user extension.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static ShardedDaemonProcess get​(ActorSystem<?> system)  
      abstract <T> void init​(java.lang.Class<T> messageClass, java.lang.String name, int numberOfInstances, java.util.function.IntFunction<Behavior<T>> behaviorFactory)
      Start a specific number of actors that is then kept alive in the cluster.
      abstract <T> void init​(java.lang.Class<T> messageClass, java.lang.String name, int numberOfInstances, java.util.function.IntFunction<Behavior<T>> behaviorFactory, ShardedDaemonProcessSettings settings, java.util.Optional<T> stopMessage)
      Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
      abstract <T> void init​(java.lang.Class<T> messageClass, java.lang.String name, int numberOfInstances, java.util.function.IntFunction<Behavior<T>> behaviorFactory, ShardedDaemonProcessSettings settings, java.util.Optional<T> stopMessage, java.util.Optional<ShardCoordinator.ShardAllocationStrategy> shardAllocationStrategy)
      Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
      abstract <T> void init​(java.lang.Class<T> messageClass, java.lang.String name, int numberOfInstances, java.util.function.IntFunction<Behavior<T>> behaviorFactory, T stopMessage)
      Start a specific number of actors that is then kept alive in the cluster.
      abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass, java.lang.String name, int initialNumberOfInstances, java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory)
      Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
      abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass, java.lang.String name, int initialNumberOfInstances, java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory, ShardedDaemonProcessSettings settings, java.util.Optional<T> stopMessage)
      Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
      abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass, java.lang.String name, int numberOfInstances, java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory, ShardedDaemonProcessSettings settings, java.util.Optional<T> stopMessage, java.util.Optional<ShardCoordinator.ShardAllocationStrategy> shardAllocationStrategy)
      Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
      • Methods inherited from class java.lang.Object

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

      • ShardedDaemonProcess

        public ShardedDaemonProcess()
    • Method Detail

      • init

        public abstract <T> void init​(java.lang.Class<T> messageClass,
                                      java.lang.String name,
                                      int numberOfInstances,
                                      java.util.function.IntFunction<Behavior<T>> behaviorFactory)
        Start a specific number of actors that is then kept alive in the cluster.
        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance create the behavior for that actor.
      • init

        public abstract <T> void init​(java.lang.Class<T> messageClass,
                                      java.lang.String name,
                                      int numberOfInstances,
                                      java.util.function.IntFunction<Behavior<T>> behaviorFactory,
                                      T stopMessage)
        Start a specific number of actors that is then kept alive in the cluster.

        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance create the behavior for that actor.
        stopMessage - sent to the actors when they need to stop because of a rebalance across the nodes of the cluster or cluster shutdown.
      • init

        public abstract <T> void init​(java.lang.Class<T> messageClass,
                                      java.lang.String name,
                                      int numberOfInstances,
                                      java.util.function.IntFunction<Behavior<T>> behaviorFactory,
                                      ShardedDaemonProcessSettings settings,
                                      java.util.Optional<T> stopMessage)
        Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance create the behavior for that actor.
        stopMessage - if defined sent to the actors when they need to stop because of a rebalance across the nodes of the cluster or cluster shutdown.
      • init

        public abstract <T> void init​(java.lang.Class<T> messageClass,
                                      java.lang.String name,
                                      int numberOfInstances,
                                      java.util.function.IntFunction<Behavior<T>> behaviorFactory,
                                      ShardedDaemonProcessSettings settings,
                                      java.util.Optional<T> stopMessage,
                                      java.util.Optional<ShardCoordinator.ShardAllocationStrategy> shardAllocationStrategy)
        Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.
        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance create the behavior for that actor.
        stopMessage - if defined sent to the actors when they need to stop because of a rebalance across the nodes of the cluster, rescale or cluster shutdown.
        shardAllocationStrategy - if defined used by entities to control the shard allocation
      • initWithContext

        public abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass,
                                                                                  java.lang.String name,
                                                                                  int initialNumberOfInstances,
                                                                                  java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory)
        Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster. The number of processing actors can be rescaled by interacting with the returned actor.

        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance and total number of processes, create the behavior for that actor.
      • initWithContext

        public abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass,
                                                                                  java.lang.String name,
                                                                                  int initialNumberOfInstances,
                                                                                  java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory,
                                                                                  ShardedDaemonProcessSettings settings,
                                                                                  java.util.Optional<T> stopMessage)
        Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster. The number of processing actors can be rescaled by interacting with the returned actor.

        Parameters:
        behaviorFactory - Given a unique id of 0 until numberOfInstance and total number of processes, create the behavior for that actor.
        stopMessage - Sent to the actors when they need to stop because of a rebalance across the nodes of the cluster or cluster shutdown.
      • initWithContext

        public abstract <T> ActorRef<ShardedDaemonProcessCommand> initWithContext​(java.lang.Class<T> messageClass,
                                                                                  java.lang.String name,
                                                                                  int numberOfInstances,
                                                                                  java.util.function.Function<ShardedDaemonProcessContext,​Behavior<T>> behaviorFactory,
                                                                                  ShardedDaemonProcessSettings settings,
                                                                                  java.util.Optional<T> stopMessage,
                                                                                  java.util.Optional<ShardCoordinator.ShardAllocationStrategy> shardAllocationStrategy)
        Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster.

        Parameters:
        behaviorFactory - Given a unique sharded daemon process context containing the total number of workers and the id the specific worker being started, create the behavior for that actor.
        stopMessage - If defined: sent to the actors when they need to stop because of a rebalance across the nodes of the cluster, rescale or cluster shutdown.
        shardAllocationStrategy - If defined: used by entities to control the shard allocation