Package com.tnsai.annotations
Annotation Interface EventEmitter
Marks a method to automatically emit an event after execution.
When a method annotated with @EventEmitter completes successfully,
an event is automatically published with the method's return value as payload.
Usage
public class AnalysisRole extends Role {
@ActionSpec(type = ActionType.LOCAL, description = "Analyze data")
@EventEmitter(event = "analysis.completed")
public AnalysisResult analyze(String data) {
// ... perform analysis
return new AnalysisResult(findings);
// Event "analysis.completed" is auto-emitted with AnalysisResult as payload
}
@ActionSpec(type = ActionType.LOCAL, description = "Process task")
@EventEmitter(
event = "task.processed",
includeParams = true,
onError = "task.failed"
)
public TaskResult processTask(String taskId, Map<String, Object> params) {
// On success: emits "task.processed" with result + params
// On error: emits "task.failed" with exception info
}
}
Event Payload
The emitted event contains:
- Method return value (if not void)
- Method parameters (if includeParams = true)
- Agent ID and timestamp
- Author:
- TnsAI Team
- See Also:
-
Nested Class Summary
Nested Classes -
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether to emit event asynchronously.Condition for emitting event (SpEL expression).booleanWhether to include method parameters in event payload.String[]Event metadata key-value pairs.Event name to emit on error/exception.Custom event payload transformer (SpEL expression).Target audience for the event.
-
Element Details
-
event
String eventEvent name to emit on successful execution.- Returns:
- event name
-
onError
String onErrorEvent name to emit on error/exception.If empty, no event is emitted on error.
- Returns:
- error event name
- Default:
""
-
includeParams
boolean includeParamsWhether to include method parameters in event payload.- Returns:
- true to include params
- Default:
false
-
async
boolean asyncWhether to emit event asynchronously.If true, event emission doesn't block method return.
- Returns:
- true for async emission
- Default:
false
-
condition
String conditionCondition for emitting event (SpEL expression).Event is only emitted if condition evaluates to true.
@EventEmitter(event = "important.result", condition = "result.score > 0.9")- Returns:
- SpEL condition
- Default:
""
-
payload
String payloadCustom event payload transformer (SpEL expression).Transforms the return value before including in event.
@EventEmitter(event = "summary", payload = "result.getSummary()")- Returns:
- SpEL payload expression
- Default:
""
-
metadata
String[] metadataEvent metadata key-value pairs.Format: "key1=value1", "key2=value2"
- Returns:
- metadata entries
- Default:
{}
-
scope
EventEmitter.Scope scopeTarget audience for the event.- Returns:
- event scope
- Default:
LOCAL
-