Class AbstractStateIterator<T>
- java.lang.Object
-
- org.apache.flink.runtime.asyncprocessing.AbstractStateIterator<T>
-
- All Implemented Interfaces:
StateIterator<T>
- Direct Known Subclasses:
ForStListIterator
,ForStMapIterator
public abstract class AbstractStateIterator<T> extends Object implements StateIterator<T>
AStateIterator
implementation to facilitate async data load of iterator. Each state backend could override this class to maintain more variables in need. Any subclass should implement two methods,hasNext()
andnextPayloadForContinuousLoading()
. The philosophy behind this class is to carry some already loaded elements and provide iterating right on the task thread, and load following ones if needed (determined byhasNext()
) by creating **ANOTHER** iterating request. Thus, later it returns another iterator instance, and we continue to apply the user iteration on that instance. The whole elements will be iterated by recursive call of#onNext()
.
-
-
Constructor Summary
Constructors Constructor Description AbstractStateIterator(State originalState, StateRequestType requestType, StateRequestHandler stateHandler, Collection<T> partialResult)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StateRequestType
getRequestType()
protected abstract boolean
hasNext()
Return whether this iterator has more elements to load besides current cache.boolean
isEmpty()
Return if this iterator is empty synchronously.protected abstract Object
nextPayloadForContinuousLoading()
To perform following loading, build and get next payload for the next request.StateFuture<Void>
onNext(Consumer<T> iterating)
Async iterate the data and call the callback when data is ready.<U> StateFuture<Collection<U>>
onNext(Function<T,StateFuture<? extends U>> iterating)
Async iterate the data and call the callback when data is ready.void
onNextSync(Consumer<T> iterating)
-
-
-
Constructor Detail
-
AbstractStateIterator
public AbstractStateIterator(State originalState, StateRequestType requestType, StateRequestHandler stateHandler, Collection<T> partialResult)
-
-
Method Detail
-
hasNext
protected abstract boolean hasNext()
Return whether this iterator has more elements to load besides current cache.
-
nextPayloadForContinuousLoading
protected abstract Object nextPayloadForContinuousLoading()
To perform following loading, build and get next payload for the next request. This will put intoStateRequest.getPayload()
.- Returns:
- the packed payload for next loading.
-
getRequestType
protected StateRequestType getRequestType()
-
onNext
public <U> StateFuture<Collection<U>> onNext(Function<T,StateFuture<? extends U>> iterating)
Description copied from interface:StateIterator
Async iterate the data and call the callback when data is ready.- Specified by:
onNext
in interfaceStateIterator<T>
- Type Parameters:
U
- the type of the inner returned StateFuture's result.- Parameters:
iterating
- the data action when it is ready. The return is the state future for chaining.- Returns:
- the Future that will trigger when this iterator and all returned state future get its results.
-
onNext
public StateFuture<Void> onNext(Consumer<T> iterating)
Description copied from interface:StateIterator
Async iterate the data and call the callback when data is ready.- Specified by:
onNext
in interfaceStateIterator<T>
- Parameters:
iterating
- the data action when it is ready.- Returns:
- the Future that will trigger when this iterator ends.
-
isEmpty
public boolean isEmpty()
Description copied from interface:StateIterator
Return if this iterator is empty synchronously.- Specified by:
isEmpty
in interfaceStateIterator<T>
-
-