Class NettyPipelinedConnection<Req,Resp>
- Type Parameters:
Req
- Type of requests sent on this connection.Resp
- Type of responses read from this connection.
- All Implemented Interfaces:
AsyncCloseable
,ListenableAsyncCloseable
,ConnectionContext
,ConnectionInfo
,NettyConnectionContext
NettyConnection
to make pipelined requests, typically for a client.
Pipelining allows to have concurrent requests processed on the server but still deliver responses in order. This eliminates the need for request-response correlation, at the cost of head-of-line blocking.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.servicetalk.transport.api.ConnectionInfo
ConnectionInfo.Protocol
Nested classes/interfaces inherited from interface io.servicetalk.transport.netty.internal.NettyConnectionContext
NettyConnectionContext.FlushStrategyProvider
-
Constructor Summary
ConstructorDescriptionNettyPipelinedConnection
(NettyConnection<Resp, Req> connection, int maxPipelinedRequests) New instance. -
Method Summary
Modifier and TypeMethodDescriptionUsed to close/shutdown a resource.Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync()
, but attempts to cleanup state before abruptly closing.Returns theFlushStrategy
used by default for thisNettyConnectionContext
.Get theExecutionContext
for thisConnectionInfo
.TheSocketAddress
to which the associated connection is bound.io.netty.channel.Channel
Return the NettyChannel
backing this connection.onClose()
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.Returns aCompletable
that is notified when closing begins.parent()
Returns a reference to a parentConnectionContext
if any.protocol()
Get theConnectionInfo.Protocol
for thisConnectionInfo
.TheSocketAddress
to which the associated connection is connected.<T> T
socketOption
(SocketOption<T> option) Get theSslConfig
for this connection.Get theSSLSession
for this connection.toString()
updateFlushStrategy
(NettyConnectionContext.FlushStrategyProvider strategyProvider) UpdatesFlushStrategy
associated with this connection.Do a write operation in a pipelined fashion.write
(Publisher<Req> requestPublisher, Supplier<FlushStrategy> flushStrategySupplier, Supplier<WriteDemandEstimator> writeDemandEstimatorSupplier) Do a write operation in a pipelined fashion.
-
Constructor Details
-
NettyPipelinedConnection
New instance.- Parameters:
connection
-NettyConnection
requests to which are to be pipelined.maxPipelinedRequests
- The maximum number of pipelined requests.
-
-
Method Details
-
write
Do a write operation in a pipelined fashion. -
write
public Publisher<Resp> write(Publisher<Req> requestPublisher, Supplier<FlushStrategy> flushStrategySupplier, Supplier<WriteDemandEstimator> writeDemandEstimatorSupplier) Do a write operation in a pipelined fashion.- Parameters:
requestPublisher
-Publisher
representing the stream of data for a single "request".flushStrategySupplier
- TheFlushStrategy
to use for this write operation.writeDemandEstimatorSupplier
- ASupplier
ofWriteDemandEstimator
for this request which impacts how many elements are requested from therequestPublisher
depending upon channel writability.- Returns:
- Response
Publisher
for this request.
-
localAddress
Description copied from interface:ConnectionInfo
TheSocketAddress
to which the associated connection is bound.- Specified by:
localAddress
in interfaceConnectionInfo
- Returns:
- The
SocketAddress
to which the associated connection is bound.
-
remoteAddress
Description copied from interface:ConnectionInfo
TheSocketAddress
to which the associated connection is connected.- Specified by:
remoteAddress
in interfaceConnectionInfo
- Returns:
- The
SocketAddress
to which the associated connection is connected.
-
sslConfig
Description copied from interface:ConnectionInfo
Get theSslConfig
for this connection.- Specified by:
sslConfig
in interfaceConnectionInfo
- Returns:
- The
SslConfig
if SSL/TLS is configured, ornull
otherwise.
-
sslSession
Description copied from interface:ConnectionInfo
Get theSSLSession
for this connection.- Specified by:
sslSession
in interfaceConnectionInfo
- Returns:
- The
SSLSession
if SSL/TLS is enabled, ornull
otherwise.
-
executionContext
Description copied from interface:ConnectionInfo
Get theExecutionContext
for thisConnectionInfo
.The
ExecutionContext.ioExecutor()
will represent the thread responsible for IO for thisConnectionInfo
. Note that this maybe different that what was used to create this object because at this time a specificIoExecutor
has been selected.- Specified by:
executionContext
in interfaceConnectionInfo
- Returns:
- the
ExecutionContext
for thisConnectionInfo
.
-
socketOption
Description copied from interface:ConnectionInfo
- Specified by:
socketOption
in interfaceConnectionInfo
- Type Parameters:
T
- the type of theSocketOption
value.- Parameters:
option
-SocketOption
to get.- Returns:
- the
SocketOption
value of typeT
for thisConnectionInfo
ornull
if thisSocketOption
is not supported by thisConnectionInfo
. - See Also:
-
protocol
Description copied from interface:ConnectionInfo
Get theConnectionInfo.Protocol
for thisConnectionInfo
.- Specified by:
protocol
in interfaceConnectionInfo
- Returns:
- the
ConnectionInfo.Protocol
for thisConnectionInfo
.
-
parent
Description copied from interface:ConnectionContext
Returns a reference to a parentConnectionContext
if any.This method is useful when multiple virtual streams are multiplexed over a single connection to get access to the actual
ConnectionContext
that represents network.- Specified by:
parent
in interfaceConnectionContext
- Returns:
- a reference to a parent
ConnectionContext
if any. Otherwise, returnsnull
.
-
transportError
Description copied from interface:NettyConnectionContext
Returns aSingle
<Throwable
> that may terminate with an error, if an error is observed at the transport.Note:The
Single
is not required to be blocking-safe and should be offloaded if theSingleSource.Subscriber
may block.- Specified by:
transportError
in interfaceNettyConnectionContext
- Returns:
- a
Single
<Throwable
> that may terminate with an error, if an error is observed at the transport.
-
onClosing
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
that is notified when closing begins.Closing begin might be when a close operation is initiated locally (e.g. subscribing to
AsyncCloseable.closeAsync()
) or it could also be a transport event received from a remote peer (e.g. read aconnection: close
header).For backwards compatibility this method maybe functionally equivalent to
ListenableAsyncCloseable.onClose()
. Therefore, provides a best-effort leading edge notification of closing, but may fall back to notification on trailing edge.The goal of this method is often to notify asap when closing so this method may not be offloaded and care must be taken to avoid blocking if subscribing to the return
Completable
.- Specified by:
onClosing
in interfaceListenableAsyncCloseable
- Specified by:
onClosing
in interfaceNettyConnectionContext
- Returns:
- a
Completable
that is notified when closing begins.
-
onClose
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.- Specified by:
onClose
in interfaceListenableAsyncCloseable
- Returns:
- the
Completable
that is notified on close.
-
closeAsync
Description copied from interface:AsyncCloseable
Used to close/shutdown a resource.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
closeAsyncGracefully
Description copied from interface:AsyncCloseable
Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync()
, but attempts to cleanup state before abruptly closing. This provides a hint that implementations can use to stop accepting new work and finish in flight work. This method is implemented on a "best effort" basis and may be equivalent toAsyncCloseable.closeAsync()
.Note: Implementations may or may not apply a timeout for this operation to complete, if a caller does not want to wait indefinitely, and are unsure if the implementation applies a timeout, it is advisable to apply a timeout and force a call to
AsyncCloseable.closeAsync()
.- Specified by:
closeAsyncGracefully
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
nettyChannel
public io.netty.channel.Channel nettyChannel()Description copied from interface:NettyConnectionContext
Return the NettyChannel
backing this connection.- Specified by:
nettyChannel
in interfaceNettyConnectionContext
- Returns:
- the Netty
Channel
backing this connection.
-
toString
-
updateFlushStrategy
public Cancellable updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider) Description copied from interface:NettyConnectionContext
UpdatesFlushStrategy
associated with this connection. UpdatedFlushStrategy
will be used in any subsequent writes on this connection.- Specified by:
updateFlushStrategy
in interfaceNettyConnectionContext
- Parameters:
strategyProvider
-NettyConnectionContext.FlushStrategyProvider
to provide a newFlushStrategy
.NettyConnectionContext.FlushStrategyProvider.computeFlushStrategy(FlushStrategy, boolean)
MAY be invoked multiple times for a single call to this method and is expected to be idempotent.- Returns:
- A
Cancellable
that will cancel this update.
-
defaultFlushStrategy
Description copied from interface:NettyConnectionContext
Returns theFlushStrategy
used by default for thisNettyConnectionContext
.- Specified by:
defaultFlushStrategy
in interfaceNettyConnectionContext
- Returns:
- The
FlushStrategy
used by default for thisNettyConnectionContext
.
-