public class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound> extends DefaultPromise<Void> implements NettyInbound, NettyOutbound, Connection, CoreSubscriber<Void>, ChannelPromise
Modifier and Type | Class and Description |
---|---|
static interface |
ChannelOperations.OnSetup
A
ChannelOperations factory |
Disposable.Composite, Disposable.Swap
Modifier | Constructor and Description |
---|---|
protected |
ChannelOperations(ChannelOperations<INBOUND,OUTBOUND> replaced) |
|
ChannelOperations(Connection connection,
ConnectionObserver listener)
Create a new
ChannelOperations attached to the Channel . |
Modifier and Type | Method and Description |
---|---|
ChannelPromise |
addListener(GenericFutureListener<? extends Future<? super Void>> listener) |
ChannelPromise |
addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) |
static void |
addReactiveBridge(Channel ch,
ChannelOperations.OnSetup opsFactory,
ConnectionObserver listener)
Add
NettyPipeline.ReactiveBridge handler at the end of Channel
pipeline. |
ByteBufAllocator |
alloc()
Return the assigned
ByteBufAllocator . |
<T extends Connection> |
as(Class<T> clazz)
Return an existing
Connection that must match the given type wrapper or
null. |
ChannelPromise |
await() |
ChannelPromise |
awaitUninterruptibly() |
Channel |
channel()
Return the underlying
Channel . |
protected Connection |
connection()
Return the delegate IO
Connection for low-level IO access |
Context |
currentContext() |
void |
discard()
Drop pending content and complete inbound
|
void |
dispose()
Release or close the underlying
Channel |
CoreSubscriber<Void> |
disposeSubscriber()
Return a
CoreSubscriber that will dispose on complete or error |
protected String |
formatName()
Return formatted name of this operation
|
static ChannelOperations<?,?> |
get(Channel ch)
Return the current
Channel bound ChannelOperations or null if none |
NettyInbound |
inbound()
Return the
NettyInbound read API from this connection. |
boolean |
isDisposed() |
boolean |
isInboundCancelled()
Return true if inbound traffic is not expected anymore
|
boolean |
isInboundDisposed()
Return true if inbound traffic is not incoming or expected anymore
|
boolean |
isPersistent()
Return false if it will force a close on terminal protocol events thus defeating
any pooling strategy
Return true (default) if it will release on terminal protocol events thus
keeping alive the channel if possible.
|
boolean |
isVoid() |
ConnectionObserver |
listener()
Return the available parent
ConnectionObserver for user-facing lifecycle
handling |
void |
onComplete() |
Mono<Void> |
onDispose()
Return an observing
Mono terminating with success when shutdown
successfully or error. |
Connection |
onDispose(Disposable onDispose)
Assign a
Disposable to be invoked when the channel is closed. |
void |
onError(Throwable t) |
protected void |
onInboundCancel()
React on inbound cancel (receive() subscriber cancelled)
|
protected void |
onInboundClose()
React on inbound close (channel closed prematurely)
|
protected void |
onInboundComplete()
React on inbound completion (last packet)
|
protected void |
onInboundError(Throwable err)
React on inbound error
|
protected void |
onInboundNext(ChannelHandlerContext ctx,
Object msg)
React on inbound
Channel.read() |
void |
onNext(Void aVoid) |
protected void |
onOutboundComplete()
React on inbound/outbound completion (last packet)
|
protected void |
onOutboundError(Throwable err)
React on inbound/outbound error
|
void |
onSubscribe(Subscription s) |
Mono<Void> |
onTerminate()
Return a Mono succeeding when a
ChannelOperations has been terminated |
NettyOutbound |
outbound()
Return the
NettyOutbound write API from this connection. |
ByteBufFlux |
receive()
A
Flux extension that allows for extra decoding operators |
Flux<?> |
receiveObject()
a Object inbound
Flux |
ChannelPromise |
removeListener(GenericFutureListener<? extends Future<? super Void>> listener) |
ChannelPromise |
removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) |
NettyOutbound |
sendObject(Object message)
Send data to the peer, listen for any error on write and close on terminal signal
(complete|error).
|
NettyOutbound |
sendObject(Publisher<?> dataStream)
Send an object through netty pipeline.
|
<S> NettyOutbound |
sendUsing(Callable<? extends S> sourceInput,
java.util.function.BiFunction<? super Connection,? super S,?> mappedInput,
java.util.function.Consumer<? super S> sourceCleanup)
Bind a send to a starting/cleanup lifecycle
Note: Nesting any send* method is not supported.
|
ChannelPromise |
setFailure(Throwable cause) |
ChannelPromise |
setSuccess() |
ChannelPromise |
setSuccess(Void result) |
ChannelPromise |
sync() |
ChannelPromise |
syncUninterruptibly() |
protected void |
terminate()
Final release/close (last packet)
|
String |
toString() |
boolean |
trySuccess() |
ChannelPromise |
unvoid() |
ChannelOperations<INBOUND,OUTBOUND> |
withConnection(java.util.function.Consumer<? super Connection> withConnection)
Call the passed callback with a
Connection to operate on the
underlying
Channel state. |
await, await, awaitUninterruptibly, awaitUninterruptibly, cancel, cause, checkDeadLock, executor, getNow, isCancellable, isCancelled, isDone, isSuccess, notifyListener, setUncancellable, toStringBuilder, tryFailure, trySuccess
get, get
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
neverComplete, options, send, sendByteArray, sendFile, sendFile, sendFileChunked, sendGroups, sendString, sendString, subscribe, then, then
addHandler, addHandler, addHandlerFirst, addHandlerFirst, addHandlerLast, addHandlerLast, bind, from, markPersistent, onReadIdle, onWriteIdle, rebind, removeHandler, replaceHandler
address, disposeNow, disposeNow
setUncancellable, tryFailure, trySuccess
await, await, awaitUninterruptibly, awaitUninterruptibly, cancel, cause, getNow, isCancellable, isSuccess
get, get, isCancelled, isDone
protected ChannelOperations(ChannelOperations<INBOUND,OUTBOUND> replaced)
public ChannelOperations(Connection connection, ConnectionObserver listener)
ChannelOperations
attached to the Channel
. Attach the NettyPipeline.ReactiveBridge
handle.connection
- the new Connection
connectionlistener
- the events callbackpublic static void addReactiveBridge(Channel ch, ChannelOperations.OnSetup opsFactory, ConnectionObserver listener)
NettyPipeline.ReactiveBridge
handler at the end of Channel
pipeline. The bridge will buffer outgoing write and pass along incoming read to
the current get(Channel)
.ch
- the channel to bridgeopsFactory
- the operations factory to invoke on channel activelistener
- the listener to forward connection events to@Nullable public static ChannelOperations<?,?> get(Channel ch)
Channel
bound ChannelOperations
or null if nonech
- the current Channel
Channel
bound ChannelOperations
or null if none@Nullable public <T extends Connection> T as(Class<T> clazz)
Connection
Connection
that must match the given type wrapper or
null.as
in interface Connection
clazz
- connection type to match toConnection
reference or nullpublic ByteBufAllocator alloc()
NettyOutbound
ByteBufAllocator
.alloc
in interface NettyOutbound
ByteBufAllocator
public NettyInbound inbound()
Connection
NettyInbound
read API from this connection. If
Connection
has not been configured with a supporting bridge, receive
operations will be unavailable.inbound
in interface Connection
NettyInbound
read API from this connection.public NettyOutbound outbound()
Connection
NettyOutbound
write API from this connection. If
Connection
has not been configured with a supporting bridge, send
operations will be unavailable.outbound
in interface Connection
NettyOutbound
read API from this connection.public final Channel channel()
DisposableChannel
Channel
. Direct interaction might be considered
insecure if that affects the underlying IO processing such as read, write or close
or state such as pipeline handler addition/removal.channel
in interface ChannelFuture
channel
in interface ChannelPromise
channel
in interface DisposableChannel
Channel
public ChannelOperations<INBOUND,OUTBOUND> withConnection(java.util.function.Consumer<? super Connection> withConnection)
NettyInbound
Connection
to operate on the
underlying
Channel
state. This allows for chaining inbound API.withConnection
in interface NettyInbound
withConnection
in interface NettyOutbound
withConnection
- connection callbackConnection
public void dispose()
DisposableChannel
Channel
dispose
in interface Disposable
dispose
in interface DisposableChannel
public CoreSubscriber<Void> disposeSubscriber()
DisposableChannel
CoreSubscriber
that will dispose on complete or errordisposeSubscriber
in interface DisposableChannel
public final boolean isDisposed()
isDisposed
in interface Disposable
isDisposed
in interface DisposableChannel
public final Mono<Void> onDispose()
DisposableChannel
Mono
terminating with success when shutdown
successfully or error.onDispose
in interface DisposableChannel
Mono
terminating with success if shutdown successfully or errorpublic Connection onDispose(Disposable onDispose)
DisposableChannel
Disposable
to be invoked when the channel is closed.onDispose
in interface Connection
onDispose
in interface DisposableChannel
onDispose
- the close event handlerpublic final void onComplete()
onComplete
in interface Subscriber<Void>
public final void onError(Throwable t)
onError
in interface Subscriber<Void>
public final void onNext(Void aVoid)
onNext
in interface Subscriber<Void>
public final void onSubscribe(Subscription s)
onSubscribe
in interface Subscriber<Void>
onSubscribe
in interface CoreSubscriber<Void>
public Flux<?> receiveObject()
NettyInbound
Flux
receiveObject
in interface NettyInbound
Flux
public ByteBufFlux receive()
NettyInbound
Flux
extension that allows for extra decoding operatorsreceive
in interface NettyInbound
ByteBufFlux
public NettyOutbound sendObject(Publisher<?> dataStream)
NettyOutbound
sendObject
in interface NettyOutbound
dataStream
- the dataStream publishing items to write on this channel
or a simple pojo supported by configured netty handlerspublic NettyOutbound sendObject(Object message)
NettyOutbound
sendObject
in interface NettyOutbound
message
- the object to publishMono
to signal successful sequence write (e.g. after "flush") or
any error during writepublic <S> NettyOutbound sendUsing(Callable<? extends S> sourceInput, java.util.function.BiFunction<? super Connection,? super S,?> mappedInput, java.util.function.Consumer<? super S> sourceCleanup)
NettyOutbound
sendUsing
in interface NettyOutbound
S
- state typesourceInput
- state generatormappedInput
- input to sendsourceCleanup
- state cleanerNettyOutbound
public final Mono<Void> onTerminate()
ChannelOperations
has been terminatedonTerminate
in interface Connection
ChannelOperations
has been terminatedpublic final ConnectionObserver listener()
ConnectionObserver
for user-facing lifecycle
handlingConnectionObserver
for user-facing lifecycle
handlingpublic String toString()
toString
in class DefaultPromise<Void>
public final void discard()
public final boolean isInboundCancelled()
public final boolean isInboundDisposed()
protected void onInboundNext(ChannelHandlerContext ctx, Object msg)
Channel.read()
ctx
- the contextmsg
- the read payloadprotected void onInboundCancel()
protected void onInboundComplete()
protected void onInboundClose()
protected void onOutboundComplete()
protected void onOutboundError(Throwable err)
err
- the Throwable
causeprotected final void terminate()
protected final void onInboundError(Throwable err)
err
- the Throwable
causeprotected final Connection connection()
Connection
for low-level IO accessConnection
for low-level IO accessprotected final String formatName()
public ChannelPromise setSuccess()
setSuccess
in interface ChannelPromise
public ChannelPromise setSuccess(Void result)
setSuccess
in interface ChannelPromise
setSuccess
in interface Promise<Void>
setSuccess
in class DefaultPromise<Void>
public boolean trySuccess()
trySuccess
in interface ChannelPromise
public ChannelPromise unvoid()
unvoid
in interface ChannelPromise
public boolean isVoid()
isVoid
in interface ChannelFuture
public ChannelPromise setFailure(Throwable cause)
setFailure
in interface ChannelPromise
setFailure
in interface Promise<Void>
setFailure
in class DefaultPromise<Void>
public ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener)
addListener
in interface ChannelFuture
addListener
in interface ChannelPromise
addListener
in interface Promise<Void>
addListener
in class DefaultPromise<Void>
public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners)
addListeners
in interface ChannelFuture
addListeners
in interface ChannelPromise
addListeners
in interface Promise<Void>
addListeners
in class DefaultPromise<Void>
public ChannelPromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener)
removeListener
in interface ChannelFuture
removeListener
in interface ChannelPromise
removeListener
in interface Promise<Void>
removeListener
in class DefaultPromise<Void>
public ChannelPromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners)
removeListeners
in interface ChannelFuture
removeListeners
in interface ChannelPromise
removeListeners
in interface Promise<Void>
removeListeners
in class DefaultPromise<Void>
public ChannelPromise sync() throws InterruptedException
sync
in interface ChannelFuture
sync
in interface ChannelPromise
sync
in interface Promise<Void>
sync
in class DefaultPromise<Void>
InterruptedException
public ChannelPromise await() throws InterruptedException
await
in interface ChannelFuture
await
in interface ChannelPromise
await
in interface Promise<Void>
await
in class DefaultPromise<Void>
InterruptedException
public ChannelPromise awaitUninterruptibly()
awaitUninterruptibly
in interface ChannelFuture
awaitUninterruptibly
in interface ChannelPromise
awaitUninterruptibly
in interface Promise<Void>
awaitUninterruptibly
in class DefaultPromise<Void>
public ChannelPromise syncUninterruptibly()
syncUninterruptibly
in interface ChannelFuture
syncUninterruptibly
in interface ChannelPromise
syncUninterruptibly
in interface Promise<Void>
syncUninterruptibly
in class DefaultPromise<Void>
public boolean isPersistent()
Connection
isPersistent
in interface Connection
Connection
will be disposed on
terminal handler eventpublic Context currentContext()
currentContext
in interface CoreSubscriber<Void>