Class CmsLockUtil

java.lang.Object
org.opencms.lock.CmsLockUtil

public final class CmsLockUtil extends Object
Locking utility class.

  • 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 use
      resource - 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 use
      resource - the resource to lock
      shallow - 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 context
      resource - 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 context
      shallow - true if we only want shallow locks
      resources - 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 context
      resources - the resources to lock
      Returns:
      the Closeable used to unlock the resources
      Throws:
      Exception - if something goes wrong