IDTYPE - The type of object to be locked. E.g. String or TypedObject. Must
implement equals and hashCode!@ThreadSafe public class DefaultLockManager<IDTYPE> extends Object implements ILockManager<IDTYPE>
| Constructor and Description |
|---|
DefaultLockManager(ICurrentUserIDProvider aCurrentUserIDProvider) |
| Modifier and Type | Method and Description |
|---|---|
Set<IDTYPE> |
getAllLockedObjects() |
Set<IDTYPE> |
getAllLockedObjectsOfCurrentUser() |
Set<IDTYPE> |
getAllLockedObjectsOfUser(String sUserID) |
Map<IDTYPE,ILockInfo> |
getAllLockInfos() |
org.joda.time.DateTime |
getLockDateTime(IDTYPE aObjID)
Get the date and time when the given object was locked.
|
ILockInfo |
getLockInfo(IDTYPE aObjID)
Get the lock information of the given object.
|
String |
getLockUserID(IDTYPE aObjID)
Get the user ID who locked the given object.
|
boolean |
isObjectLockedByAnyUser(IDTYPE aObjID)
Check if the object with the given ID is locked by any user.
|
boolean |
isObjectLockedByCurrentUser(IDTYPE aObjID)
Check if the object with the given ID is locked by the current user.
|
boolean |
isObjectLockedByOtherUser(IDTYPE aObjID)
Check if the object with the given ID is locked by any but the current
user.
|
ELocked |
lockObject(IDTYPE aObjID)
Lock the object with the given ID.
|
ELocked |
lockObject(IDTYPE aObjID,
String sUserID)
Lock the object with the given ID.
|
LockResult<IDTYPE> |
lockObjectAndUnlockAllOthers(IDTYPE aObjID)
Lock the object with the given ID and unlock all other objects.
|
LockResult<IDTYPE> |
lockObjectAndUnlockAllOthers(IDTYPE aObjID,
String sUserID)
Lock the object with the given ID and unlock all other objects.
|
void |
setCurrentUserIDProvider(ICurrentUserIDProvider aCurrentUserIDProvider) |
String |
toString() |
List<IDTYPE> |
unlockAllObjectsOfCurrentUser()
Unlock all objects of the current user.
|
List<IDTYPE> |
unlockAllObjectsOfCurrentUserExcept(Set<IDTYPE> aObjectsToKeepLocked)
Unlock all objects of the current user except for the passed objects.
|
List<IDTYPE> |
unlockAllObjectsOfUser(String sUserID)
Unlock all objects of the passed user.
|
List<IDTYPE> |
unlockAllObjectsOfUserExcept(String sUserID,
Set<IDTYPE> aObjectsToKeepLocked)
Unlock all objects of the passed user except for the passed objects.
|
com.helger.commons.state.EChange |
unlockObject(IDTYPE aObjID)
Unlock the object with the given ID.
|
com.helger.commons.state.EChange |
unlockObject(String sUserID,
IDTYPE aObjID)
Manually unlock a special object locked by a special user.
|
public DefaultLockManager(@Nonnull ICurrentUserIDProvider aCurrentUserIDProvider)
public final void setCurrentUserIDProvider(@Nonnull ICurrentUserIDProvider aCurrentUserIDProvider)
@Nullable public final ILockInfo getLockInfo(@Nullable IDTYPE aObjID)
ILockManagergetLockInfo in interface ILockManager<IDTYPE>aObjID - The object to query for lock owner.null if the object is not locked, the lock information
otherwise@Nullable public final String getLockUserID(@Nullable IDTYPE aObjID)
ILockManagergetLockUserID in interface ILockManager<IDTYPE>aObjID - The object to query for lock owner.null if the object is not locked, the user ID
otherwise@Nullable public final org.joda.time.DateTime getLockDateTime(@Nullable IDTYPE aObjID)
ILockManagergetLockDateTime in interface ILockManager<IDTYPE>aObjID - The object to query for lock owner.null if the object is not locked, the locking date
time otherwise@Nonnull public final ELocked lockObject(@Nonnull IDTYPE aObjID)
ILockManagerlockObject in interface ILockManager<IDTYPE>aObjID - The object ID to lock. May not be null.ELocked.LOCKED if the object is locked by the current user
after the call to this method, ELocked.NOT_LOCKED if the
object was already locked by another user.@Nonnull public final ELocked lockObject(@Nonnull IDTYPE aObjID, @Nullable String sUserID)
ILockManagerlockObject in interface ILockManager<IDTYPE>aObjID - The object ID to lock. May not be null.sUserID - The id of the user who locked the object. May be null.ELocked.LOCKED if the object is locked by the specified
user after the call to this method, ELocked.NOT_LOCKED if
the object was already locked by another user or no user ID was
provided.@Nonnull public final LockResult<IDTYPE> lockObjectAndUnlockAllOthers(@Nonnull IDTYPE aObjID)
ILockManagerlockObjectAndUnlockAllOthers in interface ILockManager<IDTYPE>aObjID - The object ID to lock. May not be null.null. If
ILockedIndicator.isLocked() is true, the
object is locked by the current user after the call to this method.
If ILockedIndicator.isNotLocked() is true the
object was already locked by another user.@Nonnull public final LockResult<IDTYPE> lockObjectAndUnlockAllOthers(@Nonnull IDTYPE aObjID, @Nullable String sUserID)
ILockManagerlockObjectAndUnlockAllOthers in interface ILockManager<IDTYPE>aObjID - The object ID to lock. May not be null.sUserID - The id of the user who locked the object. May be null.ELocked.LOCKED if the object is locked by the specified
user after the call to this method, ELocked.NOT_LOCKED if
the object was already locked by another user or no user ID was
provided.@Nonnull public final com.helger.commons.state.EChange unlockObject(@Nonnull IDTYPE aObjID)
ILockManagerunlockObject in interface ILockManager<IDTYPE>aObjID - The object ID to unlock.true if the object was successfully unlocked,
false if either the object is not locked or the object
is locked by another user than the current session user.@Nonnull public final com.helger.commons.state.EChange unlockObject(@Nonnull String sUserID, @Nonnull IDTYPE aObjID)
ILockManagerunlockObject in interface ILockManager<IDTYPE>sUserID - The user who locked the object.aObjID - The object to be unlocked.true if unlocking succeeded, false
otherwise.@Nonnull @ReturnsMutableCopy public final List<IDTYPE> unlockAllObjectsOfCurrentUser()
ILockManagerunlockAllObjectsOfCurrentUser in interface ILockManager<IDTYPE>null.@Nonnull @ReturnsMutableCopy public final List<IDTYPE> unlockAllObjectsOfCurrentUserExcept(@Nullable Set<IDTYPE> aObjectsToKeepLocked)
ILockManagerunlockAllObjectsOfCurrentUserExcept in interface ILockManager<IDTYPE>aObjectsToKeepLocked - An optional set of objects which should not be unlocked. May be
null or empty.null.@Nonnull @ReturnsMutableCopy public final List<IDTYPE> unlockAllObjectsOfUser(@Nullable String sUserID)
ILockManagerunlockAllObjectsOfUser in interface ILockManager<IDTYPE>sUserID - The user ID who's object are to be unlocked. May be
null or empty.null.@Nonnull @ReturnsMutableCopy public final List<IDTYPE> unlockAllObjectsOfUserExcept(@Nullable String sUserID, @Nullable Set<IDTYPE> aObjectsToKeepLocked)
ILockManagerunlockAllObjectsOfUserExcept in interface ILockManager<IDTYPE>sUserID - The user ID who's object are to be unlocked. May be
null or empty.aObjectsToKeepLocked - An optional set of objects which should not be unlocked. May be
null or empty.null.public final boolean isObjectLockedByCurrentUser(@Nullable IDTYPE aObjID)
ILockManagerisObjectLockedByCurrentUser in interface ILockManager<IDTYPE>aObjID - The object ID to check.true if the object is locked by the current user,
false if the object is either not locked or locked by
another user.public final boolean isObjectLockedByOtherUser(@Nullable IDTYPE aObjID)
ILockManagerisObjectLockedByOtherUser in interface ILockManager<IDTYPE>aObjID - The object ID to check.true if the object is locked by any user that is not
the currently logged in user, false if the object is
either not locked or locked by the current user.public final boolean isObjectLockedByAnyUser(@Nullable IDTYPE aObjID)
ILockManagerisObjectLockedByAnyUser in interface ILockManager<IDTYPE>aObjID - The object ID to check.true if the object is locked by any user,
false if the object is not locked.@Nonnull @ReturnsMutableCopy public final Set<IDTYPE> getAllLockedObjects()
getAllLockedObjects in interface ILockManager<IDTYPE>null set of all locked objects of all users.
Never null but maybe empty.@Nonnull @ReturnsMutableCopy public final Map<IDTYPE,ILockInfo> getAllLockInfos()
getAllLockInfos in interface ILockManager<IDTYPE>null map of all locked objects of all users.
Never null but maybe empty.@Nonnull @ReturnsMutableCopy public Set<IDTYPE> getAllLockedObjectsOfCurrentUser()
getAllLockedObjectsOfCurrentUser in interface ILockManager<IDTYPE>null set of all locked objects of the current
user. Never null but maybe empty.@Nonnull @ReturnsMutableCopy public Set<IDTYPE> getAllLockedObjectsOfUser(@Nullable String sUserID)
getAllLockedObjectsOfUser in interface ILockManager<IDTYPE>sUserID - The user ID to be queried for all locked objects. May be
null.null set of all locked objects of the passed
user. Never null but maybe empty.Copyright © 2014–2015 Philip Helger. All rights reserved.