Package org.opencms.lock
Class CmsLockUtil
java.lang.Object
org.opencms.lock.CmsLockUtil
Locking utility class.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Helper to handle the lock reports together with the files. -
Method Summary
Modifier and TypeMethodDescriptionstatic CmsLockActionRecord
ensureLock
(CmsObject cms, CmsResource resource) Static helper method to lock a resource.static CmsLockActionRecord
ensureLock
(CmsObject cms, CmsResource resource, boolean shallow) Static helper method to lock a resource.static void
tryUnlock
(CmsObject cms, CmsResource resource) Tries to unlock the given resource.static AutoCloseable
withLockedResources
(CmsObject cms, boolean shallow, CmsResource... resources) Utility method for locking and unlocking a set of resources conveniently with the try-with syntax from Java 1.7.static AutoCloseable
withLockedResources
(CmsObject cms, CmsResource... resources) Utility method for locking and unlocking a set of resources conveniently with the try-with syntax from Java 1.7.
-
Method Details
-
ensureLock
public static CmsLockActionRecord ensureLock(CmsObject cms, CmsResource resource) throws CmsException Static helper method to lock a resource.- Parameters:
cms
- the CMS context to useresource
- the resource to lock- Returns:
- the action that was taken
- Throws:
CmsException
- if something goes wrong
-
ensureLock
public static CmsLockActionRecord ensureLock(CmsObject cms, CmsResource resource, boolean shallow) throws CmsException Static helper method to lock a resource.- Parameters:
cms
- the CMS context to useresource
- the resource to lockshallow
- true if we only need a shallow lock- Returns:
- the action that was taken
- Throws:
CmsException
- if something goes wrong
-
tryUnlock
Tries to unlock the given resource.Will ignore any failure.
- Parameters:
cms
- the cms contextresource
- the resource to unlock
-
withLockedResources
public static AutoCloseable withLockedResources(CmsObject cms, boolean shallow, CmsResource... resources) throws Exception Utility method for locking and unlocking a set of resources conveniently with the try-with syntax from Java 1.7.This method locks a set of resources and returns a Closeable instance that will unlock the locked resources when its close() method is called.
- Parameters:
cms
- the CMS contextshallow
- true if we only want shallow locksresources
- the resources to lock- Returns:
- the Closeable used to unlock the resources
- Throws:
Exception
- if something goes wrong
-
withLockedResources
public static AutoCloseable withLockedResources(CmsObject cms, CmsResource... resources) throws Exception Utility method for locking and unlocking a set of resources conveniently with the try-with syntax from Java 1.7.This method locks a set of resources and returns a Closeable instance that will unlock the locked resources when its close() method is called.
- Parameters:
cms
- the CMS contextresources
- the resources to lock- Returns:
- the Closeable used to unlock the resources
- Throws:
Exception
- if something goes wrong
-