Package reactor.netty.channel
Class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
java.lang.Object
reactor.netty.channel.ChannelOperations<INBOUND,OUTBOUND>
- All Implemented Interfaces:
Publisher<Void>,Subscriber<Void>,CoreSubscriber<Void>,Disposable,ChannelOperationsId,Connection,DisposableChannel,NettyInbound,NettyOutbound
- Direct Known Subclasses:
HttpOperations
public class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
extends Object
implements NettyInbound, NettyOutbound, Connection, CoreSubscriber<Void>, ChannelOperationsId
- Since:
- 0.6
- Author:
- Stephane Maldini
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface reactor.core.Disposable
Disposable.Composite, Disposable.Swap -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedChannelOperations(ChannelOperations<INBOUND, OUTBOUND> replaced) ChannelOperations(Connection connection, ConnectionObserver listener) Create a newChannelOperationsattached to theChannel. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMetricsHandler(Channel ch, ChannelMetricsRecorder recorder, @Nullable SocketAddress remoteAddress, boolean onServer) AddNettyPipeline.ChannelMetricsHandlerto the channel pipeline.static voidaddReactiveBridge(Channel ch, ChannelOperations.OnSetup opsFactory, ConnectionObserver listener) AddNettyPipeline.ReactiveBridgehandler at the end ofChannelpipeline.protected voidReact after inbound completion (last packet).alloc()Returns the assignedByteBufAllocator.<T extends Connection>
@Nullable TReturn an existingConnectionthat must match the given type wrapper or null.protected StringTransforms the object to a string for debug logs.The long string is a combination of the id of the underlying connection, local and remote addresses, and in case of HTTP, the serial number of the request received on that connection.The short string is a combination of the id of the underlying connection and in case of HTTP, the serial number of the request received on that connection.final Channelchannel()Returns the underlyingChannel.protected final ConnectionReturn the delegate IOConnectionfor low-level IO access.final voiddiscard()Drop pending content and complete inbound.protected final voidDrop pending content and complete inbound.voiddispose()Releases or closes the underlyingChannel.Returns aCoreSubscriberthat will dispose on complete or error.protected final StringReturn formatted name of this operation.static @Nullable ChannelOperations<?,?> Return the currentChannelboundChannelOperationsor null if none.inbound()Return theNettyInboundread API from this connection.protected Stringfinal booleanfinal booleanReturn true if inbound traffic is not expected anymore.protected final booleanReturn true if inbound traffic is not incoming or expected anymore.final booleanReturn true if inbound traffic is not incoming or expected anymore.booleanReturn 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.final booleanReturn true if dispose subscription has been terminated.final ConnectionObserverlistener()Return the available parentConnectionObserverfor user-facing lifecycle handling.final voidReturns an observingMonoterminating with success when shutdown successfully or error.onDispose(Disposable onDispose) Assigns aDisposableto be invoked when the channel is closed.final voidprotected voidReact on inbound cancel (receive() subscriber cancelled).protected voidReact on inbound close (channel closed prematurely).protected voidReact on inbound completion (last packet).protected final voidonInboundError(Throwable err) React on inbound error.protected voidonInboundNext(ChannelHandlerContext ctx, Object msg) React on inboundChannel.read().final voidprotected voidReact on inbound/outbound completion (last packet).protected voidonOutboundError(Throwable err) React on inbound/outbound error.final voidReturn a Mono succeeding when aChannelOperationshas been terminated.protected voidReact on an unprocessed outbound error.protected voidReact on Channel writability change.outbound()Return theNettyOutboundwrite API from this connection.receive()AFluxextension that allows for extra decoding operators.Flux<?>a Object inboundFlux.Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error).sendObject(Object message) Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error).sendObject(Publisher<?> dataStream, Predicate<Object> predicate) Sends an object through Netty pipeline.<S> NettyOutboundsendUsing(Callable<? extends S> sourceInput, BiFunction<? super Connection, ? super S, ?> mappedInput, Consumer<? super S> sourceCleanup) Binds a send to a starting/cleanup lifecycleprotected final voidFinal release/close (last packet).toString()withConnection(Consumer<? super Connection> withConnection) Calls the passed callback with aConnectionto operate on the underlyingChannelstate.protected ThrowableWrap an inbound error.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.netty.Connection
addHandler, addHandler, addHandlerFirst, addHandlerFirst, addHandlerLast, addHandlerLast, bind, markPersistent, onReadIdle, onWriteIdle, rebind, removeHandler, replaceHandlerMethods inherited from interface reactor.netty.DisposableChannel
address, disposeNow, disposeNowMethods inherited from interface reactor.netty.NettyOutbound
neverComplete, send, sendByteArray, sendFile, sendFile, sendFileChunked, sendGroups, sendObject, sendString, sendString, subscribe, then, then, then
-
Constructor Details
-
ChannelOperations
-
ChannelOperations
Create a newChannelOperationsattached to theChannel. Attach theNettyPipeline.ReactiveBridgehandle.- Parameters:
connection- the newConnectionconnectionlistener- the events callback
-
-
Method Details
-
addReactiveBridge
public static void addReactiveBridge(Channel ch, ChannelOperations.OnSetup opsFactory, ConnectionObserver listener) AddNettyPipeline.ReactiveBridgehandler at the end ofChannelpipeline. The bridge will buffer outgoing write and pass along incoming read to the currentget(Channel).- Parameters:
ch- the channel to bridgeopsFactory- the operations factory to invoke on channel activelistener- the listener to forward connection events to
-
addMetricsHandler
public static void addMetricsHandler(Channel ch, ChannelMetricsRecorder recorder, @Nullable SocketAddress remoteAddress, boolean onServer) AddNettyPipeline.ChannelMetricsHandlerto the channel pipeline.- Parameters:
ch- the channelrecorder- the configured metrics recorderremoteAddress- the remote addressonServer- true ifChannelMetricsRecorderis for the server, false if it is for the client
-
get
Return the currentChannelboundChannelOperationsor null if none.- Parameters:
ch- the currentChannel- Returns:
- the current
ChannelboundChannelOperationsor null if none
-
as
Description copied from interface:ConnectionReturn an existingConnectionthat must match the given type wrapper or null.- Specified by:
asin interfaceConnection- Parameters:
clazz- connection type to match to- Returns:
- a matching
Connectionreference or null
-
alloc
Description copied from interface:NettyOutboundReturns the assignedByteBufAllocator.- Specified by:
allocin interfaceNettyOutbound- Returns:
- the
ByteBufAllocator
-
inbound
Description copied from interface:ConnectionReturn theNettyInboundread API from this connection. IfConnectionhas not been configured with a supporting bridge, receive operations will be unavailable.- Specified by:
inboundin interfaceConnection- Returns:
- the
NettyInboundread API from this connection.
-
outbound
Description copied from interface:ConnectionReturn theNettyOutboundwrite API from this connection. IfConnectionhas not been configured with a supporting bridge, send operations will be unavailable.- Specified by:
outboundin interfaceConnection- Returns:
- the
NettyOutboundread API from this connection.
-
channel
Description copied from interface:DisposableChannelReturns the underlyingChannel. Direct interaction might be considered insecure if that affects the underlying I/O processing such as read, write or close or state such as pipeline handler addition/removal.- Specified by:
channelin interfaceDisposableChannel- Returns:
- the underlying
Channel
-
withConnection
public ChannelOperations<INBOUND,OUTBOUND> withConnection(Consumer<? super Connection> withConnection) Description copied from interface:NettyInboundCalls the passed callback with aConnectionto operate on the underlyingChannelstate. This allows for chaining inbound API.- Specified by:
withConnectionin interfaceNettyInbound- Specified by:
withConnectionin interfaceNettyOutbound- Parameters:
withConnection- connection callback- Returns:
- the
Connection
-
dispose
public void dispose()Description copied from interface:DisposableChannelReleases or closes the underlyingChannel.- Specified by:
disposein interfaceDisposable- Specified by:
disposein interfaceDisposableChannel
-
disposeSubscriber
Description copied from interface:DisposableChannelReturns aCoreSubscriberthat will dispose on complete or error.- Specified by:
disposeSubscriberin interfaceDisposableChannel
-
isDisposed
public final boolean isDisposed()- Specified by:
isDisposedin interfaceDisposable- Specified by:
isDisposedin interfaceDisposableChannel
-
isSubscriptionDisposed
public final boolean isSubscriptionDisposed()Return true if dispose subscription has been terminated.- Returns:
- true if dispose subscription has been terminated
-
onDispose
Description copied from interface:DisposableChannelReturns an observingMonoterminating with success when shutdown successfully or error.- Specified by:
onDisposein interfaceDisposableChannel- Returns:
- a
Monoterminating with success if shutdown successfully or error
-
onDispose
Description copied from interface:DisposableChannelAssigns aDisposableto be invoked when the channel is closed.- Specified by:
onDisposein interfaceConnection- Specified by:
onDisposein interfaceDisposableChannel- Parameters:
onDispose- the close event handler- Returns:
- this
-
onComplete
public final void onComplete()- Specified by:
onCompletein interfaceSubscriber<INBOUND extends NettyInbound>
-
onError
- Specified by:
onErrorin interfaceSubscriber<INBOUND extends NettyInbound>
-
onNext
- Specified by:
onNextin interfaceSubscriber<INBOUND extends NettyInbound>
-
onSubscribe
- Specified by:
onSubscribein interfaceCoreSubscriber<INBOUND extends NettyInbound>- Specified by:
onSubscribein interfaceSubscriber<INBOUND extends NettyInbound>
-
receiveObject
Description copied from interface:NettyInbounda Object inboundFlux.- Specified by:
receiveObjectin interfaceNettyInbound- Returns:
- a Object inbound
Flux
-
receive
Description copied from interface:NettyInboundAFluxextension that allows for extra decoding operators.- Specified by:
receivein interfaceNettyInbound- Returns:
- a new
ByteBufFlux
-
send
Description copied from interface:NettyOutboundSends data to the peer, listens for any error on write and closes on terminal signal (complete|error).A new
NettyOutboundtype (or the same) for typed send sequences.Note: Nesting any send* method is not supported.
- Specified by:
sendin interfaceNettyOutbound- Parameters:
dataStream- the dataStream publishing OUT items to write on this channelpredicate- that returns true if explicit flush operation is needed after that buffer- Returns:
- A new
NettyOutboundto append further send. It will emit a complete signal successful sequence write (e.g. after "flush") or any error during write.
-
sendObject
Description copied from interface:NettyOutboundSends an object through Netty pipeline. If type ofPublisher, sends all signals, flushing on complete by default. Write occur in FIFO sequence.Note: Nesting any send* method is not supported.
- Specified by:
sendObjectin interfaceNettyOutbound- Parameters:
dataStream- the dataStream publishing items to write on this channel or a simple pojo supported by configured Netty handlerspredicate- that returns true if explicit flush operation is needed after that object- Returns:
- A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
-
sendObject
Description copied from interface:NettyOutboundSends data to the peer, listens for any error on write and closes on terminal signal (complete|error).Note: Nesting any send* method is not supported.
- Specified by:
sendObjectin interfaceNettyOutbound- Parameters:
message- the object to publish- Returns:
- A
Monoto signal successful sequence write (e.g. after "flush") or any error during write
-
sendUsing
public <S> NettyOutbound sendUsing(Callable<? extends S> sourceInput, BiFunction<? super Connection, ? super S, ?> mappedInput, Consumer<? super S> sourceCleanup) Description copied from interface:NettyOutboundBinds a send to a starting/cleanup lifecycleNote: Nesting any send* method is not supported.
- Specified by:
sendUsingin interfaceNettyOutbound- Type Parameters:
S- state type- Parameters:
sourceInput- state generatormappedInput- input to sendsourceCleanup- state cleaner- Returns:
- a new
NettyOutbound
-
onTerminate
Return a Mono succeeding when aChannelOperationshas been terminated.- Specified by:
onTerminatein interfaceConnection- Returns:
- a Mono succeeding when a
ChannelOperationshas been terminated
-
listener
Return the available parentConnectionObserverfor user-facing lifecycle handling.- Returns:
- the available parent
ConnectionObserverfor user-facing lifecycle handling
-
toString
-
discard
public final void discard()Drop pending content and complete inbound. Always discard content regardless whether there is a receiver. -
discardWhenNoReceiver
protected final void discardWhenNoReceiver()Drop pending content and complete inbound. Discard content only in case there is no receiver. -
isInboundCancelled
public final boolean isInboundCancelled()Return true if inbound traffic is not expected anymore.- Returns:
- true if inbound traffic is not expected anymore
-
isInboundDisposed
public final boolean isInboundDisposed()Return true if inbound traffic is not incoming or expected anymore. The buffered data is consumed.- Returns:
- true if inbound traffic is not incoming or expected anymore. The buffered data is consumed
-
isInboundComplete
protected final boolean isInboundComplete()Return true if inbound traffic is not incoming or expected anymore. The buffered data might still not be consumed.- Returns:
- true if inbound traffic is not incoming or expected anymore. The buffered data might still not be consumed.
-
onInboundNext
React on inboundChannel.read().- Parameters:
ctx- the contextmsg- the read payload
-
onInboundCancel
protected void onInboundCancel()React on inbound cancel (receive() subscriber cancelled). -
onInboundComplete
protected void onInboundComplete()React on inbound completion (last packet). -
afterInboundComplete
protected void afterInboundComplete()React after inbound completion (last packet). -
onInboundClose
protected void onInboundClose()React on inbound close (channel closed prematurely). -
onOutboundComplete
protected void onOutboundComplete()React on inbound/outbound completion (last packet). -
onOutboundError
React on inbound/outbound error.- Parameters:
err- theThrowablecause
-
terminate
protected final void terminate()Final release/close (last packet). -
onInboundError
React on inbound error.- Parameters:
err- theThrowablecause
-
connection
Return the delegate IOConnectionfor low-level IO access.- Returns:
- the delegate IO
Connectionfor low-level IO access
-
formatName
Return formatted name of this operation.- Returns:
- formatted name of this operation
-
initShortId
-
wrapInboundError
Wrap an inbound error.- Parameters:
err- theThrowablecause
-
asDebugLogMessage
Transforms the object to a string for debug logs.- Parameters:
o- the object to be transformed- Returns:
- the string to be logged
- Since:
- 1.0.24
-
onWritabilityChanged
protected void onWritabilityChanged()React on Channel writability change.- Since:
- 1.0.37
-
onUnprocessedOutboundError
React on an unprocessed outbound error.- Since:
- 1.0.39
-
isPersistent
public boolean isPersistent()Description copied from interface:ConnectionReturn 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.- Specified by:
isPersistentin interfaceConnection- Returns:
- whether the underlying
Connectionwill be disposed on terminal handler event
-
currentContext
- Specified by:
currentContextin interfaceCoreSubscriber<INBOUND extends NettyInbound>
-
asShortText
Description copied from interface:ChannelOperationsIdThe short string is a combination of the id of the underlying connection and in case of HTTP, the serial number of the request received on that connection.Format of the short string:
<CONNECTION_ID>-<REQUEST_NUMBER>Example:
<CONNECTION_ID>: 329c6ffd <REQUEST_NUMBER>: 5 Result: 329c6ffd-5- Specified by:
asShortTextin interfaceChannelOperationsId
-
asLongText
Description copied from interface:ChannelOperationsIdThe long string is a combination of the id of the underlying connection, local and remote addresses, and in case of HTTP, the serial number of the request received on that connection.Format of the long string:
<CONNECTION_ID>-<REQUEST_NUMBER>, L:<LOCAL_ADDRESS> <CONNECTION_OPENED_CLOSED> R:<REMOTE_ADDRESS>Example:
Opened connection <CONNECTION_ID>: 329c6ffd <REQUEST_NUMBER>: 5 <LOCAL_ADDRESS>: /0:0:0:0:0:0:0:1:64286 <CONNECTION_OPENED_CLOSED>: - (opened) <REMOTE_ADDRESS>: /0:0:0:0:0:0:0:1:64284 Result: 329c6ffd-5, L:/0:0:0:0:0:0:0:1:64286 - R:/0:0:0:0:0:0:0:1:64284 Closed connection <CONNECTION_ID>: 329c6ffd <REQUEST_NUMBER>: 5 <LOCAL_ADDRESS>: /0:0:0:0:0:0:0:1:64286 <CONNECTION_OPENED_CLOSED>: ! (closed) <REMOTE_ADDRESS>: /0:0:0:0:0:0:0:1:64284 Result: 329c6ffd-5, L:/0:0:0:0:0:0:0:1:64286 ! R:/0:0:0:0:0:0:0:1:64284- Specified by:
asLongTextin interfaceChannelOperationsId
-