Interface AsyncWritableChannel

  • All Superinterfaces:
    java.lang.AutoCloseable, java.nio.channels.Channel, java.io.Closeable
    All Known Subinterfaces:
    RestResponseChannel

    public interface AsyncWritableChannel
    extends java.nio.channels.Channel
    A channel that is used to perform writes asynchronously. The channel guarantees that all the data submitted to it will either be acknowledged as successfully written or the reason for failure will be notified.

    The ordering in which data is submitted to the channel (even across multiple threads) is the order in which data will be written to any underlying I/O channels or data structures.

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.util.concurrent.Future<java.lang.Long> write​(io.netty.buffer.ByteBuf src, Callback<java.lang.Long> callback)
      Write data in src to the channel and the callback will be invoked once the write succeeds or fails.
      java.util.concurrent.Future<java.lang.Long> write​(java.nio.ByteBuffer src, Callback<java.lang.Long> callback)
      The data in src will be eventually written to the channel and the callback will be invoked once the write succeeds/fails.
      • Methods inherited from interface java.nio.channels.Channel

        close, isOpen
    • Method Detail

      • write

        java.util.concurrent.Future<java.lang.Long> write​(java.nio.ByteBuffer src,
                                                          Callback<java.lang.Long> callback)
        The data in src will be eventually written to the channel and the callback will be invoked once the write succeeds/fails. The callback and the future returned will contain the bytes written (that should be equal to src.remaining() at the time of invocation if there were no exceptions) on success or failure. If the write failed, they will also contain the exception that caused the failure.

        Every single write is guaranteed to be acknowledged as either succeeded or failed even if the channel is closed. Further, writes will be acknowledged in the same order that they were received.

        src can be reused only after the callback is invoked (or after future.get() returns).

        Concurrent write calls may result in unexpected behavior.

        Parameters:
        src - the data that needs to be written to the channel.
        callback - the Callback that will be invoked once the write succeeds/fails. This can be null.
        Returns:
        a Future that will eventually contain the result of the write operation (the number of bytes written).
      • write

        default java.util.concurrent.Future<java.lang.Long> write​(io.netty.buffer.ByteBuf src,
                                                                  Callback<java.lang.Long> callback)
        Write data in src to the channel and the callback will be invoked once the write succeeds or fails. This method is the counterpart for ByteBuf. It shares the same guarantee as the write(ByteBuffer, Callback). Whoever implements this interface, shouldn't release the src. If releasing is expected after finishing writing to channel, please release this ByteBuf in the callback method.
        Parameters:
        src - The data taht needs to be written to the channel.
        callback - The Callback that will be invoked once the write succeeds/fails. This can be null.
        Returns:
        a Future that will eventually contain the result of the write operation (the number of bytes written).