Class IteratorWrapper<T>
- java.lang.Object
-
- de.aristaflow.ilm.model.common.collection.IteratorWrapper<T>
-
- Type Parameters:
T
- The type of iterator handled by this iterator wrapper.
- All Implemented Interfaces:
Runnable
public class IteratorWrapper<T> extends Object implements Runnable
A wrapper for an iterator and also a runnable for removing the iterator from anAbstractIteratorHandler
. Note that aScheduledExecutorService
does not allow to remove a scheduled runnable. Therefore this remover checks the remaining alive time of its iterator and either removes it or reschedules itself for another run.
As soon as the alive time elapses, this wrapper removes the iterator from the data structure and drops it. Dropping may fail in case the underlying iterator has its own drop mechanism.
-
-
Field Summary
Fields Modifier and Type Field Description protected Consumer<T>
dropper
The method called for dropping the iterator.protected long
dropTime
The time the iterator is dropped.protected T
iterator
The wrapped iterator of this wrapper.protected UUID
iteratorId
The ID assigned to the corresponding iterator.protected Map<UUID,?>
iterators
The data structure providing the current iterators indexed by the assigned iterator ID.protected long
remAliveTimeExtension
The time in milliseconds the alive time is extended if requested.protected ScheduledExecutorService
removerService
The scheduled executor service executing this wrapper.
-
Constructor Summary
Constructors Constructor Description IteratorWrapper(UUID iteratorId, T iterator, long remAliveTimeExtension, Consumer<T> dropper, Map<UUID,?> iterators, ScheduledExecutorService removerService)
Creates a new wrapper for the designated iterator having the designated ID.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
extendRemainingAliveTime()
Extends the remaining alive time by the usual period for extension and returns the new remaining time.T
getIterator()
Gets the wrapped iterator.protected long
getRemainingAliveTime()
Gets the remaining alive time in milliseconds before this wrapper will removed and possibly drop the iterator.void
run()
-
-
-
Field Detail
-
iteratorId
protected final UUID iteratorId
The ID assigned to the corresponding iterator.
-
iterator
protected final T iterator
The wrapped iterator of this wrapper.
-
remAliveTimeExtension
protected final long remAliveTimeExtension
The time in milliseconds the alive time is extended if requested.
-
dropTime
protected long dropTime
The time the iterator is dropped. This may not be used but overridden by the drop time of the underlying iterator.
-
dropper
protected final Consumer<T> dropper
The method called for dropping the iterator. If this isnull
, this wrapper will not drop the iterator but just remove it from the data structure.
-
iterators
protected final Map<UUID,?> iterators
The data structure providing the current iterators indexed by the assigned iterator ID. This is just for removing iterators of which the alive time has elapsed.
-
removerService
protected final ScheduledExecutorService removerService
The scheduled executor service executing this wrapper. This is used for re-scheduling in case the alive time has been extended the time the wrapper is executed.
-
-
Constructor Detail
-
IteratorWrapper
public IteratorWrapper(UUID iteratorId, T iterator, long remAliveTimeExtension, Consumer<T> dropper, Map<UUID,?> iterators, ScheduledExecutorService removerService)
Creates a new wrapper for the designated iterator having the designated ID.- Parameters:
iteratorId
- The ID of the iterator.iterator
- The iterator to wrap.remAliveTimeExtension
- The time in milliseconds the alive time is extended if requested.dropper
- The method called for dropping the iterator. If this isnull
, this wrapper will not drop the iterator but just remove it from the data structure.iterators
- The data structure providing the current iterators indexed by the assigned iterator ID. This is just for removing iterators of which the alive time has elapsed.removerService
- The scheduled executor service executing this wrapper. This is used for re-scheduling in case the alive time has been extended the time the wrapper is executed.
-
-
Method Detail
-
getRemainingAliveTime
protected long getRemainingAliveTime()
Gets the remaining alive time in milliseconds before this wrapper will removed and possibly drop the iterator. The alive time may be extended in the future.
To use the alive time of the underlying iterator, override this method appropriately.- Returns:
- The remaining alive time in milliseconds before this wrapper will removed and possibly drop the iterator.
-
extendRemainingAliveTime
public long extendRemainingAliveTime()
Extends the remaining alive time by the usual period for extension and returns the new remaining time.
To extend the alive time of the underlying iterator, override this method appropriately.- Returns:
- The remaining alive time in milliseconds after extending the alive time of this wrapper and/or the underlying iterator.
-
getIterator
public T getIterator()
Gets the wrapped iterator.- Returns:
- The wrapped iterator.
-
-