Class ClusterSharding
- java.lang.Object
- 
- org.apache.pekko.cluster.sharding.ClusterSharding
 
- 
- All Implemented Interfaces:
- Extension
 
 public class ClusterSharding extends java.lang.Object implements Extension - See Also:
- ClusterSharding companion object
 
- 
- 
Constructor SummaryConstructors Constructor Description ClusterSharding(ExtendedActorSystem system)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Tapply(ActorSystem system)static Tapply(ClassicActorSystemProvider system)static ClusterShardingcreateExtension(ExtendedActorSystem system)ShardCoordinator.ShardAllocationStrategydefaultShardAllocationStrategy(ClusterShardingSettings settings)The defaultShardAllocationStrategyis configured byleast-shard-allocation-strategyproperties.static booleanequals(java.lang.Object other)static ClusterShardingget(ActorSystem system)static ClusterShardingget(ClassicActorSystemProvider system)java.util.Set<java.lang.String>getShardTypeNames()Java API: get all currently defined sharding type names.static inthashCode()static ClusterSharding$lookup()ActorRefshardRegion(java.lang.String typeName)Retrieve the actor reference of theShardRegionactor responsible for the named entity type.ActorRefshardRegionProxy(java.lang.String typeName, java.lang.String dataCenter)Retrieve the actor reference of theShardRegionactor that will act as a proxy to the named entity type running in another data center.scala.collection.immutable.Set<java.lang.String>shardTypeNames()Scala API: get all currently defined sharding type names.ActorRefstart(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage)Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId)Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage)Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId)Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstart(java.lang.String typeName, Props entityProps, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage)Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages.ActorRefstartProxy(java.lang.String typeName, java.util.Optional<java.lang.String> role, java.util.Optional<java.lang.String> dataCenter, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)Java/Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e.ActorRefstartProxy(java.lang.String typeName, java.util.Optional<java.lang.String> role, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor)Java/Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e.ActorRefstartProxy(java.lang.String typeName, scala.Option<java.lang.String> role, scala.Option<java.lang.String> dataCenter, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId)Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e.ActorRefstartProxy(java.lang.String typeName, scala.Option<java.lang.String> role, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId)Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e.
 
- 
- 
- 
Constructor Detail- 
ClusterShardingpublic ClusterSharding(ExtendedActorSystem system) 
 
- 
 - 
Method Detail- 
getpublic static ClusterSharding get(ActorSystem system) 
 - 
getpublic static ClusterSharding get(ClassicActorSystemProvider system) 
 - 
lookuppublic static ClusterSharding$ lookup() 
 - 
createExtensionpublic static ClusterSharding createExtension(ExtendedActorSystem system) 
 - 
applypublic static T apply(ActorSystem system) 
 - 
applypublic static T apply(ClassicActorSystemProvider system) 
 - 
hashCodepublic static final int hashCode() 
 - 
equalspublic static final boolean equals(java.lang.Object other) 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage) Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.This method will start a ShardRegionin proxy mode when there is no match between the roles of the current cluster node and the role specified inClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill 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 ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage) Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.This method will start a ShardRegionin proxy mode when there is no match between the roles of the current cluster node and the role specified inClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill 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 ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId) Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategyis used.pekko.actor.PoisonPillis used ashandOffStopMessage.This method will start a ShardRegionin proxy mode when there is no match between the node roles and the role specified in theClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill be used
- Returns:
- the actor ref of the ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId) Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategyis used.pekko.actor.PoisonPillis used ashandOffStopMessage.This method will start a ShardRegionin proxy mode when there is no match between the node roles and the role specified in theClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill be used
- Returns:
- the actor ref of the ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor, ShardCoordinator.ShardAllocationStrategy allocationStrategy, java.lang.Object handOffStopMessage) Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.This method will start a ShardRegionin proxy mode when there is no match between the node roles and the role specified in theClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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 ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, ClusterShardingSettings settings, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor) Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategyis used.pekko.actor.PoisonPillis used ashandOffStopMessage.This method will start a ShardRegionin proxy mode when there is no match between the node roles and the role specified in theClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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 ShardRegionthat is to be responsible for the shard
 
 - 
startpublic ActorRef start(java.lang.String typeName, Props entityProps, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor) Java/Scala API: Register a named entity type by defining thepekko.actor.Propsof the entity actor and functions to extract entity and shard identifier from messages. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.The default shard allocation strategy ShardCoordinator.LeastShardAllocationStrategyis used.pekko.actor.PoisonPillis used ashandOffStopMessage.This method will start a ShardRegionin proxy mode when there is no match between the node roles and the role specified in theClusterShardingSettingspassed to this method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.conf.- Parameters:
- typeName- the name of the entity type
- entityProps- the- Propsof 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 ShardRegionthat is to be responsible for the shard
 
 - 
startProxypublic ActorRef startProxy(java.lang.String typeName, scala.Option<java.lang.String> role, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId) Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e. it will delegate messages to otherShardRegionactors on other nodes, but not host any entity actors itself. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill be used
- Returns:
- the actor ref of the ShardRegionthat is to be responsible for the shard
 
 - 
startProxypublic ActorRef startProxy(java.lang.String typeName, scala.Option<java.lang.String> role, scala.Option<java.lang.String> dataCenter, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId) Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e. it will delegate messages to otherShardRegionactors on other nodes, but not host any entity actors itself. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.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- Unhandledmessages on the event stream
- extractShardId- function to determine the shard id for an incoming message, only messages that passed the- extractEntityIdwill be used
- Returns:
- the actor ref of the ShardRegionthat is to be responsible for the shard
 
 - 
startProxypublic ActorRef startProxy(java.lang.String typeName, java.util.Optional<java.lang.String> role, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor) Java/Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e. it will delegate messages to otherShardRegionactors on other nodes, but not host any entity actors itself. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.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 ShardRegionthat is to be responsible for the shard
 
 - 
startProxypublic ActorRef startProxy(java.lang.String typeName, java.util.Optional<java.lang.String> role, java.util.Optional<java.lang.String> dataCenter, org.apache.pekko.cluster.sharding.ShardRegion.MessageExtractor messageExtractor) Java/Scala API: Register a named entity typeShardRegionon this node that will run in proxy only mode, i.e. it will delegate messages to otherShardRegionactors on other nodes, but not host any entity actors itself. TheShardRegionactor for this type can later be retrieved with theshardRegion(java.lang.String)method.Some settings can be configured as described in the pekko.cluster.shardingsection of thereference.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 ShardRegionthat is to be responsible for the shard
 
 - 
shardTypeNamespublic scala.collection.immutable.Set<java.lang.String> shardTypeNames() Scala API: get all currently defined sharding type names.
 - 
getShardTypeNamespublic java.util.Set<java.lang.String> getShardTypeNames() Java API: get all currently defined sharding type names.
 - 
shardRegionpublic ActorRef shardRegion(java.lang.String typeName) Retrieve the actor reference of theShardRegionactor responsible for the named entity type. The entity type must be registered with thestart(java.lang.String, org.apache.pekko.actor.Props, org.apache.pekko.cluster.sharding.ClusterShardingSettings, scala.PartialFunction<java.lang.Object, scala.Tuple2<java.lang.String, java.lang.Object>>, scala.Function1<java.lang.Object, java.lang.String>, org.apache.pekko.cluster.sharding.ShardCoordinator.ShardAllocationStrategy, java.lang.Object)orstartProxy(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 theShardRegion.
 - 
shardRegionProxypublic ActorRef shardRegionProxy(java.lang.String typeName, java.lang.String dataCenter) Retrieve the actor reference of theShardRegionactor 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 withshardRegion(java.lang.String)instead of this method. The entity type must be registered with thestartProxy(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 theShardRegion.
 - 
defaultShardAllocationStrategypublic ShardCoordinator.ShardAllocationStrategy defaultShardAllocationStrategy(ClusterShardingSettings settings) The defaultShardAllocationStrategyis configured byleast-shard-allocation-strategyproperties.
 
- 
 
-