Class ManagedChannelImpl

java.lang.Object
io.grpc.Channel
io.grpc.ManagedChannel
io.grpc.internal.ManagedChannelImpl
All Implemented Interfaces:
InternalInstrumented<InternalChannelz.ChannelStats>, InternalWithLogId

@ThreadSafe final class ManagedChannelImpl extends ManagedChannel implements InternalInstrumented<InternalChannelz.ChannelStats>
A communication channel for making outgoing RPCs.
  • Field Details

  • Constructor Details

  • Method Details

    • maybeShutdownNowSubchannels

      private void maybeShutdownNowSubchannels()
    • getStats

      public com.google.common.util.concurrent.ListenableFuture<InternalChannelz.ChannelStats> getStats()
      Description copied from interface: InternalInstrumented
      Returns the stats object.
      Specified by:
      getStats in interface InternalInstrumented<InternalChannelz.ChannelStats>
    • getLogId

      public InternalLogId 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 interface InternalWithLogId
    • 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

      public ManagedChannelImpl shutdown()
      Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.
      Specified by:
      shutdown in class ManagedChannel
      Returns:
      this
    • shutdownNow

      public ManagedChannelImpl 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 return false immediately after this method returns.
      Specified by:
      shutdownNow in class ManagedChannel
      Returns:
      this
    • panic

      void panic(Throwable t)
    • isInPanicMode

      boolean isInPanicMode()
    • updateSubchannelPicker

      private void updateSubchannelPicker(LoadBalancer.SubchannelPicker newPicker)
    • 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 class ManagedChannel
      See Also:
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Description copied from class: ManagedChannel
      Waits for the channel to become terminated, giving up if the timeout is reached.
      Specified by:
      awaitTermination in class ManagedChannel
      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 class ManagedChannel
      See Also:
    • newCall

      public <ReqT, RespT> ClientCall<ReqT,RespT> newCall(MethodDescriptor<ReqT,RespT> method, CallOptions callOptions)
      Description copied from class: Channel
      Create a ClientCall to the remote operation specified by the given MethodDescriptor. The returned ClientCall does not trigger any remote behavior until ClientCall.start(ClientCall.Listener, Metadata) is invoked.
      Specified by:
      newCall in class Channel
      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

      public String authority()
      Description copied from class: Channel
      The authority of the destination this channel connects to. Typically this is in the format host:port.
      Specified by:
      authority in class Channel
    • getCallExecutor

      private Executor getCallExecutor(CallOptions callOptions)
    • maybeTerminateChannel

      private void maybeTerminateChannel()
      Terminate the channel if termination conditions are met.
    • handleInternalSubchannelState

      private void handleInternalSubchannelState(ConnectivityStateInfo newState)
    • getState

      public ConnectivityState getState(boolean requestConnection)
      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 class ManagedChannel
      Parameters:
      requestConnection - if true, the channel will try to make a connection if it is currently IDLE
    • notifyWhenStateChanged

      public void notifyWhenStateChanged(ConnectivityState source, Runnable callback)
      Description copied from class: ManagedChannel
      Registers a one-off callback that will be run if the connectivity state of the channel diverges from the given source, which is typically what has just been returned by ManagedChannel.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 to getState(). There is a similar race between getState() and a call to notifyWhenStateChanged(). 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 class ManagedChannel
      Parameters:
      source - the assumed current state, typically just returned by ManagedChannel.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 invoke NameResolver.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 class ManagedChannel
    • 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 class ManagedChannel
    • toString

      public String toString()
      Overrides:
      toString in class Object