Class Cluster
- All Implemented Interfaces:
Extension
subscribe(org.apache.pekko.actor.ActorRef, java.lang.Class<?>...). Commands to operate the cluster is
available through methods in this class, such as join(org.apache.pekko.actor.Address), down(org.apache.pekko.actor.Address) and leave(org.apache.pekko.actor.Address).
Each cluster Member is identified by its pekko.actor.Address, and
the cluster address of this actor system is selfAddress(). A member also has a status;
initially MemberStatus Joining followed by MemberStatus Up.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Tapply(ActorSystem system) static Tapply(ClassicActorSystemProvider system) static ClustercreateExtension(ExtendedActorSystem system) voidSend command to DOWN the node specified by 'address'.static final booleanstatic Clusterget(ActorSystem system) static Clusterget(ClassicActorSystemProvider system) Java API: roles that this member hasstatic final inthashCode()booleanReturns true if this cluster instance has be shutdown.voidTry to join this cluster node with the node specified by 'address'.voidjoinSeedNodes(List<Address> seedNodes) Java APIvoidjoinSeedNodes(scala.collection.immutable.Seq<Address> seedNodes) Join the specified seed nodes without defining them in config.voidSend command to issue state transition to LEAVING for the node specified by 'address'.static Cluster$lookup()voidChange the state of every member in preparation for a full cluster shutdown.voidregisterOnMemberRemoved(Runnable callback) Java API: The supplied thunk will be run, once, when current cluster member isRemoved.<T> voidregisterOnMemberRemoved(scala.Function0<T> code) The supplied thunk will be run, once, when current cluster member isRemoved.voidregisterOnMemberUp(Runnable callback) Java API: The supplied callback will be run, once, when current cluster member isUp.<T> voidregisterOnMemberUp(scala.Function0<T> code) The supplied thunk will be run, once, when current cluster member isUp.remotePathOf(ActorRef actorRef) Generate the remote actor path by replacing the Address in the RootActor Path for the given ActorRef with the cluster'sselfAddress, unless address' host is already definedThe address of this cluster member.Data center to which this node belongs to (defaults to "default" if not configured explicitly)Current snapshot of the member itselfscala.collection.immutable.Set<String>roles that this member hasThe address including auidof this cluster member.voidsendCurrentClusterState(ActorRef receiver) Send current (full) state of the cluster to the specified receiver.settings()state()Current snapshot state of the cluster.voidSubscribe to one or more cluster domain events.voidsubscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, Class<?>... to) Subscribe to one or more cluster domain events.voidsubscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, scala.collection.immutable.Seq<Class<?>> to) Subscribe to one or more cluster domain events.voidSubscribe to one or more cluster domain events.system()voidunsubscribe(ActorRef subscriber) Unsubscribe to all cluster domain events.voidunsubscribe(ActorRef subscriber, Class<?> to) Unsubscribe to a specific type of cluster domain events, matching previoussubscriberegistration.
-
Constructor Details
-
Cluster
-
-
Method Details
-
get
-
get
-
lookup
-
createExtension
-
apply
-
apply
-
hashCode
public static final int hashCode() -
equals
-
subscribe
Subscribe to one or more cluster domain events. Thetoclasses can bepekko.cluster.ClusterEvent.ClusterDomainEventor subclasses.A snapshot of
pekko.cluster.ClusterEvent.CurrentClusterStatewill be sent to the subscriber as the first message. -
subscribe
public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, Class<?>... to) Subscribe to one or more cluster domain events. Thetoclasses can bepekko.cluster.ClusterEvent.ClusterDomainEventor subclasses.If
initialStateModeisClusterEvent.InitialStateAsEventsthe events corresponding to the current state will be sent to the subscriber to mimic what you would have seen if you were listening to the events when they occurred in the past.If
initialStateModeisClusterEvent.InitialStateAsSnapshota snapshot ofpekko.cluster.ClusterEvent.CurrentClusterStatewill be sent to the subscriber as the first message.Note that for large clusters it is more efficient to use
InitialStateAsSnapshot. -
system
-
settings
-
selfUniqueAddress
The address including auidof this cluster member. Theuidis needed to be able to distinguish different incarnations of a member with same hostname and port. -
selfAddress
The address of this cluster member. -
selfDataCenter
Data center to which this node belongs to (defaults to "default" if not configured explicitly) -
selfRoles
roles that this member has -
getSelfRoles
Java API: roles that this member has -
failureDetector
-
crossDcFailureDetector
-
downingProvider
-
isTerminated
public boolean isTerminated()Returns true if this cluster instance has be shutdown. -
state
Current snapshot state of the cluster. -
selfMember
Current snapshot of the member itself -
subscribe
Subscribe to one or more cluster domain events. Thetoclasses can bepekko.cluster.ClusterEvent.ClusterDomainEventor subclasses.A snapshot of
pekko.cluster.ClusterEvent.CurrentClusterStatewill be sent to the subscriber as the first message. -
subscribe
public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, scala.collection.immutable.Seq<Class<?>> to) Subscribe to one or more cluster domain events. Thetoclasses can bepekko.cluster.ClusterEvent.ClusterDomainEventor subclasses.If
initialStateModeisClusterEvent.InitialStateAsEventsthe events corresponding to the current state will be sent to the subscriber to mimic what you would have seen if you were listening to the events when they occurred in the past.If
initialStateModeisClusterEvent.InitialStateAsSnapshota snapshot ofpekko.cluster.ClusterEvent.CurrentClusterStatewill be sent to the subscriber as the first message.Note that for large clusters it is more efficient to use
InitialStateAsSnapshot. -
unsubscribe
Unsubscribe to all cluster domain events. -
unsubscribe
Unsubscribe to a specific type of cluster domain events, matching previoussubscriberegistration. -
sendCurrentClusterState
Send current (full) state of the cluster to the specified receiver. If you want this to happen periodically you need to schedule a call to this method yourself. Note that you can also retrieve the current state withstate(). -
join
Try to join this cluster node with the node specified by 'address'. A 'Join(selfAddress)' command is sent to the node to join.An actor system can only join a cluster once. Additional attempts will be ignored. When it has successfully joined it must be restarted to be able to join another cluster or to join the same cluster again.
The name of the
pekko.actor.ActorSystemmust be the same for all members of a cluster. -
prepareForFullClusterShutdown
public void prepareForFullClusterShutdown()Change the state of every member in preparation for a full cluster shutdown. -
joinSeedNodes
Join the specified seed nodes without defining them in config. Especially useful from tests when Addresses are unknown before startup time.An actor system can only join a cluster once. Additional attempts will be ignored. When it has successfully joined it must be restarted to be able to join another cluster or to join the same cluster again.
-
joinSeedNodes
Java APIJoin the specified seed nodes without defining them in config. Especially useful from tests when Addresses are unknown before startup time.
An actor system can only join a cluster once. Additional attempts will be ignored. When it has successfully joined it must be restarted to be able to join another cluster or to join the same cluster again.
-
leave
Send command to issue state transition to LEAVING for the node specified by 'address'. The member will go through the status changesMemberStatusLeaving(not published to subscribers) followed byMemberStatusExitingand finallyMemberStatusRemoved.Note that this command can be issued to any member in the cluster, not necessarily the one that is leaving. The cluster extension, but not the actor system or JVM, of the leaving member will be shutdown after the leader has changed status of the member to Exiting. Thereafter the member will be removed from the cluster. Normally this is handled automatically, but in case of network failures during this process it might still be necessary to set the node’s status to Down in order to complete the removal.
-
down
Send command to DOWN the node specified by 'address'.When a member is considered by the failure detector to be unreachable the leader is not allowed to perform its duties, such as changing status of new joining members to 'Up'. The status of the unreachable member must be changed to 'Down', which can be done with this method.
-
registerOnMemberUp
public <T> void registerOnMemberUp(scala.Function0<T> code) The supplied thunk will be run, once, when current cluster member isUp. Typically used together with configuration optionpekko.cluster.min-nr-of-membersto defer some action, such as starting actors, until the cluster has reached a certain size. -
registerOnMemberUp
Java API: The supplied callback will be run, once, when current cluster member isUp. Typically used together with configuration optionpekko.cluster.min-nr-of-membersto defer some action, such as starting actors, until the cluster has reached a certain size. -
registerOnMemberRemoved
public <T> void registerOnMemberRemoved(scala.Function0<T> code) The supplied thunk will be run, once, when current cluster member isRemoved. If the cluster has already been shutdown the thunk will run on the caller thread immediately. If this is called "at the same time" asshutdown()there is a possibility that the the thunk is not invoked. It's often better to usepekko.actor.CoordinatedShutdownfor this purpose. -
registerOnMemberRemoved
Java API: The supplied thunk will be run, once, when current cluster member isRemoved. If the cluster has already been shutdown the thunk will run on the caller thread immediately. If this is called "at the same time" asshutdown()there is a possibility that the the thunk is not invoked. It's often better to usepekko.actor.CoordinatedShutdownfor this purpose. -
remotePathOf
Generate the remote actor path by replacing the Address in the RootActor Path for the given ActorRef with the cluster'sselfAddress, unless address' host is already defined
-