Package com.google.cloud.grpc
Class GcpManagedChannel
java.lang.Object
io.grpc.Channel
io.grpc.ManagedChannel
com.google.cloud.grpc.GcpManagedChannel
public class GcpManagedChannel
extends io.grpc.ManagedChannel
A channel management factory that implements grpc.Channel APIs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA wrapper of real grpc channel, it provides helper functions to calculate affinity counts and active streams count. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final io.grpc.Context.Key<String>static final io.grpc.CallOptions.Key<String>static final io.grpc.CallOptions.Key<Integer>CallOptions key that will be set by grpc-gcp with the actual channel ID used for the call.static final io.grpc.Context.Key<Boolean>static final io.grpc.CallOptions.Key<Boolean> -
Constructor Summary
ConstructorsConstructorDescriptionGcpManagedChannel(io.grpc.ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, int poolSize, GcpManagedChannelOptions options) Deprecated.GcpManagedChannel(io.grpc.ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, GcpManagedChannelOptions options) Constructor for GcpManagedChannel. -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) protected voidbind(GcpManagedChannel.ChannelRef channelRef, List<String> affinityKeys) Bind channel with affinity key.Fetch the affinity key from the message.protected GcpManagedChannel.ChannelRefgetChannelRef(String key) Pick aGcpManagedChannel.ChannelRef(and create a new one if necessary).protected GcpManagedChannel.ChannelRefReturns aGcpManagedChannel.ChannelReffrom the pool for a binding call.protected GcpManagedChannel.ChannelRefReturns aGcpManagedChannel.ChannelReffrom the pool in round-robin manner.intintintintintio.grpc.ConnectivityStategetState(boolean requestConnection) Get the current connectivity state of the channel pool.intbooleanboolean<ReqT,RespT>
io.grpc.ClientCall<ReqT,RespT> newCall(io.grpc.MethodDescriptor<ReqT, RespT> methodDescriptor, io.grpc.CallOptions callOptions) Manage the channelpool using GcpClientCall().voidnotifyWhenStateChanged(io.grpc.ConnectivityState source, Runnable callback) io.grpc.ManagedChannelshutdown()io.grpc.ManagedChannelprotected voidUnbind channel with affinity key.Methods inherited from class io.grpc.ManagedChannel
enterIdle, resetConnectBackoff
-
Field Details
-
DISABLE_AFFINITY_CTX_KEY
-
DISABLE_AFFINITY_KEY
-
AFFINITY_CTX_KEY
-
AFFINITY_KEY
-
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.
-
-
Constructor Details
-
GcpManagedChannel
public GcpManagedChannel(io.grpc.ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, GcpManagedChannelOptions options) Constructor for GcpManagedChannel.- Parameters:
delegateChannelBuilder- the underlying delegate ManagedChannelBuilder.apiConfig- the ApiConfig object for configuring GcpManagedChannel.options- the options for GcpManagedChannel.
-
GcpManagedChannel
@Deprecated public GcpManagedChannel(io.grpc.ManagedChannelBuilder<?> delegateChannelBuilder, ApiConfig apiConfig, int poolSize, GcpManagedChannelOptions options) Deprecated.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:
delegateChannelBuilder- the underlying delegate ManagedChannelBuilder.apiConfig- the ApiConfig object for configuring GcpManagedChannel.poolSize- maximum number of channels the pool can have.options- the options for GcpManagedChannel.
-
-
Method Details
-
notifyWhenStateChanged
- Overrides:
notifyWhenStateChangedin classio.grpc.ManagedChannel
-
getMaxSize
public int getMaxSize() -
getMinSize
public int getMinSize() -
getNumberOfChannels
public int getNumberOfChannels() -
getStreamsLowWatermark
public int getStreamsLowWatermark() -
getMinActiveStreams
public int getMinActiveStreams() -
getMaxActiveStreams
public int getMaxActiveStreams() -
getChannelRefForBind
Returns aGcpManagedChannel.ChannelReffrom the pool for a binding call. If round-robin on bind is enabled, usesgetChannelRefRoundRobin()otherwisegetChannelRef(String)- Returns:
GcpManagedChannel.ChannelRefchannel to use for a call.
-
getChannelRefRoundRobin
Returns aGcpManagedChannel.ChannelReffrom the pool in round-robin manner. Creates a new channel in the pool until the pool reaches its max size.- Returns:
GcpManagedChannel.ChannelRef
-
getChannelRef
Pick aGcpManagedChannel.ChannelRef(and create a new one if necessary). If notReadyFallbackEnabled is true in theGcpManagedChannelOptions.GcpResiliencyOptionsthen 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.- Parameters:
key- affinity key. If it is specified, pick the ChannelRef bound with the affinity key. Otherwise pick the one with the smallest number of streams.
-
authority
- Specified by:
authorityin classio.grpc.Channel
-
newCall
public <ReqT,RespT> io.grpc.ClientCall<ReqT,RespT> newCall(io.grpc.MethodDescriptor<ReqT, RespT> methodDescriptor, io.grpc.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.
- Specified by:
newCallin classio.grpc.Channel
-
shutdownNow
public io.grpc.ManagedChannel shutdownNow()- Specified by:
shutdownNowin classio.grpc.ManagedChannel
-
shutdown
public io.grpc.ManagedChannel shutdown()- Specified by:
shutdownin classio.grpc.ManagedChannel
-
awaitTermination
- Specified by:
awaitTerminationin classio.grpc.ManagedChannel- Throws:
InterruptedException
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin classio.grpc.ManagedChannel
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin classio.grpc.ManagedChannel
-
getState
public io.grpc.ConnectivityState getState(boolean requestConnection) Get the current connectivity state of the channel pool.- Overrides:
getStatein classio.grpc.ManagedChannel
-
bind
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.
-
unbind
Unbind channel with affinity key. -
checkKeys
@Nullable protected <ReqT,RespT> List<String> checkKeys(Object message, boolean isReq, io.grpc.MethodDescriptor<ReqT, RespT> methodDescriptor) Fetch the affinity key from the message.- Parameters:
message- the <ReqT> or <RespT> prototype message.isReq- indicates if the message is a request message.
-