Class ServerCallContext
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateExtension(String extensionUri) voiddeactivateExtension(String extensionUri) @Nullable StringgetState()getUser()voidInvokes the EventConsumer cancel callback if one has been set.booleanisExtensionActivated(String extensionUri) booleanisExtensionRequested(String extensionUri) voidsetEventConsumerCancelCallback(@Nullable Runnable callback) Sets the callback to be invoked when the client disconnects or the call is cancelled.
-
Field Details
-
TRANSPORT_KEY
Key for transport protocol type in the state map. Value should be aTransportProtocolinstance.- See Also:
-
STRICT_CONTEXT_VALIDATION_KEY
Key for context ID validation mode in the state map. Value should be aBoolean. 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
Key for an execution wrapper in the state map. Value should be aUnaryOperator<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
-
ServerCallContext
-
ServerCallContext
-
-
Method Details
-
getState
-
getUser
-
getRequestedExtensions
-
getActivatedExtensions
-
activateExtension
-
deactivateExtension
-
isExtensionActivated
-
isExtensionRequested
-
getRequestedProtocolVersion
-
setEventConsumerCancelCallback
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).
- JSON-RPC/REST over HTTP/SSE: Called from Vert.x
-