Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.appbasics.security.lock;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 
Base interface for a manager that handles object locking. See DefaultLockManager for a per-instance implementation and ObjectLockManager for a singleton version.

Parameters:
<IDTYPE> The type of object to be locked. E.g. String or TypedObject. Must implement equals and hashCode!
Author(s):
Philip Helger
 
 public interface ILockManager <IDTYPE>
 {
  
Get the lock information of the given object.

Parameters:
aObjID The object to query for lock owner.
Returns:
null if the object is not locked, the lock information otherwise
 
   @Nullable
   ILockInfo getLockInfo (@Nullable IDTYPE aObjID);

  
Get the user ID who locked the given object.

Parameters:
aObjID The object to query for lock owner.
Returns:
null if the object is not locked, the user ID otherwise
 
   @Nullable
   String getLockUserID (@Nullable IDTYPE aObjID);

  
Get the date and time when the given object was locked.

Parameters:
aObjID The object to query for lock owner.
Returns:
null if the object is not locked, the locking date time otherwise
 
   @Nullable
   DateTime getLockDateTime (@Nullable IDTYPE aObjID);

  
Lock the object with the given ID. If the passed object is already locked by this user, this method has no effect. This is an atomic action.

Parameters:
aObjID The object ID to lock. May not be null.
Returns:
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
   ELocked lockObject (@Nonnull IDTYPE aObjID);

  
Lock the object with the given ID. If the passed object is already locked by this user, this method has no effect. This is an atomic action.

Parameters:
aObjID The object ID to lock. May not be null.
sUserID The id of the user who locked the object. May be null.
Returns:
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.
  ELocked lockObject (@Nonnull IDTYPE aObjID, @Nullable String sUserID);

  
Lock the object with the given ID and unlock all other objects. If the passed object is already locked by this user, this method has no effect. This is an atomic action.

Parameters:
aObjID The object ID to lock. May not be null.
Returns:
The locking result and never 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.
  LockResult <IDTYPE> lockObjectAndUnlockAllOthers (@Nonnull IDTYPE aObjID);

  
Lock the object with the given ID and unlock all other objects. If the passed object is already locked by this user, this method has no effect. This is an atomic action.

Parameters:
aObjID The object ID to lock. May not be null.
sUserID The id of the user who locked the object. May be null.
Returns:
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.
  LockResult <IDTYPE> lockObjectAndUnlockAllOthers (@Nonnull IDTYPE aObjID, @Nullable String sUserID);

  
Unlock the object with the given ID. Unlocking is only possible, if the current session user locked the object.

Parameters:
aObjID The object ID to unlock.
Returns:
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.
  EChange unlockObject (@Nonnull IDTYPE aObjID);

  
Manually unlock a special object locked by a special user. This manual version is only required for especially unlocking a user!

Parameters:
sUserID The user who locked the object.
aObjID The object to be unlocked.
Returns:
true if unlocking succeeded, false otherwise.
  EChange unlockObject (@Nonnull String sUserID, @Nonnull IDTYPE aObjID);

  
Unlock all objects of the current user.

Returns:
The list of all unlocked object IDs. Never null.
  List <IDTYPE> unlockAllObjectsOfCurrentUser ();

  
Unlock all objects of the current user except for the passed objects.

Parameters:
aObjectsToKeepLocked An optional set of objects which should not be unlocked. May be null or empty.
Returns:
The list of all unlocked object IDs. Never null.
  List <IDTYPE> unlockAllObjectsOfCurrentUserExcept (@Nullable Set <IDTYPE> aObjectsToKeepLocked);

  
Unlock all objects of the passed user.

Parameters:
sUserID The user ID who's object are to be unlocked. May be null or empty.
Returns:
The list of all unlocked object IDs. Never null.
  List <IDTYPE> unlockAllObjectsOfUser (@Nullable String sUserID);

  
Unlock all objects of the passed user except for the passed objects.

Parameters:
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.
Returns:
The list of all unlocked object IDs. Never null.
  List <IDTYPE> unlockAllObjectsOfUserExcept (@Nullable String sUserID, @Nullable Set <IDTYPE> aObjectsToKeepLocked);

  
Check if the object with the given ID is locked by the current user.

Parameters:
aObjID The object ID to check.
Returns:
true if the object is locked by the current user, false if the object is either not locked or locked by another user.
  boolean isObjectLockedByCurrentUser (@Nullable IDTYPE aObjID);

  
Check if the object with the given ID is locked by any but the current user.

Parameters:
aObjID The object ID to check.
Returns:
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.
  boolean isObjectLockedByOtherUser (@Nullable IDTYPE aObjID);

  
Check if the object with the given ID is locked by any user.

Parameters:
aObjID The object ID to check.
Returns:
true if the object is locked by any user, false if the object is not locked.
  boolean isObjectLockedByAnyUser (@Nullable IDTYPE aObjID);

  

Returns:
A non-null set of all locked objects of all users. Never null but maybe empty.
  Set <IDTYPE> getAllLockedObjects ();

  

Returns:
A non-null map of all locked objects of all users. Never null but maybe empty.
  Map <IDTYPE, ILockInfogetAllLockInfos ();

  

Returns:
A non-null set of all locked objects of the current user. Never null but maybe empty.

Parameters:
sUserID The user ID to be queried for all locked objects. May be null.
Returns:
A non-null set of all locked objects of the passed user. Never null but maybe empty.
  Set <IDTYPE> getAllLockedObjectsOfUser (@Nullable String sUserID);
New to GrepCode? Check out our FAQ X