Package com.tnsai.agents.groups
Interface MembershipManager
public interface MembershipManager
Manages membership lifecycle for an AgentGroup.
MembershipManager handles agent registration, health monitoring, and membership state tracking. It enforces group policies and coordinates with the event bus to notify about membership changes.
Features
- Health monitoring with configurable heartbeat
- Automatic removal of unhealthy members
- Membership history tracking
- Capability-based member lookup
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumMember health status.static final recordInformation about a group member.static enumMembership action types.static final recordHistorical membership event.static final recordMembership statistics.static final recordResult of membership validation. -
Method Summary
Modifier and TypeMethodDescriptionintChecks all members for health and removes unhealthy ones.findByCapability(String capability) Finds members with a specific capability.Gets members available for task assignment.getAvailableMembersWithCapability(String capability) Gets members available for task assignment with specific capability.Gets health status of a member.getHistory(int limit) Gets membership history.Gets a member by ID.intGets current member count.Gets all current members.getStats()Gets membership statistics.Gets all unhealthy members.booleanRecords a heartbeat from a member.booleanrecordTaskComplete(String agentId) Records that a task has been completed by a member.booleanrecordTaskStart(String agentId) Records that a task has been assigned to a member.Registers an agent as a group member.voidstartHealthCheck(Duration interval) Starts automatic health checking.voidStops automatic health checking.booleanunregister(String agentId, String reason) Unregisters an agent from the group.Checks if an agent can join the group.
-
Method Details
-
register
Registers an agent as a group member.- Parameters:
agent- agent to register- Returns:
- membership info, or empty if rejected
-
unregister
Unregisters an agent from the group.- Parameters:
agentId- agent IDreason- reason for leaving- Returns:
- true if was a member
-
validate
Checks if an agent can join the group.- Parameters:
agent- agent to check- Returns:
- validation result
-
heartbeat
Records a heartbeat from a member.- Parameters:
agentId- agent ID- Returns:
- true if member exists
-
getHealth
Gets health status of a member.- Parameters:
agentId- agent ID- Returns:
- health status
-
getUnhealthyMembers
List<MembershipManager.MemberInfo> getUnhealthyMembers()Gets all unhealthy members.- Returns:
- unhealthy members
-
checkAndRemoveUnhealthy
int checkAndRemoveUnhealthy()Checks all members for health and removes unhealthy ones.- Returns:
- number of members removed
-
startHealthCheck
Starts automatic health checking.- Parameters:
interval- check interval
-
stopHealthCheck
void stopHealthCheck()Stops automatic health checking. -
getMembers
List<MembershipManager.MemberInfo> getMembers()Gets all current members.- Returns:
- member list
-
getMember
Gets a member by ID.- Parameters:
agentId- agent ID- Returns:
- member info
-
findByCapability
Finds members with a specific capability.- Parameters:
capability- capability name- Returns:
- matching members
-
getMemberCount
int getMemberCount()Gets current member count.- Returns:
- member count
-
recordTaskStart
Records that a task has been assigned to a member. Increments the member's active task count.- Parameters:
agentId- agent ID- Returns:
- true if recorded successfully
-
recordTaskComplete
Records that a task has been completed by a member. Decrements the member's active task count.- Parameters:
agentId- agent ID- Returns:
- true if recorded successfully
-
getAvailableMembers
List<MembershipManager.MemberInfo> getAvailableMembers()Gets members available for task assignment. Returns healthy members that can accept more tasks, sorted by priority (highest first).- Returns:
- available members sorted by priority
-
getAvailableMembersWithCapability
Gets members available for task assignment with specific capability. Returns healthy members that can accept more tasks and have the capability, sorted by priority (highest first).- Parameters:
capability- required capability- Returns:
- available members sorted by priority
-
getStats
MembershipManager.MembershipStats getStats()Gets membership statistics.- Returns:
- statistics
-
getHistory
Gets membership history.- Parameters:
limit- maximum entries- Returns:
- history entries
-