Class IncWorklistHandler<WJ extends WorklistItem,WI extends WorklistItem,I extends InitialIncWorklistData<WI>,N extends IncWorklistData<WI>>
- java.lang.Object
-
- de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler<IteratorWrapper<IncrementalWorklist<? extends WJ>>,I,N>
-
- de.aristaflow.ilm.model.worklistmodel.IncWorklistHandler<WJ,WI,I,N>
-
- Type Parameters:
WJ
- The type ofWorklistItem
s of the Java model provided by the handled worklists.WI
- The type ofWorklistItem
s of the ILM provided by the handled worklists.I
- The type of the initial data provided when requesting the incremental worklist.N
- The type of the incremental worklist data when iterating.
public class IncWorklistHandler<WJ extends WorklistItem,WI extends WorklistItem,I extends InitialIncWorklistData<WI>,N extends IncWorklistData<WI>> extends AbstractIteratorHandler<IteratorWrapper<IncrementalWorklist<? extends WJ>>,I,N>
This class handles incremental worklists by assigning IDs to them and mapping these IDs to the respective incremental worklist. This allows to use aUUID
instead of a incremental worklist instance and thus simplifying interfaces not supporting Java objects, for instance web services.
All methods of this class (exceptinit(IncrementalWorklist, Integer)
require a UUID identifying the corresponding incremental worklist. If the ID does not refer to an incremental worklist, anIllegalArgumentException
will be thrown.All handled incremental worklists have an implicit alive time. This is extended each time an incremental worklist is accessed (except for
drop(UUID)
). Nonetheless. it can be explicitly dropped any time.This handler tries to minimise dropping effort for incremental worklists. It will drop them implicitly if
- all items are transferred initially,
- all items are requested at once (
count
isnull
), or - the incremental worklist contains no items at all.
null
will be returned instead ofIncWorklistData
if there are no items (for the current iteration). If the incremental worklist is dropped on-the-fly, anIncWorklistData
will be returned even if there is no content.This class is thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description protected BiConsumer<UUID,IncrementalWorklist<? extends WJ>>
dropLogic
Additional logic called when dropping the incremental worklist iterator due to an elapsed alive time.protected Function<WJ,WI>
transformation
The function transforming from the Java-model to ILM.-
Fields inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
aliveTimeExtension, dataCreator, initDataCreator, iterators, removerService
-
-
Constructor Summary
Constructors Constructor Description IncWorklistHandler(Function<WJ,WI> transformation, Supplier<I> initDataCreator, Supplier<N> dataCreator, long aliveTimeExtension, LogService logService)
Creates a new handler for incremental worklists.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDropLogic(BiConsumer<UUID,IncrementalWorklist<? extends WJ>> dl)
Adds some logic to be called when dropping the incremental worklist iterator due to an elapsed alive time.void
drop(@NotNull UUID incWorklistId)
CallsIncrementalWorklist.drop()
on the designated incremental worklist and removes it from this handler.N
getNext(@NotNull UUID incWorklistId, @Positive Integer count, @PositiveOrZero Integer start)
CallsIncrementalWorklist.getNext(int)
on the designated incremental worklist.protected N
getNext(UUID incWorklistId, IteratorWrapper<IncrementalWorklist<? extends WJ>> ir, Integer count, Integer start)
CallsIncrementalWorklist.getNext(int)
on the designated incremental worklist.N
getPrevious(@NotNull UUID incWorklistId, @NotNull @Positive Integer count)
CallsIncrementalWorklist.getPrevious(int)
on the designated incremental worklist.I
init(IncrementalWorklist<? extends WJ> incWorklist, @Positive Integer count)
Adds the designated incremental worklist to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
.-
Methods inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
getIterator, shutdown
-
-
-
-
Field Detail
-
transformation
protected final Function<WJ extends WorklistItem,WI extends WorklistItem> transformation
The function transforming from the Java-model to ILM.
-
dropLogic
protected BiConsumer<UUID,IncrementalWorklist<? extends WJ extends WorklistItem>> dropLogic
Additional logic called when dropping the incremental worklist iterator due to an elapsed alive time. When consuming, the corresponding iterator will already have been dropped. This may benull
.
-
-
Constructor Detail
-
IncWorklistHandler
public IncWorklistHandler(Function<WJ,WI> transformation, Supplier<I> initDataCreator, Supplier<N> dataCreator, long aliveTimeExtension, LogService logService)
Creates a new handler for incremental worklists.- Parameters:
transformation
- The function transforming from the Java-model to ILM.initDataCreator
- The creator for the data provided initially when requesting the incremental worklist.dataCreator
- The creator for the data provided when iterating.aliveTimeExtension
- The time in milliseconds to extend the alive time of the incremental worklist implicitly.logService
- The log service to retrieve the logger for the executor from.
-
-
Method Detail
-
addDropLogic
public void addDropLogic(BiConsumer<UUID,IncrementalWorklist<? extends WJ>> dl)
Adds some logic to be called when dropping the incremental worklist iterator due to an elapsed alive time. When consuming, the corresponding iterator will already have been dropped.
This needs to be a separate method since one cannot access fields within the call to the super constructor.- Parameters:
dl
- The method called when dropping the incremental worklist iterator due to an elapsed alive time. When consuming, the corresponding iterator will already have been dropped. If this isnull
, justIncrementalWorklist.drop()
will be called.
-
init
@NotNull @Valid public I init(IncrementalWorklist<? extends WJ> incWorklist, @Positive @Positive Integer count)
Adds the designated incremental worklist to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
. The added incremental worklist will be removed from this handler when it is dropped. If all data of the incremental worklist is transferred now, the incremental worklist will be dropped immediately.- Parameters:
incWorklist
- The incremental worklist to add to this handler.count
- The amount of worklist items to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all worklist items of the designated incremental worklist will be returned.- Returns:
- The initial meta data of the incremental worklist and the next n worklist items of the
designated incremental worklist, where n is the specified count. In case of an
insufficient amount of next worklist items remaining only the available worklist items
will be returned. If there are no worklist items,
null
will be returned. If nocount
orInteger.MAX_VALUE
is specified, all worklist items of the designated incremental worklist will be returned at once and the incremental worklist will be dropped. - Throws:
IllegalArgumentException
- Ifcount
is non-positive (<= 0
), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated incremental worklist has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated incremental worklist has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
getNext
@NotNull @Valid public N getNext(@NotNull @NotNull UUID incWorklistId, @Positive @Positive Integer count, @PositiveOrZero @PositiveOrZero Integer start)
CallsIncrementalWorklist.getNext(int)
on the designated incremental worklist. The alive time of the incremental worklist will be extended in case of implicit extension.- Parameters:
incWorklistId
- The ID of the incremental worklist to forward the call to.count
- The amount of worklist items to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all worklist items of the designated incremental worklist will be returned (Integer.MAX_VALUE
) and the incremental worklist will be dropped.start
- The index of the worklist item from which to retrieve the next count worklist items when requesting a limited amount of worklist items (count > 0
). 0 is the index of the first worklist item. This has to be>= 0
and it must not be bigger than the amounts of worklist items in the designated incremental worklist. If this isnull
, the nextcount
worklist items will be returned.- Returns:
- Some meta data of the incremental worklist and the next n worklist items of the
designated incremental worklist, where n is the specified count. In case of an
insufficient amount of next worklist items remaining only the available worklist items
(or no worklist items) will be returned. If no
count
orInteger.MAX_VALUE
is specified, all remaining worklist items of the designated incremental worklist will be returned at once. - Throws:
IllegalArgumentException
- If the designated ID does not refer to anIncrementalWorklist
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 worklist items of the designated incremental worklist, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated incremental worklist has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated incremental worklist has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
getNext
protected N getNext(UUID incWorklistId, IteratorWrapper<IncrementalWorklist<? extends WJ>> ir, Integer count, Integer start)
CallsIncrementalWorklist.getNext(int)
on the designated incremental worklist. The alive time of the incremental worklist will be extended in case of implicit extension. If all items of the worklist are requested (count
isnull
), it will be set to dropped at once. The caller of this method has to drop the incremental worklist!- Parameters:
incWorklistId
- The ID of the incremental worklist to forward the call to.ir
- The incremental worklist to forward the call to.count
- The amount of worklist items to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all worklist items of the designated incremental worklist will be returned (Integer.MAX_VALUE
) and the incremental worklist will be dropped.start
- The index of the worklist item from which to retrieve the next count worklist items when requesting a limited amount of worklist items (count > 0
). 0 is the index of the first worklist item. This has to be>= 0
and it must not be bigger than the amounts of worklist items in the designated incremental worklist. If this isnull
, the nextcount
worklist items will be returned.- Returns:
- Some meta data of the incremental worklist and the next n worklist items of the designated incremental worklist, where n is the specified count. In case of an insufficient amount of next worklist items remaining only the available worklist items (or no worklist items) will be returned.
- Throws:
IllegalArgumentException
- If the designated ID does not refer to anIncrementalWorklist
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 worklist items of the designated incremental worklist, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated incremental worklist has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated incremental worklist has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
getPrevious
@NotNull @Valid public N getPrevious(@NotNull @NotNull UUID incWorklistId, @NotNull @Positive @NotNull @Positive Integer count)
CallsIncrementalWorklist.getPrevious(int)
on the designated incremental worklist.- Parameters:
incWorklistId
- The ID of the incremental worklist to forward the call to.count
- The amount of worklist items to retrieve in backward direction. This has to be > 0.- Returns:
- The ID of the incremental worklist and the previous n worklist items, where n is the
specified count. The order corresponds to the one in the underlying data structure,
that is previous worklist items in the returned list are also previous worklist items
in the data structure. In case of an insufficient amount of previous worklist items
remaining only the available worklist items will be returned. If there are no more
previous worklist items,
null
will be returned as flat items. - Throws:
IllegalArgumentException
- If the designated ID does not refer to anIncrementalWorklist
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- If the designated incremental worklist does not have any previous worklist items or count is non-positive (<= 0), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated incremental worklist has been dropped implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated incremental worklist has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
drop
public void drop(@NotNull @NotNull UUID incWorklistId)
CallsIncrementalWorklist.drop()
on the designated incremental worklist and removes it from this handler.- Parameters:
incWorklistId
- The ID of the incremental worklist to forward the call to.- Throws:
IllegalArgumentException
- If the designated ID does not refer to anIncrementalWorklist
known by this handler, anIllegalArgumentException
will be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated incremental worklist has been dropped implicitly, aServiceConnectionException
will be thrown on client side.
-
-