Package com.github.ambry.router
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 insrc
to the channel and thecallback
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 insrc
will be eventually written to the channel and thecallback
will be invoked once the write succeeds/fails.
-
-
-
Method Detail
-
write
java.util.concurrent.Future<java.lang.Long> write(java.nio.ByteBuffer src, Callback<java.lang.Long> callback)
The data insrc
will be eventually written to the channel and thecallback
will be invoked once the write succeeds/fails. Thecallback
and the future returned will contain the bytes written (that should be equal tosrc.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 thecallback
is invoked (or afterfuture.get()
returns). Concurrent write calls may result in unexpected behavior.- Parameters:
src
- the data that needs to be written to the channel.callback
- theCallback
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 insrc
to the channel and thecallback
will be invoked once the write succeeds or fails. This method is the counterpart forByteBuf
. It shares the same guarantee as thewrite(ByteBuffer, Callback)
. Whoever implements this interface, shouldn't release thesrc
. If releasing is expected after finishing writing to channel, please release thisByteBuf
in the callback method.- Parameters:
src
- The data taht needs to be written to the channel.callback
- TheCallback
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).
-
-