Class ServerCallContext

java.lang.Object
org.a2aproject.sdk.server.ServerCallContext

public class ServerCallContext extends Object
  • Field Details

    • TRANSPORT_KEY

      public static final String TRANSPORT_KEY
      Key for transport protocol type in the state map. Value should be a TransportProtocol instance.
      See Also:
    • STRICT_CONTEXT_VALIDATION_KEY

      public static final String STRICT_CONTEXT_VALIDATION_KEY
      Key for context ID validation mode in the state map. Value should be a Boolean. If true or absent, strict validation is enabled (v1.0 behavior). If false, context ID mismatch validation is skipped (v0.3 compatibility).
      See Also:
    • EXECUTION_WRAPPER_KEY

      public static final String EXECUTION_WRAPPER_KEY
      Key for an execution wrapper in the state map. Value should be a UnaryOperator<Runnable> that wraps the agent execution runnable. Used by gRPC transport to fork the inbound call's context so that agent outbound calls are isolated from inbound cancellation.
      See Also:
  • Constructor Details

  • Method Details

    • getState

      public Map<String,Object> getState()
    • getUser

      public User getUser()
    • getRequestedExtensions

      public Set<String> getRequestedExtensions()
    • getActivatedExtensions

      public Set<String> getActivatedExtensions()
    • activateExtension

      public void activateExtension(String extensionUri)
    • deactivateExtension

      public void deactivateExtension(String extensionUri)
    • isExtensionActivated

      public boolean isExtensionActivated(String extensionUri)
    • isExtensionRequested

      public boolean isExtensionRequested(String extensionUri)
    • getRequestedProtocolVersion

      public @Nullable String getRequestedProtocolVersion()
    • setEventConsumerCancelCallback

      public void setEventConsumerCancelCallback(@Nullable Runnable callback)
      Sets the callback to be invoked when the client disconnects or the call is cancelled.

      This callback is typically used to stop the EventConsumer polling loop when a client disconnects from a streaming endpoint. The callback is invoked by transport layers (JSON-RPC over HTTP/SSE, REST over HTTP/SSE, gRPC streaming) when they detect that the client has closed the connection.

      Thread Safety: The callback may be invoked from any thread, depending on the transport implementation. Implementations should be thread-safe.

      Example Usage:
      
       EventConsumer consumer = new EventConsumer(queue);
       context.setEventConsumerCancelCallback(consumer::cancel);
       
      Parameters:
      callback - the callback to invoke on client disconnect, or null to clear any existing callback
      See Also:
    • invokeEventConsumerCancelCallback

      public void invokeEventConsumerCancelCallback()
      Invokes the EventConsumer cancel callback if one has been set.

      This method is called by transport layers when a client disconnects or cancels a streaming request. It triggers the callback registered via setEventConsumerCancelCallback(Runnable), which typically stops the EventConsumer polling loop.

      Transport-Specific Behavior:

      • JSON-RPC/REST over HTTP/SSE: Called from Vert.x HttpServerResponse.closeHandler() when the SSE connection is closed
      • gRPC streaming: Called from gRPC Context.CancellationListener.cancelled() when the call is cancelled

      Thread Safety: This method is thread-safe. The callback is stored in a volatile field and null-checked before invocation to prevent race conditions.

      If no callback has been set, this method does nothing (no-op).

      See Also: