Class AbstractIteratorHandler<T extends de.aristaflow.adept2.model.communication.ServerSideProxy,I,N>
- java.lang.Object
-
- de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler<T,I,N>
-
- Type Parameters:
T
- The type of the handled iterators.I
- The type of the initial data provided when requesting the iterator.N
- The type of the data when iterating.
- Direct Known Subclasses:
IncWorklistHandler
,IncWorklistUpdateHandler
,RemoteIteratorHandler
public class AbstractIteratorHandler<T extends de.aristaflow.adept2.model.communication.ServerSideProxy,I,N> extends Object
This class handles provides the basic means for handling iterators. This includes the data structure containing the iterators, runnables for removing iterators from the data structure and closing them as well as the corresponding scheduled executor service.Iterators and their handling classes are generic classes whereas the generic type specifies the elements of the iterator. However, Java's type system may become a problem for other languages. Therefore the ILM removes the generic type and makes it explicit. At runtime this handler needs to create and provide the concrete types without generics, so instantiation is delegated to
suppliers
provided when instantiating this handler.Due to the API of iterators being rather specific, this class is a mere sketch and a lot of logic has to happen in subclasses.
-
-
Field Summary
Fields Modifier and Type Field Description protected Supplier<N>
dataCreator
The creator for data provided when iterating.protected Supplier<I>
initDataCreator
The creator for data provided initially when requesting the iterator.protected Map<UUID,T>
iterators
The map containing iterators while they are active.protected String
iteratorTypeName
The name of the iterator type (for logging close problems).protected Logger
logger
The logger for logging problems, e. g. when implicitly closing after retrieving all data.protected LoggingScheduledThreadPoolExecutor
removerService
The scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler.
-
Constructor Summary
Constructors Constructor Description AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String name, LogService logService)
Deprecated, for removal: This API element is subject to removal in a future version.AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String iteratorTypeName, String executorName, LogService logService)
Creates a new iteration handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close(@NotNull UUID iteratorId)
CallsServerSideProxy.close()
on the designated iterator and removes it from this handler.protected void
closeOrDefer(boolean close, UUID iteratorId, T iterator)
Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators
.protected void
closeOrDefer(boolean close, UUID iteratorId, T iterator, de.aristaflow.adept2.model.communication.ServerSideProxy.LegacySspCloser legacyCloser)
Deprecated, for removal: This API element is subject to removal in a future version.UsecloseOrDefer(boolean, UUID, ServerSideProxy)
instead unless having a proxy object of which the server-side object does not haveServerSideProxy.close()
yet.protected T
getIterator(UUID iteratorId)
Gets the iterator (with metadata) with the designated ID.void
shutdown()
Shuts the executor service down and waits for the termination of running threads.
-
-
-
Field Detail
-
logger
protected final Logger logger
The logger for logging problems, e. g. when implicitly closing after retrieving all data.
-
iteratorTypeName
protected final String iteratorTypeName
The name of the iterator type (for logging close problems).
-
iterators
protected final Map<UUID,T extends de.aristaflow.adept2.model.communication.ServerSideProxy> iterators
The map containing iterators while they are active. The key is a random UUID identifying the iterator.
The server-side proxies will either be explicitly closed, time out viaremoverService
or being forcibly closed via running the remaining removers after shutting down the remover service.
-
removerService
protected final LoggingScheduledThreadPoolExecutor removerService
The scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler.
-
initDataCreator
protected final Supplier<I> initDataCreator
The creator for data provided initially when requesting the iterator.
-
-
Constructor Detail
-
AbstractIteratorHandler
@Deprecated(since="15.0.0", forRemoval=true) public AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String name, LogService logService)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new iteration handler.- Parameters:
initDataCreator
- The creator for data provided initially when requesting the iterator.dataCreator
- The creator for data provided when iterating.name
- The name for the executor.logService
- The log service to retrieve the logger for log messages from.
-
AbstractIteratorHandler
public AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String iteratorTypeName, String executorName, LogService logService)
Creates a new iteration handler.- Parameters:
initDataCreator
- The creator for data provided initially when requesting the iterator.dataCreator
- The creator for data provided when iterating.iteratorTypeName
- The name of the iterator type (for logging close problems).executorName
- The name for the executor.logService
- The log service to retrieve the logger for log messages from.
-
-
Method Detail
-
shutdown
public void shutdown()
Shuts the executor service down and waits for the termination of running threads.
-
closeOrDefer
protected void closeOrDefer(boolean close, UUID iteratorId, T iterator)
Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators
.- Parameters:
close
- Whether to close the designated iterator immediately.iteratorId
- The ID of the designated iterator for logging purpose.iterator
- The iterator which to close or which to remove later.
-
closeOrDefer
@Deprecated(since="15.0.0", forRemoval=true) protected void closeOrDefer(boolean close, UUID iteratorId, T iterator, de.aristaflow.adept2.model.communication.ServerSideProxy.LegacySspCloser legacyCloser)
Deprecated, for removal: This API element is subject to removal in a future version.UsecloseOrDefer(boolean, UUID, ServerSideProxy)
instead unless having a proxy object of which the server-side object does not haveServerSideProxy.close()
yet.Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators
. In case of anUndeclaredThrowableException
or aNoSuchMethodError
, the designatedLegacySspCloser
will be called allowing to call the old method for closing instead ofServerSideProxy.close()
. This is required for proxies stemming from servers before 15.0.0 where the server-side object does not implementServerSideProxy.close()
.- Parameters:
close
- Whether to close the designated iterator immediately.iteratorId
- The ID of the designated iterator for logging purpose.iterator
- The iterator which to close or which to remove later.legacyCloser
- The methods for closing theServerSideProxy
with legacy methods instead ofServerSideProxy.close()
ornull
to only use the standardServerSideProxy.close()
.
-
getIterator
protected T getIterator(UUID iteratorId)
Gets the iterator (with metadata) with the designated ID.- Parameters:
iteratorId
- The ID of the iterator with metadata to retrieve.- Returns:
- The iterator (with metadata) with the designated ID.
- Throws:
IllegalArgumentException
- If the designated ID does not refer to an iterator known by this handler, anIllegalArgumentException
will be thrown.
-
close
public void close(@NotNull @NotNull UUID iteratorId) throws IOException
CallsServerSideProxy.close()
on the designated iterator and removes it from this handler.- Parameters:
iteratorId
- The ID of the iterator to close.- Throws:
IllegalArgumentException
- If the designated ID does not refer to aServerSideProxy
known by this handler, anIllegalArgumentException
will be thrown.IOException
- If there are problems accessing the underlying data source, anIOException
will be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated server-side proxy has been closed implicitly, aServiceConnectionException
will be thrown on client side.
-
-