Class CachingIncWorklistUpdate
- java.lang.Object
-
- de.aristaflow.adept2.model.worklistmodel.CachingIncWorklistUpdate
-
- All Implemented Interfaces:
UserAttributeContainer
,IncrementalWorklistUpdate
,WorklistUpdate
,Serializable
public class CachingIncWorklistUpdate extends Object implements IncrementalWorklistUpdate
This incremental worklist update implements a cache for the underlying incremental worklist update, that is, when iterating viagetNext(int)
, all retrieved item updates will be cached. Previous item updates will always be retrieved from the cache. Note that apositioned next
will add enough item updates to the cache to fulfil the request.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
current
The reference to the current item update which is to be retrieved next.protected List<WorklistItemUpdate<ClientWorklistItem>>
itemUpdates
The item updates that have been retrieved from the underlying incremental worklist update so far.protected int
last
The index of last item update in case it has been reached in the result set, -1 otherwise.protected int
lastCached
The index of the last item update that is in the cache.protected Integer
maxPriority
The maximum priority of the worklist update.protected WorklistRevision
sourceRevision
The source revision of the worklist update.protected Long
targetRevision
The target revision of the worklist update.protected UUID
worklistId
The ID the worklist of the incremental worklist update.protected IncrementalWorklistUpdate
wrappedUpdate
The wrapped incremental worklist update of which all item updates will be cached.
-
Constructor Summary
Constructors Constructor Description CachingIncWorklistUpdate(IncrementalWorklistUpdate wrappedUpdate)
Creates a new caching incremental worklist update for the designated incremental worklist update.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
drop()
Explicitly drops this worklist update which allows to release occupied memory and resources.protected void
dropWrapped(boolean dropThis)
Drops the wrapped incremental worklist update either since it is explicitly dropped or the cache contains all items and the wrapped incremental worklist update is no longer required.List<WorklistItemUpdate<ClientWorklistItem>>
getAll()
Returns all updates, i.e. the differences from the source revision up to (and including) the target revision.int
getMaxPriority()
Returns the highest priority of this update, that is the highest priority of all items of this update.List<WorklistItemUpdate<ClientWorklistItem>>
getNext(int count)
Gets the next specified amount of worklist item updates of this incremental worklist update.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).List<WorklistItemUpdate<ClientWorklistItem>>
getPrevious(int count)
Gets the previous specified amount of item updates of this incremental worklist update.WorklistRevision
getSourceRevision()
Gets the source revision, i.e. the worklist revision (initialisation date and update count) to which this update can be applied.long
getTargetRevision()
Returns the target revision, i.e. the new revision (update count) the client worklist will have after applying this update.Map<String,String>
getUserAttributes()
Returns all user attributes as map, the key of the map is the name of the attribute.String
getUserAttributeValue(String attributeName)
Returns the value of the user attribute.UUID
getWorklistID()
The ID of the worklist for which this update is intended.void
removeUserAttributeValue(String attributeName)
Removes the user attribute with the given name.void
setUserAttributeValue(String attributeName, String attributeValue)
Set the value of an user attribute.
-
-
-
Field Detail
-
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 benull
when the incremental worklist update has been dropped.
-
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 benull
until first retrieved from the wrapped incremental worklist update.
-
sourceRevision
protected WorklistRevision sourceRevision
The source revision of the worklist update. This will benull
until first retrieved from the wrapped incremental worklist update.
-
targetRevision
protected Long targetRevision
The target revision of the worklist update. This will benull
until first retrieved from the wrapped incremental worklist update.
-
maxPriority
protected Integer maxPriority
The maximum priority of the worklist update. This will benull
until first retrieved from the wrapped incremental worklist update.
-
-
Constructor Detail
-
CachingIncWorklistUpdate
public CachingIncWorklistUpdate(IncrementalWorklistUpdate wrappedUpdate)
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 (withgetNext(int)
).
-
-
Method Detail
-
getWorklistID
public UUID getWorklistID()
Description copied from interface:IncrementalWorklistUpdate
The ID of the worklist for which this update is intended. Additionally marked asImmutable
.- Specified by:
getWorklistID
in interfaceIncrementalWorklistUpdate
- Specified by:
getWorklistID
in interfaceWorklistUpdate
- 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 thesource revision
up to (and including) thetarget revision (update count)
. Additionally marked asImmutable
.- Specified by:
getSourceRevision
in interfaceIncrementalWorklistUpdate
- Specified by:
getSourceRevision
in interfaceWorklistUpdate
- 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) thetarget revision
.Like the source revision the target revision refers to the initialisation date of the worklist. Additionally marked as
Immutable
.- Specified by:
getTargetRevision
in interfaceIncrementalWorklistUpdate
- Specified by:
getTargetRevision
in interfaceWorklistUpdate
- 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 beWorklistConstants.Priority.NORMAL
. Additionally marked asImmutable
.- Specified by:
getMaxPriority
in interfaceIncrementalWorklistUpdate
- Specified by:
getMaxPriority
in interfaceWorklistUpdate
- 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 interfaceIncrementalWorklistUpdate
- 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, anIllegalArgumentException
will be thrown. The incremental worklist update will be reset to the first item update.IllegalStateException
- If this incremental worklist update has been dropped (explicitly or implicitly), anIllegalStateException
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), anIllegalArgumentException
will be thrown.IllegalStateException
- If this iterator has been dropped (explicitly or implicitly), anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If this incremental worklist update has been dropped (explicitly or implicitly), aServiceConnectionException
will be thrown on client side.
-
getAll
public List<WorklistItemUpdate<ClientWorklistItem>> 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.
TheWorklistConstants.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 ADDED CHANGED ADDED ADDED REMOVED omit (NOTHING) ADDED ADDED_OR_CHANGED ADDED ADDED REMOVED_OR_NOTHING omit (NOTHING) CHANGED CHANGED CHANGED CHANGED REMOVED REMOVED CHANGED ADDED_OR_CHANGED CHANGED CHANGED REMOVED_OR_NOTHING REMOVED REMOVED ADDED CHANGED REMOVED ADDED_OR_CHANGED CHANGED REMOVED REMOVED_OR_NOTHING REMOVED ADDED_OR_CHANGED CHANGED ADDED_OR_CHANGED ADDED_OR_CHANGED REMOVED REMOVED_OR_NOTHING ADDED_OR_CHANGED ADDED_OR_CHANGED ADDED_OR_CHANGED ADDED_OR_CHANGED REMOVED_OR_NOTHING REMOVED_OR_NOTHING REMOVED_OR_NOTHING ADDED ADDED_OR_CHANGED REMOVED_OR_NOTHING ADDED_OR_CHANGED ADDED_OR_CHANGED REMOVED_OR_NOTHING REMOVED_OR_NOTHING REMOVED_OR_NOTHING dropped
. You will not be able to use it again, that is, every method will throw anIllegalStateException
.- Specified by:
getAll
in interfaceIncrementalWorklistUpdate
- Specified by:
getAll
in interfaceWorklistUpdate
- Returns:
- The updates / differences between source and target revision.
-
drop
public void drop()
Description copied from interface:IncrementalWorklistUpdate
Explicitly drops this worklist update which allows to release occupied memory and resources. Dropping will be done implicitly after the worklist update has been retrieved completely by callingIncrementalWorklistUpdate.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:
drop
in interfaceIncrementalWorklistUpdate
-
dropWrapped
protected void dropWrapped(boolean dropThis)
Drops the wrapped incremental worklist update either since it is explicitly dropped or the cache contains all items and the wrapped incremental worklist update is no longer required.- Parameters:
dropThis
- Whether to drop 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 interfaceUserAttributeContainer
- 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 interfaceUserAttributeContainer
- 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 interfaceUserAttributeContainer
- 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. SeeUserAttributeContainer.setUserAttributeValue(String, String)
andUserAttributeContainer.removeUserAttributeValue(String)
on how to change user attributes.- Specified by:
getUserAttributes
in interfaceUserAttributeContainer
- Returns:
- A (copy of the) map with all user defined attributes.
-
-