Class ManagedChannelImpl
- All Implemented Interfaces:
InternalInstrumented<InternalChannelz.ChannelStats>
,InternalWithLogId
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
(package private) static final class
A client call for a given channel that applies a given config selector when it starts.private final class
Called from syncContext.(package private) static final class
Lazily request for Executor from an executor pool.private final class
Must be accessed from syncContext.private class
private final class
(package private) final class
private class
(package private) static enum
A ResolutionState indicates the status of last name resolution.private static final class
private final class
private final class
A registry that prevents channel shutdown from killing existing retry attempts that are in backoff. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
private final BackoffPolicy.Provider
private final ManagedChannelImpl.ExecutorHolder
private final ObjectPool
<? extends Executor> private final CallTracer.Factory
private final long
private final RetriableStream.ChannelBufferMeter
private final CallTracer
private final ChannelLogger
private final ConnectivityStateManager
private final ChannelTracer
private final InternalChannelz
private final CompressorRegistry
private final DecompressorRegistry
private final ManagedChannelServiceConfig
private final DelayedClientTransport
private final ManagedClientTransport.Listener
private static final ManagedChannelServiceConfig
private final Executor
private final ObjectPool
<? extends Executor> private boolean
(package private) static final long
private final long
The timeout before entering idle mode.private final Rescheduler
private static final InternalConfigSelector
private final Channel
We delegate to this channel, so that we can have interceptors as necessary.(package private) final InUseStateAggregator
<Object> private ManagedChannelServiceConfig
private ManagedChannelImpl.LbHelperImpl
private final AutoConfiguredLoadBalancerFactory
(package private) static final Logger
private final InternalLogId
private final boolean
private final int
private final MetricRecorder
private NameResolver
private final NameResolver.Args
private final NameResolverProvider
private final NameResolverRegistry
private boolean
private static final ClientCall
<Object, Object> private static final LoadBalancer.PickDetailsConsumer
private final ManagedChannelImpl.ExecutorHolder
private final Set
<OobChannel> private final ClientTransportFactory
private final ChannelCredentials
private final ClientTransportFactory
private boolean
private Collection
<ManagedChannelImpl.RealChannel.PendingCall<?, ?>> private final Object
private final long
private final ManagedChannelImpl.RealChannel
private final boolean
private final ManagedChannelImpl.RestrictedScheduledExecutor
private boolean
private final AtomicBoolean
(package private) static final Status
(package private) static final Status
private boolean
private final com.google.common.base.Supplier
<com.google.common.base.Stopwatch> (package private) static final long
(package private) static final Status
private LoadBalancer.SubchannelPicker
private final Set
<InternalSubchannel> (package private) final SynchronizationContext
private final String
private final URI
private boolean
private final CountDownLatch
private boolean
private final Deadline.Ticker
private final TimeProvider
private final ClientTransportFactory
private final List
<ClientTransportFilter> private final ManagedChannelImpl.ChannelStreamProvider
private final ManagedChannelImpl.UncommittedRetriableStreamsRegistry
private 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.boolean
awaitTermination
(long timeout, TimeUnit unit) Waits for the channel to become terminated, giving up if the timeout is reached.private void
cancelIdleTimer
(boolean permanent) void
Invoking 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) void
Make the channel exit idle mode, if it's in it.private Executor
getCallExecutor
(CallOptions callOptions) (package private) InternalConfigSelector
getLogId()
Returns an ID that is primarily used in debug logs.(package private) static NameResolver
getNameResolver
(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) boolean
boolean
Returns whether the channel is shutdown.boolean
Returns whether the channel is terminated.private void
private void
Terminate the channel if termination conditions are met.<ReqT,
RespT>
ClientCall<ReqT, RespT> newCall
(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) Create aClientCall
to the remote operation specified by the givenMethodDescriptor
.void
notifyWhenStateChanged
(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) void
private void
Force name resolution refresh to happen immediately.private void
void
For 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 void
shutdownNameResolverAndLoadBalancer
(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 theBinaryLog
isnull
then 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:InternalInstrumented
Returns the stats object.- Specified by:
getStats
in interfaceInternalInstrumented<InternalChannelz.ChannelStats>
-
getLogId
Description copied from interface:InternalWithLogId
Returns 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:
getLogId
in 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:
shutdown
in 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 returnfalse
immediately after this method returns.- Specified by:
shutdownNow
in classManagedChannel
- Returns:
- this
-
panic
-
isInPanicMode
boolean isInPanicMode() -
updateSubchannelPicker
-
isShutdown
public boolean isShutdown()Description copied from class:ManagedChannel
Returns whether the channel is shutdown. Shutdown channels immediately cancel any new calls, but may still have some calls being processed.- Specified by:
isShutdown
in classManagedChannel
- See Also:
-
awaitTermination
Description copied from class:ManagedChannel
Waits for the channel to become terminated, giving up if the timeout is reached.- Specified by:
awaitTermination
in classManagedChannel
- Returns:
- whether the channel is terminated, as would be done by
ManagedChannel.isTerminated()
. - Throws:
InterruptedException
-
isTerminated
public boolean isTerminated()Description copied from class:ManagedChannel
Returns whether the channel is terminated. Terminated channels have no running calls and relevant resources released (like TCP connections).- Specified by:
isTerminated
in classManagedChannel
- See Also:
-
newCall
public <ReqT,RespT> ClientCall<ReqT,RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) Description copied from class:Channel
Create aClientCall
to the remote operation specified by the givenMethodDescriptor
. The returnedClientCall
does not trigger any remote behavior untilClientCall.start(ClientCall.Listener, Metadata)
is invoked.- Specified by:
newCall
in 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
ClientCall
bound to the specified method.
-
authority
Description copied from class:Channel
The authority of the destination this channel connects to. Typically this is in the formathost:port
. -
getCallExecutor
-
maybeTerminateChannel
private void maybeTerminateChannel()Terminate the channel if termination conditions are met. -
handleInternalSubchannelState
-
getState
Description copied from class:ManagedChannel
Gets 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:
getState
in classManagedChannel
- Parameters:
requestConnection
- iftrue
, the channel will try to make a connection if it is currently IDLE
-
notifyWhenStateChanged
Description copied from class:ManagedChannel
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)
. 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
callback
and 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:
notifyWhenStateChanged
in 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:ManagedChannel
For 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:
resetConnectBackoff
in classManagedChannel
-
enterIdle
public void enterIdle()Description copied from class:ManagedChannel
Invoking 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:
enterIdle
in classManagedChannel
-
toString
-