Interface AsyncStream<E>
-
- Type Parameters:
E- The type of the elements, usually aTransferableBlock
public interface AsyncStream<E>An interface that represents an abstract asynchronous stream of elements that can be consumed. These streams are designed to be consumed by a single thread and do not support null elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceAsyncStream.OnNewData
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddOnNewDataListener(AsyncStream.OnNewData onNewData)Registers a callback.voidcancel()Cancels this stream.ObjectgetId()The id of the stream.Epoll()Reads the next element, if there is any to read.
-
-
-
Method Detail
-
getId
Object getId()
The id of the stream. Mostly used for logging. Implementations of this method must be thread safe.
-
poll
@Nullable E poll()
Reads the next element, if there is any to read. Otherwise it returns null. Calling this method before setting acallbackwithaddOnNewDataListener(OnNewData)is illegal as it may imply losing information. Only the consumer thread can call this method.- Returns:
- the next element to consume, which cannot be null, or null if there is no element ready yet.
-
addOnNewDataListener
void addOnNewDataListener(AsyncStream.OnNewData onNewData)
Registers a callback. Once set, the callback cannot be changed. In order to callpoll(), a callback has to be registered. Only the consumer thread can call this method.- Parameters:
onNewData-
-
cancel
void cancel()
Cancels this stream. Only the consumer thread can call this method.
-
-