Class CloseStreamsHook
- All Implemented Interfaces:
TaskStreamLifecycleHook
When 3 subscribers are connected to the same task, this hook calls
StreamCloseHandle.closeStreams() to gracefully close all active streams.
The agent executor continues running, but disconnected clients can resubscribe later.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonEvent(String taskId, Event event, StreamCloseHandle handle) Called after an event has been persisted and distributed to all ChildQueues.voidonSubscribe(String taskId, StreamCloseHandle handle) Called when a new ChildQueue is created for a task (a client subscribes to the stream).voidonUnsubscribe(String taskId, StreamCloseHandle handle) Called when a ChildQueue closes for a task (a client disconnects or streams are closed).
-
Constructor Details
-
CloseStreamsHook
public CloseStreamsHook()
-
-
Method Details
-
onSubscribe
Description copied from interface:TaskStreamLifecycleHookCalled when a new ChildQueue is created for a task (a client subscribes to the stream).If this method calls
StreamCloseHandle.closeStreams(), the ChildQueue being created will be closed beforetap()returns it to the caller. The caller will receive a closed queue whosedequeueEventItem()throwsEventQueueClosedExceptionimmediately.- Specified by:
onSubscribein interfaceTaskStreamLifecycleHook- Parameters:
taskId- the task identifierhandle- handle to close streams and query subscriber count
-
onUnsubscribe
Description copied from interface:TaskStreamLifecycleHookCalled when a ChildQueue closes for a task (a client disconnects or streams are closed).Calling
StreamCloseHandle.closeStreams()from within this callback is safe but has no effect — a reentrancy guard prevents recursive iteration over the children list. To close remaining streams in response to an unsubscription, schedule the call asynchronously or handle it inTaskStreamLifecycleHook.onEvent(java.lang.String, org.a2aproject.sdk.spec.Event, org.a2aproject.sdk.server.events.StreamCloseHandle).- Specified by:
onUnsubscribein interfaceTaskStreamLifecycleHook- Parameters:
taskId- the task identifierhandle- handle to close streams and query subscriber count
-
onEvent
Description copied from interface:TaskStreamLifecycleHookCalled after an event has been persisted and distributed to all ChildQueues.- Specified by:
onEventin interfaceTaskStreamLifecycleHook- Parameters:
taskId- the task identifierevent- the event that was processedhandle- handle to close streams and query subscriber count
-