Interface TransportChannelProvider

All Known Implementing Classes:
FixedTransportChannelProvider

@InternalExtensionOnly public interface TransportChannelProvider
Provides an interface to either build a TransportChannel or provide a fixed TransportChannel that will be used to make calls to a service.

Implementations of TransportChannelProvider may choose to create a new TransportChannel for each call to getTransportChannel(), or may return a fixed TransportChannel instance.

Callers should use the following pattern to get a channel:


 TransportChannelProvider transportChannelProvider = ...;
 if (transportChannelProvider.needsHeaders()) {
   transportChannelProvider = transportChannelProvider.withHeaders(headers);
 }
 // optional: set executor for TransportChannel
 transportChannelProvider.withExecutor(executor);
 TransportChannel transportChannel = transportChannelProvider.getTransportChannel();
 
  • Method Details

    • shouldAutoClose

      boolean shouldAutoClose()
      Indicates whether the TransportChannel should be closed by the containing client class.
    • needsExecutor

      @Deprecated boolean needsExecutor()
      Deprecated.
      Channel providers will have default executors if they need one.
      True if the TransportProvider needs an executor.
    • withExecutor

      TransportChannelProvider withExecutor(Executor executor)
      Sets the executor to use when constructing a new TransportChannel.
    • withExecutor

      Deprecated.
    • needsHeaders

      boolean needsHeaders()
      True if the TransportProvider has no headers provided.
    • withHeaders

      TransportChannelProvider withHeaders(Map<String,String> headers)
      Sets the headers to use when constructing a new TransportChannel.

      This method should only be called if needsHeaders() returns true.

    • needsEndpoint

      boolean needsEndpoint()
      True if the TransportProvider has no endpoint set.
    • withEndpoint

      TransportChannelProvider withEndpoint(String endpoint)
      Sets the endpoint to use when constructing a new TransportChannel.

      This method should only be called if needsEndpoint() returns true.

    • acceptsPoolSize

      @Deprecated boolean acceptsPoolSize()
      Deprecated.
      Pool settings should be configured on the builder of the specific implementation.
      Reports whether this provider allows pool size customization.
    • withPoolSize

      @Deprecated TransportChannelProvider withPoolSize(int size)
      Deprecated.
      Pool settings should be configured on the builder of the specific implementation.
      Number of underlying transport channels to open. Calls will be load balanced across them.
    • needsCredentials

      @BetaApi("The surface to customize credentials is not stable yet and may change in the future.") boolean needsCredentials()
      True if credentials are needed before channel creation.
    • withCredentials

      @BetaApi("The surface to customize credentials is not stable yet and may change in the future.") TransportChannelProvider withCredentials(com.google.auth.Credentials credentials)
      Sets the credentials that will be applied before channel creation.
    • getTransportChannel

      TransportChannel getTransportChannel() throws IOException
      Provides a Transport, which could either be a new instance for every call, or the same instance, depending on the implementation.

      If needsExecutor() is true, then withExecutor(Executor) needs to be called first to provide an executor.

      If needsHeaders() is true, then withHeaders(Map) needs to be called first to provide headers.

      if needsEndpoint() is true, then withEndpoint(String) needs to be called first to provide an endpoint.

      Throws:
      IOException
    • getTransportName

      String getTransportName()
      The name of the transport.

      This string can be used for identifying transports for switching logic.