Class HttpClientFactory

java.lang.Object
io.confluent.telemetry.events.exporter.http.HttpClientFactory

public class HttpClientFactory extends Object
Manages shared HTTP client instances keyed by HttpExporterConfig. Exporters with equal configurations (per HttpExporterConfig.hashCode()/ HttpExporterConfig.equals(Object)) share a single underlying HTTP client, preventing native thread leaks from redundant Netty event loops.

The cache uses reference counting: the first acquire(HttpExporterConfig, Supplier) for a given config creates the resource via the supplied factory; subsequent acquires increment the count and return the same resource. release(HttpExporterConfig) decrements the count and signals the caller to close the resource when the last reference is released.

  • Method Details

    • getInstance

      public static HttpClientFactory getInstance()
    • acquire

      public <T> T acquire(HttpExporterConfig config, Supplier<T> factory)
      Acquire a shared resource for the given config. If a resource already exists for an equal config, its reference count is incremented and the existing resource is returned. Otherwise, the factory supplier is invoked to create a new resource.
      Parameters:
      config - the exporter config used as the cache key
      factory - supplier to create the resource if none exists for this config
      Returns:
      the shared resource
    • release

      public boolean release(HttpExporterConfig config)
      Release a reference to the shared resource for the given config.
      Returns:
      true if this was the last reference and the caller should close the resource; false if other references remain or if the config is not tracked