Class InProcessTransport
- java.lang.Object
-
- io.grpc.inprocess.InProcessTransport
-
- All Implemented Interfaces:
ClientTransport
,ConnectionClientTransport
,ManagedClientTransport
,ServerTransport
,InternalInstrumented<InternalChannelz.SocketStats>
,InternalWithLogId
@ThreadSafe final class InProcessTransport extends java.lang.Object implements ServerTransport, ConnectionClientTransport
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
InProcessTransport.InProcessStream
private static class
InProcessTransport.SingleMessageProducer
-
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
-
Constructor Summary
Constructors Constructor Description InProcessTransport(java.net.SocketAddress address, int maxInboundMetadataSize, java.lang.String authority, java.lang.String userAgent, Attributes eagAttrs, boolean includeCauseWithStatus, long assumedMessageSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Status
cleanStatus(Status status, boolean includeCauseWithStatus)
Returns a new status with the same code and description.private ClientStream
failedClientStream(StatsTraceContext statsTraceCtx, Status status)
Attributes
getAttributes()
Returns a set of attributes, which may vary depending on the state of the transport.InternalLogId
getLogId()
Returns an ID that is primarily used in debug logs.java.util.concurrent.ScheduledExecutorService
getScheduledExecutorService()
Returns an executor for scheduling provided by the transport.com.google.common.util.concurrent.ListenableFuture<InternalChannelz.SocketStats>
getStats()
Returns the stats object.private static int
metadataSize(Metadata metadata)
ClientStream
newStream(MethodDescriptor<?,?> method, Metadata headers, CallOptions callOptions, ClientStreamTracer[] tracers)
Creates a new stream for sending messages to a remote end-point.private void
notifyShutdown(Status s)
private void
notifyTerminated()
void
ping(ClientTransport.PingCallback callback, java.util.concurrent.Executor executor)
Pings a remote endpoint.void
shutdown()
Initiates an orderly shutdown of the transport.void
shutdown(Status reason)
Initiates an orderly shutdown of the transport.void
shutdownNow(Status reason)
Initiates a forceful shutdown in which preexisting and new calls are closed.java.lang.Runnable
start(ManagedClientTransport.Listener listener)
Starts transport.java.lang.String
toString()
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
isEnabledSupportTracingMessageSizes
static boolean isEnabledSupportTracingMessageSizes
-
logId
private final InternalLogId logId
-
address
private final java.net.SocketAddress address
-
clientMaxInboundMetadataSize
private final int clientMaxInboundMetadataSize
-
authority
private final java.lang.String authority
-
userAgent
private final java.lang.String userAgent
-
serverMaxInboundMetadataSize
private int serverMaxInboundMetadataSize
-
includeCauseWithStatus
private final boolean includeCauseWithStatus
-
serverSchedulerPool
private ObjectPool<java.util.concurrent.ScheduledExecutorService> serverSchedulerPool
-
serverScheduler
private java.util.concurrent.ScheduledExecutorService serverScheduler
-
serverTransportListener
private ServerTransportListener serverTransportListener
-
serverStreamAttributes
private Attributes serverStreamAttributes
-
clientTransportListener
private ManagedClientTransport.Listener clientTransportListener
-
assumedMessageSize
private final long assumedMessageSize
-
shutdown
private boolean shutdown
-
terminated
private boolean terminated
-
shutdownStatus
private Status shutdownStatus
-
streams
private final java.util.Set<InProcessTransport.InProcessStream> streams
-
serverStreamTracerFactories
private java.util.List<ServerStreamTracer.Factory> serverStreamTracerFactories
-
attributes
private Attributes attributes
-
uncaughtExceptionHandler
private java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler
-
inUseState
private final InUseStateAggregator<InProcessTransport.InProcessStream> inUseState
-
-
Constructor Detail
-
InProcessTransport
public InProcessTransport(java.net.SocketAddress address, int maxInboundMetadataSize, java.lang.String authority, java.lang.String userAgent, Attributes eagAttrs, boolean includeCauseWithStatus, long assumedMessageSize)
-
-
Method Detail
-
start
@CheckReturnValue public java.lang.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 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 ClientStream newStream(MethodDescriptor<?,?> method, Metadata headers, CallOptions callOptions, ClientStreamTracer[] tracers)
Description copied from interface:ClientTransport
Creates a new stream for sending messages to a remote end-point.This method returns immediately and does not wait for any validation of the request. If creation fails for any reason,
ClientStreamListener.closed(io.grpc.Status, io.grpc.internal.ClientStreamListener.RpcProgress, io.grpc.Metadata)
will be called to provide the error information. Any sent messages for this stream will be buffered until creation has completed (either successfully or unsuccessfully).This method is called under the
Context
of theClientCall
.- 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.
-
failedClientStream
private ClientStream failedClientStream(StatsTraceContext statsTraceCtx, Status status)
-
ping
public void ping(ClientTransport.PingCallback callback, java.util.concurrent.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 interfaceClientTransport
-
shutdown
public void shutdown(Status reason)
Description copied from interface:ManagedClientTransport
Initiates an orderly shutdown of the transport. Existing streams continue, but the transport will not own any new streams. New streams will either fail (onceManagedClientTransport.Listener.transportShutdown(io.grpc.Status)
callback called), or be transferred off this transport (in which case they may succeed). This method may only be called once.- Specified by:
shutdown
in interfaceManagedClientTransport
-
shutdown
public void shutdown()
Description copied from interface:ServerTransport
Initiates an orderly shutdown of the transport. Existing streams continue, but new streams will eventually begin failing. New streams "eventually" begin failing because shutdown may need to be processed on a separate thread. May only be called once.- Specified by:
shutdown
in interfaceServerTransport
-
shutdownNow
public void shutdownNow(Status reason)
Description copied from interface:ServerTransport
Initiates a forceful shutdown in which preexisting and new calls are closed. Existing calls should be closed with the providedreason
.- Specified by:
shutdownNow
in interfaceManagedClientTransport
- Specified by:
shutdownNow
in interfaceServerTransport
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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 interfaceInternalWithLogId
-
getAttributes
public Attributes getAttributes()
Description copied from interface:ConnectionClientTransport
Returns a set of attributes, which may vary depending on the state of the transport. The keys should define in what states they will be present.- Specified by:
getAttributes
in interfaceConnectionClientTransport
-
getScheduledExecutorService
public java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Description copied from interface:ServerTransport
Returns an executor for scheduling provided by the transport. The service should be configured to allow cancelled scheduled runnables to be GCed.The executor may not be used after the transport terminates. The caller should ensure any outstanding tasks are cancelled when the transport terminates.
- Specified by:
getScheduledExecutorService
in interfaceServerTransport
-
getStats
public com.google.common.util.concurrent.ListenableFuture<InternalChannelz.SocketStats> getStats()
Description copied from interface:InternalInstrumented
Returns the stats object.- Specified by:
getStats
in interfaceInternalInstrumented<InternalChannelz.SocketStats>
-
notifyShutdown
private void notifyShutdown(Status s)
-
notifyTerminated
private void notifyTerminated()
-
metadataSize
private static int metadataSize(Metadata metadata)
-
cleanStatus
private static Status cleanStatus(Status status, boolean includeCauseWithStatus)
Returns a new status with the same code and description. If includeCauseWithStatus is true, cause is also included.For InProcess transport to behave in the same way as the other transports, when exchanging statuses between client and server and vice versa, the cause should be excluded from the status. For easier debugging, the status may be optionally included.
-
-