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.FlushStrategyProviderConnectionContext.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, onCloseclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitonClosecloseAsync, closeAsyncGracefullypublic 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 SocketOptionsSingle 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()
NettyConnectionPublisher 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()
NettyConnectionNettyConnection.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)
NettyConnectionPublisher 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)
NettyConnectionPublisher 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)
NettyConnectionSingle 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)
NettyConnectionBuffer on this connection.writeAndFlush in interface NettyConnection<Read,Write>write - Buffer to write on this connection.Completable that terminates as follows:
protected void doCloseAsyncGracefully()
NettyChannelListenableAsyncCloseabledoCloseAsyncGracefully in class NettyChannelListenableAsyncCloseablepublic java.net.SocketAddress localAddress()
ConnectionContextSocketAddress to which the associated connection is bound.localAddress in interface ConnectionContextSocketAddress to which the associated connection is bound.public java.net.SocketAddress remoteAddress()
ConnectionContextSocketAddress to which the associated connection is connected.remoteAddress in interface ConnectionContextSocketAddress to which the associated connection is connected.public javax.net.ssl.SSLSession sslSession()
ConnectionContextSSLSession for this connection.sslSession in interface ConnectionContextSSLSession if SSL/TLS is enabled, or null otherwise.public ExecutionContext executionContext()
ConnectionContextExecutionContext 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 ConnectionContextExecutionContext for this ConnectionContext.@Nullable public <T> T socketOption(java.net.SocketOption<T> option)
ConnectionContextsocketOption in interface ConnectionContextT - 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,
ServiceTalkSocketOptionspublic ConnectionContext.Protocol protocol()
ConnectionContextConnectionContext.Protocol for this ConnectionContext.protocol in interface ConnectionContextConnectionContext.Protocol for this ConnectionContext.public Completable onClosing()
NettyConnectionContextCompletable that notifies when the connection has begun its closing sequence.onClosing in interface NettyConnectionContextCompletable 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()
NettyConnectionContextChannel backing this connection.nettyChannel in interface NettyConnectionContextChannel backing this connection.public java.lang.String toString()
toString in class java.lang.Objectpublic Cancellable updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)
NettyConnectionContextFlushStrategy associated with this connection. Updated FlushStrategy will be used in any
subsequent writes on this connection.updateFlushStrategy in interface NettyConnectionContextstrategyProvider - 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()
NettyConnectionContextFlushStrategy used by default for this NettyConnectionContext.defaultFlushStrategy in interface NettyConnectionContextFlushStrategy used by default for this NettyConnectionContext.public Single<java.lang.Throwable> transportError()
NettyConnectionContextSingle<Throwable> that may terminate with an error, if an error is observed at
the transport.transportError in interface NettyConnectionContextSingle<Throwable> that may terminate with an error, if an error is observed at
the transport.