Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java ResultAggregator

From Leeroopedia
Knowledge Sources
Domains Server, Event_Processing, Reactive_Streams
Last Updated 2026-10-30 00:00 GMT

Overview

Concrete event aggregator that collects streaming events from EventConsumer into a final task result (Message or Task), supporting both blocking and non-blocking consumption modes with task store reconciliation.

Description

The ResultAggregator class bridges the EventConsumer reactive stream to synchronous result collection. It provides two modes: consumeAndEmit streams all events without persistence (used for fire-and-forget streaming), and consumeAndBreakOnInterrupt consumes events until a terminal task status is reached (blocking mode), capturing the final Message or Task. When a blocking operation completes, it reconciles with the TaskStore by polling until the persisted task state matches the streamed state, with a configurable timeout. Uses AsyncUtils reactive stream operators (Mutiny Zero) for backpressure-managed processing.

Usage

  • Blocking request-response: Used by DefaultRequestHandler when `blocking=true` to collect events until task completion
  • Streaming response: Used when `blocking=false` to stream all events to the client without waiting for completion
  • Task store reconciliation: After blocking completion, polls TaskStore to ensure persisted state is consistent

Code Reference

Source Location

  • Repository: a2a-java
  • File: `server-common/src/main/java/org/a2aproject/sdk/server/tasks/ResultAggregator.java`
  • Lines: L30-303

Signature

public class ResultAggregator {
    public ResultAggregator(TaskManager taskManager, @Nullable Message message,
            Executor executor, Executor eventConsumerExecutor,
            long reconciliationTimeoutNanos);

    public @Nullable EventKind getCurrentResult();
    public Flow.Publisher<EventQueueItem> consumeAndEmit(EventConsumer consumer);
    public EventTypeAndInterrupt consumeAndBreakOnInterrupt(
            EventConsumer consumer, boolean blocking) throws A2AError;

    // Internal: reconcileWithTaskStore, EventTypeAndInterrupt record
}

Import

import org.a2aproject.sdk.server.tasks.ResultAggregator;

I/O Contract

Inputs

Name Type Required Description
taskManager TaskManager Yes Manages task state
message Message No Initial message if already known
executor Executor Yes Thread pool for event processing
eventConsumerExecutor Executor Yes Thread pool for event consumption
reconciliationTimeoutNanos long Yes Timeout for task store reconciliation
consumer EventConsumer Yes Event queue consumer
blocking boolean Yes Whether to block until completion

Outputs

Name Type Description
getCurrentResult() EventKind (nullable) Message or current Task
consumeAndEmit() Flow.Publisher<EventQueueItem> Stream of all events
consumeAndBreakOnInterrupt() EventTypeAndInterrupt Final event type and interrupt flag

Usage Examples

Blocking Aggregation

ResultAggregator aggregator = new ResultAggregator(
    taskManager, null, executor, eventConsumerExecutor,
    TimeUnit.SECONDS.toNanos(30));

// Block until task completes or interrupts
EventTypeAndInterrupt result = aggregator.consumeAndBreakOnInterrupt(
    eventConsumer, true);

EventKind finalResult = aggregator.getCurrentResult();
if (finalResult instanceof Task task) {
    System.out.println("Task state: " + task.status().state());
}

Non-Blocking Streaming

// Stream all events without blocking
Flow.Publisher<EventQueueItem> stream = aggregator.consumeAndEmit(eventConsumer);
// Subscriber receives events as they arrive

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment