# Class GcpManagedChannel (1.11.0)

    public class GcpManagedChannel extends ManagedChannel

A channel management factory that implements grpc.Channel APIs.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> io.grpc.Channel \> io.grpc.ManagedChannel \> GcpManagedChannel

## Inherited Members

io.grpc.Channel.\<RequestT,ResponseT\>newCall(io.grpc.MethodDescriptor\<RequestT,ResponseT\>,io.grpc.CallOptions) io.grpc.Channel.authority() io.grpc.ManagedChannel.awaitTermination(long,java.util.concurrent.TimeUnit) io.grpc.ManagedChannel.enterIdle() io.grpc.ManagedChannel.getState(boolean) io.grpc.ManagedChannel.isShutdown() io.grpc.ManagedChannel.isTerminated() io.grpc.ManagedChannel.notifyWhenStateChanged(io.grpc.ConnectivityState,java.lang.Runnable) io.grpc.ManagedChannel.resetConnectBackoff() io.grpc.ManagedChannel.shutdown() io.grpc.ManagedChannel.shutdownNow() [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### AFFINITY_CTX_KEY

    public static final Context.Key<String> AFFINITY_CTX_KEY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.Context.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### AFFINITY_KEY

    public static final CallOptions.Key<String> AFFINITY_KEY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.CallOptions.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### CHANNEL_AFFINITY_REF_KEY

    public static final CallOptions.Key<GcpManagedChannel.ChannelAffinityRef> CHANNEL_AFFINITY_REF_KEY

CallOptions key for sticky channel routing without affinity-key map state.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.CallOptions.Key<https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelAffinityRef>` |   |

### CHANNEL_ID_KEY

    public static final CallOptions.Key<Integer> CHANNEL_ID_KEY

CallOptions key that will be set by grpc-gcp with the actual channel ID used for the call. This
can be read by downstream interceptors to get the real channel ID after channel selection.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.CallOptions.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html>` |   |

### DISABLE_AFFINITY_CTX_KEY

    public static final Context.Key<Boolean> DISABLE_AFFINITY_CTX_KEY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.Context.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html>` |   |

### DISABLE_AFFINITY_KEY

    public static final CallOptions.Key<Boolean> DISABLE_AFFINITY_KEY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.CallOptions.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html>` |   |

### UNBIND_AFFINITY_KEY

    public static final CallOptions.Key<Boolean> UNBIND_AFFINITY_KEY

When set to true, the affinity key will be unbound after the call completes.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.CallOptions.Key<https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html>` |   |

## Constructors

### GcpManagedChannel(ManagedChannelBuilder\<?\> delegateChannelBuilder, ApiConfig apiConfig, GcpManagedChannelOptions options)

    public GcpManagedChannel(ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, GcpManagedChannelOptions options)

Constructor for GcpManagedChannel.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `delegateChannelBuilder` | `io.grpc.ManagedChannelBuilder<?>` the underlying delegate ManagedChannelBuilder. |
| `apiConfig` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.proto.ApiConfig` the ApiConfig object for configuring GcpManagedChannel. |
| `options` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions` the options for GcpManagedChannel. |

### GcpManagedChannel(ManagedChannelBuilder\<?\> delegateChannelBuilder, ApiConfig apiConfig, int poolSize, GcpManagedChannelOptions options) (deprecated)

    public GcpManagedChannel(ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, int poolSize, GcpManagedChannelOptions options)

Constructor for GcpManagedChannel. Deprecated. Use the one without the poolSize and set the
maximum pool size in options. However, note that if setting the pool size from options then
concurrent streams low watermark (even the default one) will be also taken from the options and
not apiConfig.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `delegateChannelBuilder` | `io.grpc.ManagedChannelBuilder<?>` the underlying delegate ManagedChannelBuilder. |
| `apiConfig` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.proto.ApiConfig` the ApiConfig object for configuring GcpManagedChannel. |
| `poolSize` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` maximum number of channels the pool can have. |
| `options` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions` the options for GcpManagedChannel. |

## Methods

### \<ReqT,RespT\>checkKeys(Object message, boolean isReq, MethodDescriptor\<ReqT,RespT\> methodDescriptor)

    protected List<String> <ReqT,RespT>checkKeys(Object message, boolean isReq, MethodDescriptor<ReqT,RespT> methodDescriptor)

Fetch the affinity key from the message.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` the \<ReqT\> or \<RespT\> prototype message. |
| `isReq` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` indicates if the message is a request message. |
| `methodDescriptor` | `io.grpc.MethodDescriptor<ReqT,RespT>` |

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

### \<ReqT,RespT\>newCall(MethodDescriptor\<ReqT,RespT\> methodDescriptor, CallOptions callOptions)

    public ClientCall<ReqT,RespT> <ReqT,RespT>newCall(MethodDescriptor<ReqT,RespT> methodDescriptor, CallOptions callOptions)

Manage the channelpool using GcpClientCall().

If method-affinity is specified, we will use the GcpClientCall to fetch the affinitykey and
bind/unbind the channel, otherwise we just need the SimpleGcpClientCall to keep track of the
number of streams in each channel.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `methodDescriptor` | `io.grpc.MethodDescriptor<ReqT,RespT>` |
| `callOptions` | `io.grpc.CallOptions` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.ClientCall<ReqT,RespT>` |   |

**Overrides** io.grpc.Channel.\<RequestT,ResponseT\>newCall(io.grpc.MethodDescriptor\<RequestT,ResponseT\>,io.grpc.CallOptions)

### authority()

    public String authority()

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

**Overrides** io.grpc.Channel.authority()

### awaitTermination(long timeout, TimeUnit unit)

    public boolean awaitTermination(long timeout, TimeUnit unit)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `unit` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html` |

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

**Overrides** io.grpc.ManagedChannel.awaitTermination(long,java.util.concurrent.TimeUnit)

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

### bind(GcpManagedChannel.ChannelRef channelRef, List\<String\> affinityKeys)

    protected void bind(GcpManagedChannel.ChannelRef channelRef, List<String> affinityKeys)

Bind channel with affinity key.

One channel can be mapped to more than one keys. But one key can only be mapped to one
channel.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `channelRef` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelRef` |
| `affinityKeys` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |

### getChannelRef(String key)

    protected GcpManagedChannel.ChannelRef getChannelRef(String key)

Pick a ChannelRef (and create a new one if necessary). If notReadyFallbackEnabled is
true in the GcpResiliencyOptions then instead of a channel in a non-READY state another
channel in the READY state and having fewer than maximum allowed number of active streams will
be provided if available. Subsequent calls with the same affinity key will provide the same
fallback channel as long as the fallback channel is in the READY state.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` affinity key. If it is specified, pick the ChannelRef bound with the affinity key. Otherwise pick the one with the smallest number of streams. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelRef` |   |

### getChannelRefByAffinityRef(GcpManagedChannel.ChannelAffinityRef affinityRef)

    protected GcpManagedChannel.ChannelRef getChannelRefByAffinityRef(GcpManagedChannel.ChannelAffinityRef affinityRef)

Pick a ChannelRef using a caller-owned reference instead of grpc-gcp's affinity map.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `affinityRef` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelAffinityRef` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelRef` |   |

### getChannelRefForBind()

    protected GcpManagedChannel.ChannelRef getChannelRefForBind()

Returns a ChannelRef from the pool for a binding call. If round-robin on bind is
enabled, uses [#getChannelRefRoundRobin()](https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel#com_google_cloud_grpc_GcpManagedChannel_getChannelRefRoundRobin__) otherwise [#getChannelRef(String)](https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel#com_google_cloud_grpc_GcpManagedChannel_getChannelRef_java_lang_String_)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelRef` | ChannelRef channel to use for a call. |

### getChannelRefRoundRobin()

    protected synchronized GcpManagedChannel.ChannelRef getChannelRefRoundRobin()

Returns a ChannelRef from the pool in round-robin manner. Creates a new channel in the
pool until the pool reaches its max size.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannel.ChannelRef` | ChannelRef |

### getMaxActiveStreams()

    public int getMaxActiveStreams()

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

### getMaxSize()

    public int getMaxSize()

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

### getMinActiveStreams()

    public int getMinActiveStreams()

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

### getMinSize()

    public int getMinSize()

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

### getNumberOfChannels()

    public int getNumberOfChannels()

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

### getState(boolean requestConnection)

    public ConnectivityState getState(boolean requestConnection)

Get the current connectivity state of the channel pool.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.ConnectivityState` |   |

**Overrides** io.grpc.ManagedChannel.getState(boolean)

### getStreamsLowWatermark()

    public int getStreamsLowWatermark()

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

### isShutdown()

    public boolean isShutdown()

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

**Overrides** io.grpc.ManagedChannel.isShutdown()

### isTerminated()

    public boolean isTerminated()

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

**Overrides** io.grpc.ManagedChannel.isTerminated()

### notifyWhenStateChanged(ConnectivityState source, Runnable callback)

    public void notifyWhenStateChanged(ConnectivityState source, Runnable callback)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `source` | `io.grpc.ConnectivityState` |
| `callback` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html` |

**Overrides** io.grpc.ManagedChannel.notifyWhenStateChanged(io.grpc.ConnectivityState,java.lang.Runnable)

### shutdown()

    public ManagedChannel shutdown()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.ManagedChannel` |   |

**Overrides** io.grpc.ManagedChannel.shutdown()

### shutdownNow()

    public ManagedChannel shutdownNow()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `io.grpc.ManagedChannel` |   |

**Overrides** io.grpc.ManagedChannel.shutdownNow()

### unbind(List\<String\> affinityKeys)

    protected void unbind(List<String> affinityKeys)

Unbind channel with affinity key.

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