Package reactor.netty

Interface NettyOutbound

All Superinterfaces:
Publisher<Void>
All Known Subinterfaces:
HttpServerResponse, QuicOutbound, UdpOutbound, WebsocketOutbound
All Known Implementing Classes:
ChannelOperations, HttpOperations, HttpOperations.PostHeadersNettyOutbound

public interface NettyOutbound extends Publisher<Void>
An outbound-traffic API delegating to an underlying Channel.

Note: With HTTP, chaining multiple send operations is discouraged and will not work as expected when send involves scalar or mono publishers. For instance send(flux).send(mono) or send(flux).sendObject(message) will ignore send(flux). This is an anticipation of an API simplification moving forward next versions where send will not return NettyOutbound anymore.

Author:
Stephane Maldini
  • Method Details

    • alloc

      Returns the assigned ByteBufAllocator.
      Returns:
      the ByteBufAllocator
    • neverComplete

      default Mono<Void> neverComplete()
      Returns a never completing Mono after this then() has completed.
      Returns:
      a never completing Mono after this then() has completed.
    • send

      default NettyOutbound send(Publisher<? extends ByteBuf> dataStream)
      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.

      Parameters:
      dataStream - the dataStream publishing OUT items to write on this channel
      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.
    • send

      NettyOutbound send(Publisher<? extends ByteBuf> dataStream, Predicate<ByteBuf> predicate)
      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.

      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.
    • sendByteArray

      default NettyOutbound sendByteArray(Publisher<? extends byte[]> dataStream)
      Sends bytes to the peer, listens for any error on write and closes on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Parameters:
      dataStream - the dataStream publishing Buffer items to write on this channel
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendFile

      default NettyOutbound sendFile(Path file)
      Sends content from given Path using FileChannel.transferTo(long, long, WritableByteChannel) support. If the system supports it and the path resolves to a local file system File then transfer will use zero-byte copy to the peer.

      It will listen for any error on write and close on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: this will emit FileRegion in the outbound ChannelPipeline Note: Nesting any send* method is not supported.

      Parameters:
      file - the file Path
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendFile

      default NettyOutbound sendFile(Path file, long position, long count)
      Sends content from the given Path using FileChannel.transferTo(long, long, WritableByteChannel) support, if the system supports it, the path resolves to a local file system File, compression and SSL/TLS is not enabled, then transfer will use zero-byte copy to the peer., otherwise chunked read/write will be used.

      It will listens for any error on write and closes on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Parameters:
      file - the file Path
      position - where to start
      count - how much to transfer
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendFileChunked

      default NettyOutbound sendFileChunked(Path file, long position, long count)
      Sends content from given Path using chunked read/write.

      It will listen for any error on write and close on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Parameters:
      file - the file Path
      position - where to start
      count - how much to transfer
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendGroups

      default NettyOutbound sendGroups(Publisher<? extends Publisher<? extends ByteBuf>> dataStreams)
      Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error). Each individual Publisher completion will flush the underlying IO runtime.

      Note: Nesting any send* method is not supported.

      Parameters:
      dataStreams - the dataStream publishing OUT items to write on this channel
      Returns:
      A Mono to signal successful sequence write (e.g. after "flush") or any error during write
    • sendObject

      default NettyOutbound sendObject(Publisher<?> dataStream)
      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.

      Parameters:
      dataStream - the dataStream publishing items to write on this channel or a simple pojo supported by configured Netty handlers
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendObject

      NettyOutbound sendObject(Publisher<?> dataStream, Predicate<Object> predicate)
      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.

      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

      NettyOutbound sendObject(Object message)
      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.

      Parameters:
      message - the object to publish
      Returns:
      A Mono to signal successful sequence write (e.g. after "flush") or any error during write
    • sendString

      default NettyOutbound sendString(Publisher<? extends String> dataStream)
      Sends String to the peer, listens for any error on write and closes on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Parameters:
      dataStream - the dataStream publishing Buffer items to write on this channel
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendString

      default NettyOutbound sendString(Publisher<? extends String> dataStream, Charset charset)
      Sends String to the peer, listens for any error on write and closes on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Parameters:
      dataStream - the dataStream publishing Buffer items to write on this channel
      charset - the encoding charset
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • sendUsing

      <S> NettyOutbound sendUsing(Callable<? extends S> sourceInput, BiFunction<? super Connection,? super S,?> mappedInput, Consumer<? super S> sourceCleanup)
      Binds a send to a starting/cleanup lifecycle

      Note: Nesting any send* method is not supported.

      Type Parameters:
      S - state type
      Parameters:
      sourceInput - state generator
      mappedInput - input to send
      sourceCleanup - state cleaner
      Returns:
      a new NettyOutbound
    • subscribe

      default void subscribe(Subscriber<? super Void> s)
      Subscribes a Void subscriber to this outbound and trigger all eventual parent outbound send.
      Specified by:
      subscribe in interface Publisher<Void>
      Parameters:
      s - the Subscriber to listen for send sequence completion/failure
    • then

      default Mono<Void> then()
      Obtains a Mono of pending outbound(s) write completion.
      Returns:
      a Mono of pending outbound(s) write completion
    • then

      default NettyOutbound then(Publisher<Void> other)
      Appends a Publisher task such as a Mono and returns a new NettyOutbound to sequence further send.
      Parameters:
      other - the Publisher to subscribe to when this pending outbound then() is complete;
      Returns:
      a new NettyOutbound
    • then

      default NettyOutbound then(Publisher<Void> other, Runnable onCleanup)
      Append a Publisher task such as a Mono and return a new NettyOutbound to sequence further send.
      Parameters:
      other - the Publisher to subscribe to when this pending outbound then() is complete;
      onCleanup - a cleanup hook when other has terminated or cancelled
      Returns:
      a new NettyOutbound that
    • withConnection

      NettyOutbound withConnection(Consumer<? super Connection> withConnection)
      Call the passed callback with a Connection to operate on the underlying Channel state.
      Parameters:
      withConnection - connection callback
      Returns:
      the Connection