E
- The type of the elements returned from the Parallel Iterator.public interface ParIterator<E>
extends java.util.Iterator<E>
java.util.Iterator
, the Parallel Iterator
is thread-safe and allows multiple threads to traverse it.
A Parallel Iterator instance is created using ParIteratorFactory
.
Modifier and Type | Interface and Description |
---|---|
static class |
ParIterator.Schedule
Enum representing the possible schedules that a Parallel Iterator may have.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CHUNKSIZE
The default chunk size, depending on the scheduling policy.
|
Modifier and Type | Method and Description |
---|---|
ParIteratorException<E>[] |
getAllExceptions()
Returns all the exceptions that have (so far) occurred during traversal of the Parallel Iterator.
|
int |
getID()
For test.
|
void |
globalBreak()
Causes all threads to stop processing elements at the next iteration boundary.
|
boolean |
hasNext()
Checks to see if any elements remain for the current thread.
|
boolean |
localBreak()
Attempts to excuse the current thread from continuing to iterate (and re-distribute all unprocessed elements to
the other threads).
|
E |
next()
Returns an element for the current thread to process.
|
void |
register(java.lang.Exception e)
When a thread encounters an exception during traversal of a Parallel Iterator, the exception is registered using this method.
|
void |
remove()
Removes from the underlying collection the last element returned by the Parallel Iterator to the current thread.
|
void |
reset()
Reset ParIterator for reuse.
|
static final int DEFAULT_CHUNKSIZE
boolean hasNext()
true
is returned
and the current thread must follow up with a binding call to next()
. A thread must continue to obtain elements
in this fashion until this method returns false
.
Note that this method involves an implicit barrier for the last call to hasNext()
in order to ensure all threads
finish at the same time.
hasNext
in interface java.util.Iterator<E>
true
if at least one element has been reserved for the calling thread (in which case it must follow up
with a call to next()
).
false
otherwise (in such a case, the calling thread blocks until all the other threads have completed
their iterations).next()
E next()
hasNext()
(and received true
).
Note that calls to hasNext()
(that return true
) only allow for one corresponding and binding call to
hasNext()
. Therefore, multiple calls to hasNext()
have no effect until the corresponding
call to next()
takes place.
void globalBreak()
false
is returned to every thread at the next call to
hasNext()
. Therefore, all the threads safely stop iterating when they call hasNext()
(includes
an implicit barrier to ensure all threads stop at the same time).localBreak()
boolean localBreak()
Therefore, (as opposed to globalBreak()
) this method guarantees that even if all threads attempt to
localBreak()
, at least one will fail and is left to traverse the remaining elements. Note that in many
cases, calling localBreak()
will break the original scheduling policy.
true
if the attempt is successful, false
otherwise.globalBreak()
void register(java.lang.Exception e)
ParIteratorException
):
e
- The exception that occurred
hasNext()
method serves as the iteration boundary to determine the current element).
e
- The exception to registergetAllExceptions()
ParIteratorException<E>[] getAllExceptions()
ParIteratorException
), or an empty array if none were registered.register(Exception)
void remove()
remove
in interface java.util.Iterator<E>
java.lang.UnsupportedOperationException
- If the Parallel Iterator does not support this.void reset()
int getID()