Class AbstractRemoteIterator<S,T>
java.lang.Object
de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator<S,T>
- Type Parameters:
S- The source type of the provided elements, which is subject of transformation before returning them.T- The type of the elements that is provided when iterating.
- All Implemented Interfaces:
RemoteIterator<List<T>>,de.aristaflow.adept2.model.communication.ServerSideProxy,Closeable,AutoCloseable
- Direct Known Subclasses:
AbstractTimeTrackingRemoteIterator,TransformingRemoteIterator
This class provides the basic means for a window mechanism for lists of elements, that is, the
basic means for a
While
RemoteIterator. It provides refusal of accessing a closed remote
iterator, basic active thread tracking, transformation and tracking of returned elements and
tracking of AutoCloseable elements. Such elements can either be closed on traversal
or when closing the remote iterator. closeOnTraversal() will
AutoCloseable.close() all elements of the previous traversal (call to
getNext(int), getNext(int, int) or getPrevious(int)). This reduces the
amount of memory required to keep this elements for closing. But it prevents re-accessing these
elements. If the elements are created for every traversal, this is no problem, if they are
provided via memory, closing needs to be deferred. While
AutoCloseable.close() on close() is the default, subclasses may choose to
close on traversal (useful for RemoteIterator.isForwardOnly() and iterators creating new elements when
traversing) or even to disable closing at all. The latter is required for remote iterators that
cache already accessed elements and re-provide them when traversing back.
AutoCloseable elements will be wrapped so that the using classes cannot close the
retrieved elements outside of this remote iterator.
- See Also:
-
CloseIgnoringWrapper
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.aristaflow.adept2.model.communication.ServerSideProxy
de.aristaflow.adept2.model.communication.ServerSideProxy.LegacySspCloser, de.aristaflow.adept2.model.communication.ServerSideProxy.ServerSideProxyRemover -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Cleanup<IOException>The clean-up for closing thecloseablesas post-mortem task for this instance or when closing.protected final Collection<AutoCloseable>The elements that areAutoCloseablethat should be closed at the next traversal or when closing.protected final LoggerThe logger for logging messages instead of throwing exceptions.The transformator function applied to each individual object before retrieval.Fields inherited from interface de.aristaflow.adept2.model.communication.ServerSideProxy
DEFAULT_ALIVE_TIME -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRemoteIterator(Function<S, T> transformator, Logger logger) Creates a new remote iterator with the designated transformator function applied to each element before returning it and using the designated logger for problems when closing (this remote iterator or the appropriate elements). -
Method Summary
Modifier and TypeMethodDescriptionaboutToReturn(List<S> elems) Tracks theAutoCloseables of the designated elements before returning them, handles their closing (whencloseOnTraversal) and applies the transformation.voidclose()Explicitly closes this iterator which allows to release occupied memory and resources.booleanGets whether this remote iterator closes elements ofAutoCloseabletype when traversing to the next elements.protected voidenter()Allows to track entering a method reentrant.protected Longexit()Tracks exiting a method reentrant.getAll()Gets all elements of this iterator at once.ImplementsgetAll()without the need to consider result transformation, closeable and alive time tracking.getNext(int count) Gets the next specified amount of elements of this iterator.getNext(int count, int start) Gets the next specified amount of elements of this iterator starting at the designated index (0-based).getNextImpl(int count) ImplementsgetNext(int)without the need to consider result transformation, closeable and alive time tracking.getNextImpl(int count, int start) ImplementsgetNext(int, int)without the need to consider result transformation, closeable and alive time tracking.getPrevious(int count) Gets the previous specified amount of elements of this iterator.getPreviousImpl(int count) ImplementsgetPrevious(int)without the need to consider result transformation, closeable and alive time tracking.protected abstract booleanisClosed()Gets whether this remote iterator has been closed and its data is not available any more.protected voidsetCloseOnTraversal(Boolean closeOnTraversal) Sets whether closing of elements should be applied when traversing (Boolean.TRUE), when closing this remote iterator (Boolean.FALSE) or not at all (null).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.aristaflow.adept2.model.common.collection.RemoteIterator
drop, getRemainingAliveTime, isForwardOnly, isSnapshot, keepAlive
-
Field Details
-
logger
The logger for logging messages instead of throwing exceptions. -
transformator
The transformator function applied to each individual object before retrieval. -
closeables
The elements that areAutoCloseablethat should be closed at the next traversal or when closing. -
cleanup
The clean-up for closing thecloseablesas post-mortem task for this instance or when closing.
-
-
Constructor Details
-
AbstractRemoteIterator
Creates a new remote iterator with the designated transformator function applied to each element before returning it and using the designated logger for problems when closing (this remote iterator or the appropriate elements).- Parameters:
transformator- The transformator function applied to each individual object before retrieval.logger- The logger for logging messages instead of throwing exceptions.
-
-
Method Details
-
enter
protected void enter()Allows to track entering a method reentrant. -
exit
Tracks exiting a method reentrant.- Returns:
- The possibly new remaining alive time in milliseconds or
nullin case the thread is still active and not exiting finally.
-
isClosed
protected abstract boolean isClosed()Gets whether this remote iterator has been closed and its data is not available any more.- Returns:
- Whether this remote iterator has been closed and its data is not available any more.
-
getNextImpl
protected abstract List<S> getNextImpl(int count) throws DataSourceException, DataConsistencyException ImplementsgetNext(int)without the need to consider result transformation, closeable and alive time tracking. -
getNextImpl
protected abstract List<S> getNextImpl(int count, int start) throws DataSourceException, DataConsistencyException ImplementsgetNext(int, int)without the need to consider result transformation, closeable and alive time tracking. -
getPreviousImpl
protected abstract List<S> getPreviousImpl(int count) throws DataSourceException, DataConsistencyException ImplementsgetPrevious(int)without the need to consider result transformation, closeable and alive time tracking. -
getAllImpl
ImplementsgetAll()without the need to consider result transformation, closeable and alive time tracking. -
aboutToReturn
Tracks theAutoCloseables of the designated elements before returning them, handles their closing (whencloseOnTraversal) and applies the transformation.- Parameters:
elems- The elements which are about to be returned in the current traversal and which may need to be tracked and/or transformed.- Returns:
- The designated elements transformed appropriately which are about to be returned in the current traversal.
-
setCloseOnTraversal
Sets whether closing of elements should be applied when traversing (Boolean.TRUE), when closing this remote iterator (Boolean.FALSE) or not at all (null).- Parameters:
closeOnTraversal-Boolean.TRUEfor immediate closing theAutoCloseableelements of the previous traversal,Boolean.FALSEfor closing theAutoCloseableelements when closing this remote iterator, ornullfor no element closing at all.
-
getNext
Description copied from interface:RemoteIteratorGets the next specified amount of elements of this iterator. The returned data will be consistent within the returned list (but not necessarily with respect to previous or later retrievals) due to the usage of synchronisation.- Specified by:
getNextin interfaceRemoteIterator<S>- Parameters:
count- The amount of elements to retrieve in forward direction. This has to be > 0.- Returns:
- The next n elements of this iterator, where n is the specified count. In case of an
insufficient amount of next elements remaining only the available elements will be
returned. If there are no more next elements,
nullwill be returned.
AutoCloseables will be coupled to thisRemoteIterator, so do not close them; clone them if required longer than until automatic closing which may happen when traversing or when closing thisRemoteIterator. - Throws:
DataSourceException- If there are problems accessing the underlying data source, aDataSourceExceptionwill be thrown.DataConsistencyException- If there are problems retrieving any of the next elements via the identifying attribute of the elements (for instance the primary key of a specific element identifying the next position) is not available any more, aDataConsistencyExceptionwill be thrown.
-
getNext
public final List<T> getNext(int count, int start) throws DataSourceException, DataConsistencyException Description copied from interface:RemoteIteratorGets the next specified amount of elements of this iterator starting at the designated index (0-based). The returned data will be consistent within the returned list (but not necessarily with respect to previous or later retrievals) due to the usage of synchronisation.
Afterwards the cursor to the current element will be set to the index start + count, that is, getNext(n) will be the same as calling getNext(n, start + count).- Specified by:
getNextin interfaceRemoteIterator<S>- Parameters:
count- The amount of elements to retrieve in forward direction. This has to be > 0.start- The index of the element from which to retrieve the next count elements. 0 is the index of the first element. This has to be >= 0 and it must not be bigger than the amounts of elements in this iterator.- Returns:
- The next n elements of this iterator, where n is the specified count. In case of an
insufficient amount of next elements remaining only the available elements will be
returned. If there are no more next elements,
nullwill be returned.
AutoCloseables will be coupled to thisRemoteIterator, so do not close them; clone them if required longer than until automatic closing which may happen when traversing or when closing thisRemoteIterator. - Throws:
DataSourceException- If there are problems accessing the underlying data source, aDataSourceExceptionwill be thrown.DataConsistencyException- If there are problems retrieving any of the next elements via the identifying attribute of the elements (for instance the primary key of a specific element identifying the next position) is not available any more, aDataConsistencyExceptionwill be thrown.
-
getPrevious
Description copied from interface:RemoteIteratorGets the previous specified amount of elements of this iterator. The returned data will be consistent within the returned list (but not necessarily with respect to previous or later retrievals) due to the usage of synchronisation.- Specified by:
getPreviousin interfaceRemoteIterator<S>- Parameters:
count- The amount of elements to retrieve in backward direction. This has to be > 0.- Returns:
- The previous n elements of this iterator, where n is the specified count. The order
corresponds to the one in the underlying data structure, that is previous elements in
the returned list are also previous elements in the data structure. In case of an
insufficient amount of previous elements remaining only the available elements will be
returned. If there are no more previous elements,
nullwill be returned.
AutoCloseables will be coupled to thisRemoteIterator, so do not close them; clone them if required longer than until automatic closing which may happen when traversing or when closing thisRemoteIterator. - Throws:
DataSourceException- If there are problems accessing the underlying data source, aDataSourceExceptionwill be thrown.DataConsistencyException- If there are problems retrieving any of the previous next elements via the identifying attribute of the elements (for instance the primary key of a specific element identifying the next position) is not available any more or if this iterator is forward only, aDataConsistencyExceptionwill be thrown.
-
getAll
Description copied from interface:RemoteIteratorGets all elements of this iterator at once. The returned data will be consistent (does not contain elements of different versions) due to the usage of synchronisation. Note that calling this method may take a lot of time.
Calling this method will reset the iterator before the first element if this iterator is not forward only. If this iterator is forward only and does not cache retrieved elements internally, this method will not work but throw aDataSourceExceptionsince the already returned elements may not be retrieved any more.- Specified by:
getAllin interfaceRemoteIterator<S>- Returns:
- All elements of this iterator at once.
AutoCloseables will be coupled to thisRemoteIterator, so do not close them; clone them if required longer than until automatic closing which may happen when traversing or when closing thisRemoteIterator. - Throws:
DataSourceException- If there are problems accessing the underlying data source or this iterator is forward only and currently not positioned before the first element, aDataSourceExceptionwill be thrown.DataConsistencyException- If there are problems retrieving any of the elements via the identifying attribute of the elements (for instance the primary key of a specific element identifying the next position) is not available any more, aDataConsistencyExceptionwill be thrown.
-
closeOnTraversal
public boolean closeOnTraversal()Description copied from interface:RemoteIteratorGets whether this remote iterator closes elements ofAutoCloseabletype when traversing to the next elements. If so, all elements of the previous traversal will be closed. That is, each call toRemoteIterator.getNext(int),RemoteIterator.getNext(int, int)orRemoteIterator.getPrevious(int)will cache all elements and close them with the next call to eitherRemoteIterator.getNext(int),RemoteIterator.getNext(int, int)orRemoteIterator.getPrevious(int). Otherwise the elements will be closed when closing this remote iterator.- Specified by:
closeOnTraversalin interfaceRemoteIterator<S>- Returns:
- Whether this remote iterator closes elements when traversing to the next elements.
-
close
Description copied from interface:RemoteIteratorExplicitly closes this iterator which allows to release occupied memory and resources. Closing will be done implicitly after the alive time has elapsed.
This method may be called several times. Implementors have to take care of this.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRemoteIterator<S>- Specified by:
closein interfacede.aristaflow.adept2.model.communication.ServerSideProxy- Throws:
IOException- If there are problems accessing the underlying data source, anIOExceptionwill be thrown.
-