public class GcpManagedChannel extends ManagedChannel
A channel management factory that implements grpc.Channel APIs.
Inheritance
Object >
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()
Static Fields
AFFINITY_CTX_KEY
public static final Context.Key<String> AFFINITY_CTX_KEY
| Field Value |
| Type |
Description |
io.grpc.Context.Key<String> |
|
AFFINITY_KEY
public static final CallOptions.Key<String> AFFINITY_KEY
| Field Value |
| Type |
Description |
io.grpc.CallOptions.Key<String> |
|
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.
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<Integer> |
|
DISABLE_AFFINITY_CTX_KEY
public static final Context.Key<Boolean> DISABLE_AFFINITY_CTX_KEY
| Field Value |
| Type |
Description |
io.grpc.Context.Key<Boolean> |
|
DISABLE_AFFINITY_KEY
public static final CallOptions.Key<Boolean> DISABLE_AFFINITY_KEY
| Field Value |
| Type |
Description |
io.grpc.CallOptions.Key<Boolean> |
|
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<Boolean> |
|
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 |
ApiConfig
the ApiConfig object for configuring GcpManagedChannel.
|
options |
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 |
ApiConfig
the ApiConfig object for configuring GcpManagedChannel.
|
poolSize |
int
maximum number of channels the pool can have.
|
options |
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 |
Object
the <ReqT> or <RespT> prototype message.
|
isReq |
boolean
indicates if the message is a request message.
|
methodDescriptor |
io.grpc.MethodDescriptor<ReqT,RespT>
|
<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 |
String |
|
Overrides
io.grpc.Channel.authority()
awaitTermination(long timeout, TimeUnit unit)
public boolean awaitTermination(long timeout, TimeUnit unit)
Overrides
io.grpc.ManagedChannel.awaitTermination(long,java.util.concurrent.TimeUnit)
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.
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 |
String
affinity key. If it is specified, pick the ChannelRef bound with the affinity key.
Otherwise pick the one with the smallest number of streams.
|
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.
getChannelRefForBind()
protected GcpManagedChannel.ChannelRef getChannelRefForBind()
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.
getMaxActiveStreams()
public int getMaxActiveStreams()
| Returns |
| Type |
Description |
int |
|
getMaxSize()
| Returns |
| Type |
Description |
int |
|
getMinActiveStreams()
public int getMinActiveStreams()
| Returns |
| Type |
Description |
int |
|
getMinSize()
| Returns |
| Type |
Description |
int |
|
getNumberOfChannels()
public int getNumberOfChannels()
| Returns |
| Type |
Description |
int |
|
getState(boolean requestConnection)
public ConnectivityState getState(boolean requestConnection)
Get the current connectivity state of the channel pool.
| Parameter |
| Name |
Description |
requestConnection |
boolean
|
| Returns |
| Type |
Description |
io.grpc.ConnectivityState |
|
Overrides
io.grpc.ManagedChannel.getState(boolean)
getStreamsLowWatermark()
public int getStreamsLowWatermark()
| Returns |
| Type |
Description |
int |
|
isShutdown()
public boolean isShutdown()
Overrides
io.grpc.ManagedChannel.isShutdown()
isTerminated()
public boolean isTerminated()
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 |
Runnable
|
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 |
List<String>
|