Package com.tnsai.agents.groups
Record Class GroupEvent
java.lang.Object
java.lang.Record
com.tnsai.agents.groups.GroupEvent
- Record Components:
id- unique event IDtype- event typegroupId- source group IDsourceAgentId- source agent ID (may be null for group-level events)targetAgentId- target agent ID (null for broadcasts)payload- event datametadata- additional metadatatimestamp- 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
GroupEvent.Type.MEMBER_JOINED- Agent joined the groupGroupEvent.Type.MEMBER_LEFT- Agent left the groupGroupEvent.Type.LEADER_ELECTED- New leader electedGroupEvent.Type.TASK_ASSIGNED- Task assigned to memberGroupEvent.Type.TASK_COMPLETED- Task completed by memberGroupEvent.Type.MESSAGE- General message broadcastGroupEvent.Type.LIFECYCLE_CHANGED- Group lifecycle state changed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for GroupEvent.static enumEvent types for group events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GroupEvent.Builderbuilder()Creates a builder for custom events.final booleanIndicates whether some other object is "equal to" this one.<T> TgetPayloadAs(Class<T> clazz) Gets payload as specific type.groupId()Returns the value of thegroupIdrecord component.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.booleanChecks if this event is a broadcast.booleanChecks if this event is targeted at a specific agent.static GroupEventleaderElected(String groupId, Agent leader) Creates a leader elected event.static GroupEventlifecycleChanged(String groupId, GroupLifecycle oldState, GroupLifecycle newState) Creates a lifecycle changed event.static GroupEventmemberJoined(String groupId, Agent agent) Creates a member joined event.static GroupEventmemberLeft(String groupId, String agentId, String reason) Creates a member left event.static GroupEventCreates a message event.metadata()Returns the value of themetadatarecord component.payload()Returns the value of thepayloadrecord component.Returns the value of thesourceAgentIdrecord component.Returns the value of thetargetAgentIdrecord component.static GroupEventtaskAssigned(String groupId, GroupTask task, String assigneeId) Creates a task assigned event.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
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
Gets payload as specific type.- Type Parameters:
T- payload type- Parameters:
clazz- expected type- Returns:
- typed payload or null if not matching
-
memberJoined
Creates a member joined event.- Parameters:
groupId- group IDagent- joined agent- Returns:
- event
-
memberLeft
Creates a member left event.- Parameters:
groupId- group IDagentId- left agent IDreason- reason for leaving- Returns:
- event
-
leaderElected
Creates a leader elected event.- Parameters:
groupId- group IDleader- elected leader- Returns:
- event
-
lifecycleChanged
public static GroupEvent lifecycleChanged(String groupId, GroupLifecycle oldState, GroupLifecycle newState) Creates a lifecycle changed event.- Parameters:
groupId- group IDoldState- old lifecycle statenewState- new lifecycle state- Returns:
- event
-
message
Creates a message event.- Parameters:
groupId- group IDsourceAgentId- sender agent IDcontent- message content- Returns:
- event
-
taskAssigned
Creates a task assigned event.- Parameters:
groupId- group IDtask- assigned taskassigneeId- assigned agent ID- Returns:
- event
-
builder
Creates a builder for custom events.- Returns:
- builder
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
groupId
Returns the value of thegroupIdrecord component.- Returns:
- the value of the
groupIdrecord component
-
sourceAgentId
Returns the value of thesourceAgentIdrecord component.- Returns:
- the value of the
sourceAgentIdrecord component
-
targetAgentId
Returns the value of thetargetAgentIdrecord component.- Returns:
- the value of the
targetAgentIdrecord component
-
payload
Returns the value of thepayloadrecord component.- Returns:
- the value of the
payloadrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-
timestamp
Returns the value of thetimestamprecord component.- Returns:
- the value of the
timestamprecord component
-