Read
- Type of objects read from this connection.Write
- Type of objects written to this connection.public final class DefaultNettyConnection<Read,Write> extends NettyChannelListenableAsyncCloseable implements NettyConnection<Read,Write>
NettyConnection
backed by a netty Channel
.NettyConnection.RequestNSupplier, NettyConnection.TerminalPredicate<Read>
NettyConnectionContext.FlushStrategyProvider
ConnectionContext.Protocol
Modifier and Type | Method and Description |
---|---|
FlushStrategy |
defaultFlushStrategy()
Returns the
FlushStrategy used by default for this NettyConnectionContext . |
protected void |
doCloseAsyncGracefully()
Initiate graceful closure.
|
ExecutionContext |
executionContext()
Get the
ExecutionContext for this ConnectionContext . |
static <Read,Write> |
initChannel(io.netty.channel.Channel channel,
BufferAllocator allocator,
Executor executor,
NettyConnection.TerminalPredicate<Read> terminalMsgPredicate,
CloseHandler closeHandler,
FlushStrategy flushStrategy,
java.lang.Long idleTimeoutMs,
ChannelInitializer initializer,
ExecutionStrategy executionStrategy,
ConnectionContext.Protocol protocol)
|
static <Read,Write> |
initChildChannel(io.netty.channel.Channel channel,
BufferAllocator allocator,
Executor executor,
NettyConnection.TerminalPredicate<Read> terminalMsgPredicate,
CloseHandler closeHandler,
FlushStrategy flushStrategy,
java.lang.Long idleTimeoutMs,
ExecutionStrategy executionStrategy,
ConnectionContext.Protocol protocol,
javax.net.ssl.SSLSession sslSession,
io.netty.channel.ChannelConfig parentChannelConfig)
|
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 |
onClosing()
Returns a
Completable that notifies when the connection has begun its closing sequence. |
ConnectionContext.Protocol |
protocol()
Get the
ConnectionContext.Protocol for this ConnectionContext . |
Publisher<Read> |
read()
Returns
Publisher that emits all items as read from this connection. |
java.net.SocketAddress |
remoteAddress()
The
SocketAddress to which the associated connection is connected. |
<T> T |
socketOption(java.net.SocketOption<T> option)
|
javax.net.ssl.SSLSession |
sslSession()
Get the
SSLSession for this connection. |
NettyConnection.TerminalPredicate<Read> |
terminalMsgPredicate()
Returns the
NettyConnection.TerminalPredicate associated with this NettyConnection to detect terminal messages
for the otherwise infinite Publisher returned by NettyConnection.read() . |
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. |
Completable |
write(Publisher<Write> write)
Writes all elements emitted by the passed
Publisher on this connection. |
Completable |
write(Publisher<Write> write,
java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory)
Writes all elements emitted by the passed
Publisher on this connection. |
Completable |
writeAndFlush(Single<Write> write)
Write and flushes the object emitted by the passed
Single on this connection. |
Completable |
writeAndFlush(Write write)
Write and flushes the passed
Buffer on this connection. |
channel, closeAsync, closeAsyncGracefully, onClose
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onClose
closeAsync, closeAsyncGracefully
public static <Read,Write> DefaultNettyConnection<Read,Write> initChildChannel(io.netty.channel.Channel channel, BufferAllocator allocator, Executor executor, NettyConnection.TerminalPredicate<Read> terminalMsgPredicate, CloseHandler closeHandler, FlushStrategy flushStrategy, @Nullable java.lang.Long idleTimeoutMs, ExecutionStrategy executionStrategy, ConnectionContext.Protocol protocol, @Nullable javax.net.ssl.SSLSession sslSession, @Nullable io.netty.channel.ChannelConfig parentChannelConfig)
Channel
this will initialize the ChannelPipeline
just to create a
DefaultNettyConnection
. It is assumed this is a child channel and all TLS handshaking is completed.Read
- Type of objects read from the NettyConnection
.Write
- Type of objects written to the NettyConnection
.channel
- A newly created Channel
.allocator
- The BufferAllocator
to use for the DefaultNettyConnection
.executor
- The Executor
to use for the DefaultNettyConnection
.terminalMsgPredicate
- Used to determine which inbound signal on the read()
stream terminates the
current message framing and will allow a resubscribe to consume the next framing.closeHandler
- Manages the half closure of the DefaultNettyConnection
.flushStrategy
- Manages flushing of data for the DefaultNettyConnection
.idleTimeoutMs
- Value for IDLE_TIMEOUT
socket option.executionStrategy
- Used to derive the executionContext()
.protocol
- Protocol
for the returned DefaultNettyConnection
.sslSession
- Provides access to the SSLSession
associated with this connection.parentChannelConfig
- ChannelConfig
of the parent Channel
to query SocketOption
sSingle
that completes with a DefaultNettyConnection
after the channel is activated and
ready to use.public static <Read,Write> Single<DefaultNettyConnection<Read,Write>> initChannel(io.netty.channel.Channel channel, BufferAllocator allocator, Executor executor, NettyConnection.TerminalPredicate<Read> terminalMsgPredicate, CloseHandler closeHandler, FlushStrategy flushStrategy, @Nullable java.lang.Long idleTimeoutMs, ChannelInitializer initializer, ExecutionStrategy executionStrategy, ConnectionContext.Protocol protocol)
Channel
this will initialize the ChannelPipeline
and create a
DefaultNettyConnection
. The resulting single will complete after the TLS handshake has completed
(if applicable) or otherwise after the channel is active and ready to use.Read
- Type of objects read from the NettyConnection
.Write
- Type of objects written to the NettyConnection
.channel
- A newly created Channel
.allocator
- The BufferAllocator
to use for the DefaultNettyConnection
.executor
- The Executor
to use for the DefaultNettyConnection
.terminalMsgPredicate
- Used to determine which inbound signal on the read()
stream terminates the
current message framing and will allow a resubscribe to consume the next framing.closeHandler
- Manages the half closure of the DefaultNettyConnection
.flushStrategy
- Manages flushing of data for the DefaultNettyConnection
.idleTimeoutMs
- Value for IDLE_TIMEOUT
socket option.initializer
- Synchronously initializes the pipeline upon subscribe.executionStrategy
- ExecutionStrategy
to use for this connection.protocol
- Protocol
for the returned DefaultNettyConnection
.Single
that completes with a DefaultNettyConnection
after the channel is activated and
ready to use.public Publisher<Read> read()
NettyConnection
Publisher
that emits all items as read from this connection.read
in interface NettyConnection<Read,Write>
Publisher
that emits all items as read from this connection.
Concurrent subscribes when a PublisherSource.Subscriber
is already active) are disallowed but sequential subscribes when
a previous PublisherSource.Subscriber
has terminated) are allowed.public NettyConnection.TerminalPredicate<Read> terminalMsgPredicate()
NettyConnection
NettyConnection.TerminalPredicate
associated with this NettyConnection
to detect terminal messages
for the otherwise infinite Publisher
returned by NettyConnection.read()
.terminalMsgPredicate
in interface NettyConnection<Read,Write>
NettyConnection.TerminalPredicate
for this connection.public Completable write(Publisher<Write> write)
NettyConnection
Publisher
on this connection.write
in interface NettyConnection<Read,Write>
write
- Publisher
, all objects emitted from which are written on this connection.Completable
that terminates as follows:
public Completable write(Publisher<Write> write, java.util.function.Supplier<NettyConnection.RequestNSupplier> requestNSupplierFactory)
NettyConnection
Publisher
on this connection.write
in interface NettyConnection<Read,Write>
write
- Publisher
, all objects emitted from which are written on this connection.requestNSupplierFactory
- A Supplier
of NettyConnection.RequestNSupplier
for this write.Completable
that terminates as follows:
public Completable writeAndFlush(Single<Write> write)
NettyConnection
Single
on this connection.writeAndFlush
in interface NettyConnection<Read,Write>
write
- Single
, result of which is written on this connection.Completable
that terminates as follows:
public Completable writeAndFlush(Write write)
NettyConnection
Buffer
on this connection.writeAndFlush
in interface NettyConnection<Read,Write>
write
- Buffer
to write on this connection.Completable
that terminates as follows:
protected void doCloseAsyncGracefully()
NettyChannelListenableAsyncCloseable
doCloseAsyncGracefully
in class NettyChannelListenableAsyncCloseable
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.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
.@Nullable public <T> T socketOption(java.net.SocketOption<T> option)
ConnectionContext
socketOption
in interface ConnectionContext
T
- the type of the SocketOption
value.option
- SocketOption
to get.SocketOption
value of type T
for this ConnectionContext
or null
if
this SocketOption
is not supported by this ConnectionContext
.StandardSocketOptions
,
ServiceTalkSocketOptions
public ConnectionContext.Protocol protocol()
ConnectionContext
ConnectionContext.Protocol
for this ConnectionContext
.protocol
in interface ConnectionContext
ConnectionContext.Protocol
for this ConnectionContext
.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 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
.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.