Class RemoteIteratorHandler<T,I extends InitialRemoteIteratorData<T>,N extends RemoteIteratorData<T>>
- java.lang.Object
-
- de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler<de.aristaflow.ilm.model.common.collection.RemoteIteratorWrapper<T>,I,N>
-
- de.aristaflow.ilm.model.common.collection.RemoteIteratorHandler<T,I,N>
-
- Type Parameters:
T
- The collection type of the handledRemoteIterator
s.I
- The type of the initial remote iterator data provided when requesting the remote iterator.N
- The type of the remote iterator data provided when iterating.
public class RemoteIteratorHandler<T,I extends InitialRemoteIteratorData<T>,N extends RemoteIteratorData<T>> extends AbstractIteratorHandler<de.aristaflow.ilm.model.common.collection.RemoteIteratorWrapper<T>,I,N>
This class handles remote iterators by assigning IDs to them and mapping these IDs to the respective handler. This allows to use aUUID
instead of a remote iterator instance and thus simplifying interfaces not supporting Java objects, for instance web services.
All methods of this class (exceptinit(RemoteIterator, Integer)
require a UUID identifying the corresponding remote iterator. If the ID does not refer to a remote iterator, anIllegalArgumentException
will be thrown. Additionally, this handler keeps track of the alive time of known remote iterators. As soon as their alive time elapses, they will be removed from this handler.Remote iterators handled by this class also have an implicit extension of their alive time. That is, every time, a remote iterator is accessed, its alive time is extended. This applies until the first time, the alive time of the remote iterator is explicitly extended via API. After that, this alive time applies and needs to be explicitly extended.
This handler tries to minimise dropping effort for remote iterators. It will drop them implicitly if
- all content is transferred initially,
- all content is retrieved at once (
count
isnull
), - the end of the data is reached and the iterator is forward-only, or
- the iterator contains no data at all.
null
will be returned instead ofRemoteIteratorData
if there is no content (for the current iteration). If the iterator is dropped on-the-fly, aRemoteIteratorData
will be returned even if there is no content.This class is thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
logger
The logger for problems when dropping a wrapped remote iterator.-
Fields inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
aliveTimeExtension, dataCreator, initDataCreator, iterators, removerService
-
-
Constructor Summary
Constructors Constructor Description RemoteIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, long aliveTimeExtension, LogService logService)
Creates a new handler for remote iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
drop(@NotNull UUID iteratorId)
CallsRemoteIterator.drop()
on the designated iterator and removes it from this handler.N
getNext(@NotNull UUID iteratorId, @Positive Integer count, @PositiveOrZero Integer start)
CallsRemoteIterator.getNext(int)
orRemoteIterator.getNext(int, int)
on the designated iterator.protected N
getNext(UUID iteratorId, de.aristaflow.ilm.model.common.collection.RemoteIteratorWrapper<T> iterator, Integer count, Integer start)
CallsRemoteIterator.getNext(int)
,RemoteIterator.getNext(int, int)
orRemoteIterator.getAll()
on the designated iterator.N
getPrevious(@NotNull UUID iteratorId, @NotNull @Positive Integer count)
CallsRemoteIterator.getPrevious(int)
on the designated iterator.I
init(@NotNull RemoteIterator<List<T>> iterator, @Positive Integer count)
Adds the designated iterator to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
.long
keepAlive(@NotNull UUID iteratorId, @NotNull Long aliveTime)
CallsRemoteIterator.keepAlive(long)
on the designated iterator and sets the alive time to explicit extension.-
Methods inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
getIterator, shutdown
-
-
-
-
Field Detail
-
logger
protected final Logger logger
The logger for problems when dropping a wrapped remote iterator.
-
-
Constructor Detail
-
RemoteIteratorHandler
public RemoteIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, long aliveTimeExtension, LogService logService)
Creates a new handler for remote iterator.- Parameters:
initDataCreator
- The creator for the data provided initially when requesting the remote iterator.dataCreator
- The creator for remote iterator data provided when iterating.aliveTimeExtension
- The time in milliseconds to extend the alive time of the iterator implicitly.logService
- The log service to retrieve the logger for the executor from.
-
-
Method Detail
-
init
@Valid public I init(@NotNull @NotNull RemoteIterator<List<T>> iterator, @Positive @Positive Integer count) throws DataSourceException, DataConsistencyException
Adds the designated iterator to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
. The added iterator will be removed from this handler when its alive time elapsed. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be dropped as soon as the last entry is transferred.
Also if all entries of the iterator are retrieved now or the iterator has no entries at all, it will be dropped immediately.- Parameters:
iterator
- The iterator to add to this handler.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned.- Returns:
- The initial meta data of the remote iterator and the next n elements of the designated
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
elements,
null
will be returned. If nocount
orInteger.MAX_VALUE
is specified, all elements of the designated iterator will be returned at once and the iterator will be dropped. - Throws:
DataSourceException
- If there are problems accessing the underlying data source or all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
will 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, aDataConsistencyException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getNext
@Valid public N getNext(@NotNull @NotNull UUID iteratorId, @Positive @Positive Integer count, @PositiveOrZero @PositiveOrZero Integer start) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getNext(int)
orRemoteIterator.getNext(int, int)
on the designated iterator. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be dropped as soon as the last entry is transferred.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned and the iterator will be dropped.start
- The index of the element from which to retrieve the next count elements when requesting a limited amount of elements (count > 0
). 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 the designated iterator. If this isnull
, the nextcount
elements will be returned.- Returns:
- Some meta data of the remote iterator and the next n elements of the designated
iterator, where n is the specified count. In case of an insufficient amount of next
elements remaining only the available elements (or no elements) will be returned. If no
count
orInteger.MAX_VALUE
is specified, all remaining elements of the designated iterator will be returned at once. If nocount
orInteger.MAX_VALUE
is specified and there are no more next elements and the forward-only iterator has been dropped,null
will be returned. - Throws:
DataSourceException
- If there are problems accessing the underlying data source or all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
will 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, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
) orstart
is negative (< 0
) orstart
refers to an index that is bigger than the amount of elements of the designated iterator, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getNext
protected N getNext(UUID iteratorId, de.aristaflow.ilm.model.common.collection.RemoteIteratorWrapper<T> iterator, Integer count, Integer start) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getNext(int)
,RemoteIterator.getNext(int, int)
orRemoteIterator.getAll()
on the designated iterator. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be set to be dropped as soon as the last entry is transferred. It will also be set to be dropped in case all content is provided at once. The caller of this method has to drop the iterator!- Parameters:
iteratorId
- The ID of the iterator to forward the call to.iterator
- The iterator to forward the call to.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned and the iterator will be dropped. Thereforenull
is only allowed for the first element retrieval.start
- The index of the element from which to retrieve the next count elements when requesting a limited amount of elements (count > 0
). 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 the designated iterator. If this isnull
, the nextcount
elements will be returned.- Returns:
- Some meta data of the remote iterator and the next n elements of the designated iterator, where n is the specified count. In case of an insufficient amount of next elements remaining only the available elements (or no elements) will be returned.
- Throws:
DataSourceException
- If there are problems accessing the underlying data source or all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
will 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, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
) orstart
is negative (< 0
) orstart
refers to an index that is bigger than the amount of elements of the designated iterator, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getPrevious
@Valid public N getPrevious(@NotNull @NotNull UUID iteratorId, @NotNull @Positive @NotNull @Positive Integer count) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getPrevious(int)
on the designated iterator.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.count
- The amount of elements to retrieve in backward direction. This has to be > 0.- Returns:
- Some meta data of the remote iterator and the previous n elements of the designated
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,
null
will be returned as content. - Throws:
DataSourceException
- If there are problems accessing the underlying data source, aDataSourceException
will 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 the designated iterator is forward only, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- If the designated iterator does not have any previous elements or count is non-positive (<= 0), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
keepAlive
public long keepAlive(@NotNull @NotNull UUID iteratorId, @NotNull @NotNull Long aliveTime) throws DataSourceException
CallsRemoteIterator.keepAlive(long)
on the designated iterator and sets the alive time to explicit extension.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.aliveTime
- The time in milliseconds to keep the designated iterator alive that is not to drop it automatically.- Returns:
- The relative time the designated iterator will be kept alive longer. 0 indicates
immediate dropping. A negative value represents the failure of extending the alive
time, check
RemoteIterator.getRemainingAliveTime()
in this case whether extending the keep alive time has been successful or not. - Throws:
IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.DataSourceException
- If there are problems accessing the underlying data source, aDataSourceException
will be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
drop
public void drop(@NotNull @NotNull UUID iteratorId) throws DataSourceException
CallsRemoteIterator.drop()
on the designated iterator and removes it from this handler.
Forward only remote iterators will be automatically dropped as soon as the last data is transferred.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.- Throws:
IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.DataSourceException
- If there are problems accessing the underlying data source, aDataSourceException
will be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
-