Req
- Type of requests sent on this connection.Resp
- Type of responses read from this connection.public final class DefaultNettyPipelinedConnection<Req,Resp> extends java.lang.Object implements NettyPipelinedConnection<Req,Resp>
NettyPipelinedConnection
using a NettyConnection
.NettyPipelinedConnection.Writer
NettyConnectionContext.FlushStrategyProvider
Constructor and Description |
---|
DefaultNettyPipelinedConnection(NettyConnection<Resp,Req> connection,
int initialQueueSize)
New instance.
|
Modifier and Type | Method and Description |
---|---|
Completable |
closeAsync()
Used to close/shutdown a resource.
|
Completable |
closeAsyncGracefully()
Used to close/shutdown a resource, similar to
AsyncCloseable.closeAsync() , but attempts to cleanup state before
abruptly closing. |
FlushStrategy |
defaultFlushStrategy()
Returns the
FlushStrategy used by default for this NettyConnectionContext . |
ExecutionContext |
executionContext()
Get the
ExecutionContext for this ConnectionContext . |
java.net.SocketAddress |
localAddress()
The
SocketAddress to which the associated connection is bound. |
io.netty.channel.Channel |
nettyChannel()
Return the Netty
Channel backing this connection. |
Completable |
onClose()
Returns a
Completable that is notified once the ListenableAsyncCloseable was closed. |
Completable |
onClosing()
Returns a
Completable that notifies when the connection has begun its closing sequence. |
java.net.SocketAddress |
remoteAddress()
The
SocketAddress to which the associated connection is connected. |
Publisher<Resp> |
request(NettyPipelinedConnection.Writer writer)
Writes on this connection a request encapsulated in the passed
NettyPipelinedConnection.Writer . |
Publisher<Resp> |
request(NettyPipelinedConnection.Writer writer,
java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
Writes on this connection a request encapsulated in the passed
NettyPipelinedConnection.Writer . |
Publisher<Resp> |
request(Publisher<Req> request)
Send request(s) produced by a
Publisher on this connection. |
Publisher<Resp> |
request(Publisher<Req> request,
java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory)
Send request(s) produced by a
Publisher on this connection. |
Publisher<Resp> |
request(Publisher<Req> request,
java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory,
java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
Send request(s) produced by a
Publisher on this connection. |
Publisher<Resp> |
request(Req request)
Writes a
Req object on this connection. |
Publisher<Resp> |
request(Req request,
java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
Writes a
Req object on this connection. |
Publisher<Resp> |
request(Single<Req> request)
Send request produced by a
Single on this connection. |
Publisher<Resp> |
request(Single<Req> request,
java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
Send request produced by a
Single on this connection. |
Publisher<Resp> |
request(java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier,
Publisher<Req> request)
Send request(s) produced by a
Publisher on this connection. |
javax.net.ssl.SSLSession |
sslSession()
Get the
SSLSession for this connection. |
java.lang.String |
toString() |
Single<java.lang.Throwable> |
transportError()
Returns a
Single <Throwable > that may terminate with an error, if an error is observed at
the transport. |
Cancellable |
updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)
Updates
FlushStrategy associated with this connection. |
public DefaultNettyPipelinedConnection(NettyConnection<Resp,Req> connection, int initialQueueSize)
connection
- NettyConnection
requests to which are to be pipelined.initialQueueSize
- Initial size for the write and read queues.public Publisher<Resp> request(Req request)
NettyPipelinedConnection
Req
object on this connection.
Use NettyPipelinedConnection.request(Object, Supplier)
to override the predicate used to mark the end of response.
request
in interface NettyPipelinedConnection<Req,Resp>
request
- to write.Publisher
for this request.public Publisher<Resp> request(NettyPipelinedConnection.Writer writer)
NettyPipelinedConnection
NettyPipelinedConnection.Writer
.
Use NettyPipelinedConnection.request(Writer, Supplier)
to override the predicate used to mark the end of response.
request
in interface NettyPipelinedConnection<Req,Resp>
writer
- to write the request.Publisher
for this request.public Publisher<Resp> request(NettyPipelinedConnection.Writer writer, java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
NettyPipelinedConnection
NettyPipelinedConnection.Writer
.request
in interface NettyPipelinedConnection<Req,Resp>
writer
- to write the request.terminalMsgPredicateSupplier
- Supplier
of a dynamic Predicate
for this request that will
mark the end of the response.Publisher
for this request.public Publisher<Resp> request(Req request, java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
NettyPipelinedConnection
Req
object on this connection.request
in interface NettyPipelinedConnection<Req,Resp>
request
- to write.terminalMsgPredicateSupplier
- Supplier
of a dynamic Predicate
for this request that will
mark the end of the response.Publisher
for this request.public Publisher<Resp> request(Single<Req> request)
NettyPipelinedConnection
Single
on this connection.
Use NettyPipelinedConnection.request(Single, Supplier)
to override the predicate used to mark the end of response.
request
in interface NettyPipelinedConnection<Req,Resp>
request
- to write.Publisher
for this request.public Publisher<Resp> request(Single<Req> request, java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
NettyPipelinedConnection
Single
on this connection.public Publisher<Resp> request(Publisher<Req> request)
NettyPipelinedConnection
Publisher
on this connection.
Use NettyPipelinedConnection.request(Publisher, Supplier)
to override the predicate used to mark the end of response.
public Publisher<Resp> request(java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier, Publisher<Req> request)
NettyPipelinedConnection
Publisher
on this connection.request
in interface NettyPipelinedConnection<Req,Resp>
terminalMsgPredicateSupplier
- Supplier
of a dynamic Predicate
for this request that will
mark the end of the response.request
- Publisher
producing the request(s) to write.Publisher
for this request.public Publisher<Resp> request(Publisher<Req> request, java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory)
NettyPipelinedConnection
Publisher
on this connection.
Use NettyPipelinedConnection.request(Publisher, Supplier, Supplier)
to override the predicate used to mark the end of
response.
request
in interface NettyPipelinedConnection<Req,Resp>
request
- Publisher
producing the request(s) to write.requestNSupplierFactory
- A Supplier
of NettyConnection.RequestNSupplier
for this request.Publisher
for this request.public Publisher<Resp> request(Publisher<Req> request, java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory, java.util.function.Supplier<java.util.function.Predicate<Resp>> terminalMsgPredicateSupplier)
NettyPipelinedConnection
Publisher
on this connection.request
in interface NettyPipelinedConnection<Req,Resp>
request
- Publisher
producing the request(s) to write.requestNSupplierFactory
- A Supplier
of NettyConnection.RequestNSupplier
for this request.terminalMsgPredicateSupplier
- Supplier
of a dynamic Predicate
for this request that will
mark the end of the response.Publisher
for this request.public java.net.SocketAddress localAddress()
ConnectionContext
SocketAddress
to which the associated connection is bound.localAddress
in interface ConnectionContext
SocketAddress
to which the associated connection is bound.public java.net.SocketAddress remoteAddress()
ConnectionContext
SocketAddress
to which the associated connection is connected.remoteAddress
in interface ConnectionContext
SocketAddress
to which the associated connection is connected.@Nullable public javax.net.ssl.SSLSession sslSession()
ConnectionContext
SSLSession
for this connection.sslSession
in interface ConnectionContext
SSLSession
if SSL/TLS is enabled, or null
otherwise.public ExecutionContext executionContext()
ConnectionContext
ExecutionContext
for this ConnectionContext
.
The ExecutionContext.ioExecutor()
will represent the thread responsible for IO for this
ConnectionContext
. Note that this maybe different that what was used to create this object because
at this time a specific IoExecutor
has been selected.
executionContext
in interface ConnectionContext
ExecutionContext
for this ConnectionContext
.public Single<java.lang.Throwable> transportError()
NettyConnectionContext
Single
<Throwable
> that may terminate with an error, if an error is observed at
the transport.transportError
in interface NettyConnectionContext
Single
<Throwable
> that may terminate with an error, if an error is observed at
the transport.public Completable onClosing()
NettyConnectionContext
Completable
that notifies when the connection has begun its closing sequence.onClosing
in interface NettyConnectionContext
Completable
that notifies when the connection has begun its closing sequence. A configured
CloseHandler
will determine whether more reads or writes will be allowed on this
NettyConnectionContext
.public Completable onClose()
ListenableAsyncCloseable
Completable
that is notified once the ListenableAsyncCloseable
was closed.onClose
in interface ListenableAsyncCloseable
Completable
that is notified on close.public Completable closeAsync()
AsyncCloseable
closeAsync
in interface AsyncCloseable
CompletableSource
that is notified once the close is complete.public Completable closeAsyncGracefully()
AsyncCloseable
AsyncCloseable.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 to AsyncCloseable.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()
.
closeAsyncGracefully
in interface AsyncCloseable
Completable
that is notified once the close is complete.public io.netty.channel.Channel nettyChannel()
NettyConnectionContext
Channel
backing this connection.nettyChannel
in interface NettyConnectionContext
Channel
backing this connection.public java.lang.String toString()
toString
in class java.lang.Object
public Cancellable updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)
NettyConnectionContext
FlushStrategy
associated with this connection. Updated FlushStrategy
will be used in any
subsequent writes on this connection.updateFlushStrategy
in interface NettyConnectionContext
strategyProvider
- NettyConnectionContext.FlushStrategyProvider
to provide a new FlushStrategy
.
NettyConnectionContext.FlushStrategyProvider.computeFlushStrategy(FlushStrategy, boolean)
MAY be invoked
multiple times for a single call to this method and is expected to be idempotent.Cancellable
that will cancel this update.public FlushStrategy defaultFlushStrategy()
NettyConnectionContext
FlushStrategy
used by default for this NettyConnectionContext
.defaultFlushStrategy
in interface NettyConnectionContext
FlushStrategy
used by default for this NettyConnectionContext
.