# Class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder (1.11.0)

    public static class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

## Inherited Members

[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-)

## Constructors

### Builder()

    public Builder()

### Builder(GcpManagedChannelOptions.GcpChannelPoolOptions options)

    public Builder(GcpManagedChannelOptions.GcpChannelPoolOptions options)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions` |

## Methods

### build()

    public GcpManagedChannelOptions.GcpChannelPoolOptions build()

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

### disableDynamicScaling()

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder disableDynamicScaling()

Disables dynamic scaling functionality.
See Also: [#setDynamicScaling(int, int, Duration)](https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions.Builder#com_google_cloud_grpc_GcpManagedChannelOptions_GcpChannelPoolOptions_Builder_setDynamicScaling_int_int_java_time_Duration_)

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

### setAffinityKeyLifetime(Duration affinityKeyLifetime)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setAffinityKeyLifetime(Duration affinityKeyLifetime)

How long to keep an affinity key after its last use. Zero value means keeping keys forever.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `affinityKeyLifetime` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` time since last use of a key to include the key in a cleanup. |

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

### setChannelPickStrategy(GcpManagedChannelOptions.ChannelPickStrategy strategy)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPickStrategy(GcpManagedChannelOptions.ChannelPickStrategy strategy)

Sets the strategy for picking the least busy channel from the pool.

Defaults to ChannelPickStrategy#POWER_OF_TWO which avoids the thundering herd
problem by randomly sampling two channels and picking the less busy one, with ties broken
by channel warmth (most recently active).

Use ChannelPickStrategy#LINEAR_SCAN to restore the legacy behavior of scanning
all channels and always picking the one with the fewest active streams.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `strategy` | `https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions.ChannelPickStrategy` the channel pick strategy to use. |

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

### setCleanupInterval(Duration cleanupInterval)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setCleanupInterval(Duration cleanupInterval)

How frequently affinity key cleanup process should run. Zero value disables cleanup
process. If affinityKeyLifetime is not zero, this defaults to affinityKeyLifetime / 10.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cleanupInterval` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` frequency of affinity key cleanup. |

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

### setConcurrentStreamsLowWatermark(int concurrentStreamsLowWatermark)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setConcurrentStreamsLowWatermark(int concurrentStreamsLowWatermark)

Sets the concurrent streams low watermark. If every channel in the pool has at least this
amount of concurrent streams then a new channel will be created in the pool unless the pool
reached its maximum size.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `concurrentStreamsLowWatermark` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` number of streams every channel must reach before adding a new channel to the pool. |

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

### setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval)

Enables dynamic scaling functionality.

When the average number of concurrent calls per channel reaches `maxRpcPerChannel
` the pool will create and add a new channel unless already at max size.

Every `scaleDownInterval` a check for downscaling is performed. Based on the
maximum total concurrent calls observed since the last check, the desired number of
channels is calculated as:

`(max_total_concurrent_calls / minRpcPerChannel)` rounded up.

If the calculated desired number of channels is lower than the current number of
channels, the pool will be downscaled to the desired number or min size (whichever is
greater).

When downscaling, channels with the oldest connections are selected. Then the selected
channels are removed from the pool but are not instructed to shutdown until all calls are
completed. In a case when the pool is scaling up and there is a ready channel awaiting
calls completion, the channel will be re-used instead of creating a new channel.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `minRpcPerChannel` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` minimum desired average concurrent calls per channel. |
| `maxRpcPerChannel` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` maximum desired average concurrent calls per channel. |
| `scaleDownInterval` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` how often to check for a possibility to scale down. |

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

### setInitSize(int initSize)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setInitSize(int initSize)

Sets the initial channel pool size. This is the number of channels that the pool will start
with. If it is less than [#setMinSize(int)](https://docs.cloud.google.com/java/docs/reference/grpc-gcp/latest/com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions.Builder#com_google_cloud_grpc_GcpManagedChannelOptions_GcpChannelPoolOptions_Builder_setMinSize_int_) it is ignored.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initSize` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` number of channels to start the pool with. |

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

### setMaxSize(int maxSize)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMaxSize(int maxSize)

Sets the maximum size of the channel pool.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxSize` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` maximum number of channels the pool can have. |

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

### setMinSize(int minSize)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMinSize(int minSize)

Sets the minimum size of the channel pool. This number of channels will be created and
these channels will try to always keep connection to the server established.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `minSize` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` minimum number of channels the pool must have. |

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

### setUseRoundRobinOnBind(boolean enabled)

    public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setUseRoundRobinOnBind(boolean enabled)

Enables/disables using round-robin channel selection for affinity binding calls.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `enabled` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` If true, use round-robin channel selection for affinity binding calls. |

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