Class DelayedClientTransport
- All Implemented Interfaces:
ClientTransport
,ManagedClientTransport
,InternalInstrumented<InternalChannelz.SocketStats>
,InternalWithLogId
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
(package private) static final class
Nested classes/interfaces inherited from interface io.grpc.internal.ClientTransport
ClientTransport.PingCallback
Nested classes/interfaces inherited from interface io.grpc.internal.ManagedClientTransport
ManagedClientTransport.Listener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Executor
private ManagedClientTransport.Listener
private final Object
private final InternalLogId
Immutable state needed for picking.private Runnable
private Runnable
private Runnable
private final SynchronizationContext
-
Constructor Summary
ConstructorsConstructorDescriptionDelayedClientTransport
(Executor defaultAppExecutor, SynchronizationContext syncContext) Creates a new delayed transport. -
Method Summary
Modifier and TypeMethodDescriptioncreatePendingStream
(LoadBalancer.PickSubchannelArgs args, ClientStreamTracer[] tracers) Caller must callsyncContext.drain()
outside of lock because this method may schedule tasks on syncContext.getLogId()
Returns an ID that is primarily used in debug logs.(package private) final int
com.google.common.util.concurrent.ListenableFuture
<InternalChannelz.SocketStats> getStats()
Returns the stats object.final boolean
final ClientStream
newStream
(MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions, ClientStreamTracer[] tracers) If aLoadBalancer.SubchannelPicker
is being, or has been provided viareprocess(io.grpc.LoadBalancer.SubchannelPicker)
, the last picker will be consulted.final void
ping
(ClientTransport.PingCallback callback, Executor executor) Pings a remote endpoint.(package private) final void
Use the picker to try picking a transport for every pending stream, proceed the stream if the pick is successful, otherwise keep it pending.final void
Prevents creating any new streams.final void
shutdownNow
(Status status) Shuts down this transport and cancels all streams that it owns, hence immediately terminates this transport.final Runnable
start
(ManagedClientTransport.Listener listener) Starts transport.
-
Field Details
-
logId
-
lock
-
defaultAppExecutor
-
syncContext
-
reportTransportInUse
-
reportTransportNotInUse
-
reportTransportTerminated
-
listener
-
pendingStreams
-
pickerState
Immutable state needed for picking. 'lock' must be held for writing.
-
-
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 inCallOptions
.syncContext
- all listener callbacks of the delayed transport will be run from this SynchronizationContext.
-
-
Method Details
-
start
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 interfaceManagedClientTransport
- 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 aLoadBalancer.SubchannelPicker
is being, or has been provided viareprocess(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 aFailingClientStream
is returned.- Specified by:
newStream
in interfaceClientTransport
- Parameters:
method
- the descriptor of the remote method to be called for this stream.headers
- to send at the beginning of the callcallOptions
- runtime options of the calltracers
- 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
private DelayedClientTransport.PendingStream createPendingStream(LoadBalancer.PickSubchannelArgs args, ClientStreamTracer[] tracers) Caller must callsyncContext.drain()
outside of lock because this method may schedule tasks on syncContext. -
ping
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 interfaceClientTransport
-
getStats
Description copied from interface:InternalInstrumented
Returns the stats object.- Specified by:
getStats
in interfaceInternalInstrumented<InternalChannelz.SocketStats>
-
shutdown
Prevents creating any new streams. Buffered streams are not failed and may still proceed whenreprocess(io.grpc.LoadBalancer.SubchannelPicker)
is called. The delayed transport will be terminated when there is no more buffered streams.- Specified by:
shutdown
in interfaceManagedClientTransport
-
shutdownNow
Shuts down this transport and cancels all streams that it owns, hence immediately terminates this transport.- Specified by:
shutdownNow
in interfaceManagedClientTransport
-
hasPendingStreams
public final boolean hasPendingStreams() -
getPendingStreamsCount
final int getPendingStreamsCount() -
reprocess
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
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
-