public class AsyncOperationBatchIterator<T> extends java.lang.Object implements BatchIterator<T>
BatchAccumulator
.
Every BatchAccumulator.batchSize()
items, BatchAccumulator.processBatch(boolean)
is used
to create the data for *this* BatchIterator.
(encapsulated via {@link #loadNextBatch()})
+-> source data
| |
| batchAccumulator.onItem
| |
| batchSize reached?
| |
+----------+---+
|
batchAccumulator.processBatch
onResult -> fill-up data of *this* BatchIterator
Constructor and Description |
---|
AsyncOperationBatchIterator(BatchIterator<T> source,
BatchAccumulator<T,java.util.Iterator<? extends T>> batchAccumulator) |
Modifier and Type | Method and Description |
---|---|
boolean |
allLoaded() |
void |
close()
Closes the iterator and frees all resources.
|
T |
currentElement()
This method returns the item that is at the current position of the BatchIterator.
|
void |
kill(java.lang.Throwable throwable)
Interrupt the operation, increasing the likelihood that it will terminate early with an error.
|
java.util.concurrent.CompletionStage<?> |
loadNextBatch()
Loads the next batch if there is still data available for loading.
|
boolean |
moveNext()
Advances the iterator.
|
void |
moveToStart()
Moves the Iterator back to the starting position.
|
public AsyncOperationBatchIterator(BatchIterator<T> source, BatchAccumulator<T,java.util.Iterator<? extends T>> batchAccumulator)
public T currentElement()
BatchIterator
currentElement
in interface BatchIterator<T>
public void moveToStart()
BatchIterator
BatchIterator.moveNext()
and BatchIterator.loadNextBatch()
as appropriate.moveToStart
in interface BatchIterator<T>
public boolean moveNext()
BatchIterator
moveNext
in interface BatchIterator<T>
BatchIterator.allLoaded()
returns true the iterator is out of data. Otherwise BatchIterator.loadNextBatch()
can be used to load the next batch - after which moveNext()
can be used again.public void close()
BatchIterator
close
in interface BatchIterator<T>
public java.util.concurrent.CompletionStage<?> loadNextBatch()
BatchIterator
BatchIterator.allLoaded()
returns false.
If BatchIterator.allLoaded()
returns true, calling this method will return a failed CompletionStage.
NOTE: while loading takes place the iterator must not be moved. The iterator behaviour in this case is undetermined.
loadNextBatch
in interface BatchIterator<T>
BatchIterator.moveNext()
can be called again if the next batch contains more data.public boolean allLoaded()
allLoaded
in interface BatchIterator<T>
public void kill(@Nonnull java.lang.Throwable throwable)
Killable
Interrupt the operation, increasing the likelihood that it will terminate early with an error. This method can be called concurrently from a different thread while an operation is running.
Implementations must: