Record Class GroupEvent

java.lang.Object
java.lang.Record
com.tnsai.agents.groups.GroupEvent
Record Components:
id - unique event ID
type - event type
groupId - source group ID
sourceAgentId - source agent ID (may be null for group-level events)
targetAgentId - target agent ID (null for broadcasts)
payload - event data
metadata - additional metadata
timestamp - when event occurred

public record GroupEvent(String id, GroupEvent.Type type, String groupId, String sourceAgentId, String targetAgentId, Object payload, Map<String,Object> metadata, Instant timestamp) extends Record
Event occurring within an AgentGroup.

GroupEvents are used for intra-group communication via the GroupEventBus. They carry typed payloads and metadata about the source and target of events.

Event Types

  • Constructor Details

  • Method Details

    • isTargeted

      public boolean isTargeted()
      Checks if this event is targeted at a specific agent.
      Returns:
      true if targeted
    • isBroadcast

      public boolean isBroadcast()
      Checks if this event is a broadcast.
      Returns:
      true if broadcast
    • getPayloadAs

      public <T> T getPayloadAs(Class<T> clazz)
      Gets payload as specific type.
      Type Parameters:
      T - payload type
      Parameters:
      clazz - expected type
      Returns:
      typed payload or null if not matching
    • memberJoined

      public static GroupEvent memberJoined(String groupId, Agent agent)
      Creates a member joined event.
      Parameters:
      groupId - group ID
      agent - joined agent
      Returns:
      event
    • memberLeft

      public static GroupEvent memberLeft(String groupId, String agentId, String reason)
      Creates a member left event.
      Parameters:
      groupId - group ID
      agentId - left agent ID
      reason - reason for leaving
      Returns:
      event
    • leaderElected

      public static GroupEvent leaderElected(String groupId, Agent leader)
      Creates a leader elected event.
      Parameters:
      groupId - group ID
      leader - elected leader
      Returns:
      event
    • lifecycleChanged

      public static GroupEvent lifecycleChanged(String groupId, GroupLifecycle oldState, GroupLifecycle newState)
      Creates a lifecycle changed event.
      Parameters:
      groupId - group ID
      oldState - old lifecycle state
      newState - new lifecycle state
      Returns:
      event
    • message

      public static GroupEvent message(String groupId, String sourceAgentId, String content)
      Creates a message event.
      Parameters:
      groupId - group ID
      sourceAgentId - sender agent ID
      content - message content
      Returns:
      event
    • taskAssigned

      public static GroupEvent taskAssigned(String groupId, GroupTask task, String assigneeId)
      Creates a task assigned event.
      Parameters:
      groupId - group ID
      task - assigned task
      assigneeId - assigned agent ID
      Returns:
      event
    • builder

      public static GroupEvent.Builder builder()
      Creates a builder for custom events.
      Returns:
      builder
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • type

      public GroupEvent.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • groupId

      public String groupId()
      Returns the value of the groupId record component.
      Returns:
      the value of the groupId record component
    • sourceAgentId

      public String sourceAgentId()
      Returns the value of the sourceAgentId record component.
      Returns:
      the value of the sourceAgentId record component
    • targetAgentId

      public String targetAgentId()
      Returns the value of the targetAgentId record component.
      Returns:
      the value of the targetAgentId record component
    • payload

      public Object payload()
      Returns the value of the payload record component.
      Returns:
      the value of the payload record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component