@InternalExtensionOnly
public interface TransportChannelProvider
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.needsExecutor()) {
transportChannelProvider = transportChannelProvider.withExecutor(executor);
}
if (transportChannelProvider.needsHeaders()) {
transportChannelProvider = transportChannelProvider.withHeaders(headers);
}
TransportChannel transportChannel = transportChannelProvider.getTransportChannel();
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsPoolSize()
Reports whether this provider allows pool size customization.
|
TransportChannel |
getTransportChannel()
Provides a Transport, which could either be a new instance for every call, or the same
instance, depending on the implementation.
|
java.lang.String |
getTransportName()
The name of the transport.
|
boolean |
needsCredentials()
True if credentials are needed before channel creation.
|
boolean |
needsEndpoint()
True if the TransportProvider has no endpoint set.
|
boolean |
needsExecutor()
True if the TransportProvider needs an executor.
|
boolean |
needsHeaders()
True if the TransportProvider has no headers provided.
|
boolean |
shouldAutoClose()
Indicates whether the TransportChannel should be closed by the containing client class.
|
TransportChannelProvider |
withCredentials(com.google.auth.Credentials credentials)
Sets the credentials that will be applied before channel creation.
|
TransportChannelProvider |
withEndpoint(java.lang.String endpoint)
Sets the endpoint to use when constructing a new
TransportChannel . |
TransportChannelProvider |
withExecutor(java.util.concurrent.Executor executor)
Sets the executor to use when constructing a new
TransportChannel .. |
TransportChannelProvider |
withExecutor(java.util.concurrent.ScheduledExecutorService executor)
Deprecated.
Please use
withExecutor(Executor) . |
TransportChannelProvider |
withHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Sets the headers to use when constructing a new
TransportChannel .. |
TransportChannelProvider |
withPoolSize(int size)
Number of underlying transport channels to open.
|
boolean shouldAutoClose()
boolean needsExecutor()
TransportChannelProvider withExecutor(java.util.concurrent.Executor executor)
TransportChannel
..
This method should only be called if needsExecutor()
returns true.
@Deprecated TransportChannelProvider withExecutor(java.util.concurrent.ScheduledExecutorService executor)
withExecutor(Executor)
.@BetaApi(value="The surface for customizing headers is not stable yet and may change in the future.") boolean needsHeaders()
@BetaApi(value="The surface for customizing headers is not stable yet and may change in the future.") TransportChannelProvider withHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
TransportChannel
..
This method should only be called if needsHeaders()
returns true.
boolean needsEndpoint()
TransportChannelProvider withEndpoint(java.lang.String endpoint)
TransportChannel
.
This method should only be called if needsEndpoint()
returns true.
@BetaApi(value="The surface for customizing pool size is not stable yet and may change in the future.") boolean acceptsPoolSize()
@BetaApi(value="The surface for customizing pool size is not stable yet and may change in the future.") TransportChannelProvider withPoolSize(int size)
@BetaApi(value="The surface to customize credentials is not stable yet and may change in the future.") boolean needsCredentials()
@BetaApi(value="The surface to customize credentials is not stable yet and may change in the future.") TransportChannelProvider withCredentials(com.google.auth.Credentials credentials)
TransportChannel getTransportChannel() throws java.io.IOException
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.
java.io.IOException
java.lang.String getTransportName()
This string can be used for identifying transports for switching logic.