Class CachingIncWorklistUpdate

java.lang.Object
de.aristaflow.adept2.model.worklistmodel.CachingIncWorklistUpdate
All Implemented Interfaces:
UserAttributeContainer, de.aristaflow.adept2.model.communication.ServerSideProxy, de.aristaflow.adept2.model.communication.TimeTrackingSsProxy, IncrementalWorklistUpdate, WorklistUpdate, Closeable, Serializable, AutoCloseable

public class CachingIncWorklistUpdate extends Object implements IncrementalWorklistUpdate, de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
This incremental worklist update implements a cache for the underlying incremental worklist update, that is, when iterating via getNext(int), all retrieved item updates will be cached. Previous item updates will always be retrieved from the cache. Note that a positioned next will add enough item updates to the cache to fulfil the request. As soon as all elements have been retrieved, the wrapped worklist update will be closed. Until then, retrieving already cached item updates will contact the underlying incremental worklist update to extend its alive time and adapt it to the alive time of this caching worklist update.
See Also:
  • Field Details

    • wrappedUpdate

      protected IncrementalWorklistUpdate wrappedUpdate
      The wrapped incremental worklist update of which all item updates will be cached. Note that the current cursor need not correspond to the current cursor of the underlying incremental worklist update. This will be null when the incremental worklist update has been closed.
    • itemUpdates

      protected List<WorklistItemUpdate<ClientWorklistItem>> itemUpdates
      The item updates that have been retrieved from the underlying incremental worklist update so far.
    • lastCached

      protected int lastCached
      The index of the last item update that is in the cache. This corresponds to the current index of the wrapped incremental worklist update.
    • last

      protected int last
      The index of last item update in case it has been reached in the result set, -1 otherwise.
    • current

      protected int current
      The reference to the current item update which is to be retrieved next.
    • worklistId

      protected UUID worklistId
      The ID the worklist of the incremental worklist update. This will be null until first retrieved from the wrapped incremental worklist update.
    • sourceRevision

      protected WorklistRevision sourceRevision
      The source revision of the worklist update. This will be null until first retrieved from the wrapped incremental worklist update.
    • targetRevision

      protected Long targetRevision
      The target revision of the worklist update. This will be null until first retrieved from the wrapped incremental worklist update.
    • maxPriority

      protected Integer maxPriority
      The maximum priority of the worklist update. This will be null until first retrieved from the wrapped incremental worklist update.
    • cleanup

      protected transient Cleanup<RuntimeException> cleanup
      The clean-up for closing the wrapped update as post-mortem task for this instance.
  • Constructor Details

    • CachingIncWorklistUpdate

      @Deprecated(since="15.0.0", forRemoval=true) public CachingIncWorklistUpdate(IncrementalWorklistUpdate wrappedUpdate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new caching incremental worklist update for the designated incremental worklist update sending no close notification for the designated incremental worklist update.
      Parameters:
      wrappedUpdate - The incremental worklist update of which the item updates should be cached as soon as they are iterated (with getNext(int)).
    • CachingIncWorklistUpdate

      public CachingIncWorklistUpdate(IncrementalWorklistUpdate wrappedUpdate, long initialAliveTime, long aliveTimeExtension, Logger logger)
      Creates a new caching incremental worklist update for the designated incremental worklist update.
      Parameters:
      wrappedUpdate - The incremental worklist update of which the item updates should be cached as soon as they are iterated (with getNext(int)).
      initialAliveTime - The initial time in milliseconds this incremental worklist update remains available before automatically being closed.
      aliveTimeExtension - The time in milliseconds to extend the alive time when accessing this incremental worklist update.
      logger - The logger for logging exceptions from the wrapped update that cannot be forwarded or are irrelevant.
  • Method Details

    • exit

      protected Long exit()
      Tracks exiting a method reentrant and possibly extends the alive time of the wrapped worklist update. This is required when retrieving cached data that does not access the wrapped update thus not extending the alive time of the wrapped worklist update possibly closing it before the alive time of this caching worklist update has elapsed.
      Returns:
      The possibly new remaining alive time in milliseconds or null in case the thread is still active and not exiting finally.
    • getCloseTime

      public long getCloseTime()
      Specified by:
      getCloseTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • setCloseTime

      public long setCloseTime(long closeTime)
      Specified by:
      setCloseTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • isBusy

      public boolean isBusy()
      Specified by:
      isBusy in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • getRemainingAliveTime

      public long getRemainingAliveTime()
      Specified by:
      getRemainingAliveTime in interface de.aristaflow.adept2.model.communication.ServerSideProxy
      Specified by:
      getRemainingAliveTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • keepAlive

      public long keepAlive(long aliveTime) throws IOException
      Specified by:
      keepAlive in interface de.aristaflow.adept2.model.communication.ServerSideProxy
      Specified by:
      keepAlive in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
      Throws:
      IOException
    • getWorklistID

      public UUID getWorklistID()
      Description copied from interface: IncrementalWorklistUpdate
      The ID of the worklist for which this update is intended. Additionally marked as Immutable.
      Specified by:
      getWorklistID in interface IncrementalWorklistUpdate
      Specified by:
      getWorklistID in interface WorklistUpdate
      Returns:
      The ID of the worklist for which this update is intended.
    • getSourceRevision

      public WorklistRevision getSourceRevision()
      Description copied from interface: IncrementalWorklistUpdate
      Gets the source revision, i.e. the worklist revision (initialisation date and update count) to which this update can be applied. An exception is the initial revision can always be applied (by clearing the list before applying the update). The update contains all changes that have been made to the worklist since the update count of the source revision up to (and including) the target revision (update count). Additionally marked as Immutable.
      Specified by:
      getSourceRevision in interface IncrementalWorklistUpdate
      Specified by:
      getSourceRevision in interface WorklistUpdate
      Returns:
      The source revision, i.e. the revision of the worklist (initialisation date and update count) to which this update can be applied.
    • getTargetRevision

      public long getTargetRevision()
      Description copied from interface: IncrementalWorklistUpdate
      Returns the target revision, i.e. the new revision (update count) the client worklist will have after applying this update.

      The update contains all changes that have been made to the worklist since the source revision (update count) up to (and including) the target revision.

      Like the source revision the target revision refers to the initialisation date of the worklist. Additionally marked as Immutable.

      Specified by:
      getTargetRevision in interface IncrementalWorklistUpdate
      Specified by:
      getTargetRevision in interface WorklistUpdate
      Returns:
      The target revision, i.e. the new revision the client worklist will have after applying this update.
    • getMaxPriority

      public int getMaxPriority()
      Description copied from interface: IncrementalWorklistUpdate
      Returns the highest priority of this update, that is the highest priority of all items of this update. This also includes removed items! In case of an empty complete update (source revision 0), the priority will be WorklistConstants.Priority.NORMAL. Additionally marked as Immutable.
      Specified by:
      getMaxPriority in interface IncrementalWorklistUpdate
      Specified by:
      getMaxPriority in interface WorklistUpdate
      Returns:
      The highest priority of all items of this update.
    • getNext

      public List<WorklistItemUpdate<ClientWorklistItem>> getNext(int count)
      Description copied from interface: IncrementalWorklistUpdate
      Gets the next specified amount of worklist item updates of this incremental worklist update.
      Be sure to call this method afterwards to release occupied memory and resources.
      Specified by:
      getNext in interface IncrementalWorklistUpdate
      Parameters:
      count - The amount of worklist item updates to retrieve. This has to be > 0.
      Returns:
      The next n worklist item updates of this incremental worklist update, 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, null will be returned.
    • getNext

      public List<WorklistItemUpdate<ClientWorklistItem>> getNext(int count, int start)
      Gets the next specified amount of item updates of this incremental worklist update 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 item update will be set to the index start + count, that is, getNext(n) will be the same as calling getNext(n, start + count).
      Parameters:
      count - The amount of item updates to retrieve in forward direction. This has to be > 0.
      start - The index of the item update from which to retrieve the next count item updates. 0 is the index of the first item update . This has to be >= 0 and it must not be bigger than the amounts of item updates in this incremental worklist update.
      Returns:
      The next n item updates of this incremental worklist update, where n is the specified count. In case of an insufficient amount of next item updates remaining only the available item updates will be returned. If there are no more next item updates, null will be returned.
      Throws:
      IllegalArgumentException - If count is non-positive (<= 0) or start is negative (< 0) or it refers to an index that is bigger than the amount of item updates of this incremental worklist update, an IllegalArgumentException will be thrown. The incremental worklist update will be reset to the first item update.
      IllegalStateException - If this incremental worklist update has been closed (explicitly or implicitly), an IllegalStateException will be thrown on server side.
    • getPrevious

      public List<WorklistItemUpdate<ClientWorklistItem>> getPrevious(int count)
      Gets the previous specified amount of item updates of this incremental worklist update. 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.
      Parameters:
      count - The amount of item updates to retrieve in backward direction. This has to be > 0.
      Returns:
      The previous n item updates of this incremental worklist update, where n is the specified count. The order corresponds to the one in the underlying data structure, that is previous item updates in the returned list are also previous item updates in the data structure. In case of an insufficient amount of previous item updates remaining only the available item updates will be returned. If there are no more previous item updates, null will be returned.
      Throws:
      IllegalArgumentException - If this incremental worklist update does not have any previous item updates or count is non-positive (<= 0), an IllegalArgumentException will be thrown.
      IllegalStateException - If this iterator has been closed (explicitly or implicitly), an IllegalStateException will be thrown on server side.
      de.aristaflow.adept2.model.communication.ServiceConnectionException - If this incremental worklist update has been closed (explicitly or implicitly), a ServiceConnectionException will be thrown on client side.
    • getAll

      Description copied from interface: IncrementalWorklistUpdate
      Returns all updates, i.e. the differences from the source revision up to (and including) the target revision. The map contains all worklist items including the ones which are deleted since the source revision.

      The returned collection is unmodifiable.

      When compiling the individual recorded updates into a worklist update, the case when there are multiple recorded updates for the same worklist item (i.e. same ID, not necessarily same state) needs special attention. In this case the recorded updates need to be compressed, since a worklist update may only contain one update per worklist item. It is assumed, that every revision only contains one added, removed or changed worklist item. To compress these individual updates, only the first (since the source revision) and the last recorded update of a certain worklist item need to be considered: The state of the client worklist item (which is the key of the map), is the state at the time of its last update.
      The WorklistConstants.WorklistItemUpdateType (which is the value in the map) is determined by looking at the type of the first and the last recorded update for that item. The following shows the relevant combinations and their results.

      How different worklist item update types aggregate.
      type of first recorded update type of last recorded update resulting update type
      ADDEDCHANGEDADDED
      ADDEDREMOVEDomit (NOTHING)
      ADDEDADDED_OR_CHANGEDADDED
      ADDEDREMOVED_OR_NOTHINGomit (NOTHING)
      CHANGEDCHANGEDCHANGED
      CHANGEDREMOVEDREMOVED
      CHANGEDADDED_OR_CHANGEDCHANGED
      CHANGEDREMOVED_OR_NOTHINGREMOVED
      REMOVEDADDEDCHANGED
      REMOVEDADDED_OR_CHANGEDCHANGED
      REMOVEDREMOVED_OR_NOTHINGREMOVED
      ADDED_OR_CHANGEDCHANGEDADDED_OR_CHANGED
      ADDED_OR_CHANGEDREMOVEDREMOVED_OR_NOTHING
      ADDED_OR_CHANGEDADDED_OR_CHANGEDADDED_OR_CHANGED
      ADDED_OR_CHANGEDREMOVED_OR_NOTHINGREMOVED_OR_NOTHING
      REMOVED_OR_NOTHINGADDEDADDED_OR_CHANGED
      REMOVED_OR_NOTHINGADDED_OR_CHANGEDADDED_OR_CHANGED
      REMOVED_OR_NOTHINGREMOVED_OR_NOTHINGREMOVED_OR_NOTHING
      Other combinations don't make any sense and therefore shouldn't occur. If there's only one recorded update for an item use that update's type. After calling this method once, this incremental worklist update will be closed. You will not be able to use it again, that is, every method will throw an IllegalStateException.
      Specified by:
      getAll in interface IncrementalWorklistUpdate
      Specified by:
      getAll in interface WorklistUpdate
      Returns:
      The updates / differences between source and target revision.
    • close

      public void close()
      Description copied from interface: IncrementalWorklistUpdate
      Explicitly closes this worklist update which allows to release occupied memory and resources. Closing will be done implicitly after the worklist update has been retrieved completely by calling IncrementalWorklistUpdate.getAll() once. When retrieving incrementally, be sure to call this method afterwards to release occupied memory and resources.
      This method may be called several times. Implementors have to take care of this.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface IncrementalWorklistUpdate
      Specified by:
      close in interface de.aristaflow.adept2.model.communication.ServerSideProxy
    • closeWrapped

      protected void closeWrapped(boolean closeThis)
      Closes the wrapped incremental worklist update either since it is explicitly closed or the cache contains all items and the wrapped incremental worklist update is no longer required.
      Parameters:
      closeThis - Whether to close this caching incremental worklist update or only the wrapped incremental worklist update. This affects whether the cached fields will be set or not.
    • getUserAttributeValue

      public String getUserAttributeValue(String attributeName)
      Description copied from interface: UserAttributeContainer
      Returns the value of the user attribute.
      Specified by:
      getUserAttributeValue in interface UserAttributeContainer
      Parameters:
      attributeName - The name of the user attribute.
      Returns:
      The value of the user attribute.
    • setUserAttributeValue

      public void setUserAttributeValue(String attributeName, String attributeValue)
      Description copied from interface: UserAttributeContainer
      Set the value of an user attribute.

      This method must not be called directly! Use the change primitive of the corresponding model instead! In case of the process model, refer to ChangePrimitives.updateUserAttribute(UserAttributeContainer, String, String).

      Specified by:
      setUserAttributeValue in interface UserAttributeContainer
      Parameters:
      attributeName - The name of the attribute.
      attributeValue - The new value of the attribute.
    • removeUserAttributeValue

      public void removeUserAttributeValue(String attributeName)
      Description copied from interface: UserAttributeContainer
      Removes the user attribute with the given name.

      This method must not be called directly! Use the change primitive of the corresponding model instead! In case of the process model, refer to ChangePrimitives.updateUserAttribute(UserAttributeContainer, String, String).

      Specified by:
      removeUserAttributeValue in interface UserAttributeContainer
      Parameters:
      attributeName - The key of the value to remove.
    • getUserAttributes

      public Map<String,String> getUserAttributes()
      Description copied from interface: UserAttributeContainer
      Returns all user attributes as map, the key of the map is the name of the attribute. Do not change the returned map even if it is modifiable. Implementations will usually return a copy of the map. See UserAttributeContainer.setUserAttributeValue(String, String) and UserAttributeContainer.removeUserAttributeValue(String) on how to change user attributes.
      Specified by:
      getUserAttributes in interface UserAttributeContainer
      Returns:
      A (copy of the) map with all user defined attributes.