# Interface TransportChannelProvider (2.81.0)

2.81.0 (latest) 2.80.0 2.79.0 2.76.0 2.75.0 2.74.1 2.73.1 2.72.2 2.71.0 2.70.3 2.69.0 2.68.2 2.67.0 2.66.0 2.65.0 2.63.1 2.62.0 2.61.0 2.60.0 2.59.1 2.58.0 2.57.0 2.55.0 2.54.1 2.53.0 2.52.0 2.51.0 2.50.0 2.49.0 2.48.1 2.47.0 2.46.1 2.45.0 2.43.0 2.42.0 2.41.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.1 2.33.0 2.32.1 2.31.1 2.30.1 2.24.0 2.23.3 2.22.0 2.21.0 2.20.1 2.19.6 2.18.7 2.17.0 2.16.0 2.15.0 2.14.0 2.13.0 2.12.2 2.11.0 2.10.0 2.9.0 2.8.1 2.7.1

    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](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider) may choose to create a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel) for each call to [#getTransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_getTransportChannel_), or may return a fixed [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.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();
     
## Methods

### acceptsPoolSize() (deprecated)

    public abstract boolean acceptsPoolSize()

**Deprecated.** *Pool settings should be configured on the builder of the specific implementation.*

Reports whether this provider allows pool size customization.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getEndpoint()

    public default String getEndpoint()

User set custom endpoint for the Transport Channel Provider

This is the unresolved endpoint used by GAPICs

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getTransportChannel()

    public abstract TransportChannel getTransportChannel()

Provides a Transport, which could either be a new instance for every call, or the same
instance, depending on the implementation.

If [#needsExecutor()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsExecutor__) is true, then [#withExecutor(Executor)](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_withExecutor_java_util_concurrent_Executor_) needs to be called
first to provide an executor.

If [#needsHeaders()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsHeaders__) is true, then [#withHeaders(Map)](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_withHeaders_java_util_Map_java_lang_String_java_lang_String__) needs to be called first
to provide headers.

if [#needsEndpoint()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsEndpoint__) is true, then [#withEndpoint(String)](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_withEndpoint_java_lang_String_) needs to be called
first to provide an endpoint.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### getTransportName()

    public abstract String getTransportName()

The name of the transport.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### needsBackgroundExecutor()

    public default boolean needsBackgroundExecutor()

True if the TransportProvider needs a background executor. The background executor can be used
for refreshing channels, resizing the channel pool etc.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### needsCredentials()

    public abstract boolean needsCredentials()

> [!WARNING]
> **Beta**
>
> *The surface to customize credentials is not stable yet and may change in the future.*
>
> This feature is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.

True if credentials are needed before channel creation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### needsEndpoint()

    public abstract boolean needsEndpoint()

True if the TransportProvider has no endpoint set.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### needsExecutor() (deprecated)

    public abstract boolean needsExecutor()

**Deprecated.** *Channel providers will have default executors if they need one.*

True if the TransportProvider needs an executor.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### needsHeaders()

    public abstract boolean needsHeaders()

True if the TransportProvider has no headers provided.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### needsMtlsEndpoint()

    public default boolean needsMtlsEndpoint()

True for gRPC transport provider which has no mtlsEndpoint set.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### shouldAutoClose()

    public abstract boolean shouldAutoClose()

Indicates whether the TransportChannel should be closed by the containing client class.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### withBackgroundExecutor(ScheduledExecutorService executor)

    public default TransportChannelProvider withBackgroundExecutor(ScheduledExecutorService executor)

Sets the background executor when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `executor` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withCredentials(Credentials credentials)

    public abstract TransportChannelProvider withCredentials(Credentials credentials)

> [!WARNING]
> **Beta**
>
> *The surface to customize credentials is not stable yet and may change in the future.*
>
> This feature is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.

Sets the credentials that will be applied before channel creation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentials` | `com.google.auth.Credentials` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withEndpoint(String endpoint)

    public abstract TransportChannelProvider withEndpoint(String endpoint)

Sets the endpoint to use when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel).

This method should only be called if [#needsEndpoint()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsEndpoint__) returns true.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `endpoint` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withExecutor(Executor executor)

    public abstract TransportChannelProvider withExecutor(Executor executor)

Sets the executor to use when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `executor` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withExecutor(ScheduledExecutorService executor) (deprecated)

    public abstract TransportChannelProvider withExecutor(ScheduledExecutorService executor)

**Deprecated.** *Please use [#withExecutor(Executor)](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_withExecutor_java_util_concurrent_Executor_).*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `executor` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withHeaders(Map\<String,String\> headers)

    public abstract TransportChannelProvider withHeaders(Map<String,String> headers)

Sets the headers to use when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel).

This method should only be called if [#needsHeaders()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsHeaders__) returns true.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `headers` | `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withMtlsEndpoint(String mtlsEndpoint)

    public default TransportChannelProvider withMtlsEndpoint(String mtlsEndpoint)

Sets the mTLS endpoint to use when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel) using S2A.

This method should only be called if [#needsMtlsEndpoint()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider#com_google_api_gax_rpc_TransportChannelProvider_needsMtlsEndpoint__) returns true.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mtlsEndpoint` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withPoolSize(int size) (deprecated)

    public abstract 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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `size` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |

### withUseS2A(boolean useS2A)

    public default TransportChannelProvider withUseS2A(boolean useS2A)

> [!WARNING]
> **Beta**
>
> *The S2A feature is not stable yet and may change in the future. <https://github.com/grpc/grpc-java/issues/11533>.*
>
> This feature is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.

Sets whether to use S2A when constructing a new [TransportChannel](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannel).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `useS2A` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.TransportChannelProvider` |   |