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();
 
  • Field Details

    • DEFAULT

      public static final GroupPolicy DEFAULT
      Default group policy with sensible defaults.
  • Constructor Details

  • 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

      public static GroupPolicy.Builder builder()
      Creates a new builder with default values.
      Returns:
      new builder
    • toBuilder

      public GroupPolicy.Builder toBuilder()
      Creates a builder pre-populated with this policy's values.
      Returns:
      builder with current values
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • minMembers

      public int minMembers()
      Returns the value of the minMembers record component.
      Returns:
      the value of the minMembers record component
    • maxMembers

      public int maxMembers()
      Returns the value of the maxMembers record component.
      Returns:
      the value of the maxMembers record component
    • memberTimeout

      public Duration memberTimeout()
      Returns the value of the memberTimeout record component.
      Returns:
      the value of the memberTimeout record component
    • scatterTimeout

      public Duration scatterTimeout()
      Returns the value of the scatterTimeout record component.
      Returns:
      the value of the scatterTimeout record component
    • allowDynamicMembership

      public boolean allowDynamicMembership()
      Returns the value of the allowDynamicMembership record component.
      Returns:
      the value of the allowDynamicMembership record component
    • failurePolicy

      public GroupPolicy.FailurePolicy failurePolicy()
      Returns the value of the failurePolicy record component.
      Returns:
      the value of the failurePolicy record component
    • selectionStrategy

      public GroupPolicy.MemberSelectionStrategy selectionStrategy()
      Returns the value of the selectionStrategy record component.
      Returns:
      the value of the selectionStrategy record component
    • electionStrategy

      public LeaderElectionStrategy electionStrategy()
      Returns the value of the electionStrategy record component.
      Returns:
      the value of the electionStrategy record component