Class ClusterSingletonProxy
- All Implemented Interfaces:
Actor,ActorLogging
ClusterSingletonProxy works together with the pekko.cluster.singleton.ClusterSingletonManager to provide a
distributed proxy to the singleton actor.
The proxy can be started on every node where the singleton needs to be reached and used as if it were the singleton itself. It will then act as a router to the currently running singleton instance. If the singleton is not currently available, e.g., during hand off or startup, the proxy will buffer the messages sent to the singleton and then deliver them when the singleton is finally available. The size of the buffer is configurable and it can be disabled by using a buffer size of 0. When the buffer is full old messages will be dropped when new messages are sent via the proxy.
The proxy works by keeping track of the oldest cluster member. When a new oldest member is identified, e.g. because
the older one left the cluster, or at startup, the proxy will try to identify the singleton on the oldest member by
periodically sending an pekko.actor.Identify message until the singleton responds with its
pekko.actor.ActorIdentity.
Note that this is a best effort implementation: messages can always be lost due to the distributed nature of the actors involved.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.pekko.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$ -
Constructor Summary
ConstructorsConstructorDescriptionClusterSingletonProxy(String singletonManagerPath, ClusterSingletonProxySettings settings) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds new member if it has the right role.scala.math.Ordering<Member>buffer()voidvoidbuffer_$eq(MessageBuffer x$1) voidcluster()context()Scala API: Stores the context for this actor, including self, and sender.createIdentifyId(int i) voidintvoididentifyCounter_$eq(int x$1) voididentifyId_$eq(String x$1) voidDiscard old singleton ActorRef and send a periodic message to self to identify the singleton.scala.Option<Cancellable>voididentifyTimer_$eq(scala.Option<Cancellable> x$1) booleanmatchingRole(Member member) scala.collection.immutable.SortedSet<Member>voidmembersByAge_$eq(scala.collection.immutable.SortedSet<Member> x$1) protected voidScala API: Stores the context for this actor, including self, and sender.protected final voidThe 'self' field holds the ActorRef for this actor.voidpostStop()User overridable callback.voidpreStart()User overridable callback.static Propsprops(String singletonManagerPath, ClusterSingletonProxySettings settings) Scala API: Factory method forClusterSingletonProxypekko.actor.Props.scala.PartialFunction<Object,scala.runtime.BoxedUnit> receive()Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.voidRemoves a member.final ActorRefself()The 'self' field holds the ActorRef for this actor.voidscala.Option<ActorRef>voidsingleton_$eq(scala.Option<ActorRef> x$1) String[]voidtrackChange(scala.Function0<scala.runtime.BoxedUnit> block) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pekko.actor.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, postRestart, preRestart, sender, supervisorStrategy, unhandledMethods inherited from interface org.apache.pekko.actor.ActorLogging
_log_$eq, log
-
Constructor Details
-
ClusterSingletonProxy
-
-
Method Details
-
props
Scala API: Factory method forClusterSingletonProxypekko.actor.Props.- Parameters:
singletonManagerPath- The logical path of the singleton manager, e.g./user/singletonManager, which ends with the name you defined inactorOfwhen creating theClusterSingletonManager.settings- seeClusterSingletonProxySettings
-
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. -
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_$eq
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 interfaceActor
-
org$apache$pekko$actor$Actor$_setter_$self_$eq
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 interfaceActor
-
singletonPath
-
identifyCounter
public int identifyCounter() -
identifyCounter_$eq
public void identifyCounter_$eq(int x$1) -
identifyId
-
identifyId_$eq
-
createIdentifyId
-
identifyTimer
-
identifyTimer_$eq
-
cluster
-
singleton
-
singleton_$eq
-
ageOrdering
-
membersByAge
-
membersByAge_$eq
-
buffer
-
buffer_$eq
-
preStart
public 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. -
postStop
public void postStop()Description copied from interface:ActorUser overridable callback. Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation. -
cancelTimer
public void cancelTimer() -
matchingRole
-
handleInitial
-
identifySingleton
public void identifySingleton()Discard old singleton ActorRef and send a periodic message to self to identify the singleton. -
trackChange
public void trackChange(scala.Function0<scala.runtime.BoxedUnit> block) -
add
Adds new member if it has the right role.- Parameters:
m- New cluster member.
-
remove
Removes a member.- Parameters:
m- Cluster member to remove.
-
receive
Description copied from interface:ActorScala API: This defines the initial actor behavior, it must return a partial function with the actor logic. -
buffer
-
sendBuffered
public void sendBuffered()
-