Interface Cluster
All the methods on the Cluster are thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionaddMembershipListener
(MembershipListener listener) Adds MembershipListener to listen for membership updates.long
Returns the cluster-wide time in milliseconds.Returns this Hazelcast instance member.Set of the current members in the cluster.boolean
removeMembershipListener
(UUID registrationId) Removes the specified MembershipListener.
-
Method Details
-
addMembershipListener
Adds MembershipListener to listen for membership updates.The addMembershipListener method returns a registration ID. This ID is needed to remove the MembershipListener using the
removeMembershipListener(UUID)
method.If the MembershipListener implements the
InitialMembershipListener
interface, it will also receive theInitialMembershipEvent
.There is no check for duplicate registrations, so if you register the listener twice, it will get events twice. The listener doesn't notify when a lite member is promoted to a data member.
- Parameters:
listener
- membership listener- Returns:
- the registration ID
- Throws:
NullPointerException
- if listener is null- See Also:
-
removeMembershipListener
Removes the specified MembershipListener.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.
- Parameters:
registrationId
- the registrationId of MembershipListener to remove- Returns:
- true if the registration is removed, false otherwise
- Throws:
NullPointerException
- if the registration ID is null- See Also:
-
getMembers
Set of the current members in the cluster. The returned set is an immutable set; it can't be modified.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()'.
- Returns:
- current members in the cluster
-
getLocalMember
Returns this Hazelcast instance member.The returned value will never be null, but it may change when local lite member is promoted to a data member via server side operation 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.
Supported only for members of the cluster, clients will throw a
UnsupportedOperationException
.- Returns:
- this Hazelcast instance member
-
getClusterTime
long getClusterTime()Returns the cluster-wide time in milliseconds.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.
- Returns:
- cluster-wide time
-