Class NettyClientTransport
- java.lang.Object
-
- io.grpc.netty.NettyClientTransport
-
- All Implemented Interfaces:
ClientTransport
,ConnectionClientTransport
,ManagedClientTransport
,InternalInstrumented<InternalChannelz.SocketStats>
,InternalWithLogId
class NettyClientTransport extends java.lang.Object implements ConnectionClientTransport
A Netty-basedConnectionClientTransport
implementation.
-
-
Nested Class Summary
-
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
Fields Modifier and Type Field Description private io.netty.util.AsciiString
authority
private java.lang.String
authorityString
private boolean
autoFlowControl
private io.netty.channel.Channel
channel
private io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel>
channelFactory
private ChannelLogger
channelLogger
private java.util.Map<io.netty.channel.ChannelOption<?>,?>
channelOptions
private Attributes
eagAttributes
private int
flowControlWindow
private io.netty.channel.EventLoopGroup
group
private NettyClientHandler
handler
private KeepAliveManager
keepAliveManager
private long
keepAliveTimeNanos
private long
keepAliveTimeoutNanos
private boolean
keepAliveWithoutCalls
private ClientTransportLifecycleManager
lifecycleManager
Since not thread-safe, may only be used from event loop.private NettyChannelBuilder.LocalSocketPicker
localSocketPicker
private InternalLogId
logId
private int
maxHeaderListSize
private int
maxMessageSize
private io.netty.util.AsciiString
negotiationScheme
private ProtocolNegotiator
negotiator
private java.net.SocketAddress
remoteAddress
private Status
statusExplainingWhyTheChannelIsNull
Ifstart(io.grpc.internal.ManagedClientTransport.Listener)
has been called, non-null
if channel isnull
.private com.google.common.base.Ticker
ticker
private java.lang.Runnable
tooManyPingsRunnable
private TransportTracer
transportTracer
Since not thread-safe, may only be used from event loop.private boolean
useGetForSafeMethods
private io.netty.util.AsciiString
userAgent
-
Constructor Summary
Constructors Constructor Description NettyClientTransport(java.net.SocketAddress address, io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory, java.util.Map<io.netty.channel.ChannelOption<?>,?> channelOptions, io.netty.channel.EventLoopGroup group, ProtocolNegotiator negotiator, boolean autoFlowControl, int flowControlWindow, int maxMessageSize, int maxHeaderListSize, long keepAliveTimeNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls, java.lang.String authority, java.lang.String userAgent, java.lang.Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, NettyChannelBuilder.LocalSocketPicker localSocketPicker, ChannelLogger channelLogger, boolean useGetForSafeMethods, com.google.common.base.Ticker ticker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) io.netty.channel.Channel
channel()
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.com.google.common.util.concurrent.ListenableFuture<InternalChannelz.SocketStats>
getStats()
Returns the stats object.private InternalChannelz.SocketStats
getStatsHelper(io.netty.channel.Channel ch)
(package private) KeepAliveManager
keepAliveManager()
ClientStream
newStream(MethodDescriptor<?,?> method, Metadata headers, CallOptions callOptions, ClientStreamTracer[] tracers)
Creates a new stream for sending messages to a remote end-point.void
ping(ClientTransport.PingCallback callback, java.util.concurrent.Executor executor)
Pings a remote endpoint.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 transportListener)
Starts transport.private Status
statusFromFailedFuture(io.netty.channel.ChannelFuture f)
Convert ChannelFuture.cause() to a Status, taking into account that all handlers are removed from the pipeline when the channel is closed.java.lang.String
toString()
-
-
-
Field Detail
-
logId
private final InternalLogId logId
-
channelOptions
private final java.util.Map<io.netty.channel.ChannelOption<?>,?> channelOptions
-
remoteAddress
private final java.net.SocketAddress remoteAddress
-
channelFactory
private final io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory
-
group
private final io.netty.channel.EventLoopGroup group
-
negotiator
private final ProtocolNegotiator negotiator
-
authorityString
private final java.lang.String authorityString
-
authority
private final io.netty.util.AsciiString authority
-
userAgent
private final io.netty.util.AsciiString userAgent
-
autoFlowControl
private final boolean autoFlowControl
-
flowControlWindow
private final int flowControlWindow
-
maxMessageSize
private final int maxMessageSize
-
maxHeaderListSize
private final int maxHeaderListSize
-
keepAliveManager
private KeepAliveManager keepAliveManager
-
keepAliveTimeNanos
private final long keepAliveTimeNanos
-
keepAliveTimeoutNanos
private final long keepAliveTimeoutNanos
-
keepAliveWithoutCalls
private final boolean keepAliveWithoutCalls
-
negotiationScheme
private final io.netty.util.AsciiString negotiationScheme
-
tooManyPingsRunnable
private final java.lang.Runnable tooManyPingsRunnable
-
handler
private NettyClientHandler handler
-
channel
private io.netty.channel.Channel channel
-
statusExplainingWhyTheChannelIsNull
private Status statusExplainingWhyTheChannelIsNull
Ifstart(io.grpc.internal.ManagedClientTransport.Listener)
has been called, non-null
if channel isnull
.
-
lifecycleManager
private ClientTransportLifecycleManager lifecycleManager
Since not thread-safe, may only be used from event loop.
-
transportTracer
private final TransportTracer transportTracer
Since not thread-safe, may only be used from event loop.
-
eagAttributes
private final Attributes eagAttributes
-
localSocketPicker
private final NettyChannelBuilder.LocalSocketPicker localSocketPicker
-
channelLogger
private final ChannelLogger channelLogger
-
useGetForSafeMethods
private final boolean useGetForSafeMethods
-
ticker
private final com.google.common.base.Ticker ticker
-
-
Constructor Detail
-
NettyClientTransport
NettyClientTransport(java.net.SocketAddress address, io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory, java.util.Map<io.netty.channel.ChannelOption<?>,?> channelOptions, io.netty.channel.EventLoopGroup group, ProtocolNegotiator negotiator, boolean autoFlowControl, int flowControlWindow, int maxMessageSize, int maxHeaderListSize, long keepAliveTimeNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls, java.lang.String authority, @Nullable java.lang.String userAgent, java.lang.Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, NettyChannelBuilder.LocalSocketPicker localSocketPicker, ChannelLogger channelLogger, boolean useGetForSafeMethods, com.google.common.base.Ticker ticker)
-
-
Method Detail
-
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
-
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.
-
start
public java.lang.Runnable start(ManagedClientTransport.Listener transportListener)
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:
transportListener
- non-null
listener of transport events- Returns:
- a
Runnable
that is executed after-the-fact by the original caller, typically after locks are released
-
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
-
shutdownNow
public void shutdownNow(Status reason)
Description copied from interface:ManagedClientTransport
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
-
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
-
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>
-
getStatsHelper
private InternalChannelz.SocketStats getStatsHelper(io.netty.channel.Channel ch)
-
channel
io.netty.channel.Channel channel()
-
keepAliveManager
KeepAliveManager keepAliveManager()
-
statusFromFailedFuture
private Status statusFromFailedFuture(io.netty.channel.ChannelFuture f)
Convert ChannelFuture.cause() to a Status, taking into account that all handlers are removed from the pipeline when the channel is closed. Since handlers are removed, you may get an unhelpful exception like ClosedChannelException.This method must only be called on the event loop.
-
-