Class ManagedChannelImpl
- All Implemented Interfaces:
InternalInstrumented<InternalChannelz.ChannelStats>, InternalWithLogId
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class(package private) static final classA client call for a given channel that applies a given config selector when it starts.private final classCalled from syncContext.(package private) static final classLazily request for Executor from an executor pool.private final classMust be accessed from syncContext.private classprivate final class(package private) final classprivate class(package private) static enumA ResolutionState indicates the status of last name resolution.private static final classprivate final classprivate final classA registry that prevents channel shutdown from killing existing retry attempts that are in backoff. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate final BackoffPolicy.Providerprivate final ManagedChannelImpl.ExecutorHolderprivate final ObjectPool<? extends Executor> private final CallTracer.Factoryprivate final longprivate final RetriableStream.ChannelBufferMeterprivate final CallTracerprivate final ChannelLoggerprivate final ConnectivityStateManagerprivate final ChannelTracerprivate final InternalChannelzprivate final CompressorRegistryprivate final DecompressorRegistryprivate final ManagedChannelServiceConfigprivate final DelayedClientTransportprivate final ManagedClientTransport.Listenerprivate static final ManagedChannelServiceConfigprivate final Executorprivate final ObjectPool<? extends Executor> private boolean(package private) static final longprivate final longThe timeout before entering idle mode.private final Reschedulerprivate static final InternalConfigSelectorprivate final ChannelWe delegate to this channel, so that we can have interceptors as necessary.(package private) final InUseStateAggregator<Object> private ManagedChannelServiceConfigprivate ManagedChannelImpl.LbHelperImplprivate final AutoConfiguredLoadBalancerFactory(package private) static final Loggerprivate final InternalLogIdprivate final booleanprivate final intprivate final MetricRecorderprivate NameResolverprivate final NameResolver.Argsprivate final NameResolverProviderprivate final NameResolverRegistryprivate booleanprivate static final ClientCall<Object, Object> private static final LoadBalancer.PickDetailsConsumerprivate final ManagedChannelImpl.ExecutorHolderprivate final Set<OobChannel> private final ClientTransportFactoryprivate final ChannelCredentialsprivate final ClientTransportFactoryprivate booleanprivate Collection<ManagedChannelImpl.RealChannel.PendingCall<?, ?>> private final Objectprivate final longprivate final ManagedChannelImpl.RealChannelprivate final booleanprivate final ManagedChannelImpl.RestrictedScheduledExecutorprivate booleanprivate final AtomicBoolean(package private) static final Status(package private) static final Statusprivate booleanprivate final com.google.common.base.Supplier<com.google.common.base.Stopwatch> (package private) static final long(package private) static final Statusprivate LoadBalancer.SubchannelPickerprivate final Set<InternalSubchannel> (package private) final SynchronizationContextprivate final Stringprivate final URIprivate booleanprivate final CountDownLatchprivate booleanprivate final Deadline.Tickerprivate final TimeProviderprivate final ClientTransportFactoryprivate final List<ClientTransportFilter> private final ManagedChannelImpl.ChannelStreamProviderprivate final ManagedChannelImpl.UncommittedRetriableStreamsRegistryprivate final String -
Constructor Summary
ConstructorsConstructorDescriptionManagedChannelImpl(ManagedChannelImplBuilder builder, ClientTransportFactory clientTransportFactory, URI targetUri, NameResolverProvider nameResolverProvider, BackoffPolicy.Provider backoffPolicyProvider, ObjectPool<? extends Executor> balancerRpcExecutorPool, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, List<ClientInterceptor> interceptors, TimeProvider timeProvider) -
Method Summary
Modifier and TypeMethodDescriptionThe authority of the destination this channel connects to.booleanawaitTermination(long timeout, TimeUnit unit) Waits for the channel to become terminated, giving up if the timeout is reached.private voidcancelIdleTimer(boolean permanent) voidInvoking this method moves the channel into the IDLE state and triggers tear-down of the channel's name resolver and load balancer, while still allowing on-going RPCs on the channel to continue.private void(package private) voidMake the channel exit idle mode, if it's in it.private ExecutorgetCallExecutor(CallOptions callOptions) (package private) InternalConfigSelectorgetLogId()Returns an ID that is primarily used in debug logs.(package private) static NameResolvergetNameResolver(URI targetUri, String overrideAuthority, NameResolverProvider provider, NameResolver.Args nameResolverArgs) getState(boolean requestConnection) Gets the current connectivity state.com.google.common.util.concurrent.ListenableFuture<InternalChannelz.ChannelStats> getStats()Returns the stats object.private void(package private) boolean(package private) booleanbooleanReturns whether the channel is shutdown.booleanReturns whether the channel is terminated.private voidprivate voidTerminate the channel if termination conditions are met.<ReqT,RespT>
ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) Create aClientCallto the remote operation specified by the givenMethodDescriptor.voidnotifyWhenStateChanged(ConnectivityState source, Runnable callback) Registers a one-off callback that will be run if the connectivity state of the channel diverges from the givensource, which is typically what has just been returned byManagedChannel.getState(boolean).(package private) voidprivate voidForce name resolution refresh to happen immediately.private voidvoidFor subchannels that are in TRANSIENT_FAILURE state, short-circuit the backoff timer and make them reconnect immediately.shutdown()Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.private voidshutdownNameResolverAndLoadBalancer(boolean channelIsActive) Initiates a forceful shutdown in which preexisting and new calls are cancelled.toString()private void
-
Field Details
-
logger
-
IDLE_TIMEOUT_MILLIS_DISABLE
static final long IDLE_TIMEOUT_MILLIS_DISABLE- See Also:
-
SUBCHANNEL_SHUTDOWN_DELAY_SECONDS
static final long SUBCHANNEL_SHUTDOWN_DELAY_SECONDS- See Also:
-
SHUTDOWN_NOW_STATUS
-
SHUTDOWN_STATUS
-
SUBCHANNEL_SHUTDOWN_STATUS
-
EMPTY_SERVICE_CONFIG
-
INITIAL_PENDING_SELECTOR
-
NOOP_PICK_DETAILS_CONSUMER
-
logId
-
target
-
authorityOverride
-
nameResolverRegistry
-
targetUri
-
nameResolverProvider
-
nameResolverArgs
-
loadBalancerFactory
-
originalTransportFactory
-
originalChannelCreds
-
transportFactory
-
oobTransportFactory
-
scheduledExecutor
-
executor
-
executorPool
-
balancerRpcExecutorPool
-
balancerRpcExecutorHolder
-
offloadExecutorHolder
-
timeProvider
-
maxTraceEvents
private final int maxTraceEvents -
syncContext
-
fullStreamDecompression
private boolean fullStreamDecompression -
decompressorRegistry
-
compressorRegistry
-
stopwatchSupplier
private final com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier -
idleTimeoutMillis
private final long idleTimeoutMillisThe timeout before entering idle mode. -
channelStateManager
-
backoffPolicyProvider
-
interceptorChannel
We delegate to this channel, so that we can have interceptors as necessary. If there aren't any interceptors and theBinaryLogisnullthen this will just be aManagedChannelImpl.RealChannel. -
transportFilters
-
userAgent
-
nameResolver
-
nameResolverStarted
private boolean nameResolverStarted -
lbHelper
-
subchannelPicker
-
panicMode
private boolean panicMode -
subchannels
-
pendingCalls
-
pendingCallsInUseObject
-
oobChannels
-
delayedTransport
-
uncommittedRetriableStreamsRegistry
private final ManagedChannelImpl.UncommittedRetriableStreamsRegistry uncommittedRetriableStreamsRegistry -
shutdown
-
shutdownNowed
private boolean shutdownNowed -
terminating
private boolean terminating -
terminated
private volatile boolean terminated -
terminatedLatch
-
callTracerFactory
-
channelCallTracer
-
channelTracer
-
channelLogger
-
channelz
-
realChannel
-
lastResolutionState
-
lastServiceConfig
-
defaultServiceConfig
-
serviceConfigUpdated
private boolean serviceConfigUpdated -
lookUpServiceConfig
private final boolean lookUpServiceConfig -
channelBufferUsed
-
perRpcBufferLimit
private final long perRpcBufferLimit -
channelBufferLimit
private final long channelBufferLimit -
retryEnabled
private final boolean retryEnabled -
ticker
-
delayedTransportListener
-
inUseStateAggregator
-
transportProvider
-
idleTimer
-
metricRecorder
-
NOOP_CALL
-
-
Constructor Details
-
ManagedChannelImpl
ManagedChannelImpl(ManagedChannelImplBuilder builder, ClientTransportFactory clientTransportFactory, URI targetUri, NameResolverProvider nameResolverProvider, BackoffPolicy.Provider backoffPolicyProvider, ObjectPool<? extends Executor> balancerRpcExecutorPool, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, List<ClientInterceptor> interceptors, TimeProvider timeProvider)
-
-
Method Details
-
maybeShutdownNowSubchannels
private void maybeShutdownNowSubchannels() -
getStats
Description copied from interface:InternalInstrumentedReturns the stats object.- Specified by:
getStatsin interfaceInternalInstrumented<InternalChannelz.ChannelStats>
-
getLogId
Description copied from interface:InternalWithLogIdReturns an ID that is primarily used in debug logs. It usually contains the class name and a numeric ID that is unique among the instances.The subclasses of this interface usually want to include the log ID in their
Object.toString()results.- Specified by:
getLogIdin interfaceInternalWithLogId
-
shutdownNameResolverAndLoadBalancer
private void shutdownNameResolverAndLoadBalancer(boolean channelIsActive) -
exitIdleMode
void exitIdleMode()Make the channel exit idle mode, if it's in it.Must be called from syncContext
-
enterIdleMode
private void enterIdleMode() -
cancelIdleTimer
private void cancelIdleTimer(boolean permanent) -
rescheduleIdleTimer
private void rescheduleIdleTimer() -
refreshNameResolution
private void refreshNameResolution()Force name resolution refresh to happen immediately. Must be run from syncContext. -
getNameResolver
static NameResolver getNameResolver(URI targetUri, @Nullable String overrideAuthority, NameResolverProvider provider, NameResolver.Args nameResolverArgs) -
getConfigSelector
InternalConfigSelector getConfigSelector() -
hasThrottle
boolean hasThrottle() -
shutdown
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.- Specified by:
shutdownin classManagedChannel- Returns:
- this
-
shutdownNow
Initiates a forceful shutdown in which preexisting and new calls are cancelled. Although forceful, the shutdown process is still not instantaneous;isTerminated()will likely returnfalseimmediately after this method returns.- Specified by:
shutdownNowin classManagedChannel- Returns:
- this
-
panic
-
isInPanicMode
boolean isInPanicMode() -
updateSubchannelPicker
-
isShutdown
public boolean isShutdown()Description copied from class:ManagedChannelReturns whether the channel is shutdown. Shutdown channels immediately cancel any new calls, but may still have some calls being processed.- Specified by:
isShutdownin classManagedChannel- See Also:
-
awaitTermination
Description copied from class:ManagedChannelWaits for the channel to become terminated, giving up if the timeout is reached.- Specified by:
awaitTerminationin classManagedChannel- Returns:
- whether the channel is terminated, as would be done by
ManagedChannel.isTerminated(). - Throws:
InterruptedException
-
isTerminated
public boolean isTerminated()Description copied from class:ManagedChannelReturns whether the channel is terminated. Terminated channels have no running calls and relevant resources released (like TCP connections).- Specified by:
isTerminatedin classManagedChannel- See Also:
-
newCall
public <ReqT,RespT> ClientCall<ReqT,RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) Description copied from class:ChannelCreate aClientCallto the remote operation specified by the givenMethodDescriptor. The returnedClientCalldoes not trigger any remote behavior untilClientCall.start(ClientCall.Listener, Metadata)is invoked.- Specified by:
newCallin classChannel- Parameters:
method- describes the name and parameter types of the operation to call.callOptions- runtime options to be applied to this call.- Returns:
- a
ClientCallbound to the specified method.
-
authority
-
getCallExecutor
-
maybeTerminateChannel
private void maybeTerminateChannel()Terminate the channel if termination conditions are met. -
handleInternalSubchannelState
-
getState
Description copied from class:ManagedChannelGets the current connectivity state. Note the result may soon become outdated.Note that the core library did not provide an implementation of this method until v1.6.1.
- Overrides:
getStatein classManagedChannel- Parameters:
requestConnection- iftrue, the channel will try to make a connection if it is currently IDLE
-
notifyWhenStateChanged
Description copied from class:ManagedChannelRegisters a one-off callback that will be run if the connectivity state of the channel diverges from the givensource, which is typically what has just been returned byManagedChannel.getState(boolean). If the states are already different, the callback will be called immediately. The callback is run in the same executor that runs Call listeners.There is an inherent race between the notification to
callbackand any call togetState(). There is a similar race betweengetState()and a call tonotifyWhenStateChanged(). The state can change during those races, so there is not a way to see every state transition. "Transitions" to the same state are possible, because intermediate states may not have been observed. The API is only reliable in tracking the current state.Note that the core library did not provide an implementation of this method until v1.6.1.
- Overrides:
notifyWhenStateChangedin classManagedChannel- Parameters:
source- the assumed current state, typically just returned byManagedChannel.getState(boolean)callback- the one-off callback
-
resetConnectBackoff
public void resetConnectBackoff()Description copied from class:ManagedChannelFor subchannels that are in TRANSIENT_FAILURE state, short-circuit the backoff timer and make them reconnect immediately. May also attempt to invokeNameResolver.refresh().This is primarily intended for Android users, where the network may experience frequent temporary drops. Rather than waiting for gRPC's name resolution and reconnect timers to elapse before reconnecting, the app may use this method as a mechanism to notify gRPC that the network is now available and a reconnection attempt may occur immediately.
No-op if not supported by the implementation.
- Overrides:
resetConnectBackoffin classManagedChannel
-
enterIdle
public void enterIdle()Description copied from class:ManagedChannelInvoking this method moves the channel into the IDLE state and triggers tear-down of the channel's name resolver and load balancer, while still allowing on-going RPCs on the channel to continue. New RPCs on the channel will trigger creation of a new connection.This is primarily intended for Android users when a device is transitioning from a cellular to a wifi connection. The OS will issue a notification that a new network (wifi) has been made the default, but for approximately 30 seconds the device will maintain both the cellular and wifi connections. Apps may invoke this method to ensure that new RPCs are created using the new default wifi network, rather than the soon-to-be-disconnected cellular network.
No-op if not supported by implementation.
- Overrides:
enterIdlein classManagedChannel
-
toString
-