Annotation Interface EventEmitter


@Documented @Retention(RUNTIME) @Target(METHOD) public @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
    Modifier and Type
    Class
    Description
    static enum 
    Event scope definitions.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Event name to emit on successful execution.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether to emit event asynchronously.
    Condition for emitting event (SpEL expression).
    boolean
    Whether to include method parameters in event payload.
    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 event
      Event name to emit on successful execution.
      Returns:
      event name
    • onError

      String onError
      Event name to emit on error/exception.

      If empty, no event is emitted on error.

      Returns:
      error event name
      Default:
      ""
    • includeParams

      boolean includeParams
      Whether to include method parameters in event payload.
      Returns:
      true to include params
      Default:
      false
    • async

      boolean async
      Whether to emit event asynchronously.

      If true, event emission doesn't block method return.

      Returns:
      true for async emission
      Default:
      false
    • condition

      String condition
      Condition 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 payload
      Custom 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[] metadata
      Event metadata key-value pairs.

      Format: "key1=value1", "key2=value2"

      Returns:
      metadata entries
      Default:
      {}
    • scope

      Target audience for the event.
      Returns:
      event scope
      Default:
      LOCAL