Class CmsLockUtil


  • public final class CmsLockUtil
    extends java.lang.Object
    Locking utility class.

    • Method Detail

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