Class ParallelIteratorIterator<T>
java.lang.Object
com.github.basking2.sdsai.itrex.iterators.ParallelIteratorIterator<T>
- All Implemented Interfaces:
Iterator<T>
- Direct Known Subclasses:
PrefetchingIterator
Fetch from a set of iterators concurrently and return the first ready element.
Similar to
IteratorIterator
, this aggregates a set of iterators.-
Constructor Details
-
ParallelIteratorIterator
-
ParallelIteratorIterator
public ParallelIteratorIterator(Executor executor, int queueSize, List<Iterator<T>> inputs, Consumer<Throwable> reportError) Constructor.- Parameters:
executor
- The executor that provide the parallelism.queueSize
- The depth of the queue to use for iterated results. For performance reasons the actual depth of cached results is the length of the inputs + queueSize. The reason for this is that in some very contrived timing situations all iterators can begin producing values and exhaust the last queue space. Typically only 1 producing iterator will do this.inputs
- The list of input iterators. Each iterator may be accessed in parallel with another. If iterators share resources, this behavior must be accounted for.reportError
- A way to communicate errors.
-
-
Method Details
-
hasNext
public boolean hasNext()Check if a new result should be expected and fetch with a call tonext()
. This first checks if the internal queue has a cached result, and returns true if it does. Otherwise, each actor is checked if it still has results to fetch. If any returns true, this returns true. Finally, the results queue is re-checked in case an actor published a result between the time we first checked the results queue and then checked each actor individually. -
next
-