Package com.tnsai.agents.groups
Record Class GroupPolicy
java.lang.Object
java.lang.Record
com.tnsai.agents.groups.GroupPolicy
- Record Components:
minMembers- minimum members required to start (default: 1)maxMembers- maximum allowed members (default: Integer.MAX_VALUE)memberTimeout- timeout for member health checks (default: 30 seconds)scatterTimeout- default timeout for scatter operations (default: 60 seconds)allowDynamicMembership- allow join/leave after start (default: true)failurePolicy- how to handle member failures (default: REMOVE_FAILED)selectionStrategy- how to select members for tasks (default: ROUND_ROBIN)electionStrategy- how to elect leaders (default: RANDOM)
public record GroupPolicy(int minMembers, int maxMembers, Duration memberTimeout, Duration scatterTimeout, boolean allowDynamicMembership, GroupPolicy.FailurePolicy failurePolicy, GroupPolicy.MemberSelectionStrategy selectionStrategy, LeaderElectionStrategy electionStrategy)
extends Record
Configuration policy for an AgentGroup.
GroupPolicy defines constraints and behavior for group membership, timeouts, failure handling, and coordination strategies.
Usage Example
GroupPolicy policy = GroupPolicy.builder()
.minMembers(2)
.maxMembers(10)
.memberTimeout(Duration.ofMinutes(5))
.failurePolicy(FailurePolicy.REMOVE_FAILED)
.allowDynamicMembership(true)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for GroupPolicy.static enumPolicy for handling member failures.static enumStrategy for selecting members for task assignment. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GroupPolicyDefault group policy with sensible defaults. -
Constructor Summary
ConstructorsConstructorDescriptionGroupPolicy(int minMembers, int maxMembers, Duration memberTimeout, Duration scatterTimeout, boolean allowDynamicMembership, GroupPolicy.FailurePolicy failurePolicy, GroupPolicy.MemberSelectionStrategy selectionStrategy, LeaderElectionStrategy electionStrategy) Creates a GroupPolicy with validation. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of theallowDynamicMembershiprecord component.static GroupPolicy.Builderbuilder()Creates a new builder with default values.booleancanAddMember(int currentCount) Checks if adding a new member would violate the policy.Returns the value of theelectionStrategyrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of thefailurePolicyrecord component.final inthashCode()Returns a hash code value for this object.booleanhasMinimumMembers(int currentCount) Checks if the group has enough members to start.intReturns the value of themaxMembersrecord component.Returns the value of thememberTimeoutrecord component.intReturns the value of theminMembersrecord component.Returns the value of thescatterTimeoutrecord component.Returns the value of theselectionStrategyrecord component.Creates a builder pre-populated with this policy's values.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
DEFAULT
Default group policy with sensible defaults.
-
-
Constructor Details
-
GroupPolicy
public GroupPolicy(int minMembers, int maxMembers, Duration memberTimeout, Duration scatterTimeout, boolean allowDynamicMembership, GroupPolicy.FailurePolicy failurePolicy, GroupPolicy.MemberSelectionStrategy selectionStrategy, LeaderElectionStrategy electionStrategy) Creates a GroupPolicy with validation.
-
-
Method Details
-
canAddMember
public boolean canAddMember(int currentCount) Checks if adding a new member would violate the policy.- Parameters:
currentCount- current member count- Returns:
- true if a new member can be added
-
hasMinimumMembers
public boolean hasMinimumMembers(int currentCount) Checks if the group has enough members to start.- Parameters:
currentCount- current member count- Returns:
- true if minimum members requirement is met
-
builder
Creates a new builder with default values.- Returns:
- new builder
-
toBuilder
Creates a builder pre-populated with this policy's values.- Returns:
- builder with current values
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
minMembers
public int minMembers()Returns the value of theminMembersrecord component.- Returns:
- the value of the
minMembersrecord component
-
maxMembers
public int maxMembers()Returns the value of themaxMembersrecord component.- Returns:
- the value of the
maxMembersrecord component
-
memberTimeout
Returns the value of thememberTimeoutrecord component.- Returns:
- the value of the
memberTimeoutrecord component
-
scatterTimeout
Returns the value of thescatterTimeoutrecord component.- Returns:
- the value of the
scatterTimeoutrecord component
-
allowDynamicMembership
public boolean allowDynamicMembership()Returns the value of theallowDynamicMembershiprecord component.- Returns:
- the value of the
allowDynamicMembershiprecord component
-
failurePolicy
Returns the value of thefailurePolicyrecord component.- Returns:
- the value of the
failurePolicyrecord component
-
selectionStrategy
Returns the value of theselectionStrategyrecord component.- Returns:
- the value of the
selectionStrategyrecord component
-
electionStrategy
Returns the value of theelectionStrategyrecord component.- Returns:
- the value of the
electionStrategyrecord component
-