Class ShardCoordinator
- java.lang.Object
- 
- org.apache.pekko.cluster.sharding.ShardCoordinator
 
- 
- Direct Known Subclasses:
- PersistentShardCoordinator
 
 public abstract class ShardCoordinator extends java.lang.Object implements Actor, Timers Singleton coordinator that decides where to allocate shards.- See Also:
- ClusterSharding extension
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classShardCoordinator.AbstractShardAllocationStrategyJava API: Java implementations of custom shard allocation and rebalancing logic used by theShardCoordinatorshould extend this abstract class and implement the two methods.static interfaceShardCoordinator.ActorSystemDependentAllocationStrategyShard allocation strategy where start is called by the shard coordinator before any calls to rebalance or allocate shard.static classShardCoordinator.Internal$INTERNAL APIstatic classShardCoordinator.LeastShardAllocationStrategyUsepekko.cluster.sharding.ShardCoordinator.ShardAllocationStrategy.leastShardAllocationStrategyinstead.static classShardCoordinator.RebalanceWorker$static interfaceShardCoordinator.ShardAllocationStrategyInterface of the pluggable shard allocation and rebalancing logic used by theShardCoordinator.static classShardCoordinator.ShardAllocationStrategy$static interfaceShardCoordinator.StartableAllocationStrategyShard allocation strategy where start is called by the shard coordinator before any calls to rebalance or allocate shard.- 
Nested classes/interfaces inherited from interface org.apache.pekko.actor.ActorActor.emptyBehavior$, Actor.ignoringBehavior$
 
- 
 - 
Constructor SummaryConstructors Constructor Description ShardCoordinator(ClusterShardingSettings settings, ShardCoordinator.ShardAllocationStrategy allocationStrategy)
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>active()scala.collection.immutable.Set<ActorRef>aliveRegions()voidaliveRegions_$eq(scala.collection.immutable.Set<ActorRef> x$1)voidallocateShardHomesForRememberEntities()booleanallRegionsRegistered()voidallRegionsRegistered_$eq(boolean x$1)Clustercluster()ActorContextcontext()Scala API: Stores the context for this actor, including self, and sender.voidcontinueGetShardHome(java.lang.String shard, ActorRef region, ActorRef getShardHomeSender)voidcontinueRebalance(scala.collection.immutable.Set<java.lang.String> shards)scala.collection.immutable.Set<ActorRef>gracefulShutdownInProgress()voidgracefulShutdownInProgress_$eq(scala.collection.immutable.Set<ActorRef> x$1)booleanhandleGetShardHome(java.lang.String shard)booleanhasAllRegionsRegistered()booleanisMember(ActorRef region)static ShardCoordinator.ShardAllocationStrategyleastShardAllocationStrategy(int absoluteLimit, double relativeLimit)Java API:ShardAllocationStrategythat allocates new shards to theShardRegion(node) with least number of previously allocated shards.MarkerLoggingAdapterlog()intminMembers()protected voidorg$apache$pekko$actor$Actor$_setter_$context_$eq(ActorContext x$1)Scala API: Stores the context for this actor, including self, and sender.protected voidorg$apache$pekko$actor$Actor$_setter_$self_$eq(ActorRef x$1)The 'self' field holds the ActorRef for this actor.voidpostStop()User overridable callback.booleanpreparingForShutdown()voidpreparingForShutdown_$eq(boolean x$1)voidpreStart()User overridable callback.scala.collection.immutable.Map<java.lang.String,scala.collection.immutable.Set<ActorRef>>rebalanceInProgress()voidrebalanceInProgress_$eq(scala.collection.immutable.Map<java.lang.String,scala.collection.immutable.Set<ActorRef>> x$1)scala.collection.immutable.Set<ActorRef>rebalanceWorkers()voidrebalanceWorkers_$eq(scala.collection.immutable.Set<ActorRef> x$1)scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>receiveTerminated()voidregionProxyTerminated(ActorRef ref)voidregionTerminated(ActorRef ref)scala.collection.immutable.Set<ActorRef>regionTerminationInProgress()voidregionTerminationInProgress_$eq(scala.collection.immutable.Set<ActorRef> x$1)scala.concurrent.duration.FiniteDurationremovalMargin()ActorRefself()The 'self' field holds the ActorRef for this actor.voidsendHostShardMsg(java.lang.String shard, ActorRef region)voidshutdownShards(ActorRef shuttingDownRegion, scala.collection.immutable.Set<java.lang.String> shards)scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>shuttingDown()org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.Statestate()voidstate_$eq(org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.State x$1)voidstateInitialized()protected abstract java.lang.StringtypeName()scala.collection.immutable.Map<java.lang.String,Cancellable>unAckedHostShards()voidunAckedHostShards_$eq(scala.collection.immutable.Map<java.lang.String,Cancellable> x$1)protected abstract voidunstashOneGetShardHomeRequest()abstract <E extends org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.DomainEvent>
 voidupdate(E evt, scala.Function1<E,scala.runtime.BoxedUnit> f)booleanwaitingForLocalRegionToTerminate()voidwaitingForLocalRegionToTerminate_$eq(boolean x$1)voidwatchStateActors()- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.pekko.actor.ActoraroundPostRestart, aroundPreStart, postRestart, preRestart, receive, sender, supervisorStrategy, unhandled
 - 
Methods inherited from interface org.apache.pekko.actor.TimersactorCell, aroundPostStop, aroundPreRestart, aroundReceive, super$aroundPostStop, super$aroundPreRestart, super$aroundReceive, timers
 
- 
 
- 
- 
- 
Constructor Detail- 
ShardCoordinatorpublic ShardCoordinator(ClusterShardingSettings settings, ShardCoordinator.ShardAllocationStrategy allocationStrategy) 
 
- 
 - 
Method Detail- 
leastShardAllocationStrategypublic static ShardCoordinator.ShardAllocationStrategy leastShardAllocationStrategy(int absoluteLimit, double relativeLimit) Java API:ShardAllocationStrategythat allocates new shards to theShardRegion(node) with least number of previously allocated shards.When a node is added to the cluster the shards on the existing nodes will be rebalanced to the new node. The LeastShardAllocationStrategypicks shards for rebalancing from theShardRegions with most number of previously allocated shards. They will then be allocated to theShardRegionwith least number of previously allocated shards, i.e. new members in the cluster. The amount of shards to rebalance in each round can be limited to make it progress slower since rebalancing too many shards at the same time could result in additional load on the system. For example, causing many Event Sourced entites to be started at the same time.It will not rebalance when there is already an ongoing rebalance in progress. - Parameters:
- absoluteLimit- the maximum number of shards that will be rebalanced in one rebalance round
- relativeLimit- fraction (< 1.0) of total number of (known) shards that will be rebalanced in one rebalance round
 
 - 
contextpublic ActorContext context() Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads! pekko.actor.ActorContextis the Scala API.getContextreturns apekko.actor.AbstractActor.ActorContext, which is the Java API of the actor context.
 - 
selfpublic final ActorRef self() Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message 
 - 
org$apache$pekko$actor$Actor$_setter_$context_$eqprotected void org$apache$pekko$actor$Actor$_setter_$context_$eq(ActorContext x$1) Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads! pekko.actor.ActorContextis the Scala API.getContextreturns apekko.actor.AbstractActor.ActorContext, which is the Java API of the actor context.- Specified by:
- org$apache$pekko$actor$Actor$_setter_$context_$eqin interface- Actor
 
 - 
org$apache$pekko$actor$Actor$_setter_$self_$eqprotected final void org$apache$pekko$actor$Actor$_setter_$self_$eq(ActorRef x$1) Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message - Specified by:
- org$apache$pekko$actor$Actor$_setter_$self_$eqin interface- Actor
 
 - 
logpublic MarkerLoggingAdapter log() 
 - 
clusterpublic Cluster cluster() 
 - 
removalMarginpublic scala.concurrent.duration.FiniteDuration removalMargin() 
 - 
minMemberspublic int minMembers() 
 - 
allRegionsRegisteredpublic boolean allRegionsRegistered() 
 - 
allRegionsRegistered_$eqpublic void allRegionsRegistered_$eq(boolean x$1) 
 - 
statepublic org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.State state() 
 - 
state_$eqpublic void state_$eq(org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.State x$1) 
 - 
preparingForShutdownpublic boolean preparingForShutdown() 
 - 
preparingForShutdown_$eqpublic void preparingForShutdown_$eq(boolean x$1) 
 - 
rebalanceInProgresspublic scala.collection.immutable.Map<java.lang.String,scala.collection.immutable.Set<ActorRef>> rebalanceInProgress() 
 - 
rebalanceInProgress_$eqpublic void rebalanceInProgress_$eq(scala.collection.immutable.Map<java.lang.String,scala.collection.immutable.Set<ActorRef>> x$1) 
 - 
rebalanceWorkerspublic scala.collection.immutable.Set<ActorRef> rebalanceWorkers() 
 - 
rebalanceWorkers_$eqpublic void rebalanceWorkers_$eq(scala.collection.immutable.Set<ActorRef> x$1) 
 - 
unAckedHostShardspublic scala.collection.immutable.Map<java.lang.String,Cancellable> unAckedHostShards() 
 - 
unAckedHostShards_$eqpublic void unAckedHostShards_$eq(scala.collection.immutable.Map<java.lang.String,Cancellable> x$1) 
 - 
gracefulShutdownInProgresspublic scala.collection.immutable.Set<ActorRef> gracefulShutdownInProgress() 
 - 
gracefulShutdownInProgress_$eqpublic void gracefulShutdownInProgress_$eq(scala.collection.immutable.Set<ActorRef> x$1) 
 - 
waitingForLocalRegionToTerminatepublic boolean waitingForLocalRegionToTerminate() 
 - 
waitingForLocalRegionToTerminate_$eqpublic void waitingForLocalRegionToTerminate_$eq(boolean x$1) 
 - 
aliveRegionspublic scala.collection.immutable.Set<ActorRef> aliveRegions() 
 - 
aliveRegions_$eqpublic void aliveRegions_$eq(scala.collection.immutable.Set<ActorRef> x$1) 
 - 
regionTerminationInProgresspublic scala.collection.immutable.Set<ActorRef> regionTerminationInProgress() 
 - 
regionTerminationInProgress_$eqpublic void regionTerminationInProgress_$eq(scala.collection.immutable.Set<ActorRef> x$1) 
 - 
typeNameprotected abstract java.lang.String typeName() 
 - 
preStartpublic void preStart() Description copied from interface:ActorUser overridable callback. Is called when an Actor is started. Actors are automatically started asynchronously when created. Empty default implementation.
 - 
postStoppublic void postStop() Description copied from interface:ActorUser overridable callback. Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.
 - 
isMemberpublic boolean isMember(ActorRef region) 
 - 
activepublic scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> active() 
 - 
handleGetShardHomepublic boolean handleGetShardHome(java.lang.String shard) - Returns:
- trueif the message could be handled without state update, i.e. the shard location was known or the request was deferred or ignored
 
 - 
receiveTerminatedpublic scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receiveTerminated() 
 - 
updatepublic abstract <E extends org.apache.pekko.cluster.sharding.ShardCoordinator.Internal.DomainEvent> void update(E evt, scala.Function1<E,scala.runtime.BoxedUnit> f)
 - 
watchStateActorspublic void watchStateActors() 
 - 
stateInitializedpublic void stateInitialized() 
 - 
hasAllRegionsRegisteredpublic boolean hasAllRegionsRegistered() 
 - 
regionTerminatedpublic void regionTerminated(ActorRef ref) 
 - 
regionProxyTerminatedpublic void regionProxyTerminated(ActorRef ref) 
 - 
shuttingDownpublic scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> shuttingDown() 
 - 
sendHostShardMsgpublic void sendHostShardMsg(java.lang.String shard, ActorRef region)
 - 
allocateShardHomesForRememberEntitiespublic void allocateShardHomesForRememberEntities() 
 - 
continueGetShardHomepublic void continueGetShardHome(java.lang.String shard, ActorRef region, ActorRef getShardHomeSender)
 - 
unstashOneGetShardHomeRequestprotected abstract void unstashOneGetShardHomeRequest() 
 - 
continueRebalancepublic void continueRebalance(scala.collection.immutable.Set<java.lang.String> shards) 
 - 
shutdownShardspublic void shutdownShards(ActorRef shuttingDownRegion, scala.collection.immutable.Set<java.lang.String> shards) 
 
- 
 
-