Class OpenSearchConnector
Ownership: Clients are cached per base URL (and optional credentials) and reused. Do not close the returned client; lifecycle is managed here.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseAll()Closes every cached OpenSearch client and classic HTTP client, then clears both caches.static org.opensearch.client.opensearch.OpenSearchClientReturns a cached client for the given base URL, creating it on first use (no auth).static org.opensearch.client.opensearch.OpenSearchClientReturns a cached client for the given base URL and optional basic-auth credentials.
-
Method Details
-
getClient
Returns a cached client for the given base URL, creating it on first use (no auth).- Parameters:
baseUrl- e.g., https://opensearch.url:9200- Returns:
- shared client
- Throws:
OpenSearchClientBuildException- when the client cannot be constructed
-
getClient
public static org.opensearch.client.opensearch.OpenSearchClient getClient(String baseUrl, String username, String password) Returns a cached client for the given base URL and optional basic-auth credentials. When both username and password are non-null and non-empty, basic auth is configured.- Parameters:
baseUrl- e.g., https://opensearch.url:9200username- optional; null or empty to skip authpassword- optional; null or empty to skip auth- Returns:
- shared client
- Throws:
OpenSearchClientBuildException- when the client cannot be constructed
-
closeAll
public static void closeAll()Closes every cached OpenSearch client and classic HTTP client, then clears both caches.Each client owns a pooled connection manager, TLS session cache, and reactor/scheduler threads that hold substantial off-heap state (direct
ByteBuffers, SSL session state). Because the caches arestatic, those resources outlive any Stop/Start cycle unless this method runs; otherwise they are released only on extension unload via classloader GC.Close exceptions are logged at debug and swallowed so a single misbehaving client cannot prevent the other entries from being released. The method is idempotent: subsequent calls on an already-empty cache are no-ops, and a later
getClient(String)rebuilds a fresh client rather than returning a closed one.
-