Package org.opencms.lock
Class CmsLockUtil
- java.lang.Object
-
- org.opencms.lock.CmsLockUtil
-
public final class CmsLockUtil extends java.lang.Object
Locking utility class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsLockUtil.LockedFile
Helper to handle the lock reports together with the files.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 java.lang.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 java.lang.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 Detail
-
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
public static void tryUnlock(CmsObject cms, CmsResource resource)
Tries to unlock the given resource.Will ignore any failure.
- Parameters:
cms
- the cms contextresource
- the resource to unlock
-
withLockedResources
public static java.lang.AutoCloseable withLockedResources(CmsObject cms, boolean shallow, CmsResource... resources) throws java.lang.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:
java.lang.Exception
- if something goes wrong
-
withLockedResources
public static java.lang.AutoCloseable withLockedResources(CmsObject cms, CmsResource... resources) throws java.lang.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:
java.lang.Exception
- if something goes wrong
-
-