Class DefaultRequestHandler
java.lang.Object
org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler
- All Implemented Interfaces:
RequestHandler
Central request orchestrator that coordinates transport requests with agent execution,
task persistence, event routing, and push notifications.
This class is the core of the A2A server runtime. It receives requests from transport
layers (JSON-RPC, gRPC, REST), executes user-provided AgentExecutor logic
asynchronously, manages event queues for response streaming, and ensures task state
is persisted through TaskStore.
Architecture Overview
Transport Layer (JSON-RPC/gRPC/REST)
↓ calls DefaultRequestHandler methods
DefaultRequestHandler (orchestrates)
↓
┌─────────────┬──────────────┬─────────────────┬──────────────────┐
│ AgentExecutor│ TaskStore │ QueueManager │ PushNotification │
│ (user logic) │ (persistence)│ (event routing) │ (notifications) │
└─────────────┴──────────────┴─────────────────┴──────────────────┘
Request Flow - Blocking Mode (onMessageSend)
- Transport calls
onMessageSend(MessageSendParams, ServerCallContext) - Initialize
TaskManagerandRequestContext - Create or tap
EventQueueviaQueueManager - Execute
AgentExecutor.execute(RequestContext, AgentEmitter)asynchronously in background thread pool - Consume events from queue on Vert.x worker thread via
EventConsumer - For blocking=true: wait for agent completion and full event consumption
- Return
TaskorMessageto transport - Cleanup queue and agent future in background
Request Flow - Streaming Mode (onMessageSendStream)
- Transport calls
onMessageSendStream(MessageSendParams, ServerCallContext) - Initialize components (same as blocking)
- Execute
AgentExecutor.execute(RequestContext, AgentEmitter)asynchronously - Return
Flow.Publisher<StreamingEventKind> immediately - Events stream to client as they arrive in the queue
- On client disconnect: continue consumption in background (fire-and-forget)
- Cleanup after streaming completes
Queue Lifecycle Management
QueueManager.createOrTap(String)creates a MainQueue (new task) or ChildQueue (resubscription)- Agent enqueues events on background thread via
EventQueue.enqueueEvent(Event) EventConsumerpolls and processes events on Vert.x worker thread- Queue closes automatically on final event (COMPLETED/FAILED/CANCELED)
- Cleanup waits for both agent execution AND event consumption to complete
Threading Model
- Vert.x worker threads: Execute request handler methods (onMessageSend, etc.)
- Agent-executor pool (@Internal): Execute
AgentExecutor.execute(RequestContext, AgentEmitter) - Background cleanup:
CompletableFutureasync tasks
Important: Avoid blocking operations on Vert.x worker threads - they are limited and shared across all requests.
Blocking vs Streaming
- Blocking (configuration.blocking=true): Client waits for first event or final task state
- Streaming: Client receives events as they arrive via reactive streams
- Both modes support fire-and-forget (agent continues after client disconnect)
- Configurable timeouts via
a2a.blocking.agent.timeout.secondsanda2a.blocking.consumption.timeout.seconds
CDI Dependencies
This class is@ApplicationScoped and automatically injects:
AgentExecutor- User-provided agent business logic (required)TaskStore- Task persistence (default:InMemoryTaskStore)QueueManager- Event queue management (default:InMemoryQueueManager)PushNotificationConfigStore- Push config storage (default:InMemoryPushNotificationConfigStore)PushNotificationSender- Push notification delivery (default:BasePushNotificationSender)A2AConfigProvider- Configuration valuesExecutor(@Internal) - Background thread pool
Extension Strategy
Users typically don't replace DefaultRequestHandler. Instead, provide custom implementations of its dependencies via CDI:AgentExecutor(required) - Your agent business logicTaskStore(@Alternative @Priority) - Database persistence (see extras/task-store-database-jpa)QueueManager(@Alternative @Priority) - Replication support (see extras/queue-manager-replicated)PushNotificationSender(@Alternative @Priority) - Custom notification delivery
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-args constructor for CDI proxy creation.DefaultRequestHandler(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager, PushNotificationConfigStore pushConfigStore, MainEventBusProcessor mainEventBusProcessor, Executor executor, Executor eventConsumerExecutor) -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultRequestHandlercreate(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager, PushNotificationConfigStore pushConfigStore, MainEventBusProcessor mainEventBusProcessor, Executor executor, Executor eventConsumerExecutor) For testingonCancelTask(CancelTaskParams params, ServerCallContext context) voidonDeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigParams params, ServerCallContext context) onGetTask(TaskQueryParams params, ServerCallContext context) onGetTaskPushNotificationConfig(GetTaskPushNotificationConfigParams params, ServerCallContext context) onListTaskPushNotificationConfigs(ListTaskPushNotificationConfigsParams params, ServerCallContext context) onListTasks(ListTasksParams params, ServerCallContext context) onMessageSend(MessageSendParams params, ServerCallContext context) onMessageSendStream(MessageSendParams params, ServerCallContext context) onSubscribeToTask(TaskIdParams params, ServerCallContext context) voidvalidateRequestedTask(@Nullable String requestedTaskId)
-
Constructor Details
-
DefaultRequestHandler
protected DefaultRequestHandler()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. -
DefaultRequestHandler
@Inject public DefaultRequestHandler(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager, PushNotificationConfigStore pushConfigStore, MainEventBusProcessor mainEventBusProcessor, Executor executor, Executor eventConsumerExecutor)
-
-
Method Details
-
create
public static DefaultRequestHandler create(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager, PushNotificationConfigStore pushConfigStore, MainEventBusProcessor mainEventBusProcessor, Executor executor, Executor eventConsumerExecutor) For testing -
onGetTask
- Specified by:
onGetTaskin interfaceRequestHandler- Throws:
A2AError
-
onListTasks
public ListTasksResult onListTasks(ListTasksParams params, ServerCallContext context) throws A2AError - Specified by:
onListTasksin interfaceRequestHandler- Throws:
A2AError
-
onCancelTask
- Specified by:
onCancelTaskin interfaceRequestHandler- Throws:
A2AError
-
onMessageSend
- Specified by:
onMessageSendin interfaceRequestHandler- Throws:
A2AError
-
onMessageSendStream
public Flow.Publisher<StreamingEventKind> onMessageSendStream(MessageSendParams params, ServerCallContext context) throws A2AError - Specified by:
onMessageSendStreamin interfaceRequestHandler- Throws:
A2AError
-
onCreateTaskPushNotificationConfig
public TaskPushNotificationConfig onCreateTaskPushNotificationConfig(TaskPushNotificationConfig params, ServerCallContext context) throws A2AError - Specified by:
onCreateTaskPushNotificationConfigin interfaceRequestHandler- Throws:
A2AError
-
onGetTaskPushNotificationConfig
public TaskPushNotificationConfig onGetTaskPushNotificationConfig(GetTaskPushNotificationConfigParams params, ServerCallContext context) throws A2AError - Specified by:
onGetTaskPushNotificationConfigin interfaceRequestHandler- Throws:
A2AError
-
onSubscribeToTask
public Flow.Publisher<StreamingEventKind> onSubscribeToTask(TaskIdParams params, ServerCallContext context) throws A2AError - Specified by:
onSubscribeToTaskin interfaceRequestHandler- Throws:
A2AError
-
onListTaskPushNotificationConfigs
public ListTaskPushNotificationConfigsResult onListTaskPushNotificationConfigs(ListTaskPushNotificationConfigsParams params, ServerCallContext context) throws A2AError - Specified by:
onListTaskPushNotificationConfigsin interfaceRequestHandler- Throws:
A2AError
-
onDeleteTaskPushNotificationConfig
public void onDeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigParams params, ServerCallContext context) - Specified by:
onDeleteTaskPushNotificationConfigin interfaceRequestHandler
-
validateRequestedTask
- Specified by:
validateRequestedTaskin interfaceRequestHandler- Throws:
A2AError
-