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 creates
B - 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 Details

  • Constructor Details

    • ClientTransportConfigBuilder

      public ClientTransportConfigBuilder()
  • Method Details

    • addInterceptor

      public B addInterceptor(ClientCallInterceptor interceptor)
      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 interceptor is null, 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

      public abstract T build()
      Build the transport configuration with all configured options.

      Concrete implementations should:

      1. Validate required configuration (e.g., gRPC channel factory)
      2. Apply defaults for optional configuration (e.g., HTTP client)
      3. Create the configuration instance
      4. Transfer interceptors to the configuration
      Returns:
      the configured transport configuration instance
      Throws:
      IllegalStateException - if required configuration is missing