Class DefaultNettyConnection<Read,Write>
- java.lang.Object
-
- io.servicetalk.transport.netty.internal.NettyChannelListenableAsyncCloseable
-
- io.servicetalk.transport.netty.internal.DefaultNettyConnection<Read,Write>
-
- Type Parameters:
Read
- Type of objects read from this connection.Write
- Type of objects written to this connection.
- All Implemented Interfaces:
AsyncCloseable
,ListenableAsyncCloseable
,ConnectionContext
,ConnectionInfo
,NettyConnection<Read,Write>
,NettyConnectionContext
public final class DefaultNettyConnection<Read,Write> extends NettyChannelListenableAsyncCloseable implements NettyConnection<Read,Write>
Implementation ofNettyConnection
backed by a nettyChannel
.
-
-
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FlushStrategy
defaultFlushStrategy()
Returns theFlushStrategy
used by default for thisNettyConnectionContext
.protected void
doCloseAsyncGracefully()
Initiate graceful closure.ExecutionContext
executionContext()
Get theExecutionContext
for thisConnectionInfo
.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, java.lang.Long idleTimeoutMs, ChannelInitializer initializer, ExecutionStrategy executionStrategy, ConnectionInfo.Protocol protocol, ConnectionObserver observer, boolean isClient)
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, 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.util.function.UnaryOperator<java.lang.Throwable> enrichProtocolError)
java.net.SocketAddress
localAddress()
TheSocketAddress
to which the associated connection is bound.io.netty.channel.Channel
nettyChannel()
Return the NettyChannel
backing this connection.Completable
onClosing()
Returns aCompletable
that notifies when the connection has begun its closing sequence.ConnectionInfo.Protocol
protocol()
Get theConnectionInfo.Protocol
for thisConnectionInfo
.Publisher<Read>
read()
ReturnsPublisher
that emits all items as read from this connection.java.net.SocketAddress
remoteAddress()
TheSocketAddress
to which the associated connection is connected.<T> T
socketOption(java.net.SocketOption<T> option)
javax.net.ssl.SSLSession
sslSession()
Get theSSLSession
for this connection.java.lang.String
toString()
Single<java.lang.Throwable>
transportError()
Returns aSingle
<Throwable
> that may terminate with an error, if an error is observed at the transport.Cancellable
updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)
UpdatesFlushStrategy
associated with this connection.Completable
write(Publisher<Write> write)
Writes all elements emitted by the passedPublisher
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 passedPublisher
on this connection.-
Methods inherited from class io.servicetalk.transport.netty.internal.NettyChannelListenableAsyncCloseable
channel, closeAsync, closeAsyncGracefully, onClose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.servicetalk.concurrent.api.AsyncCloseable
closeAsync, closeAsyncGracefully
-
Methods inherited from interface io.servicetalk.concurrent.api.ListenableAsyncCloseable
onClose
-
-
-
-
Method Detail
-
initChildChannel
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, java.util.function.UnaryOperator<java.lang.Throwable> enrichProtocolError)
Given aChannel
this will initialize theChannelPipeline
just to create aDefaultNettyConnection
. It is assumed this is a child channel and all TLS handshaking is completed.- Type Parameters:
Read
- Type of objects read from theNettyConnection
.Write
- Type of objects written to theNettyConnection
.- Parameters:
channel
- A newly createdChannel
.allocator
- TheBufferAllocator
to use for theDefaultNettyConnection
.executor
- TheExecutor
to use for theDefaultNettyConnection
.terminalPredicate
- Used to determine which inbound signal on theread()
stream terminates the current message framing and will allow a resubscribe to consume the next framing.closeHandler
- Manages the half closure of theDefaultNettyConnection
.flushStrategy
- Manages flushing of data for theDefaultNettyConnection
.idleTimeoutMs
- Value forIDLE_TIMEOUT
socket option.executionStrategy
- Used to derive theexecutionContext()
.protocol
-ConnectionInfo.Protocol
for the returnedDefaultNettyConnection
.sslSession
- Provides access to theSSLSession
associated with this connection.parentChannelConfig
-ChannelConfig
of the parentChannel
to querySocketOption
s.streamObserver
-ConnectionObserver.StreamObserver
to report internal events.isClient
- tells if thisChannel
is for the client.enrichProtocolError
- enriches protocol-specificThrowable
s.- Returns:
- A
Single
that completes with aDefaultNettyConnection
after the channel is activated and ready to use.
-
initChannel
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)
Given aChannel
this will initialize theChannelPipeline
and create aDefaultNettyConnection
. The resulting single will complete after the TLS handshake has completed (if applicable) or otherwise after the channel is active and ready to use.- Type Parameters:
Read
- Type of objects read from theNettyConnection
.Write
- Type of objects written to theNettyConnection
.- Parameters:
channel
- A newly createdChannel
.allocator
- TheBufferAllocator
to use for theDefaultNettyConnection
.executor
- TheExecutor
to use for theDefaultNettyConnection
.terminalPredicate
- Used to determine which inbound signal on theread()
stream terminates the current message framing and will allow a resubscribe to consume the next framing.closeHandler
- Manages the half closure of theDefaultNettyConnection
.flushStrategy
- Manages flushing of data for theDefaultNettyConnection
.idleTimeoutMs
- Value forIDLE_TIMEOUT
socket option.initializer
- Synchronously initializes the pipeline upon subscribe.executionStrategy
-ExecutionStrategy
to use for this connection.protocol
-ConnectionInfo.Protocol
for the returnedDefaultNettyConnection
.observer
-ConnectionObserver
to report network events.isClient
- tells if thisChannel
is for the client.- Returns:
- A
Single
that completes with aDefaultNettyConnection
after the channel is activated and ready to use.
-
read
public Publisher<Read> read()
Description copied from interface:NettyConnection
ReturnsPublisher
that emits all items as read from this connection.- Specified by:
read
in interfaceNettyConnection<Read,Write>
- Returns:
Publisher
that emits all items as read from this connection. Concurrent subscribes when aPublisherSource.Subscriber
is already active) are disallowed but sequential subscribes when a previousPublisherSource.Subscriber
has terminated) are allowed.
-
write
public Completable write(Publisher<Write> write)
Description copied from interface:NettyConnection
Writes all elements emitted by the passedPublisher
on this connection.- Specified by:
write
in interfaceNettyConnection<Read,Write>
- Parameters:
write
-Publisher
, all objects emitted from which are written on this connection.- Returns:
Completable
that terminates as follows:
-
write
public Completable write(Publisher<Write> write, java.util.function.Supplier<FlushStrategy> flushStrategySupplier, java.util.function.Supplier<WriteDemandEstimator> demandEstimatorSupplier)
Description copied from interface:NettyConnection
Writes all elements emitted by the passedPublisher
on this connection.- Specified by:
write
in interfaceNettyConnection<Read,Write>
- Parameters:
write
-Publisher
, all objects emitted from which are written on this connection.flushStrategySupplier
-Supplier
ofFlushStrategy
which controls the flush operations for this write.demandEstimatorSupplier
- ASupplier
ofWriteDemandEstimator
for this write.- Returns:
Completable
that terminates as follows:
-
doCloseAsyncGracefully
protected void doCloseAsyncGracefully()
Description copied from class:NettyChannelListenableAsyncCloseable
Initiate graceful closure.- Overrides:
doCloseAsyncGracefully
in classNettyChannelListenableAsyncCloseable
-
localAddress
public java.net.SocketAddress 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
public java.net.SocketAddress 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.
-
sslSession
public javax.net.ssl.SSLSession 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
public ExecutionContext 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
@Nullable public <T> T socketOption(java.net.SocketOption<T> option)
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:
StandardSocketOptions
,ServiceTalkSocketOptions
-
protocol
public ConnectionInfo.Protocol protocol()
Description copied from interface:ConnectionInfo
Get theConnectionInfo.Protocol
for thisConnectionInfo
.- Specified by:
protocol
in interfaceConnectionInfo
- Returns:
- the
ConnectionInfo.Protocol
for thisConnectionInfo
.
-
onClosing
public Completable onClosing()
Description copied from interface:NettyConnectionContext
Returns aCompletable
that notifies when the connection has begun its closing sequence.- Specified by:
onClosing
in interfaceNettyConnectionContext
- Returns:
- a
Completable
that notifies when the connection has begun its closing sequence. A configuredCloseHandler
will determine whether more reads or writes will be allowed on thisNettyConnectionContext
.
-
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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
public FlushStrategy 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
.
-
transportError
public Single<java.lang.Throwable> transportError()
Description copied from interface:NettyConnectionContext
Returns aSingle
<Throwable
> that may terminate with an error, if an error is observed at the transport.- Specified by:
transportError
in interfaceNettyConnectionContext
- Returns:
- a
Single
<Throwable
> that may terminate with an error, if an error is observed at the transport.
-
-