public class Cluster extends java.lang.Object implements Extension
subscribe(akka.actor.ActorRef, java.lang.Class<?>...)
. Commands to operate the cluster is
available through methods in this class, such as join(akka.actor.Address)
, down(akka.actor.Address)
and leave(akka.actor.Address)
.
Each cluster Member
is identified by its Address
, and
the cluster address of this actor system is selfAddress()
. A member also has a status;
initially MemberStatus
Joining
followed by MemberStatus
Up
.
Modifier and Type | Class and Description |
---|---|
class |
Cluster.InfoLogger$
INTERNAL API
|
Constructor and Description |
---|
Cluster(ExtendedActorSystem system) |
Modifier and Type | Method and Description |
---|---|
ActorRef |
clusterCore()
INTERNAL API
|
static Cluster |
createExtension(ExtendedActorSystem system) |
void |
down(Address address)
Send command to DOWN the node specified by 'address'.
|
DowningProvider |
downingProvider() |
FailureDetectorRegistry<Address> |
failureDetector() |
static Cluster |
get(ActorSystem system) |
java.util.Set<java.lang.String> |
getSelfRoles()
Java API: roles that this member has
|
Cluster.InfoLogger$ |
InfoLogger()
Accessor for nested Scala object
|
static boolean |
isAssertInvariantsEnabled()
INTERNAL API
|
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 API
|
void |
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() |
ClusterReadView |
readView() |
<T> void |
registerOnMemberRemoved(scala.Function0<T> code)
The supplied thunk will be run, once, when current cluster member is
Removed . |
void |
registerOnMemberRemoved(java.lang.Runnable callback)
Java API: The supplied thunk will be run, once, when current cluster member is
Removed . |
<T> void |
registerOnMemberUp(scala.Function0<T> code)
The supplied thunk will be run, once, when current cluster member is
Up . |
void |
registerOnMemberUp(java.lang.Runnable callback)
Java API: The supplied callback will be run, once, when current cluster member is
Up . |
ActorPath |
remotePathOf(ActorRef actorRef)
Generate the remote actor path by replacing the Address in the RootActor Path for the given
ActorRef with the cluster's
selfAddress , unless address' host is already defined |
Scheduler |
scheduler()
INTERNAL API
|
Address |
selfAddress()
The address of this cluster member.
|
scala.collection.immutable.Set<java.lang.String> |
selfRoles()
roles that this member has
|
UniqueAddress |
selfUniqueAddress()
The address including a
uid of this cluster member. |
void |
sendCurrentClusterState(ActorRef receiver)
Send current (full) state of the cluster to the specified
receiver.
|
ClusterSettings |
settings() |
void |
shutdown()
INTERNAL API.
|
ClusterEvent.CurrentClusterState |
state()
Current snapshot state of the cluster.
|
void |
subscribe(ActorRef subscriber,
java.lang.Class<?>... to)
Subscribe to one or more cluster domain events.
|
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.Seq<java.lang.Class<?>> to)
Subscribe to one or more cluster domain events.
|
void |
subscribe(ActorRef subscriber,
scala.collection.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 previous
subscribe registration. |
public Cluster(ExtendedActorSystem system)
public static Cluster get(ActorSystem system)
public static Cluster$ lookup()
public static Cluster createExtension(ExtendedActorSystem system)
public static final boolean isAssertInvariantsEnabled()
public Cluster.InfoLogger$ InfoLogger()
public void subscribe(ActorRef subscriber, java.lang.Class<?>... to)
to
classes can be ClusterEvent.ClusterDomainEvent
or subclasses.
A snapshot of ClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.
subscriber
- (undocumented)to
- (undocumented)public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, java.lang.Class<?>... to)
to
classes can be ClusterEvent.ClusterDomainEvent
or subclasses.
If initialStateMode
is ClusterEvent.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
is ClusterEvent.InitialStateAsSnapshot
a snapshot of
ClusterEvent.CurrentClusterState
will be sent to the subscriber as the
first message.
Note that for large clusters it is more efficient to use InitialStateAsSnapshot
.
subscriber
- (undocumented)initialStateMode
- (undocumented)to
- (undocumented)public ExtendedActorSystem system()
public ClusterSettings settings()
public UniqueAddress selfUniqueAddress()
uid
of this cluster member.
The uid
is needed to be able to distinguish different
incarnations of a member with same hostname and port.public Address selfAddress()
public scala.collection.immutable.Set<java.lang.String> selfRoles()
public java.util.Set<java.lang.String> getSelfRoles()
public FailureDetectorRegistry<Address> failureDetector()
public DowningProvider downingProvider()
public Scheduler scheduler()
public ActorRef clusterCore()
public ClusterReadView readView()
public boolean isTerminated()
public ClusterEvent.CurrentClusterState state()
public void subscribe(ActorRef subscriber, scala.collection.Seq<java.lang.Class<?>> to)
to
classes can be ClusterEvent.ClusterDomainEvent
or subclasses.
A snapshot of ClusterEvent.CurrentClusterState
will be sent to the subscriber as the first message.
subscriber
- (undocumented)to
- (undocumented)public void subscribe(ActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, scala.collection.Seq<java.lang.Class<?>> to)
to
classes can be ClusterEvent.ClusterDomainEvent
or subclasses.
If initialStateMode
is ClusterEvent.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
is ClusterEvent.InitialStateAsSnapshot
a snapshot of
ClusterEvent.CurrentClusterState
will be sent to the subscriber as the
first message.
Note that for large clusters it is more efficient to use InitialStateAsSnapshot
.
subscriber
- (undocumented)initialStateMode
- (undocumented)to
- (undocumented)public void unsubscribe(ActorRef subscriber)
subscriber
- (undocumented)public void unsubscribe(ActorRef subscriber, java.lang.Class<?> to)
subscribe
registration.subscriber
- (undocumented)to
- (undocumented)public void sendCurrentClusterState(ActorRef receiver)
state()
.receiver
- (undocumented)public void join(Address address)
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.
address
- (undocumented)public void joinSeedNodes(scala.collection.immutable.Seq<Address> seedNodes)
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.
seedNodes
- (undocumented)public void joinSeedNodes(java.util.List<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.
seedNodes
- (undocumented)public void leave(Address address)
MemberStatus
Leaving
(not published to
subscribers) followed by MemberStatus
Exiting
and finally MemberStatus
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.
address
- (undocumented)public void down(Address 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.
address
- (undocumented)public <T> void registerOnMemberUp(scala.Function0<T> code)
Up
.
Typically used together with configuration option akka.cluster.min-nr-of-members
to defer some action, such as starting actors, until the cluster has reached
a certain size.code
- (undocumented)public void registerOnMemberUp(java.lang.Runnable callback)
Up
.
Typically used together with configuration option akka.cluster.min-nr-of-members
to defer some action, such as starting actors, until the cluster has reached
a certain size.callback
- (undocumented)public <T> void registerOnMemberRemoved(scala.Function0<T> code)
Removed
.
If the cluster has already been shutdown the thunk will run on the caller thread immediately.
Typically used together cluster.leave(cluster.selfAddress)
and then system.terminate()
.code
- (undocumented)public void registerOnMemberRemoved(java.lang.Runnable callback)
Removed
.
If the cluster has already been shutdown the thunk will run on the caller thread immediately.
Typically used together cluster.leave(cluster.selfAddress)
and then system.terminate()
.callback
- (undocumented)public ActorPath remotePathOf(ActorRef actorRef)
selfAddress
, unless address' host is already definedactorRef
- (undocumented)public void shutdown()
Shuts down all connections to other members, the cluster daemon and the periodic gossip and cleanup tasks.
Should not called by the user. The user can issue a LEAVE command which will tell the node
to go through graceful handoff process LEAVE -> EXITING -> REMOVED -> SHUTDOWN
.