public class ClusterServiceImpl extends Object implements ClusterService, ConnectionListener, ManagedService, EventPublishingService<MembershipEvent,MembershipListener>, TransactionalService
Modifier and Type | Field and Description |
---|---|
static String |
SERVICE_NAME |
Constructor and Description |
---|
ClusterServiceImpl(Node node,
MemberImpl localMember) |
Modifier and Type | Method and Description |
---|---|
String |
addMembershipListener(MembershipListener listener)
Adds MembershipListener to listen for membership updates.
|
void |
changeClusterState(ClusterState newState)
Changes state of the cluster to the given state transactionally.
|
void |
changeClusterState(ClusterState newState,
TransactionOptions options)
Changes state of the cluster to the given state transactionally.
|
void |
changeClusterVersion(Version version)
Changes the cluster version transactionally.
|
void |
changeClusterVersion(Version version,
TransactionOptions options)
Changes the cluster version transactionally, with the transaction options provided.
|
void |
connectionAdded(Connection connection) |
void |
connectionRemoved(Connection connection) |
<T extends TransactionalObject> |
createTransactionalObject(String name,
Transaction transaction) |
void |
dispatchEvent(MembershipEvent event,
MembershipListener listener)
Notifies the service of a published event.
|
boolean |
finalizeJoin(MembersView membersView,
Address callerAddress,
String callerUuid,
String clusterId,
ClusterState clusterState,
Version clusterVersion,
long clusterStartTime,
long masterTime,
OnJoinOp preJoinOp) |
ClusterClockImpl |
getClusterClock()
Returns the
ClusterClock of the cluster. |
ClusterHeartbeatManager |
getClusterHeartbeatManager() |
String |
getClusterId()
Returns UUID for the cluster.
|
ClusterJoinManager |
getClusterJoinManager() |
ClusterState |
getClusterState()
Returns the state of the cluster.
|
ClusterStateManager |
getClusterStateManager() |
long |
getClusterTime()
Returns the cluster-wide time in milliseconds.
|
Version |
getClusterVersion()
The cluster version indicates the operating version of the cluster.
|
Collection<Member> |
getCurrentMembersAndMembersRemovedInNotJoinableState() |
HotRestartService |
getHotRestartService()
Returns the Hot Restart service for interacting with Hot Restart.
|
MemberImpl |
getLocalMember()
Gets the local member instance.
|
Address |
getMasterAddress()
Returns the address of the master member.
|
MemberImpl |
getMember(Address address)
Gets the member for the given address.
|
MemberImpl |
getMember(String uuid)
Gets the member with the given UUID.
|
Collection<Address> |
getMemberAddresses() |
Collection<MemberImpl> |
getMemberImpls()
Gets the collection of members.
|
String |
getMemberListString() |
int |
getMemberListVersion()
Returns the current version of member list.
|
Set<Member> |
getMembers()
Set of the current members in the cluster.
|
Collection<Member> |
getMembers(MemberSelector selector)
Returns a collection of the members that satisfy the given
MemberSelector . |
MembershipManager |
getMembershipManager() |
MembershipManagerCompat |
getMembershipManagerCompat() |
NodeEngineImpl |
getNodeEngine() |
int |
getSize()
Gets the current number of members.
|
int |
getSize(MemberSelector selector)
Gets the number of members that satisfy the given
MemberSelector instance. |
Address |
getThisAddress()
Gets the address of this member.
|
String |
getThisUuid() |
void |
handleExplicitSuspicion(MembersViewMetadata expectedMembersViewMetadata,
Address suspectedAddress) |
void |
handleExplicitSuspicionTrigger(Address caller,
int callerMemberListVersion,
MembersViewMetadata suspectedMembersViewMetadata) |
void |
handleMasterConfirmation(MembersViewMetadata membersViewMetadata,
long timestamp) |
MembersView |
handleMastershipClaim(Address candidateAddress,
String candidateUuid) |
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this ManagedService
|
boolean |
isJoined()
Returns whether this member joined to a cluster.
|
boolean |
isMaster()
Checks if this member is the master.
|
boolean |
isMemberRemovedInNotJoinableState(Address target) |
void |
merge(Address newTargetAddress) |
void |
notifyForRemovedMember(MemberImpl member) |
void |
promoteLocalLiteMember()
Promotes local lite member to data member.
|
boolean |
removeMembershipListener(String registrationId)
Removes the specified MembershipListener.
|
void |
reset()
reset this ManagedService back to initial state.
|
void |
resetJoinState() |
void |
rollbackTransaction(String transactionId) |
void |
sendLocalMembershipEvent() |
boolean |
setMasterAddressToJoin(Address master) |
void |
shrinkMembersRemovedInNotJoinableState(Collection<String> memberUuidsToRemove) |
void |
shutdown()
Changes state of the cluster to the
ClusterState.PASSIVE transactionally,
then triggers the shutdown process on each node. |
void |
shutdown(boolean terminate)
Shuts down this ManagedService.
|
void |
shutdown(TransactionOptions options)
Changes state of the cluster to the
ClusterState.PASSIVE transactionally, then
triggers the shutdown process on each node. |
void |
suspectAddressIfNotConnected(Address address) |
void |
suspectMember(Member suspectedMember,
String reason,
boolean destroyConnection) |
String |
toString() |
void |
updateMemberAttribute(String uuid,
MemberAttributeOperationType operationType,
String key,
Object value) |
boolean |
updateMembers(MembersView membersView,
Address callerAddress,
String callerUuid) |
public static final String SERVICE_NAME
public ClusterServiceImpl(Node node, MemberImpl localMember)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedService
init
in interface ManagedService
nodeEngine
- the NodeEngine that this ManagedService belongs to.properties
- the Properties. Can be used to pass settings to the service.public void sendLocalMembershipEvent()
public void handleExplicitSuspicion(MembersViewMetadata expectedMembersViewMetadata, Address suspectedAddress)
public void handleExplicitSuspicionTrigger(Address caller, int callerMemberListVersion, MembersViewMetadata suspectedMembersViewMetadata)
public void suspectMember(Member suspectedMember, String reason, boolean destroyConnection)
public void suspectAddressIfNotConnected(Address address)
public void handleMasterConfirmation(MembersViewMetadata membersViewMetadata, long timestamp)
public MembersView handleMastershipClaim(Address candidateAddress, String candidateUuid)
public void merge(Address newTargetAddress)
public void reset()
ManagedService
reset
in interface ManagedService
public void resetJoinState()
public boolean finalizeJoin(MembersView membersView, Address callerAddress, String callerUuid, String clusterId, ClusterState clusterState, Version clusterVersion, long clusterStartTime, long masterTime, OnJoinOp preJoinOp)
public boolean updateMembers(MembersView membersView, Address callerAddress, String callerUuid)
public void updateMemberAttribute(String uuid, MemberAttributeOperationType operationType, String key, Object value)
public void connectionAdded(Connection connection)
connectionAdded
in interface ConnectionListener
public void connectionRemoved(Connection connection)
connectionRemoved
in interface ConnectionListener
public NodeEngineImpl getNodeEngine()
public boolean isMemberRemovedInNotJoinableState(Address target)
public Collection<Member> getCurrentMembersAndMembersRemovedInNotJoinableState()
public void notifyForRemovedMember(MemberImpl member)
public void shrinkMembersRemovedInNotJoinableState(Collection<String> memberUuidsToRemove)
public MemberImpl getMember(Address address)
ClusterService
getMember
in interface ClusterService
address
- the address of the member to lookupnull
if not found (if the address is null
, null
is returned)public MemberImpl getMember(String uuid)
ClusterService
getMember
in interface ClusterService
uuid
- the UUID of the membernull
if not found (if the UUID is null
, null
is returned)public Collection<MemberImpl> getMemberImpls()
ClusterService
If we take care of the generics.
getMemberImpls
in interface ClusterService
null
)public Collection<Address> getMemberAddresses()
public Set<Member> getMembers()
Cluster
The returned set is backed by an ordered set. Every member in the cluster returns the 'members' in the same order. To obtain the oldest member (the master) in the cluster, you can retrieve the first item in the set using 'getMembers().iterator().next()'.
getMembers
in interface Cluster
public Collection<Member> getMembers(MemberSelector selector)
ClusterService
MemberSelector
.getMembers
in interface ClusterService
selector
- MemberSelector
instance to filter members to returnMemberSelector
public void shutdown(boolean terminate)
ManagedService
shutdown
in interface ManagedService
terminate
- true to shut down the ManagedServicepublic boolean setMasterAddressToJoin(Address master)
public Address getMasterAddress()
ClusterService
getMasterAddress
in interface ClusterService
null
if the master is not yet known)public boolean isMaster()
ClusterService
isMaster
in interface ClusterService
true
if master, false
otherwisepublic Address getThisAddress()
ClusterService
getThisAddress
in interface ClusterService
null
)public MemberImpl getLocalMember()
ClusterService
The returned value will never be null, but it may change when local lite member is promoted to a data member
via Cluster.promoteLocalLiteMember()
or when this member merges to a new cluster after split-brain detected. Returned value should not be
cached but instead this method should be called each time when local member is needed.
getLocalMember
in interface Cluster
getLocalMember
in interface ClusterService
null
)public String getThisUuid()
public boolean isJoined()
ClusterService
isJoined
in interface ClusterService
true
if this member is joined to a cluster, false
otherwisepublic int getSize()
ClusterService
getSize
in interface ClusterService
public int getSize(MemberSelector selector)
ClusterService
MemberSelector
instance.getSize
in interface ClusterService
selector
- MemberSelector
instance that filters members to be countedMemberSelector
instancepublic ClusterClockImpl getClusterClock()
ClusterService
ClusterClock
of the cluster.
The returned value will never be null
and will never change.
getClusterClock
in interface ClusterService
public long getClusterTime()
Cluster
Cluster tries to keep a cluster-wide time which might be different than the member's own system time. Cluster-wide time is -almost- the same on all members of the cluster.
getClusterTime
in interface Cluster
public String getClusterId()
ClusterService
getClusterId
in interface ClusterService
public String addMembershipListener(MembershipListener listener)
Cluster
The addMembershipListener method returns a register ID. This ID is needed to remove the MembershipListener using the
Cluster.removeMembershipListener(String)
method.
If the MembershipListener implements the InitialMembershipListener
interface, it will also receive
the InitialMembershipEvent
.
There is no check for duplicate registrations, so if you register the listener twice, it will get events twice.
addMembershipListener
in interface Cluster
listener
- membership listenerCluster.removeMembershipListener(String)
public boolean removeMembershipListener(String registrationId)
Cluster
If the same MembershipListener is registered multiple times, it needs to be removed multiple times. This method can safely be called multiple times for the same registration ID; subsequent calls are ignored.
removeMembershipListener
in interface Cluster
registrationId
- the registrationId of MembershipListener to removeCluster.addMembershipListener(MembershipListener)
public void dispatchEvent(MembershipEvent event, MembershipListener listener)
EventPublishingService
dispatchEvent
in interface EventPublishingService<MembershipEvent,MembershipListener>
event
- the published eventlistener
- the listener registered for this eventpublic String getMemberListString()
public ClusterState getClusterState()
Cluster
If cluster state change is in process, ClusterState.IN_TRANSITION
will be returned.
This is a local operation, state will be read directly from local member.
getClusterState
in interface Cluster
public <T extends TransactionalObject> T createTransactionalObject(String name, Transaction transaction)
createTransactionalObject
in interface TransactionalService
public void rollbackTransaction(String transactionId)
rollbackTransaction
in interface TransactionalService
public void changeClusterState(ClusterState newState)
Cluster
TWO_PHASE
and will have 1 durability by default. If you want to override
transaction options, use Cluster.changeClusterState(ClusterState, TransactionOptions)
.
If the given state is already same as current state of the cluster, then this method will have no effect.
If there's an ongoing state change transaction in the cluster, this method will fail
immediately with a TransactionException
.
If a membership change occurs in the cluster during state change, a new member joins or
an existing member leaves, then this method will fail with an IllegalStateException
.
If there are ongoing/pending migration/replication operations, because of re-balancing due to
member join or leave, then trying to change from ACTIVE
to FROZEN
or PASSIVE
will fail with an IllegalStateException
.
If transaction timeouts during state change, then this method will fail with a TransactionException
.
changeClusterState
in interface Cluster
newState
- new state of the clusterpublic void changeClusterState(ClusterState newState, TransactionOptions options)
Cluster
TWO_PHASE
transaction.
If the given state is already same as current state of the cluster, then this method will have no effect.
If there's an ongoing state change transaction in the cluster, this method will fail
immediately with a TransactionException
.
If a membership change occurs in the cluster during state change, a new member joins or
an existing member leaves, then this method will fail with an IllegalStateException
.
If there are ongoing/pending migration/replication operations, because of re-balancing due to
member join or leave, then trying to change from ACTIVE
to FROZEN
or PASSIVE
will fail with an IllegalStateException
.
If transaction timeouts during state change, then this method will fail with a TransactionException
.
changeClusterState
in interface Cluster
newState
- new state of the clusteroptions
- transaction optionspublic Version getClusterVersion()
Cluster
LifecycleEvent.LifecycleState.STARTING
is triggered.
For example, consider a cluster comprised of nodes running on hazelcast-3.8.0.jar
. Each node's codebase version
is 3.8.0 and on startup the cluster version is 3.8. After a while, another node joins, running on
hazelcast-3.9.0jar
; this node's codebase version is 3.9.0. If deemed compatible, it is allowed to join the cluster.
At this point, the cluster version is still 3.8 and the 3.9.0 member should be able to adapt its behaviour to be compatible
with the other 3.8.0 members. Once all 3.8.0 members have been shutdown and replaced by other members on codebase
version 3.9.0, still the cluster version will be 3.8. At this point, it is possible to update the cluster version to
3.9, since all cluster members will be compatible with the new cluster version. Once cluster version
is updated to 3.9, further communication among members will take place in 3.9 and all new features and functionality
of version 3.9 will be available.getClusterVersion
in interface Cluster
public HotRestartService getHotRestartService()
Cluster
getHotRestartService
in interface Cluster
public void changeClusterVersion(Version version)
Cluster
Cluster.changeClusterState(ClusterState)
and the transaction defaults are the same in this case as well
(TWO_PHASE
transaction with durability 1 by default).
If the requested cluster version is same as the current one, nothing happens.
If a member of the cluster is not compatible with the given cluster version
, as implemented by
NodeExtension.isNodeVersionCompatibleWith(Version)
, then a
VersionMismatchException
is thrown.
If an invalid version transition is requested, for example changing to a different major version, an
IllegalArgumentException
is thrown.
If a membership change occurs in the cluster during locking phase, a new member joins or
an existing member leaves, then this method will fail with an IllegalStateException
.
Likewise, once locking phase is completed successfully, Cluster.getClusterState()
will report being ClusterState.IN_TRANSITION
, disallowing membership changes until the new cluster version is
committed.
changeClusterVersion
in interface Cluster
version
- new version of the clusterpublic void changeClusterVersion(Version version, TransactionOptions options)
Cluster
Cluster.changeClusterState(ClusterState, TransactionOptions)
. The transaction
options must specify a TWO_PHASE
transaction.
If the requested cluster version is same as the current one, nothing happens.
If a member of the cluster is not compatible with the given cluster version
, as implemented by
NodeExtension.isNodeVersionCompatibleWith(Version)
, then a
VersionMismatchException
is thrown.
If an invalid version transition is requested, for example changing to a different major version, an
IllegalArgumentException
is thrown.
If a membership change occurs in the cluster during locking phase, a new member joins or
an existing member leaves, then this method will fail with an IllegalStateException
.
Likewise, once locking phase is completed successfully, Cluster.getClusterState()
will report being ClusterState.IN_TRANSITION
, disallowing membership changes until the new cluster version is
committed.
changeClusterVersion
in interface Cluster
version
- new version of the clusteroptions
- options by which to execute the transactionpublic void shutdown()
Cluster
ClusterState.PASSIVE
transactionally,
then triggers the shutdown process on each node. Transaction will be TWO_PHASE
and will have 1 durability by default. If you want to override transaction options,
use Cluster.shutdown(TransactionOptions)
.
If the cluster is already in ClusterState.PASSIVE
, shutdown process begins immediately.
All the node join / leave rules described in ClusterState.PASSIVE
state also applies here.
Any node can start the shutdown process. A shutdown command is sent to other nodes periodically until
either all other nodes leave the cluster or a configurable timeout occurs
(see GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS
). If some of the nodes do not
shutdown before the timeout duration, shutdown can be also invoked on them.
shutdown
in interface Cluster
GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS
,
Cluster.changeClusterState(ClusterState)
,
ClusterState.PASSIVE
public void shutdown(TransactionOptions options)
Cluster
ClusterState.PASSIVE
transactionally, then
triggers the shutdown process on each node. Transaction must be a TWO_PHASE
transaction.
If the cluster is already in ClusterState.PASSIVE
, shutdown process begins immediately.
All the node join / leave rules described in ClusterState.PASSIVE
state also applies here.
Any node can start the shutdown process. A shutdown command is sent to other nodes periodically until
either all other nodes leave the cluster or a configurable timeout occurs
(see GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS
). If some of the nodes do not
shutdown before the timeout duration, shutdown can be also invoked on them.
shutdown
in interface Cluster
options
- transaction optionsGroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS
,
Cluster.changeClusterState(ClusterState)
,
ClusterState.PASSIVE
public MembershipManager getMembershipManager()
public ClusterStateManager getClusterStateManager()
public ClusterJoinManager getClusterJoinManager()
public ClusterHeartbeatManager getClusterHeartbeatManager()
public MembershipManagerCompat getMembershipManagerCompat()
public void promoteLocalLiteMember()
Cluster
Cluster.getLocalMember()
and Cluster.getMembers()
reflects the promotion.promoteLocalLiteMember
in interface Cluster
public int getMemberListVersion()
ClusterService
getMemberListVersion
in interface ClusterService
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.