Class ClientTransportConfigBuilder<T extends ClientTransportConfig<? extends ClientTransport>,B extends ClientTransportConfigBuilder<T,B>>
java.lang.Object
org.a2aproject.sdk.client.transport.spi.ClientTransportConfigBuilder<T,B>
- Type Parameters:
T- the transport configuration type this builder createsB- the concrete builder type (for method chaining)
public abstract class ClientTransportConfigBuilder<T extends ClientTransportConfig<? extends ClientTransport>,B extends ClientTransportConfigBuilder<T,B>>
extends Object
Base builder class for constructing transport configuration instances.
This abstract builder provides common functionality for building transport configurations, particularly interceptor management. Concrete builders extend this class to add transport-specific configuration options.
Self-typed builder pattern: This class uses the "self-typed" or "curiously recurring template pattern" to enable method chaining in subclasses while maintaining type safety:
JSONRPCTransportConfig config = new JSONRPCTransportConfigBuilder()
.addInterceptor(loggingInterceptor) // Returns JSONRPCTransportConfigBuilder
.httpClient(myHttpClient) // Returns JSONRPCTransportConfigBuilder
.build(); // Returns JSONRPCTransportConfig
Interceptor ordering: Interceptors are invoked in the order they were added:
builder
.addInterceptor(authInterceptor) // Runs first
.addInterceptor(loggingInterceptor) // Runs second
.addInterceptor(metricsInterceptor);// Runs third
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddInterceptor(ClientCallInterceptor interceptor) Add a request/response interceptor to this transport configuration.abstract Tbuild()Build the transport configuration with all configured options.
-
Field Details
-
interceptors
-
-
Constructor Details
-
ClientTransportConfigBuilder
public ClientTransportConfigBuilder()
-
-
Method Details
-
addInterceptor
Add a request/response interceptor to this transport configuration.Interceptors can be used for cross-cutting concerns such as:
- Logging requests and responses
- Adding authentication headers
- Collecting metrics and telemetry
- Request/response transformation
- Error handling and retry logic
Interceptors are invoked in the order they were added. If
interceptorisnull, this method is a no-op (for convenience in conditional addition).Example:
builder .addInterceptor(new LoggingInterceptor()) .addInterceptor(authToken != null ? new AuthInterceptor(authToken) : null) .addInterceptor(new MetricsInterceptor());- Parameters:
interceptor- the interceptor to add (null values are ignored)- Returns:
- this builder for method chaining
- See Also:
-
build
Build the transport configuration with all configured options.Concrete implementations should:
- Validate required configuration (e.g., gRPC channel factory)
- Apply defaults for optional configuration (e.g., HTTP client)
- Create the configuration instance
- Transfer interceptors to the configuration
- Returns:
- the configured transport configuration instance
- Throws:
IllegalStateException- if required configuration is missing
-