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 ofNettyConnectionbacked 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 FlushStrategydefaultFlushStrategy()Returns theFlushStrategyused by default for thisNettyConnectionContext.protected voiddoCloseAsyncGracefully()Initiate graceful closure.ExecutionContextexecutionContext()Get theExecutionContextfor 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.SocketAddresslocalAddress()TheSocketAddressto which the associated connection is bound.io.netty.channel.ChannelnettyChannel()Return the NettyChannelbacking this connection.CompletableonClosing()Returns aCompletablethat notifies when the connection has begun its closing sequence.ConnectionInfo.Protocolprotocol()Get theConnectionInfo.Protocolfor thisConnectionInfo.Publisher<Read>read()ReturnsPublisherthat emits all items as read from this connection.java.net.SocketAddressremoteAddress()TheSocketAddressto which the associated connection is connected.<T> TsocketOption(java.net.SocketOption<T> option)javax.net.ssl.SSLSessionsslSession()Get theSSLSessionfor this connection.java.lang.StringtoString()Single<java.lang.Throwable>transportError()Returns aSingle<Throwable> that may terminate with an error, if an error is observed at the transport.CancellableupdateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)UpdatesFlushStrategyassociated with this connection.Completablewrite(Publisher<Write> write)Writes all elements emitted by the passedPublisheron this connection.Completablewrite(Publisher<Write> write, java.util.function.Supplier<FlushStrategy> flushStrategySupplier, java.util.function.Supplier<WriteDemandEstimator> demandEstimatorSupplier)Writes all elements emitted by the passedPublisheron 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 aChannelthis will initialize theChannelPipelinejust 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- TheBufferAllocatorto use for theDefaultNettyConnection.executor- TheExecutorto 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_TIMEOUTsocket option.executionStrategy- Used to derive theexecutionContext().protocol-ConnectionInfo.Protocolfor the returnedDefaultNettyConnection.sslSession- Provides access to theSSLSessionassociated with this connection.parentChannelConfig-ChannelConfigof the parentChannelto querySocketOptions.streamObserver-ConnectionObserver.StreamObserverto report internal events.isClient- tells if thisChannelis for the client.enrichProtocolError- enriches protocol-specificThrowables.- Returns:
- A
Singlethat completes with aDefaultNettyConnectionafter 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 aChannelthis will initialize theChannelPipelineand 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- TheBufferAllocatorto use for theDefaultNettyConnection.executor- TheExecutorto 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_TIMEOUTsocket option.initializer- Synchronously initializes the pipeline upon subscribe.executionStrategy-ExecutionStrategyto use for this connection.protocol-ConnectionInfo.Protocolfor the returnedDefaultNettyConnection.observer-ConnectionObserverto report network events.isClient- tells if thisChannelis for the client.- Returns:
- A
Singlethat completes with aDefaultNettyConnectionafter the channel is activated and ready to use.
-
read
public Publisher<Read> read()
Description copied from interface:NettyConnectionReturnsPublisherthat emits all items as read from this connection.- Specified by:
readin interfaceNettyConnection<Read,Write>- Returns:
Publisherthat emits all items as read from this connection. Concurrent subscribes when aPublisherSource.Subscriberis already active) are disallowed but sequential subscribes when a previousPublisherSource.Subscriberhas terminated) are allowed.
-
write
public Completable write(Publisher<Write> write)
Description copied from interface:NettyConnectionWrites all elements emitted by the passedPublisheron this connection.- Specified by:
writein interfaceNettyConnection<Read,Write>- Parameters:
write-Publisher, all objects emitted from which are written on this connection.- Returns:
Completablethat 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:NettyConnectionWrites all elements emitted by the passedPublisheron this connection.- Specified by:
writein interfaceNettyConnection<Read,Write>- Parameters:
write-Publisher, all objects emitted from which are written on this connection.flushStrategySupplier-SupplierofFlushStrategywhich controls the flush operations for this write.demandEstimatorSupplier- ASupplierofWriteDemandEstimatorfor this write.- Returns:
Completablethat terminates as follows:
-
doCloseAsyncGracefully
protected void doCloseAsyncGracefully()
Description copied from class:NettyChannelListenableAsyncCloseableInitiate graceful closure.- Overrides:
doCloseAsyncGracefullyin classNettyChannelListenableAsyncCloseable
-
localAddress
public java.net.SocketAddress localAddress()
Description copied from interface:ConnectionInfoTheSocketAddressto which the associated connection is bound.- Specified by:
localAddressin interfaceConnectionInfo- Returns:
- The
SocketAddressto which the associated connection is bound.
-
remoteAddress
public java.net.SocketAddress remoteAddress()
Description copied from interface:ConnectionInfoTheSocketAddressto which the associated connection is connected.- Specified by:
remoteAddressin interfaceConnectionInfo- Returns:
- The
SocketAddressto which the associated connection is connected.
-
sslSession
public javax.net.ssl.SSLSession sslSession()
Description copied from interface:ConnectionInfoGet theSSLSessionfor this connection.- Specified by:
sslSessionin interfaceConnectionInfo- Returns:
- The
SSLSessionif SSL/TLS is enabled, ornullotherwise.
-
executionContext
public ExecutionContext executionContext()
Description copied from interface:ConnectionInfoGet theExecutionContextfor 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 specificIoExecutorhas been selected.- Specified by:
executionContextin interfaceConnectionInfo- Returns:
- the
ExecutionContextfor thisConnectionInfo.
-
socketOption
@Nullable public <T> T socketOption(java.net.SocketOption<T> option)
Description copied from interface:ConnectionInfo- Specified by:
socketOptionin interfaceConnectionInfo- Type Parameters:
T- the type of theSocketOptionvalue.- Parameters:
option-SocketOptionto get.- Returns:
- the
SocketOptionvalue of typeTfor thisConnectionInfoornullif thisSocketOptionis not supported by thisConnectionInfo. - See Also:
StandardSocketOptions,ServiceTalkSocketOptions
-
protocol
public ConnectionInfo.Protocol protocol()
Description copied from interface:ConnectionInfoGet theConnectionInfo.Protocolfor thisConnectionInfo.- Specified by:
protocolin interfaceConnectionInfo- Returns:
- the
ConnectionInfo.Protocolfor thisConnectionInfo.
-
onClosing
public Completable onClosing()
Description copied from interface:NettyConnectionContextReturns aCompletablethat notifies when the connection has begun its closing sequence.- Specified by:
onClosingin interfaceNettyConnectionContext- Returns:
- a
Completablethat notifies when the connection has begun its closing sequence. A configuredCloseHandlerwill determine whether more reads or writes will be allowed on thisNettyConnectionContext.
-
nettyChannel
public io.netty.channel.Channel nettyChannel()
Description copied from interface:NettyConnectionContextReturn the NettyChannelbacking this connection.- Specified by:
nettyChannelin interfaceNettyConnectionContext- Returns:
- the Netty
Channelbacking this connection.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
updateFlushStrategy
public Cancellable updateFlushStrategy(NettyConnectionContext.FlushStrategyProvider strategyProvider)
Description copied from interface:NettyConnectionContextUpdatesFlushStrategyassociated with this connection. UpdatedFlushStrategywill be used in any subsequent writes on this connection.- Specified by:
updateFlushStrategyin interfaceNettyConnectionContext- Parameters:
strategyProvider-NettyConnectionContext.FlushStrategyProviderto 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
Cancellablethat will cancel this update.
-
defaultFlushStrategy
public FlushStrategy defaultFlushStrategy()
Description copied from interface:NettyConnectionContextReturns theFlushStrategyused by default for thisNettyConnectionContext.- Specified by:
defaultFlushStrategyin interfaceNettyConnectionContext- Returns:
- The
FlushStrategyused by default for thisNettyConnectionContext.
-
transportError
public Single<java.lang.Throwable> transportError()
Description copied from interface:NettyConnectionContextReturns aSingle<Throwable> that may terminate with an error, if an error is observed at the transport.- Specified by:
transportErrorin interfaceNettyConnectionContext- Returns:
- a
Single<Throwable> that may terminate with an error, if an error is observed at the transport.
-
-