Class ShardRegion
- java.lang.Object
-
- akka.cluster.sharding.ShardRegion
-
public class ShardRegion extends java.lang.Object implements Actor, Timers
INTERNAL APIThis actor creates children shard actors on demand that it is told to be responsible for. The shard actors in turn create entity actors on demand. It delegates messages targeted to other shards to the responsible
ShardRegion
actor on other nodes.- See Also:
ClusterSharding extension
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShardRegion.ClusterShardingStats
Reply toShardRegion.GetClusterShardingStats
, contains statistics about all the sharding regions in the cluster.static class
ShardRegion.ClusterShardingStats$
static class
ShardRegion.CurrentRegions
Reply toGetCurrentRegions
static class
ShardRegion.CurrentRegions$
static class
ShardRegion.CurrentShardRegionState
Reply toShardRegion.GetShardRegionState$
static class
ShardRegion.CurrentShardRegionState$
static class
ShardRegion.GetClusterShardingStats
Send this message to theShardRegion
actor to request forShardRegion.ClusterShardingStats
, which contains statistics about the currently running sharded entities in the entire cluster.static class
ShardRegion.GetClusterShardingStats$
static class
ShardRegion.GetCurrentRegions$
Send this message to theShardRegion
actor to request forShardRegion.CurrentRegions
, which contains the addresses of all registered regions.static class
ShardRegion.GetShardRegionState$
Send this message to aShardRegion
actor instance to request aShardRegion.CurrentShardRegionState
which describes the current state of the region.static class
ShardRegion.GetShardRegionStats$
Send this message to theShardRegion
actor to request forShardRegion.ShardRegionStats
, which contains statistics about the currently running sharded entities in the entire region.static class
ShardRegion.GracefulShutdown$
static class
ShardRegion.HandOffStopper
INTERNAL API.static class
ShardRegion.HashCodeMessageExtractor
Convenience implementation ofShardRegion.MessageExtractor
that constructshardId
based on thehashCode
of theentityId
.static class
ShardRegion.HashCodeMessageExtractor$
static interface
ShardRegion.MessageExtractor
Java API: Interface of functions to extract entity id, shard id, and the message to send to the entity from an incoming message.static class
ShardRegion.Passivate
If the state of the entities are persistent you may stop entities that are not used to reduce memory consumption.static class
ShardRegion.Passivate$
static class
ShardRegion.ShardInitialized
We must be sure that a shard is initialized before to start send messages to it.static class
ShardRegion.ShardInitialized$
static interface
ShardRegion.ShardRegionCommand
static interface
ShardRegion.ShardRegionQuery
static class
ShardRegion.ShardRegionStats
param: stats the region stats mapping ofShardId
to number of entities param: failed set of shards if any failed to respond within the timeoutstatic class
ShardRegion.ShardRegionStats$
static class
ShardRegion.ShardState
static class
ShardRegion.ShardState$
static class
ShardRegion.StartEntity
When remembering entities and a shard is started, each entity id that needs to be running will trigger this message being sent through sharding.static class
ShardRegion.StartEntity$
static class
ShardRegion.StartEntityAck
Sent back when aShardRegion.StartEntity
message was received and triggered the entity to start (it does not guarantee the entity successfully started)static class
ShardRegion.StartEntityAck$
-
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$
-
-
Constructor Summary
Constructors Constructor Description ShardRegion(java.lang.String typeName, scala.Option<scala.Function1<java.lang.String,Props>> entityProps, scala.Option<java.lang.String> dataCenter, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, java.lang.Object handOffStopMessage, ActorRef replicator, int majorityMinCap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description scala.math.Ordering<Member>
ageOrdering()
protected void
akka$actor$Actor$_setter_$context_$eq(ActorContext x$1)
Scala API: Stores the context for this actor, including self, and sender.protected void
akka$actor$Actor$_setter_$self_$eq(ActorRef x$1)
The 'self' field holds the ActorRef for this actor.void
bufferMessage(java.lang.String shardId, java.lang.Object msg, ActorRef snd)
void
changeMembers(scala.collection.immutable.SortedSet<Member> newMembers)
Cluster
cluster()
ActorContext
context()
Scala API: Stores the context for this actor, including self, and sender.scala.Option<ActorRef>
coordinator()
void
coordinator_$eq(scala.Option<ActorRef> x$1)
scala.collection.immutable.List<ActorSelection>
coordinatorSelection()
When leaving the coordinator singleton is started rather quickly on next oldest node and therefore it is good to send the Register and GracefulShutdownReq to the likely locations of the coordinator.void
deliverBufferedMessages(java.lang.String shardId, ActorRef receiver)
void
deliverMessage(java.lang.Object msg, ActorRef snd)
void
deliverStartEntity(ShardRegion.StartEntity msg, ActorRef snd)
void
finishRegistration()
static ShardRegion.GetCurrentRegions$
getCurrentRegionsInstance()
Java API:static ShardRegion.GetShardRegionStats$
getRegionStatsInstance()
Java API:scala.Option<ActorRef>
getShard(java.lang.String id)
static ShardRegion.GetShardRegionState$
getShardRegionStateInstance()
Java API:boolean
gracefulShutdownInProgress()
void
gracefulShutdownInProgress_$eq(boolean x$1)
static ShardRegion.GracefulShutdown$
gracefulShutdownInstance()
Java API: Send this message to theShardRegion
actor to handoff all shards that are hosted by theShardRegion
and then theShardRegion
actor will be stopped.scala.concurrent.Promise<Done>
gracefulShutdownProgress()
scala.collection.immutable.Set<ActorRef>
handingOff()
void
handingOff_$eq(scala.collection.immutable.Set<ActorRef> x$1)
static Props
handOffStopperProps(java.lang.String shard, ActorRef replyTo, scala.collection.immutable.Set<ActorRef> entities, java.lang.Object stopMessage, scala.concurrent.duration.FiniteDuration handoffTimeout)
void
initializeShard(java.lang.String id, ActorRef shard)
scala.concurrent.duration.FiniteDuration
initRegistrationDelay()
MarkerLoggingAdapter
log()
boolean
loggedFullBufferWarning()
void
loggedFullBufferWarning_$eq(boolean x$1)
boolean
matchingRole(Member member)
scala.collection.immutable.SortedSet<Member>
membersByAge()
void
membersByAge_$eq(scala.collection.immutable.SortedSet<Member> x$1)
scala.concurrent.duration.FiniteDuration
nextRegistrationDelay()
void
nextRegistrationDelay_$eq(scala.concurrent.duration.FiniteDuration x$1)
void
postStop()
User overridable callback.void
preStart()
User overridable callback.static Props
props(java.lang.String typeName, scala.Function1<java.lang.String,Props> entityProps, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, java.lang.Object handOffStopMessage, ActorRef replicator, int majorityMinCap)
INTERNAL API Factory method for theProps
of theShardRegion
actor.static Props
proxyProps(java.lang.String typeName, scala.Option<java.lang.String> dataCenter, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ActorRef replicator, int majorityMinCap)
INTERNAL API Factory method for theProps
of theShardRegion
actor when using it in proxy only mode.<T> scala.concurrent.Future<ShardingQueries.ShardsQueryResult<T>>
queryShards(scala.collection.immutable.Map<java.lang.String,ActorRef> shards, java.lang.Object msg, scala.reflect.ClassTag<T> evidence$1)
Query all or a subset of shards, e.g.scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>
receive()
Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.void
receiveClusterEvent(ClusterEvent.ClusterDomainEvent evt)
void
receiveClusterState(ClusterEvent.CurrentClusterState state)
void
receiveCommand(ShardRegion.ShardRegionCommand cmd)
void
receiveCoordinatorMessage(akka.cluster.sharding.ShardCoordinator.Internal.CoordinatorMessage msg)
void
receiveQuery(ShardRegion.ShardRegionQuery query)
void
receiveTerminated(ActorRef ref)
scala.collection.immutable.Map<java.lang.String,ActorRef>
regionByShard()
void
regionByShard_$eq(scala.collection.immutable.Map<java.lang.String,ActorRef> x$1)
scala.collection.immutable.Map<ActorRef,scala.collection.immutable.Set<java.lang.String>>
regions()
void
regions_$eq(scala.collection.immutable.Map<ActorRef,scala.collection.immutable.Set<java.lang.String>> x$1)
void
register()
java.lang.Object
registrationMessage()
void
replyToRegionStateQuery(ActorRef ref)
void
replyToRegionStatsQuery(ActorRef ref)
void
requestShardBufferHomes()
int
retryCount()
void
retryCount_$eq(int x$1)
void
scheduleNextRegistration()
ActorRef
self()
The 'self' field holds the ActorRef for this actor.void
sendGracefulShutdownToCoordinator()
MessageBufferMap<java.lang.String>
shardBuffers()
void
shardBuffers_$eq(MessageBufferMap<java.lang.String> x$1)
scala.collection.immutable.Map<java.lang.String,ActorRef>
shards()
void
shards_$eq(scala.collection.immutable.Map<java.lang.String,ActorRef> x$1)
scala.collection.immutable.Map<ActorRef,java.lang.String>
shardsByRef()
void
shardsByRef_$eq(scala.collection.immutable.Map<ActorRef,java.lang.String> x$1)
scala.collection.immutable.Set<java.lang.String>
startingShards()
void
startingShards_$eq(scala.collection.immutable.Set<java.lang.String> x$1)
void
startRegistration()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface akka.actor.Actor
aroundPostRestart, aroundPreStart, postRestart, preRestart, sender, supervisorStrategy, unhandled
-
Methods inherited from interface akka.actor.Timers
actorCell, aroundPostStop, aroundPreRestart, aroundReceive, super$aroundPostStop, super$aroundPreRestart, super$aroundReceive, timers
-
-
-
-
Constructor Detail
-
ShardRegion
public ShardRegion(java.lang.String typeName, scala.Option<scala.Function1<java.lang.String,Props>> entityProps, scala.Option<java.lang.String> dataCenter, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, java.lang.Object handOffStopMessage, ActorRef replicator, int majorityMinCap)
-
-
Method Detail
-
props
public static Props props(java.lang.String typeName, scala.Function1<java.lang.String,Props> entityProps, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, java.lang.Object handOffStopMessage, ActorRef replicator, int majorityMinCap)
INTERNAL API Factory method for theProps
of theShardRegion
actor.
-
proxyProps
public static Props proxyProps(java.lang.String typeName, scala.Option<java.lang.String> dataCenter, ClusterShardingSettings settings, java.lang.String coordinatorPath, scala.PartialFunction<java.lang.Object,scala.Tuple2<java.lang.String,java.lang.Object>> extractEntityId, scala.Function1<java.lang.Object,java.lang.String> extractShardId, ActorRef replicator, int majorityMinCap)
INTERNAL API Factory method for theProps
of theShardRegion
actor when using it in proxy only mode.
-
gracefulShutdownInstance
public static ShardRegion.GracefulShutdown$ gracefulShutdownInstance()
Java API: Send this message to theShardRegion
actor to handoff all shards that are hosted by theShardRegion
and then theShardRegion
actor will be stopped. You canwatch
it to know when it is completed.
-
getCurrentRegionsInstance
public static ShardRegion.GetCurrentRegions$ getCurrentRegionsInstance()
Java API:
-
getRegionStatsInstance
public static ShardRegion.GetShardRegionStats$ getRegionStatsInstance()
Java API:
-
getShardRegionStateInstance
public static ShardRegion.GetShardRegionState$ getShardRegionStateInstance()
Java API:
-
handOffStopperProps
public static Props handOffStopperProps(java.lang.String shard, ActorRef replyTo, scala.collection.immutable.Set<ActorRef> entities, java.lang.Object stopMessage, scala.concurrent.duration.FiniteDuration handoffTimeout)
-
context
public ActorContext context()
Description copied from interface:Actor
Scala 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!
ActorContext
is the Scala API.getContext
returns aAbstractActor.ActorContext
, which is the Java API of the actor context.
-
self
public final ActorRef self()
Description copied from interface:Actor
The 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message
-
akka$actor$Actor$_setter_$context_$eq
protected void akka$actor$Actor$_setter_$context_$eq(ActorContext x$1)
Description copied from interface:Actor
Scala 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!
ActorContext
is the Scala API.getContext
returns aAbstractActor.ActorContext
, which is the Java API of the actor context.- Specified by:
akka$actor$Actor$_setter_$context_$eq
in interfaceActor
-
akka$actor$Actor$_setter_$self_$eq
protected final void akka$actor$Actor$_setter_$self_$eq(ActorRef x$1)
Description copied from interface:Actor
The 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message
- Specified by:
akka$actor$Actor$_setter_$self_$eq
in interfaceActor
-
log
public MarkerLoggingAdapter log()
-
cluster
public Cluster cluster()
-
ageOrdering
public scala.math.Ordering<Member> ageOrdering()
-
membersByAge
public scala.collection.immutable.SortedSet<Member> membersByAge()
-
membersByAge_$eq
public void membersByAge_$eq(scala.collection.immutable.SortedSet<Member> x$1)
-
regions
public scala.collection.immutable.Map<ActorRef,scala.collection.immutable.Set<java.lang.String>> regions()
-
regions_$eq
public void regions_$eq(scala.collection.immutable.Map<ActorRef,scala.collection.immutable.Set<java.lang.String>> x$1)
-
regionByShard
public scala.collection.immutable.Map<java.lang.String,ActorRef> regionByShard()
-
regionByShard_$eq
public void regionByShard_$eq(scala.collection.immutable.Map<java.lang.String,ActorRef> x$1)
-
shardBuffers
public MessageBufferMap<java.lang.String> shardBuffers()
-
shardBuffers_$eq
public void shardBuffers_$eq(MessageBufferMap<java.lang.String> x$1)
-
loggedFullBufferWarning
public boolean loggedFullBufferWarning()
-
loggedFullBufferWarning_$eq
public void loggedFullBufferWarning_$eq(boolean x$1)
-
shards
public scala.collection.immutable.Map<java.lang.String,ActorRef> shards()
-
shards_$eq
public void shards_$eq(scala.collection.immutable.Map<java.lang.String,ActorRef> x$1)
-
shardsByRef
public scala.collection.immutable.Map<ActorRef,java.lang.String> shardsByRef()
-
shardsByRef_$eq
public void shardsByRef_$eq(scala.collection.immutable.Map<ActorRef,java.lang.String> x$1)
-
startingShards
public scala.collection.immutable.Set<java.lang.String> startingShards()
-
startingShards_$eq
public void startingShards_$eq(scala.collection.immutable.Set<java.lang.String> x$1)
-
handingOff
public scala.collection.immutable.Set<ActorRef> handingOff()
-
handingOff_$eq
public void handingOff_$eq(scala.collection.immutable.Set<ActorRef> x$1)
-
gracefulShutdownInProgress
public boolean gracefulShutdownInProgress()
-
gracefulShutdownInProgress_$eq
public void gracefulShutdownInProgress_$eq(boolean x$1)
-
retryCount
public int retryCount()
-
retryCount_$eq
public void retryCount_$eq(int x$1)
-
initRegistrationDelay
public scala.concurrent.duration.FiniteDuration initRegistrationDelay()
-
nextRegistrationDelay
public scala.concurrent.duration.FiniteDuration nextRegistrationDelay()
-
nextRegistrationDelay_$eq
public void nextRegistrationDelay_$eq(scala.concurrent.duration.FiniteDuration x$1)
-
gracefulShutdownProgress
public scala.concurrent.Promise<Done> gracefulShutdownProgress()
-
preStart
public void preStart()
Description copied from interface:Actor
User overridable callback. Is called when an Actor is started. Actors are automatically started asynchronously when created. Empty default implementation.
-
postStop
public void postStop()
Description copied from interface:Actor
User overridable callback. Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.
-
matchingRole
public boolean matchingRole(Member member)
-
coordinatorSelection
public scala.collection.immutable.List<ActorSelection> coordinatorSelection()
When leaving the coordinator singleton is started rather quickly on next oldest node and therefore it is good to send the Register and GracefulShutdownReq to the likely locations of the coordinator.
-
coordinator
public scala.Option<ActorRef> coordinator()
-
coordinator_$eq
public void coordinator_$eq(scala.Option<ActorRef> x$1)
-
changeMembers
public void changeMembers(scala.collection.immutable.SortedSet<Member> newMembers)
-
receive
public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Description copied from interface:Actor
Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.
-
receiveClusterState
public void receiveClusterState(ClusterEvent.CurrentClusterState state)
-
receiveClusterEvent
public void receiveClusterEvent(ClusterEvent.ClusterDomainEvent evt)
-
receiveCoordinatorMessage
public void receiveCoordinatorMessage(akka.cluster.sharding.ShardCoordinator.Internal.CoordinatorMessage msg)
-
receiveCommand
public void receiveCommand(ShardRegion.ShardRegionCommand cmd)
-
receiveQuery
public void receiveQuery(ShardRegion.ShardRegionQuery query)
-
receiveTerminated
public void receiveTerminated(ActorRef ref)
-
replyToRegionStateQuery
public void replyToRegionStateQuery(ActorRef ref)
-
replyToRegionStatsQuery
public void replyToRegionStatsQuery(ActorRef ref)
-
queryShards
public <T> scala.concurrent.Future<ShardingQueries.ShardsQueryResult<T>> queryShards(scala.collection.immutable.Map<java.lang.String,ActorRef> shards, java.lang.Object msg, scala.reflect.ClassTag<T> evidence$1)
Query all or a subset of shards, e.g. unresponsive shards that initially timed out. If the number ofshards
are less than this.shards.size, this could be a retry. Returns a partitioned set of any shards that may have not replied within the timeout and shards that did reply, to provide retry on only that subset.Logs a warning if any of the group timed out.
To check subset unresponsive:
queryShards[T](shards.filterKeys(u.contains), shardQuery)
-
startRegistration
public void startRegistration()
-
scheduleNextRegistration
public void scheduleNextRegistration()
-
finishRegistration
public void finishRegistration()
-
register
public void register()
-
registrationMessage
public java.lang.Object registrationMessage()
-
requestShardBufferHomes
public void requestShardBufferHomes()
-
initializeShard
public void initializeShard(java.lang.String id, ActorRef shard)
-
bufferMessage
public void bufferMessage(java.lang.String shardId, java.lang.Object msg, ActorRef snd)
-
deliverBufferedMessages
public void deliverBufferedMessages(java.lang.String shardId, ActorRef receiver)
-
deliverStartEntity
public void deliverStartEntity(ShardRegion.StartEntity msg, ActorRef snd)
-
deliverMessage
public void deliverMessage(java.lang.Object msg, ActorRef snd)
-
getShard
public scala.Option<ActorRef> getShard(java.lang.String id)
-
sendGracefulShutdownToCoordinator
public void sendGracefulShutdownToCoordinator()
-
-