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
.NettyConnectionContext.FlushStrategyProvider
ConnectionInfo.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 ConnectionInfo . |
static <Read,Write> |
initChannel(io.netty.channel.Channel channel,
BufferAllocator allocator,
Executor executor,
java.util.function.Predicate<Read> terminalPredicate,
CloseHandler closeHandler,
FlushStrategy flushStrategy,
java.lang.Long idleTimeoutMs,
ChannelInitializer initializer,
ExecutionStrategy executionStrategy,
ConnectionInfo.Protocol protocol,
ConnectionObserver observer,
boolean isClient)
|
static <Read,Write> |
initChildChannel(io.netty.channel.Channel channel,
BufferAllocator allocator,
Executor executor,
java.util.function.Predicate<Read> terminalPredicate,
CloseHandler closeHandler,
FlushStrategy flushStrategy,
java.lang.Long idleTimeoutMs,
ExecutionStrategy executionStrategy,
ConnectionInfo.Protocol protocol,
javax.net.ssl.SSLSession sslSession,
io.netty.channel.ChannelConfig parentChannelConfig,
ConnectionObserver.StreamObserver streamObserver,
boolean isClient)
|
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. |
ConnectionInfo.Protocol |
protocol()
Get the
ConnectionInfo.Protocol for this ConnectionInfo . |
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. |
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<FlushStrategy> flushStrategySupplier,
java.util.function.Supplier<WriteDemandEstimator> demandEstimatorSupplier)
Writes all elements emitted by the passed
Publisher 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, java.util.function.Predicate<Read> terminalPredicate, CloseHandler closeHandler, FlushStrategy flushStrategy, @Nullable java.lang.Long idleTimeoutMs, ExecutionStrategy executionStrategy, ConnectionInfo.Protocol protocol, @Nullable javax.net.ssl.SSLSession sslSession, @Nullable io.netty.channel.ChannelConfig parentChannelConfig, ConnectionObserver.StreamObserver streamObserver, boolean isClient)
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
.terminalPredicate
- 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
s.streamObserver
- ConnectionObserver.StreamObserver
to report internal events.isClient
- tells if this Channel
is for the client.Single
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, java.util.function.Predicate<Read> terminalPredicate, CloseHandler closeHandler, FlushStrategy flushStrategy, @Nullable java.lang.Long idleTimeoutMs, ChannelInitializer initializer, ExecutionStrategy executionStrategy, ConnectionInfo.Protocol protocol, ConnectionObserver observer, boolean isClient)
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
.terminalPredicate
- 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
.observer
- ConnectionObserver
to report network events.isClient
- tells if this Channel
is for the client.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 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<FlushStrategy> flushStrategySupplier, java.util.function.Supplier<WriteDemandEstimator> demandEstimatorSupplier)
NettyConnection
Publisher
on this connection.write
in interface NettyConnection<Read,Write>
write
- Publisher
, all objects emitted from which are written on this connection.flushStrategySupplier
- Supplier
of FlushStrategy
which controls the flush operations
for this write.demandEstimatorSupplier
- A Supplier
of WriteDemandEstimator
for this write.Completable
that terminates as follows:
protected void doCloseAsyncGracefully()
NettyChannelListenableAsyncCloseable
doCloseAsyncGracefully
in class NettyChannelListenableAsyncCloseable
public java.net.SocketAddress localAddress()
ConnectionInfo
SocketAddress
to which the associated connection is bound.localAddress
in interface ConnectionInfo
SocketAddress
to which the associated connection is bound.public java.net.SocketAddress remoteAddress()
ConnectionInfo
SocketAddress
to which the associated connection is connected.remoteAddress
in interface ConnectionInfo
SocketAddress
to which the associated connection is connected.public javax.net.ssl.SSLSession sslSession()
ConnectionInfo
SSLSession
for this connection.sslSession
in interface ConnectionInfo
SSLSession
if SSL/TLS is enabled, or null
otherwise.public ExecutionContext executionContext()
ConnectionInfo
ExecutionContext
for this ConnectionInfo
.
The ExecutionContext.ioExecutor()
will represent the thread responsible for IO for this
ConnectionInfo
. 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 ConnectionInfo
ExecutionContext
for this ConnectionInfo
.@Nullable public <T> T socketOption(java.net.SocketOption<T> option)
ConnectionInfo
socketOption
in interface ConnectionInfo
T
- the type of the SocketOption
value.option
- SocketOption
to get.SocketOption
value of type T
for this ConnectionInfo
or null
if
this SocketOption
is not supported by this ConnectionInfo
.StandardSocketOptions
,
ServiceTalkSocketOptions
public ConnectionInfo.Protocol protocol()
ConnectionInfo
ConnectionInfo.Protocol
for this ConnectionInfo
.protocol
in interface ConnectionInfo
ConnectionInfo.Protocol
for this ConnectionInfo
.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.