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 AsyncUtils

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

Overview

Concrete reactive stream utility providing backpressure-managed publishers and consumers built on Mutiny Zero for event processing pipelines.

Description

The AsyncUtils class provides static factory methods for creating TubeConfiguration (backpressure buffer with configurable size, default 256), consumer operators that subscribe to a source publisher and apply a filtering function, and processor operators that transform publisher items. It wraps the Mutiny Zero ZeroPublisher and Tube APIs with convenient static methods. Used throughout the server event processing pipeline by ResultAggregator, EventConsumer, and MainEventBusProcessor.

Usage

  • Event pipeline construction: Used by ResultAggregator and EventConsumer to build reactive stream pipelines
  • Backpressure configuration: `createTubeConfig(bufferSize)` controls the internal buffer size for event streaming
  • Stream filtering: `consumer()` applies a predicate to filter events in the stream
  • Stream transformation: `processor()` transforms events as they flow through the pipeline

Code Reference

Source Location

  • Repository: a2a-java
  • File: `server-common/src/main/java/org/a2aproject/sdk/server/util/async/AsyncUtils.java`
  • Lines: L18-316

Signature

public class AsyncUtils {
    public static final int DEFAULT_TUBE_BUFFER_SIZE = 256;

    public static TubeConfiguration createTubeConfig();
    public static TubeConfiguration createTubeConfig(int bufferSize);

    public static <T> void consumer(TubeConfiguration config,
            Flow.Publisher<T> source,
            Function<T, Boolean> nextFunction,
            Consumer<Throwable> errorConsumer);

    public static <T> Flow.Publisher<T> processor(TubeConfiguration config,
            Flow.Publisher<T> source,
            BiFunction<Consumer<Throwable>, T, Boolean> nextFunction);

    // Internal: ConsumingSubscriber, Transform operators
}

Import

import org.a2aproject.sdk.server.util.async.AsyncUtils;

I/O Contract

Inputs

Name Type Required Description
config TubeConfiguration Yes Backpressure buffer config
source Flow.Publisher<T> Yes Upstream event publisher
nextFunction Function<T, Boolean> Yes Filter predicate (true = continue)
errorConsumer Consumer<Throwable> Yes Error callback
bufferSize int No (256) Internal buffer size

Outputs

Name Type Description
consumer() void Subscribes and processes stream
processor() Flow.Publisher<T> Transformed publisher
createTubeConfig() TubeConfiguration Buffer config with BUFFER strategy

Usage Examples

Creating a Backpressure-Managed Stream

import org.a2aproject.sdk.server.util.async.AsyncUtils;
import mutiny.zero.TubeConfiguration;

// Create config with default 256 buffer
TubeConfiguration config = AsyncUtils.createTubeConfig();

// Consume events with filtering
AsyncUtils.consumer(config, eventPublisher,
    item -> {
        System.out.println("Processing: " + item);
        return true;  // continue processing
    },
    error -> System.err.println("Error: " + error)
);

Processing Pipeline

// Transform and filter events
Flow.Publisher<EventQueueItem> processed = AsyncUtils.processor(
    AsyncUtils.createTubeConfig(512),  // larger buffer
    eventConsumer.consumeAll(),
    (errorConsumer, item) -> {
        // Return true to continue, false to stop
        return item.isTerminal();
    }
);

Related Pages

Page Connections

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