Class HttpClientFactory
java.lang.Object
io.confluent.telemetry.events.exporter.http.HttpClientFactory
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(io.confluent.telemetry.events.exporter.http.HttpExporterConfig, java.util.function.Supplier<T>) for a given config
creates the resource via the supplied factory; subsequent acquires increment the count
and return the same resource. release(io.confluent.telemetry.events.exporter.http.HttpExporterConfig) decrements the count and signals the
caller to close the resource when the last reference is released.
-
Method Summary
Modifier and TypeMethodDescription<T> Tacquire(HttpExporterConfig config, Supplier<T> factory) Acquire a shared resource for the given config.static HttpClientFactorybooleanrelease(HttpExporterConfig config) Release a reference to the shared resource for the given config.
-
Method Details
-
getInstance
-
acquire
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 keyfactory- supplier to create the resource if none exists for this config- Returns:
- the shared resource
-
release
Release a reference to the shared resource for the given config.- Returns:
trueif this was the last reference and the caller should close the resource;falseif other references remain or if the config is not tracked
-