Package org.nuxeo.wopi.lock
Class LockHelper
- java.lang.Object
-
- org.nuxeo.wopi.lock.LockHelper
-
public class LockHelper extends Object
- Since:
- 10.3
-
-
Field Summary
Fields Modifier and Type Field Description protected static ThreadLocal<Boolean>isWOPIRequestFlag to know if the request originated from a WOPI client.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddLock(String fileId, String lock)Stores the given WOPI lock for the given file id with a timestamp for expiration purpose.static voidaddLock(String fileId, String repository, String docId, String lock)static voiddoPrivilegedOnLockDirectory(Consumer<Session> consumer)Performs the given consumer with a privileged session on the lock directory.static <R> RdoPrivilegedOnLockDirectory(Function<Session,R> function)Applies the given function with a privileged session on the lock directory.static voidflagWOPIRequest()Flags the request as originating from a WOPI client.protected static Map<String,List<DocumentModel>>getExpiredLocks(Session session, String repository)static Map<String,List<DocumentModel>>getExpiredLocksByRepository(Session session)Returns the list of expired stored WOPI locks according to theConstants.LOCK_TTLfor each repository.static StringgetLock(String fileId)Gets the WOPI lock stored for the given file id if it exists, returnsnullotherwise.static booleanisLocked(String fileId)Checks if a WOPI lock is stored for the given file id.static booleanisLocked(String repository, String docId)Checks if a WOPI lock is stored for the given repository and doc id, no matter the xpath.static booleanisWOPIRequest()Returnstrueif the request originated from a WOPI client.protected static SessionopenLockDirectorySession()static voidrefreshLock(String fileId)Updates the WOPI lock stored for the given file id with a fresh timestamp.static voidremoveLock(String fileId)Removes the WOPI lock stored for the given file id.static voidremoveLocks(String repository, String docId)Removes all the WOPI locks stored for the given repository and doc id.static voidunflagWOPIRequest()Unflags the request as originating from a WOPI client.static voidupdateLock(String fileId, String lock)Updates the WOPI lock stored for the given file id with the given lock and a fresh timestamp.
-
-
-
Field Detail
-
isWOPIRequest
protected static ThreadLocal<Boolean> isWOPIRequest
Flag to know if the request originated from a WOPI client.
-
-
Method Detail
-
addLock
public static void addLock(String fileId, String lock)
Stores the given WOPI lock for the given file id with a timestamp for expiration purpose.
-
addLock
public static void addLock(String fileId, String repository, String docId, String lock)
- See Also:
addLock(String, String)
-
getLock
public static String getLock(String fileId)
Gets the WOPI lock stored for the given file id if it exists, returnsnullotherwise.
-
isLocked
public static boolean isLocked(String repository, String docId)
Checks if a WOPI lock is stored for the given repository and doc id, no matter the xpath.
-
isLocked
public static boolean isLocked(String fileId)
Checks if a WOPI lock is stored for the given file id.
-
updateLock
public static void updateLock(String fileId, String lock)
Updates the WOPI lock stored for the given file id with the given lock and a fresh timestamp.
-
refreshLock
public static void refreshLock(String fileId)
Updates the WOPI lock stored for the given file id with a fresh timestamp.
-
removeLock
public static void removeLock(String fileId)
Removes the WOPI lock stored for the given file id.
-
removeLocks
public static void removeLocks(String repository, String docId)
Removes all the WOPI locks stored for the given repository and doc id.
-
doPrivilegedOnLockDirectory
public static void doPrivilegedOnLockDirectory(Consumer<Session> consumer)
Performs the given consumer with a privileged session on the lock directory.
-
doPrivilegedOnLockDirectory
public static <R> R doPrivilegedOnLockDirectory(Function<Session,R> function)
Applies the given function with a privileged session on the lock directory.
-
getExpiredLocksByRepository
public static Map<String,List<DocumentModel>> getExpiredLocksByRepository(Session session)
Returns the list of expired stored WOPI locks according to theConstants.LOCK_TTLfor each repository.The given session must be privileged.
-
isWOPIRequest
public static boolean isWOPIRequest()
Returnstrueif the request originated from a WOPI client.
-
flagWOPIRequest
public static void flagWOPIRequest()
Flags the request as originating from a WOPI client.
-
unflagWOPIRequest
public static void unflagWOPIRequest()
Unflags the request as originating from a WOPI client.
-
getExpiredLocks
protected static Map<String,List<DocumentModel>> getExpiredLocks(Session session, String repository)
-
openLockDirectorySession
protected static Session openLockDirectorySession()
-
-