The buffer is softly bounded, i.e the producer can write any number of elements and shall
cooperate with the buffer to not overload it.
write method indicates
whether it can continue safely adding more elements or stop.
The producer can set a drainHandler to be signaled when it can resume writing again. When a write
returns false, the drain handler will be called when the buffer becomes writable again. Note that subsequent
call to write will not prevent the drain handler to be called.
handler to consume elements.
handler.handler.pause(), resume() and fetch methods:
resume() sets the flowing modepause() sets the fetch mode and resets the demand to 0fetch(long) requests a specific amount of elements and adds it to the actual demandIllegalStateException is thrown.
Other methods can be called from any thread.
The handlers will always be called from a context thread.
Warning
this class is mostly useful for implementing the io.
and has little or no use within a regular application.
| Modifier and Type | Field and Description |
|---|---|
| private final ContextInternal | |
| private long | |
| private Handler | |
| private boolean | |
| private Handler | |
| public static final Object | END_SENTINEL
A reusable sentinel for signaling the end of a stream. |
| private Handler | |
| private Handler | |
| private final long | |
| private boolean | |
| private ArrayDeque |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| private | InboundBuffer(Context context, long highWaterMark, long demand, Handler<Void> drainHandler, Handler<E> handler)
|
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private static void | |
| private void | |
| private boolean | |
| public synchronized InboundBuffer | |
| public static <E> InboundBuffer | createAndFetch(Context context, long highWaterMark, long demand, Handler<Void> drainHandler, Handler<E> handler)
|
| public static <E> InboundBuffer | |
| private void | |
| public synchronized InboundBuffer | Returns: a reference to this, so the API can be used fluentlythe handler to be called handler)Set an |
| private boolean | |
| private boolean | |
| public synchronized InboundBuffer | Returns: a reference to this, so the API can be used fluentlythe handler to be called handler)Set an |
| public synchronized InboundBuffer | Returns: a reference to this, so the API can be used fluentlythe handler handler)Set an |
| public boolean | Returns: true when the buffer will be drainedRequest a specific |
| private <T> void | |
| private void | |
| public synchronized InboundBuffer | |
| public synchronized boolean | |
| public synchronized boolean | |
| public synchronized boolean | |
| public synchronized InboundBuffer | Returns: a reference to this, so the API can be used fluentlyPause the buffer, it sets the buffer in |
| public E | Returns: the most recent element ornull if no element was in the bufferRead the most recent element synchronously. |
| public boolean | Returns: true when the buffer will be drainedResume the buffer, and sets the buffer in |
| public synchronized int | |
| public boolean | Returns: false when the producer should stop writingthe element to add element)Write an |
| public boolean |
| context | back to summary |
|---|---|
| private final ContextInternal context | |
| demand | back to summary |
|---|---|
| private long demand | |
| drainHandler | back to summary |
|---|---|
| private Handler<Void> drainHandler | |
| emitting | back to summary |
|---|---|
| private boolean emitting | |
| emptyHandler | back to summary |
|---|---|
| private Handler<Void> emptyHandler | |
| END_SENTINEL | back to summary |
|---|---|
| public static final Object END_SENTINEL A reusable sentinel for signaling the end of a stream. | |
| exceptionHandler | back to summary |
|---|---|
| private Handler<Throwable> exceptionHandler | |
| handler | back to summary |
|---|---|
| private Handler<E> handler | |
| highWaterMark | back to summary |
|---|---|
| private final long highWaterMark | |
| overflow | back to summary |
|---|---|
| private boolean overflow | |
| pending | back to summary |
|---|---|
| private ArrayDeque<E> pending | |
| InboundBuffer | back to summary |
|---|---|
| public InboundBuffer(Context context) | |
| InboundBuffer | back to summary |
|---|---|
| public InboundBuffer(Context context, long highWaterMark) | |
| InboundBuffer | back to summary |
|---|---|
| private InboundBuffer(Context context, long highWaterMark, long demand, Handler<Void> drainHandler, Handler<E> handler) | |
| asyncDrain | back to summary |
|---|---|
| private void asyncDrain() | |
| checkPositiveAmount | back to summary |
|---|---|
| private static void checkPositiveAmount(long amount) | |
| checkThread | back to summary |
|---|---|
| private void checkThread() | |
| checkWritable | back to summary |
|---|---|
| private boolean checkWritable() | |
| clear | back to summary |
|---|---|
| public synchronized InboundBuffer Clear the buffer synchronously. No handler will be called.
| |
| createAndFetch | back to summary |
|---|---|
| public static <E> InboundBuffer | |
| createPaused | back to summary |
|---|---|
| public static <E> InboundBuffer | |
| drain | back to summary |
|---|---|
| private void drain() Drain the buffer.
Calling this assumes | |
| drainHandler | back to summary |
|---|---|
| public synchronized InboundBuffer Set an
| |
| emit | back to summary |
|---|---|
| private boolean emit(long amount) | |
| emitPending | back to summary |
|---|---|
| private boolean emitPending() | |
| emptyHandler | back to summary |
|---|---|
| public synchronized InboundBuffer Set an
| |
| exceptionHandler | back to summary |
|---|---|
| public synchronized InboundBuffer Set an
| |
| fetch | back to summary |
|---|---|
| public boolean fetch(long amount) Request a specific Pending elements in the buffer will be delivered asynchronously on the context to the handler. This method can be called from any thread.
| |
| handleEvent | back to summary |
|---|---|
| private <T> void handleEvent(Handler<T> handler, T element) | |
| handleException | back to summary |
|---|---|
| private void handleException(Throwable err) | |
| handler | back to summary |
|---|---|
| public synchronized InboundBuffer Set an
| |
| isEmpty | back to summary |
|---|---|
public synchronized boolean isEmpty()
| |
| isPaused | back to summary |
|---|---|
public synchronized boolean isPaused()
| |
| isWritable | back to summary |
|---|---|
public synchronized boolean isWritable()
| |
| pause | back to summary |
|---|---|
| public synchronized InboundBuffer Pause the buffer, it sets the buffer in
| |
| read | back to summary |
|---|---|
| public E read() Read the most recent element synchronously. No handler will be called.
| |
| resume | back to summary |
|---|---|
| public boolean resume() Resume the buffer, and sets the buffer in Pending elements in the buffer will be delivered asynchronously on the context to the handler. This method can be called from any thread.
| |
| size | back to summary |
|---|---|
public synchronized int size()
| |
| write | back to summary |
|---|---|
| public boolean write(E element) Write an
| |
| write | back to summary |
|---|---|
| public boolean write(Iterable<E> elements) Write an | |