Package com.github.ambry.router
Interface ReadableStreamChannel
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.nio.channels.Channel
,java.io.Closeable
- All Known Subinterfaces:
RestRequest
public interface ReadableStreamChannel extends java.nio.channels.Channel
A channel that represents a stream of bytes that can be read into different types of destinations asynchronously. In most implementations, the channel likely can be used for only one read operation after which it cannot be reused. If more than one thread invokes read operations at the same time, only one of them may succeed and the other read operations may be rejected.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
getSize()
Return the size of stream that is available on this channel.java.util.concurrent.Future<java.lang.Long>
readInto(AsyncWritableChannel asyncWritableChannel, Callback<java.lang.Long> callback)
Reads all the data inside this channel into the givenasyncWritableChannel
asynchronously.
-
-
-
Method Detail
-
getSize
long getSize()
Return the size of stream that is available on this channel. If -1, then size is unknown.- Returns:
- the size of the stream available on this channel. -1 if size is unknown.
-
readInto
java.util.concurrent.Future<java.lang.Long> readInto(AsyncWritableChannel asyncWritableChannel, Callback<java.lang.Long> callback)
Reads all the data inside this channel into the givenasyncWritableChannel
asynchronously. Thecallback
will be invoked once the read is complete. Thecallback
and the future returned will contain the bytes read (that should be equal to the size of the channel if there were no exceptions) on success or failure. If the read failed, they will also contain the exception that caused the failure. It is guaranteed that a read will be acknowledged as either a success or failure.- Parameters:
asyncWritableChannel
- theAsyncWritableChannel
to read the data into.callback
- theCallback
that will be invoked either when all the data in the channel has been emptied into theasyncWritableChannel
or if there is an exception in doing so. This can be null.- Returns:
- the
Future
that will eventually contain the result of the operation.
-
-