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
  • Constructor Details

  • Method Details

    • addReactiveBridge

      public static void addReactiveBridge(Channel ch, ChannelOperations.OnSetup opsFactory, ConnectionObserver listener)
      Add 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).
      Parameters:
      ch - the channel to bridge
      opsFactory - the operations factory to invoke on channel active
      listener - the listener to forward connection events to
    • addMetricsHandler

      public static void addMetricsHandler(Channel ch, ChannelMetricsRecorder recorder, @Nullable SocketAddress remoteAddress, boolean onServer)
      Add NettyPipeline.ChannelMetricsHandler to the channel pipeline.
      Parameters:
      ch - the channel
      recorder - the configured metrics recorder
      remoteAddress - the remote address
      onServer - true if ChannelMetricsRecorder is for the server, false if it is for the client
    • get

      public static @Nullable ChannelOperations<?,?> get(Channel ch)
      Return the current Channel bound ChannelOperations or null if none.
      Parameters:
      ch - the current Channel
      Returns:
      the current Channel bound ChannelOperations or null if none
    • as

      public <T extends Connection> @Nullable T as(Class<T> clazz)
      Description copied from interface: Connection
      Return an existing Connection that must match the given type wrapper or null.
      Specified by:
      as in interface Connection
      Parameters:
      clazz - connection type to match to
      Returns:
      a matching Connection reference or null
    • alloc

      public ByteBufAllocator alloc()
      Description copied from interface: NettyOutbound
      Returns the assigned ByteBufAllocator.
      Specified by:
      alloc in interface NettyOutbound
      Returns:
      the ByteBufAllocator
    • inbound

      public NettyInbound inbound()
      Description copied from interface: Connection
      Return the NettyInbound read API from this connection. If Connection has not been configured with a supporting bridge, receive operations will be unavailable.
      Specified by:
      inbound in interface Connection
      Returns:
      the NettyInbound read API from this connection.
    • outbound

      public NettyOutbound outbound()
      Description copied from interface: Connection
      Return the NettyOutbound write API from this connection. If Connection has not been configured with a supporting bridge, send operations will be unavailable.
      Specified by:
      outbound in interface Connection
      Returns:
      the NettyOutbound read API from this connection.
    • channel

      public final Channel channel()
      Description copied from interface: DisposableChannel
      Returns the underlying Channel. 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:
      channel in interface DisposableChannel
      Returns:
      the underlying Channel
    • withConnection

      public ChannelOperations<INBOUND,OUTBOUND> withConnection(Consumer<? super Connection> withConnection)
      Description copied from interface: NettyInbound
      Calls the passed callback with a Connection to operate on the underlying Channel state. This allows for chaining inbound API.
      Specified by:
      withConnection in interface NettyInbound
      Specified by:
      withConnection in interface NettyOutbound
      Parameters:
      withConnection - connection callback
      Returns:
      the Connection
    • dispose

      public void dispose()
      Description copied from interface: DisposableChannel
      Releases or closes the underlying Channel.
      Specified by:
      dispose in interface Disposable
      Specified by:
      dispose in interface DisposableChannel
    • disposeSubscriber

      public CoreSubscriber<Void> disposeSubscriber()
      Description copied from interface: DisposableChannel
      Returns a CoreSubscriber that will dispose on complete or error.
      Specified by:
      disposeSubscriber in interface DisposableChannel
    • isDisposed

      public final boolean isDisposed()
      Specified by:
      isDisposed in interface Disposable
      Specified by:
      isDisposed in interface DisposableChannel
    • isSubscriptionDisposed

      public final boolean isSubscriptionDisposed()
      Return true if dispose subscription has been terminated.
      Returns:
      true if dispose subscription has been terminated
    • onDispose

      public final Mono<Void> onDispose()
      Description copied from interface: DisposableChannel
      Returns an observing Mono terminating with success when shutdown successfully or error.
      Specified by:
      onDispose in interface DisposableChannel
      Returns:
      a Mono terminating with success if shutdown successfully or error
    • onDispose

      public Connection onDispose(Disposable onDispose)
      Description copied from interface: DisposableChannel
      Assigns a Disposable to be invoked when the channel is closed.
      Specified by:
      onDispose in interface Connection
      Specified by:
      onDispose in interface DisposableChannel
      Parameters:
      onDispose - the close event handler
      Returns:
      this
    • onComplete

      public final void onComplete()
      Specified by:
      onComplete in interface Subscriber<INBOUND extends NettyInbound>
    • onError

      public final void onError(Throwable t)
      Specified by:
      onError in interface Subscriber<INBOUND extends NettyInbound>
    • onNext

      public final void onNext(Void aVoid)
      Specified by:
      onNext in interface Subscriber<INBOUND extends NettyInbound>
    • onSubscribe

      public final void onSubscribe(Subscription s)
      Specified by:
      onSubscribe in interface CoreSubscriber<INBOUND extends NettyInbound>
      Specified by:
      onSubscribe in interface Subscriber<INBOUND extends NettyInbound>
    • receiveObject

      public Flux<?> receiveObject()
      Description copied from interface: NettyInbound
      a Object inbound Flux.
      Specified by:
      receiveObject in interface NettyInbound
      Returns:
      a Object inbound Flux
    • receive

      public ByteBufFlux receive()
      Description copied from interface: NettyInbound
      A Flux extension that allows for extra decoding operators.
      Specified by:
      receive in interface NettyInbound
      Returns:
      a new ByteBufFlux
    • send

      public NettyOutbound send(Publisher<? extends ByteBuf> dataStream, Predicate<ByteBuf> predicate)
      Description copied from interface: NettyOutbound
      Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error).

      A new NettyOutbound type (or the same) for typed send sequences.

      Note: Nesting any send* method is not supported.

      Specified by:
      send in interface NettyOutbound
      Parameters:
      dataStream - the dataStream publishing OUT items to write on this channel
      predicate - that returns true if explicit flush operation is needed after that buffer
      Returns:
      A new NettyOutbound to append further send. It will emit a complete signal successful sequence write (e.g. after "flush") or any error during write.
    • sendObject

      public NettyOutbound sendObject(Publisher<?> dataStream, Predicate<Object> predicate)
      Description copied from interface: NettyOutbound
      Sends an object through Netty pipeline. If type of Publisher, sends all signals, flushing on complete by default. Write occur in FIFO sequence.

      Note: Nesting any send* method is not supported.

      Specified by:
      sendObject in interface NettyOutbound
      Parameters:
      dataStream - the dataStream publishing items to write on this channel or a simple pojo supported by configured Netty handlers
      predicate - 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

      public NettyOutbound sendObject(Object message)
      Description copied from interface: NettyOutbound
      Sends 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:
      sendObject in interface NettyOutbound
      Parameters:
      message - the object to publish
      Returns:
      A Mono to 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: NettyOutbound
      Binds a send to a starting/cleanup lifecycle

      Note: Nesting any send* method is not supported.

      Specified by:
      sendUsing in interface NettyOutbound
      Type Parameters:
      S - state type
      Parameters:
      sourceInput - state generator
      mappedInput - input to send
      sourceCleanup - state cleaner
      Returns:
      a new NettyOutbound
    • onTerminate

      public final Mono<Void> onTerminate()
      Return a Mono succeeding when a ChannelOperations has been terminated.
      Specified by:
      onTerminate in interface Connection
      Returns:
      a Mono succeeding when a ChannelOperations has been terminated
    • listener

      public final ConnectionObserver listener()
      Return the available parent ConnectionObserver for user-facing lifecycle handling.
      Returns:
      the available parent ConnectionObserverfor user-facing lifecycle handling
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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

      protected void onInboundNext(ChannelHandlerContext ctx, Object msg)
      React on inbound Channel.read().
      Parameters:
      ctx - the context
      msg - 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

      protected void onOutboundError(Throwable err)
      React on inbound/outbound error.
      Parameters:
      err - the Throwable cause
    • terminate

      protected final void terminate()
      Final release/close (last packet).
    • onInboundError

      protected final void onInboundError(Throwable err)
      React on inbound error.
      Parameters:
      err - the Throwable cause
    • connection

      protected final Connection connection()
      Return the delegate IO Connection for low-level IO access.
      Returns:
      the delegate IO Connection for low-level IO access
    • formatName

      protected final String formatName()
      Return formatted name of this operation.
      Returns:
      formatted name of this operation
    • initShortId

      protected String initShortId()
    • wrapInboundError

      protected Throwable wrapInboundError(Throwable err)
      Wrap an inbound error.
      Parameters:
      err - the Throwable cause
    • asDebugLogMessage

      protected String asDebugLogMessage(Object o)
      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

      protected void onUnprocessedOutboundError(Throwable t)
      React on an unprocessed outbound error.
      Since:
      1.0.39
    • isPersistent

      public boolean isPersistent()
      Description copied from interface: Connection
      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.
      Specified by:
      isPersistent in interface Connection
      Returns:
      whether the underlying Connection will be disposed on terminal handler event
    • currentContext

      public Context currentContext()
      Specified by:
      currentContext in interface CoreSubscriber<INBOUND extends NettyInbound>
    • asShortText

      public String asShortText()
      Description copied from interface: ChannelOperationsId
      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.

      Format of the short string:

       <CONNECTION_ID>-<REQUEST_NUMBER>
       

      Example:

       
           <CONNECTION_ID>: 329c6ffd
           <REQUEST_NUMBER>: 5
      
           Result: 329c6ffd-5
       
       

      Specified by:
      asShortText in interface ChannelOperationsId
    • asLongText

      public String asLongText()
      Description copied from interface: ChannelOperationsId
      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.

      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:
      asLongText in interface ChannelOperationsId