Class MembershipProtocol
java.lang.Object
com.loomcache.server.cluster.MembershipProtocol
Protocol-level membership change tracking for cluster membership management.
Responsibilities:
- Maintains cluster membership view with versioning
- Processes membership events (join, leave, suspect, recover, leader change)
- Implements gossip-based view dissemination (anti-entropy protocol)
- Conflict resolution: higher version wins, ties broken by nodeId
- Membership statistics tracking
Thread safety: Uses ReentrantReadWriteLock for membership view, CopyOnWriteArrayList for listeners.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumReason for member leaving the cluster.static interfaceSealed interface for membership events.static interfaceListener for membership events.static final recordMembership statistics.static final recordCurrent snapshot of cluster membership. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGet count of active (UP) members.@Nullable StringGet the current leader.Get the current membership view (snapshot).Get all members in a specific state.longgetPeerViewVersion(String peerId) Get gossip state for a peer.getStats()Get current membership statistics.booleanCheck if a node is a member of the cluster.booleanmergeView(MembershipProtocol.MembershipView remoteView) Merge a remote membership view via gossip protocol.voidProcess a membership event and update the view accordingly.voidrecordGossipInteraction(String peerId, long viewVersion) Record gossip interaction with a peer.voidRegister a membership event listener.protected voidReset all statistics (for testing).voidUnregister a membership event listener.
-
Constructor Details
-
MembershipProtocol
-
-
Method Details
-
processEvent
Process a membership event and update the view accordingly.- Parameters:
event- the membership event to process
-
mergeView
Merge a remote membership view via gossip protocol. Higher version wins. If versions are equal, compare by nodeId.- Parameters:
remoteView- the remote membership view- Returns:
- true if the view was updated, false otherwise
-
getMembershipView
Get the current membership view (snapshot).- Returns:
- immutable copy of the current view
-
getActiveMemberCount
public int getActiveMemberCount()Get count of active (UP) members.- Returns:
- number of members in UP state
-
isMember
Check if a node is a member of the cluster.- Parameters:
nodeId- the node ID to check- Returns:
- true if the node is in the membership view
-
getLeader
Get the current leader.- Returns:
- the leader node ID, or
nullif no leader is currently known
-
registerListener
Register a membership event listener.- Parameters:
listener- the listener to register
-
unregisterListener
Unregister a membership event listener.- Parameters:
listener- the listener to unregister
-
recordGossipInteraction
Record gossip interaction with a peer.- Parameters:
peerId- the peer node IDviewVersion- the peer's view version
-
getPeerViewVersion
Get gossip state for a peer.- Parameters:
peerId- the peer node ID- Returns:
- the last known view version from this peer
-
getStats
Get current membership statistics.- Returns:
- membership statistics record
-
getMembersInState
Get all members in a specific state.- Parameters:
state- the member state to filter by- Returns:
- set of member IDs in the given state
-
resetStats
protected void resetStats()Reset all statistics (for testing).
-