Class OpenSearchConnector

java.lang.Object
ai.attackframework.tools.burp.utils.opensearch.OpenSearchConnector

public final class OpenSearchConnector extends Object
Factory/cache for OpenSearch clients.

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 Type
    Method
    Description
    static void
    Closes every cached OpenSearch client and classic HTTP client, then clears both caches.
    static org.opensearch.client.opensearch.OpenSearchClient
    getClient(String baseUrl)
    Returns a cached client for the given base URL, creating it on first use (no auth).
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getClient

      public static org.opensearch.client.opensearch.OpenSearchClient getClient(String baseUrl)
      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:9200
      username - optional; null or empty to skip auth
      password - 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 are static, 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.