Class HttpClientFactory

java.lang.Object
com.google.adk.internal.http.HttpClientFactory

public final class HttpClientFactory extends Object
Creates OkHttpClients for the ADK. The default clients are cached per name so the dispatcher and connection pool are reused across the ADK; a caller that supplies its own executor gets a fresh, non-cached client it owns.
  • Method Details

    • getOrCreateSharedHttpClient

      public static okhttp3.OkHttpClient getOrCreateSharedHttpClient(String name)
      Returns the shared OkHttpClient cached by name, using OkHttp's default threading.
    • createHttpClient

      public static okhttp3.OkHttpClient createHttpClient(ExecutorService executorService)
      Returns a new OkHttpClient whose dispatcher runs on executorService. Pass daemonExecutor(String) so a standalone JVM can exit once work is done, or a container-managed executor in a managed environment. The client is not cached: the caller owns the executor and the returned client.
      Parameters:
      executorService - executor for the dispatcher.
    • daemonExecutor

      public static ExecutorService daemonExecutor(String name)
      Returns an unbounded pool of daemon threads, matching OkHttp's own dispatcher pool but with daemon threads so a standalone JVM can exit once work is done. Managed container environments should inject their own executor instead of calling this.
      Parameters:
      name - prefix for the dispatcher thread names.