Class InMemoryQueueManager
- All Implemented Interfaces:
QueueManager
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-args constructor for CDI proxy creation.InMemoryQueueManager(EventQueueFactory factory, TaskStateProvider taskStateProvider, MainEventBus mainEventBus) InMemoryQueueManager(TaskStateProvider taskStateProvider, MainEventBus mainEventBus) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(String taskId, EventQueue queue) Adds a queue to the manager with the given task ID.voidawaitQueuePollerStart(EventQueue eventQueue) Waits for the queue's consumer polling to start.voidCloses and removes the queue for a task.createBaseEventQueueBuilder(String taskId) Creates a base EventQueueBuilder with standard configuration for this QueueManager.createOrTap(String taskId) Creates a MainQueue if none exists, or taps the existing queue to create a ChildQueue.@Nullable EventQueueRetrieves the MainQueue for a task, if it exists.intgetActiveChildQueueCount(String taskId) Returns the number of active ChildQueues for a task.getCleanupCallback(String taskId) Get the cleanup callback that removes a queue from the map when it closes.getEventQueueBuilder(String taskId) Returns an EventQueueBuilder for creating queues with task-specific configuration.@Nullable EventQueueCreates a ChildQueue that receives copies of events from the MainQueue.
-
Constructor Details
-
InMemoryQueueManager
protected InMemoryQueueManager()No-args constructor for CDI proxy creation. CDI requires a non-private constructor to create proxies for @ApplicationScoped beans. All fields are initialized by the @Inject constructor during actual bean creation. -
InMemoryQueueManager
-
InMemoryQueueManager
public InMemoryQueueManager(EventQueueFactory factory, TaskStateProvider taskStateProvider, MainEventBus mainEventBus)
-
-
Method Details
-
add
Description copied from interface:QueueManagerAdds a queue to the manager with the given task ID.Throws
TaskQueueExistsExceptionif a queue already exists for this task. Typically used internally - preferQueueManager.createOrTap(String)for most use cases.- Specified by:
addin interfaceQueueManager- Parameters:
taskId- the task identifierqueue- the queue to add
-
get
Description copied from interface:QueueManagerRetrieves the MainQueue for a task, if it exists.Returns the primary queue for the task. Does not create a new queue if none exists.
- Specified by:
getin interfaceQueueManager- Parameters:
taskId- the task identifier- Returns:
- the MainQueue, or null if no queue exists for this task
-
tap
Description copied from interface:QueueManagerCreates a ChildQueue that receives copies of events from the MainQueue.Use this for:
- Resubscribing to an ongoing task (receive future events)
- Canceling a task while still receiving status updates
- Multiple concurrent consumers of the same task
The ChildQueue receives events enqueued AFTER it's created. Historical events are not replayed.
- Specified by:
tapin interfaceQueueManager- Parameters:
taskId- the task identifier- Returns:
- a ChildQueue that receives future events, or null if the MainQueue doesn't exist
-
close
Description copied from interface:QueueManagerCloses and removes the queue for a task.This closes the MainQueue and all ChildQueues, then removes it from the manager. Called during cleanup after task completion or error conditions.
- Specified by:
closein interfaceQueueManager- Parameters:
taskId- the task identifier
-
createOrTap
Description copied from interface:QueueManagerCreates a MainQueue if none exists, or taps the existing queue to create a ChildQueue.This is the primary method used by
DefaultRequestHandler:- New task: Creates and returns a MainQueue
- Resubscription: Taps existing MainQueue and returns a ChildQueue
- Specified by:
createOrTapin interfaceQueueManager- Parameters:
taskId- the task identifier- Returns:
- a MainQueue (if new task) or ChildQueue (if tapping existing)
-
awaitQueuePollerStart
Description copied from interface:QueueManagerWaits for the queue's consumer polling to start.Used internally to ensure the consumer is ready before the agent starts enqueueing events, avoiding race conditions where events might be enqueued before the consumer begins polling.
- Specified by:
awaitQueuePollerStartin interfaceQueueManager- Parameters:
eventQueue- the queue to wait for- Throws:
InterruptedException- if interrupted while waiting
-
getEventQueueBuilder
Description copied from interface:QueueManagerReturns an EventQueueBuilder for creating queues with task-specific configuration.Implementations can override to provide custom queue configurations per task, such as different capacities, hooks, or event processors.
Default implementation returns a standard builder with no customization.
- Specified by:
getEventQueueBuilderin interfaceQueueManager- Parameters:
taskId- the task ID for context (may be used to customize queue configuration)- Returns:
- a builder for creating event queues
-
getActiveChildQueueCount
Description copied from interface:QueueManagerReturns the number of active ChildQueues for a task.Used for testing to verify reference counting and queue lifecycle management. In production, indicates how many consumers are actively subscribed to a task's events.
- Specified by:
getActiveChildQueueCountin interfaceQueueManager- Parameters:
taskId- the task ID- Returns:
- number of active child queues, or -1 if the MainQueue doesn't exist
-
createBaseEventQueueBuilder
Description copied from interface:QueueManagerCreates a base EventQueueBuilder with standard configuration for this QueueManager. This method provides the foundation for creating event queues with proper configuration (MainEventBus, TaskStateProvider, cleanup callbacks, etc.).QueueManager implementations that use custom factories can call this method directly to get the base builder without going through the factory (which could cause infinite recursion if the factory delegates back to getEventQueueBuilder()).
Callers can then add additional configuration (hooks, callbacks) before building the queue.
- Specified by:
createBaseEventQueueBuilderin interfaceQueueManager- Parameters:
taskId- the task ID for the queue- Returns:
- a builder with base configuration specific to this QueueManager implementation
-
getCleanupCallback
Get the cleanup callback that removes a queue from the map when it closes. This is exposed so that subclasses (like ReplicatedQueueManager) can reuse this cleanup logic while adding their own callbacks in the correct order.The cleanup callback checks if the task is finalized before removing the queue. If the task is not finalized, the queue remains in the map to handle late-arriving events.
- Parameters:
taskId- the task ID for the queue- Returns:
- a Runnable that removes the queue from the map if appropriate
-