Class CdiA2AHttpClientProvider

java.lang.Object
org.a2aproject.sdk.client.http.cdi.CdiA2AHttpClientProvider
All Implemented Interfaces:
A2AHttpClientProvider

public final class CdiA2AHttpClientProvider extends Object implements A2AHttpClientProvider
CDI-based A2AHttpClientProvider that resolves an A2AHttpClient bean from the CDI container.

When a user declares a CDI producer for A2AHttpClient, this provider picks it up at priority 200 (above Vert.x at 100 and JDK at 0), allowing application-level customization without replacing the ServiceLoader mechanism.

If no CDI container is active, or if no unambiguous A2AHttpClient bean is registered, this provider throws and the factory falls back to the next lower-priority provider.

Scope requirement: The producer must use a normal scope (e.g. @ApplicationScoped). A @Dependent-scoped producer will leak a new unmanaged instance on every create() call, because the Instance used to obtain the bean is discarded after this method returns and CDI cannot destroy the dependent instance.

Usage


 @Produces
 @ApplicationScoped
 public A2AHttpClient myHttpClient(MyConfig config) {
     return ...; // custom client
 }
 
  • Constructor Details

    • CdiA2AHttpClientProvider

      public CdiA2AHttpClientProvider()
  • Method Details

    • create

      public A2AHttpClient create()
      Description copied from interface: A2AHttpClientProvider
      Creates a new instance of an A2AHttpClient.
      Specified by:
      create in interface A2AHttpClientProvider
      Returns:
      a new A2AHttpClient instance
    • priority

      public int priority()
      Description copied from interface: A2AHttpClientProvider
      Returns the priority of this provider. Higher priority providers are tried first; the first one whose A2AHttpClientProvider.create() succeeds is used.

      Built-in priorities (for reference when choosing a custom value):

      • CdiA2AHttpClient: 200 (CDI-provided bean, when a container and bean are active)
      • AndroidA2AHttpClient: 110 (Android runtime only)
      • VertxA2AHttpClient: 100 (when vertx-web-client is on the classpath)
      • JdkA2AHttpClient: 0 (always available, last resort)
      Specified by:
      priority in interface A2AHttpClientProvider
      Returns:
      the priority value (higher is better)
    • name

      public String name()
      Description copied from interface: A2AHttpClientProvider
      Returns the name of this provider for logging and debugging purposes.
      Specified by:
      name in interface A2AHttpClientProvider
      Returns:
      the provider name