E
- The generic type of the elements in the chunks.public interface IBlockingBuffer<E> extends IRunnableBuffer<E>
Interface provides an iterator to drain chunks from an IBuffer
.
This interface is useful where one (or more) processes will write
asynchronously on the IBuffer
while another drains it via the
iterator()
. For better performance in a multi-threaded environment,
each thread is given an UnsynchronizedArrayBuffer
of some capacity.
The threads populate their UnsynchronizedArrayBuffer
s in parallel
using non-blocking operations. The UnsynchronizedArrayBuffer
s in
turn are configured to flush chunks of elements onto an either an
IBuffer
whose generic type is E[]
. Each element in
the target IBuffer
is therefore a chunk of elements from one of the
source UnsynchronizedArrayBuffer
s.
There are two families of synchronized IBuffer
s
IBuffer
that targets a mutable IRelation
;IBlockingBuffer
that exposes an IAsynchronousIterator
for reading chunks of elements.
This design means that blocking operations are restricted to chunk-at-a-time
operations, primarily when an UnsynchronizedArrayBuffer
<E>
overflows onto an IBuffer
<<E[]>
and when the
IBuffer
<<E[]>
either is flushed onto an
IMutableRelation
or drained by an IChunkedIterator
.
Modifier and Type | Method and Description |
---|---|
long |
flush()
This is a NOP since the
iterator() is the only way to consume
data written on the buffer. |
IAsynchronousIterator<E> |
iterator()
Return an iterator reading from the buffer.
|
void |
setFuture(Future future)
Set the
Future for the source processing writing on the
IBlockingBuffer (the producer). |
IAsynchronousIterator<E> iterator()
IBlockingBuffer
by concurrent
processes in which case the order is not predictable without additional
synchronization.long flush()
iterator()
is the only way to consume
data written on the buffer.void setFuture(Future future)
Future
for the source processing writing on the
IBlockingBuffer
(the producer).
Note: You should always wrap the task as a FutureTask
and set the
Future
on the IBlockingBuffer
before you start the
consumer. This ensures that the producer will be cancelled if the
consumer is interrupted.
future
- The Future
.IllegalArgumentException
- if the argument is null
.IllegalStateException
- if the future has already been set.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.