Class ClusterSharding

java.lang.Object
org.apache.pekko.cluster.sharding.ClusterSharding
All Implemented Interfaces:
Extension

public class ClusterSharding extends Object implements Extension
See Also:
  • Constructor Details

  • Method Details

    • get

      public static ClusterSharding get(ActorSystem system)
    • get

      public static ClusterSharding get(ClassicActorSystemProvider system)
    • lookup

      public static ClusterSharding$ lookup()
    • createExtension

      public static ClusterSharding createExtension(ExtendedActorSystem system)
    • apply

      public static T apply(ActorSystem system)
    • apply

      public static T apply(ClassicActorSystemProvider system)
    • hashCode

      public static final int hashCode()
    • equals

      public static final boolean equals(Object other)
    • start

      public ActorRef start(String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, Object handOffStopMessage)
      Scala API: Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      This method will start a ShardRegion in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      settings - configuration settings, see ClusterShardingSettings
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      allocationStrategy - possibility to use a custom shard allocation and rebalancing logic
      handOffStopMessage - the message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill.
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, Object handOffStopMessage)
      Scala API: Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      This method will start a ShardRegion in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      allocationStrategy - possibility to use a custom shard allocation and rebalancing logic
      handOffStopMessage - the message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill.
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId)
      Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategy is used. pekko.actor.PoisonPill is used as handOffStopMessage.

      This method will start a ShardRegion in proxy mode when there is no match between the node roles and the role specified in the ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      settings - configuration settings, see ClusterShardingSettings
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId)
      Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategy is used. pekko.actor.PoisonPill is used as handOffStopMessage.

      This method will start a ShardRegion in proxy mode when there is no match between the node roles and the role specified in the ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor, ShardCoordinator.ShardAllocationStrategy allocationStrategy, Object handOffStopMessage)
      Java/Scala API: Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      This method will start a ShardRegion in proxy mode when there is no match between the node roles and the role specified in the ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      settings - configuration settings, see ClusterShardingSettings
      messageExtractor - functions to extract the entity id, shard id, and the message to send to the entity from the incoming message, see ShardRegion.MessageExtractor
      allocationStrategy - possibility to use a custom shard allocation and rebalancing logic
      handOffStopMessage - the message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill.
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)
      Java/Scala API: Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategy is used. pekko.actor.PoisonPill is used as handOffStopMessage.

      This method will start a ShardRegion in proxy mode when there is no match between the node roles and the role specified in the ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      settings - configuration settings, see ClusterShardingSettings
      messageExtractor - functions to extract the entity id, shard id, and the message to send to the entity from the incoming message
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • start

      public ActorRef start(String typeName, Props entityProps, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)
      Java/Scala API: Register a named entity type by defining the pekko.actor.Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategy is used. pekko.actor.PoisonPill is used as handOffStopMessage.

      This method will start a ShardRegion in proxy mode when there is no match between the node roles and the role specified in the ClusterShardingSettings passed to this method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      entityProps - the Props of the entity actors that will be created by the ShardRegion
      messageExtractor - functions to extract the entity id, shard id, and the message to send to the entity from the incoming message
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • startProxy

      public ActorRef startProxy(String typeName, scala.Option<String> role, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId)
      Scala API: Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      role - specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used.
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • startProxy

      public ActorRef startProxy(String typeName, scala.Option<String> role, scala.Option<String> dataCenter, scala.PartialFunction<Object,scala.Tuple2<String,Object>> extractEntityId, scala.Function1<Object,String> extractShardId)
      Scala API: Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      role - specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used.
      dataCenter - The data center of the cluster nodes where the cluster sharding is running. If None then the same data center as current node.
      extractEntityId - partial function to extract the entity id and the message to send to the entity from the incoming message, if the partial function does not match the message will be unhandled, i.e. posted as Unhandled messages on the event stream
      extractShardId - function to determine the shard id for an incoming message, only messages that passed the extractEntityId will be used
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • startProxy

      public ActorRef startProxy(String typeName, Optional<String> role, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)
      Java/Scala API: Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      role - specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used.
      messageExtractor - functions to extract the entity id, shard id, and the message to send to the entity from the incoming message
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • startProxy

      public ActorRef startProxy(String typeName, Optional<String> role, Optional<String> dataCenter, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)
      Java/Scala API: Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the shardRegion(java.lang.String) method.

      Some settings can be configured as described in the pekko.cluster.sharding section of the reference.conf.

      Parameters:
      typeName - the name of the entity type
      role - specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used.
      dataCenter - The data center of the cluster nodes where the cluster sharding is running. If None then the same data center as current node.
      messageExtractor - functions to extract the entity id, shard id, and the message to send to the entity from the incoming message
      Returns:
      the actor ref of the ShardRegion that is to be responsible for the shard
    • shardTypeNames

      public scala.collection.immutable.Set<String> shardTypeNames()
      Scala API: get all currently defined sharding type names.
    • getShardTypeNames

      public Set<String> getShardTypeNames()
      Java API: get all currently defined sharding type names.
    • shardRegion

      public ActorRef shardRegion(String typeName)
    • shardRegionProxy

      public ActorRef shardRegionProxy(String typeName, String dataCenter)
      Retrieve the actor reference of the ShardRegion actor that will act as a proxy to the named entity type running in another data center. A proxy within the same data center can be accessed with shardRegion(java.lang.String) instead of this method. The entity type must be registered with the startProxy(java.lang.String, scala.Option<java.lang.String>, scala.PartialFunction<java.lang.Object, scala.Tuple2<java.lang.String, java.lang.Object>>, scala.Function1<java.lang.Object, java.lang.String>) method before it can be used here. Messages to the entity is always sent via the ShardRegion.
    • defaultShardAllocationStrategy

      public ShardCoordinator.ShardAllocationStrategy defaultShardAllocationStrategy(ClusterShardingSettings settings)
      The default ShardAllocationStrategy is configured by least-shard-allocation-strategy properties.