Class Cluster
- java.lang.Object
-
- akka.cluster.Cluster
-
- All Implemented Interfaces:
Extension
public class Cluster extends java.lang.Object implements Extension
This module is responsible cluster membership information. Changes to the cluster information is retrieved throughsubscribe(akka.actor.ActorRef, java.lang.Class<?>...)
. Commands to operate the cluster is available through methods in this class, such asjoin(akka.actor.Address)
,down(akka.actor.Address)
andleave(akka.actor.Address)
.Each cluster
Member
is identified by itsAddress
, and the cluster address of this actor system isselfAddress()
. A member also has a status; initiallyMemberStatus
Joining
followed byMemberStatus
Up
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Cluster.ClusterLogger$
INTERNAL API
-
Constructor Summary
Constructors Constructor Description Cluster(ExtendedActorSystem system)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static T
apply(ActorSystem system)
static T
apply(ClassicActorSystemProvider system)
static Cluster
createExtension(ExtendedActorSystem system)
FailureDetectorRegistry<Address>
crossDcFailureDetector()
void
down(Address address)
Send command to DOWN the node specified by 'address'.DowningProvider
downingProvider()
static boolean
equals(java.lang.Object other)
FailureDetectorRegistry<Address>
failureDetector()
static Cluster
get(ActorSystem system)
static Cluster
get(ClassicActorSystemProvider system)
java.util.Set<java.lang.String>
getSelfRoles()
Java API: roles that this member hasstatic int
hashCode()
boolean
isTerminated()
Returns true if this cluster instance has be shutdown.void
join(Address address)
Try to join this cluster node with the node specified by 'address'.void
joinSeedNodes(java.util.List<Address> seedNodes)
Java APIvoid
joinSeedNodes(scala.collection.immutable.Seq<Address> seedNodes)
Join the specified seed nodes without defining them in config.void
leave(Address address)
Send command to issue state transition to LEAVING for the node specified by 'address'.static Cluster$
lookup()
void
prepareForFullClusterShutdown()
Change the state of every member in preparation for a full cluster shutdown.void
registerOnMemberRemoved(java.lang.Runnable callback)
Java API: The supplied thunk will be run, once, when current cluster member isRemoved
.<T> void
registerOnMemberRemoved(scala.Function0<T> code)
The supplied thunk will be run, once, when current cluster member isRemoved
.void
registerOnMemberUp(java.lang.Runnable callback)
Java API: The supplied callback will be run, once, when current cluster member isUp
.<T> void
registerOnMemberUp(scala.Function0<T> code)
The supplied thunk will be run, once, when current cluster member isUp
.ActorPath
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 definedAddress
selfAddress()
The address of this cluster member.java.lang.String
selfDataCenter()
Deprecated.Use Akka Distributed Cluster instead.Member
selfMember()
Current snapshot of the member itselfscala.collection.immutable.Set<java.lang.String>
selfRoles()
roles that this member hasUniqueAddress
selfUniqueAddress()
The address including auid
of this cluster member.void
sendCurrentClusterState(ActorRef receiver)
Send current (full) state of the cluster to the specified receiver.void
setAppVersionLater(java.util.concurrent.CompletionStage<Version> appVersion)
Java API: If theappVersion
is read from an external system (e.g.void
setAppVersionLater(scala.concurrent.Future<Version> appVersion)
Scala API: If theappVersion
is read from an external system (e.g.ClusterSettings
settings()
ClusterEvent.CurrentClusterState
state()
Current snapshot state of the cluster.void
subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, java.lang.Class<?>... to)
Subscribe to one or more cluster domain events.void
subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, scala.collection.immutable.Seq<java.lang.Class<?>> to)
Subscribe to one or more cluster domain events.void
subscribe(ActorRef subscriber, java.lang.Class<?>... to)
Subscribe to one or more cluster domain events.void
subscribe(ActorRef subscriber, scala.collection.immutable.Seq<java.lang.Class<?>> to)
Subscribe to one or more cluster domain events.ExtendedActorSystem
system()
void
unsubscribe(ActorRef subscriber)
Unsubscribe to all cluster domain events.void
unsubscribe(ActorRef subscriber, java.lang.Class<?> to)
Unsubscribe to a specific type of cluster domain events, matching previoussubscribe
registration.
-
-
-
Constructor Detail
-
Cluster
public Cluster(ExtendedActorSystem system)
-
-
Method Detail
-
get
public static Cluster get(ActorSystem system)
-
get
public static Cluster get(ClassicActorSystemProvider system)
-
lookup
public static Cluster$ lookup()
-
createExtension
public static Cluster createExtension(ExtendedActorSystem system)
-
apply
public static T apply(ActorSystem system)
-
apply
public static T apply(ClassicActorSystemProvider system)
-
hashCode
public static final int hashCode()
-
equals
public static final boolean equals(java.lang.Object other)
-
subscribe
public void subscribe(ActorRef subscriber, java.lang.Class<?>... to)
Subscribe to one or more cluster domain events. Theto
classes can beClusterEvent.ClusterDomainEvent
or subclasses.A snapshot of
ClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.
-
subscribe
public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, java.lang.Class<?>... to)
Subscribe to one or more cluster domain events. Theto
classes can beClusterEvent.ClusterDomainEvent
or subclasses.If
initialStateMode
isClusterEvent.InitialStateAsEvents
the 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
initialStateMode
isClusterEvent.InitialStateAsSnapshot
a snapshot ofClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.Note that for large clusters it is more efficient to use
InitialStateAsSnapshot
.
-
system
public ExtendedActorSystem system()
-
settings
public ClusterSettings settings()
-
selfUniqueAddress
public UniqueAddress selfUniqueAddress()
The address including auid
of this cluster member. Theuid
is needed to be able to distinguish different incarnations of a member with same hostname and port.
-
selfAddress
public Address selfAddress()
The address of this cluster member.
-
selfDataCenter
public java.lang.String selfDataCenter()
Deprecated.Use Akka Distributed Cluster instead. Since 2.10.0.
-
selfRoles
public scala.collection.immutable.Set<java.lang.String> selfRoles()
roles that this member has
-
getSelfRoles
public java.util.Set<java.lang.String> getSelfRoles()
Java API: roles that this member has
-
failureDetector
public FailureDetectorRegistry<Address> failureDetector()
-
crossDcFailureDetector
public FailureDetectorRegistry<Address> crossDcFailureDetector()
-
downingProvider
public DowningProvider downingProvider()
-
isTerminated
public boolean isTerminated()
Returns true if this cluster instance has be shutdown.
-
state
public ClusterEvent.CurrentClusterState state()
Current snapshot state of the cluster.
-
selfMember
public Member selfMember()
Current snapshot of the member itself
-
subscribe
public void subscribe(ActorRef subscriber, scala.collection.immutable.Seq<java.lang.Class<?>> to)
Subscribe to one or more cluster domain events. Theto
classes can beClusterEvent.ClusterDomainEvent
or subclasses.A snapshot of
ClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.
-
subscribe
public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, scala.collection.immutable.Seq<java.lang.Class<?>> to)
Subscribe to one or more cluster domain events. Theto
classes can beClusterEvent.ClusterDomainEvent
or subclasses.If
initialStateMode
isClusterEvent.InitialStateAsEvents
the 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
initialStateMode
isClusterEvent.InitialStateAsSnapshot
a snapshot ofClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.Note that for large clusters it is more efficient to use
InitialStateAsSnapshot
.
-
unsubscribe
public void unsubscribe(ActorRef subscriber)
Unsubscribe to all cluster domain events.
-
unsubscribe
public void unsubscribe(ActorRef subscriber, java.lang.Class<?> to)
Unsubscribe to a specific type of cluster domain events, matching previoussubscribe
registration.
-
sendCurrentClusterState
public void sendCurrentClusterState(ActorRef receiver)
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
public void join(Address address)
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
ActorSystem
must 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
public void joinSeedNodes(scala.collection.immutable.Seq<Address> seedNodes)
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
public void joinSeedNodes(java.util.List<Address> seedNodes)
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.
-
setAppVersionLater
public void setAppVersionLater(scala.concurrent.Future<Version> appVersion)
Scala API: If theappVersion
is read from an external system (e.g. Kubernetes) it can be defined after system startup but before joining by completing theappVersion
Future
. In that case,setAppVersionLater
should be called before callingjoin
orjoinSeedNodes
. It's fine to calljoin
orjoinSeedNodes
immediately afterwards (before theFuture
is completed. The join will then wait for theappVersion
to be completed.
-
setAppVersionLater
public void setAppVersionLater(java.util.concurrent.CompletionStage<Version> appVersion)
Java API: If theappVersion
is read from an external system (e.g. Kubernetes) it can be defined after system startup but before joining by completing theappVersion
CompletionStage
. In that case,setAppVersionLater
should be called before callingjoin
orjoinSeedNodes
. It's fine to calljoin
orjoinSeedNodes
immediately afterwards (before theCompletionStage
is completed. The join will then wait for theappVersion
to be completed.
-
leave
public void leave(Address address)
Send command to issue state transition to LEAVING for the node specified by 'address'. The member will go through the status changesMemberStatus
Leaving
(not published to subscribers) followed byMemberStatus
Exiting
and finallyMemberStatus
Removed
.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
public void down(Address address)
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 optionakka.cluster.min-nr-of-members
to defer some action, such as starting actors, until the cluster has reached a certain size.
-
registerOnMemberUp
public void registerOnMemberUp(java.lang.Runnable callback)
Java API: The supplied callback will be run, once, when current cluster member isUp
. Typically used together with configuration optionakka.cluster.min-nr-of-members
to 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 useCoordinatedShutdown
for this purpose.
-
registerOnMemberRemoved
public void registerOnMemberRemoved(java.lang.Runnable callback)
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 useCoordinatedShutdown
for this purpose.
-
-