Class IncWorklistHandler<WJ extends WorklistItem,​WI extends WorklistItem,​I extends InitialIncWorklistData<WI>,​N extends IncWorklistData<WI>>

  • Type Parameters:
    WJ - The type of WorklistItems of the Java model provided by the handled worklists.
    WI - The type of WorklistItems 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 a UUID instead of a incremental worklist instance and thus simplifying interfaces not supporting Java objects, for instance web services.
    All methods of this class (except init(IncrementalWorklist, Integer) require a UUID identifying the corresponding incremental worklist. If the ID does not refer to an incremental worklist, an IllegalArgumentException 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 is null), or
    • the incremental worklist contains no items at all.
    Usually null will be returned instead of IncWorklistData if there are no items (for the current iteration). If the incremental worklist is dropped on-the-fly, an IncWorklistData will be returned even if there is no content.

    This class is thread-safe.

    • Field Detail

      • 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 be null.
    • 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 is null, just IncrementalWorklist.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 calls getNext(UUID, Integer, Integer) with the designated parameters and start = 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 or null. If this is null, 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 no count or Integer.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 - If count is non-positive (<= 0), an IllegalArgumentException will be thrown.
        IllegalStateException - If the designated incremental worklist has been dropped implicitly, an IllegalStateException will be thrown on server side.
        de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated incremental worklist has been dropped implicitly, a ServiceConnectionException will be thrown on client side.
      • getNext

        @NotNull
        @Valid
        public N getNext​(@NotNull
                         @NotNull UUID incWorklistId,
                         @Positive
                         @Positive Integer count,
                         @PositiveOrZero
                         @PositiveOrZero Integer start)
        Calls IncrementalWorklist.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 or null. If this is null, 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 is null, the next count 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 or Integer.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 an IncrementalWorklist known by this handler, an IllegalArgumentException will be thrown.
        IllegalArgumentException - If count is non-positive (<= 0) or start is negative (< 0) or start refers to an index that is bigger than the amount of worklist items of the designated incremental worklist, an IllegalArgumentException will be thrown.
        IllegalStateException - If the designated incremental worklist has been dropped implicitly, an IllegalStateException will be thrown on server side.
        de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated incremental worklist has been dropped implicitly, a ServiceConnectionException will be thrown on client side.
      • getNext

        protected N getNext​(UUID incWorklistId,
                            IteratorWrapper<IncrementalWorklist<? extends WJ>> ir,
                            Integer count,
                            Integer start)
        Calls IncrementalWorklist.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 is null), 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 or null. If this is null, 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 is null, the next count 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 an IncrementalWorklist known by this handler, an IllegalArgumentException will be thrown.
        IllegalArgumentException - If count is non-positive (<= 0) or start is negative (< 0) or start refers to an index that is bigger than the amount of worklist items of the designated incremental worklist, an IllegalArgumentException will be thrown.
        IllegalStateException - If the designated incremental worklist has been dropped implicitly, an IllegalStateException will be thrown on server side.
        de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated incremental worklist has been dropped implicitly, a ServiceConnectionException will be thrown on client side.
      • getPrevious

        @NotNull
        @Valid
        public N getPrevious​(@NotNull
                             @NotNull UUID incWorklistId,
                             @NotNull @Positive
                             @NotNull @Positive Integer count)
        Calls IncrementalWorklist.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 an IncrementalWorklist known by this handler, an IllegalArgumentException will be thrown.
        IllegalArgumentException - If the designated incremental worklist does not have any previous worklist items or count is non-positive (<= 0), an IllegalArgumentException will be thrown.
        IllegalStateException - If the designated incremental worklist has been dropped implicitly, an IllegalStateException will be thrown on server side.
        de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated incremental worklist has been dropped implicitly, a ServiceConnectionException will be thrown on client side.
      • drop

        public void drop​(@NotNull
                         @NotNull UUID incWorklistId)
        Calls IncrementalWorklist.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 an IncrementalWorklist known by this handler, an IllegalArgumentException will be thrown.
        de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated incremental worklist has been dropped implicitly, a ServiceConnectionException will be thrown on client side.