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 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. 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CachingIncWorklistUpdate.CachingIncWorklistUpdateCloseTask
The clean-up task for closing/dropping theIncrementalWorklistUpdate
.
-
Field Summary
Fields Modifier and Type Field Description protected Cleanup<RuntimeException>
cleanup
The clean-up for closing the wrapped update as post-mortem task for this instance.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)
Deprecated, for removal: This API element is subject to removal in a future version.CachingIncWorklistUpdate(IncrementalWorklistUpdate wrappedUpdate, long initialAliveTime, long aliveTimeExtension, Logger logger)
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
close()
Explicitly closes this worklist update which allows to release occupied memory and resources.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.protected Long
exit()
Tracks exiting a method reentrant and possibly extends the alive time of the wrapped worklist update.List<WorklistItemUpdate<ClientWorklistItem>>
getAll()
Returns all updates, i.e. the differences from the source revision up to (and including) the target revision.long
getCloseTime()
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.long
getRemainingAliveTime()
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.boolean
isBusy()
long
keepAlive(long aliveTime)
void
removeUserAttributeValue(String attributeName)
Removes the user attribute with the given name.long
setCloseTime(long closeTime)
void
setUserAttributeValue(String attributeName, String attributeValue)
Set the value of an user attribute.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.worklistmodel.IncrementalWorklistUpdate
drop
-
-
-
-
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 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 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.
-
cleanup
protected transient Cleanup<RuntimeException> cleanup
The clean-up for closing the wrapped update as post-mortem task for this instance.
-
-
Constructor Detail
-
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 (withgetNext(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 (withgetNext(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 Detail
-
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 interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
setCloseTime
public long setCloseTime(long closeTime)
- Specified by:
setCloseTime
in interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
isBusy
public boolean isBusy()
- Specified by:
isBusy
in interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
getRemainingAliveTime
public long getRemainingAliveTime()
- Specified by:
getRemainingAliveTime
in interfacede.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
getRemainingAliveTime
in interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
keepAlive
public long keepAlive(long aliveTime) throws IOException
- Specified by:
keepAlive
in interfacede.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
keepAlive
in interfacede.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 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 closed (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 closed (explicitly or implicitly), anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If this incremental worklist update has been closed (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 closed
. 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.
-
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 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceIncrementalWorklistUpdate
- Specified by:
close
in interfacede.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 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.
-
-