Implementation:A2aproject A2a java Server Config and ThreadPool
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Server, Configuration, Thread_Pools, Versioning |
| Last Updated | 2026-10-30 00:00 GMT |
Overview
Concrete server-side configuration SPI with classpath defaults, thread pool producers for agent execution and event consumption, protocol version validation, and SSE response formatting.
Description
This implementation page groups the server infrastructure:
- A2AConfigProvider: Configuration SPI — get required and optional string values from any source (classpath properties, MicroProfile Config, custom).
- DefaultValuesConfigProvider: CDI default that loads from `META-INF/a2a-defaults.properties` on classpath. Fails on duplicate keys across files to prevent ambiguity.
- AsyncExecutorProducer: CDI producer for the agent execution thread pool — bounded `ThreadPoolExecutor` with configurable core/max pool size, keep-alive, and queue capacity.
- EventConsumerExecutorProducer: CDI producer for a separate cached thread pool for EventConsumer polling — critical: must not share the agent executor pool to avoid deadlock. Unbounded with 10s idle reclamation.
- A2AVersionValidator: Validates protocol version compatibility — major versions must match exactly, minor versions are compatible. Defaults to "0.3" when no version specified (backward compat).
- SseFormatter: Framework-agnostic SSE response formatter — serializes A2A responses to JSON and wraps in SSE event format for any HTTP server framework.
Usage
- Configuration: Override defaults via classpath properties or implement A2AConfigProvider with MicroProfile Config
- Thread pool tuning: Configure `a2a.executor.core-pool-size`, `max-pool-size`, etc. via config provider
- Version validation: Automatic in AgentCardRequestPolicy — throws VersionNotSupportedError on mismatch
- SSE formatting: Used by transport handlers (JSON-RPC, REST) for streaming response formatting
Code Reference
Source Location
- Repository: a2a-java
- Files:
- `server-common/src/main/java/org/a2aproject/sdk/server/config/A2AConfigProvider.java` (L1-35)
- `server-common/src/main/java/org/a2aproject/sdk/server/config/DefaultValuesConfigProvider.java` (L1-96)
- `server-common/src/main/java/org/a2aproject/sdk/server/util/async/AsyncExecutorProducer.java` (L1-148)
- `server-common/src/main/java/org/a2aproject/sdk/server/util/async/EventConsumerExecutorProducer.java` (L1-93)
- `server-common/src/main/java/org/a2aproject/sdk/server/version/A2AVersionValidator.java` (L1-122)
- `server-common/src/main/java/org/a2aproject/sdk/server/util/sse/SseFormatter.java` (L1-136)
Signature
public interface A2AConfigProvider {
String getValue(String name);
Optional<String> getOptionalValue(String name);
}
@ApplicationScoped
public class DefaultValuesConfigProvider implements A2AConfigProvider {
// Loads META-INF/a2a-defaults.properties, merges all, fails on duplicates
}
@ApplicationScoped
public class AsyncExecutorProducer {
// Config: a2a.executor.core-pool-size (default 5),
// a2a.executor.max-pool-size (default 50),
// a2a.executor.keep-alive-seconds (default 60),
// a2a.executor.queue-capacity (default 100)
}
@ApplicationScoped
public class EventConsumerExecutorProducer {
// Cached thread pool, 10s idle reclamation
// Separate from AsyncExecutorProducer to prevent deadlock
}
public class A2AVersionValidator {
public static void validateProtocolVersion(AgentCard agentCard,
ServerCallContext context) throws VersionNotSupportedError;
}
public class SseFormatter {
public static String formatResponseAsSSE(A2AResponse<?> response, long eventId);
public static String formatJsonAsSSE(String json, long eventId);
}
Import
import org.a2aproject.sdk.server.config.A2AConfigProvider;
import org.a2aproject.sdk.server.version.A2AVersionValidator;
import org.a2aproject.sdk.server.util.sse.SseFormatter;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | String | Yes (config) | Property name |
| agentCard | AgentCard | Yes (version) | Card with supported versions |
| context | ServerCallContext | Yes (version) | Request with client version |
| response | A2AResponse<?> | Yes (SSE) | Response to format |
Outputs
| Name | Type | Description |
|---|---|---|
| getValue returns | String | Configuration value |
| validateProtocolVersion | void / throws | VersionNotSupportedError on mismatch |
| formatResponseAsSSE returns | String | SSE-formatted event string |
Usage Examples
Version Validation
import org.a2aproject.sdk.server.version.A2AVersionValidator;
// Throws VersionNotSupportedError if client version incompatible
A2AVersionValidator.validateProtocolVersion(agentCard, context);
// If client sends no version, defaults to "0.3" (backward compat)
SSE Formatting in Transport Handler
import org.a2aproject.sdk.server.util.sse.SseFormatter;
import java.util.concurrent.atomic.AtomicLong;
AtomicLong eventId = new AtomicLong(0);
Flow.Publisher<A2AResponse<?>> responses = handler.onMessageSendStream(request, context);
// Map each response to SSE format
responses.subscribe(new Flow.Subscriber<>() {
public void onNext(A2AResponse<?> response) {
String sseEvent = SseFormatter.formatResponseAsSSE(
response, eventId.getAndIncrement());
httpResponse.write(sseEvent);
}
// ...
});
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment