Class DelayedClientTransport

java.lang.Object
io.grpc.internal.DelayedClientTransport
All Implemented Interfaces:
ClientTransport, ManagedClientTransport, InternalInstrumented<InternalChannelz.SocketStats>, InternalWithLogId

final class DelayedClientTransport extends Object implements ManagedClientTransport
A client transport that queues requests before a real transport is available. When reprocess(io.grpc.LoadBalancer.SubchannelPicker) is called, this class applies the provided LoadBalancer.SubchannelPicker to pick a transport for each pending stream.

This transport owns every stream that it has created until a real transport has been picked for that stream, at which point the ownership of the stream is transferred to the real transport, thus the delayed transport stops owning the stream.

  • Field Details

  • Constructor Details

    • DelayedClientTransport

      DelayedClientTransport(Executor defaultAppExecutor, SynchronizationContext syncContext)
      Creates a new delayed transport.
      Parameters:
      defaultAppExecutor - pending streams will create real streams and run buffered operations in an application executor, which will be this executor, unless there is on provided in CallOptions.
      syncContext - all listener callbacks of the delayed transport will be run from this SynchronizationContext.
  • Method Details

    • start

      public final Runnable start(ManagedClientTransport.Listener listener)
      Description copied from interface: ManagedClientTransport
      Starts transport. This method may only be called once.

      This method and the returned Runnable should not throw any exceptions.

      Specified by:
      start in interface ManagedClientTransport
      Parameters:
      listener - non-null listener of transport events
      Returns:
      a Runnable that is executed after-the-fact by the original caller, typically after locks are released
    • newStream

      public final ClientStream newStream(MethodDescriptor<?,?> method, Metadata headers, CallOptions callOptions, ClientStreamTracer[] tracers)
      If a LoadBalancer.SubchannelPicker is being, or has been provided via reprocess(io.grpc.LoadBalancer.SubchannelPicker), the last picker will be consulted.

      Otherwise, if the delayed transport is not shutdown, then a DelayedClientTransport.PendingStream is returned; if the transport is shutdown, then a FailingClientStream is returned.

      Specified by:
      newStream in interface ClientTransport
      Parameters:
      method - the descriptor of the remote method to be called for this stream.
      headers - to send at the beginning of the call
      callOptions - runtime options of the call
      tracers - a non-empty array of tracers. The last element in it is reserved to be set by the load balancer's pick result and otherwise is a no-op tracer.
      Returns:
      the newly created stream.
    • createPendingStream

      Caller must call syncContext.drain() outside of lock because this method may schedule tasks on syncContext.
    • ping

      public final void ping(ClientTransport.PingCallback callback, Executor executor)
      Description copied from interface: ClientTransport
      Pings a remote endpoint. When an acknowledgement is received, the given callback will be invoked using the given executor.

      Pings are not necessarily sent to the same endpoint, thus a successful ping only means at least one endpoint responded, but doesn't imply the availability of other endpoints (if there is any).

      This is an optional method. Transports that do not have any mechanism by which to ping the remote endpoint may throw UnsupportedOperationException.

      Specified by:
      ping in interface ClientTransport
    • getStats

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

      public final void shutdown(Status status)
      Prevents creating any new streams. Buffered streams are not failed and may still proceed when reprocess(io.grpc.LoadBalancer.SubchannelPicker) is called. The delayed transport will be terminated when there is no more buffered streams.
      Specified by:
      shutdown in interface ManagedClientTransport
    • shutdownNow

      public final void shutdownNow(Status status)
      Shuts down this transport and cancels all streams that it owns, hence immediately terminates this transport.
      Specified by:
      shutdownNow in interface ManagedClientTransport
    • hasPendingStreams

      public final boolean hasPendingStreams()
    • getPendingStreamsCount

      final int getPendingStreamsCount()
    • reprocess

      final void reprocess(@Nullable LoadBalancer.SubchannelPicker picker)
      Use the picker to try picking a transport for every pending stream, proceed the stream if the pick is successful, otherwise keep it pending.

      This method may be called concurrently with newStream(), and it's safe. All pending streams will be served by the latest picker (if a same picker is given more than once, they are considered different pickers) as soon as possible.

      This method must not be called concurrently with itself.

    • 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