Class InMemoryLockManager


  • public final class InMemoryLockManager
    extends java.lang.Object
    In-Memory Lock Manager - manages locks in the COARSE GRAINED LOCK example
    In non-distributed scenarios it often makes more sense to leverage an in-memory lock management rather than storing lock information in database tables.
    A big advantage (besides performance) of in-memory management is the fact that the system is always in a clean state after startup (no lock zombies surviving in lock tables).
    Author:
    Karl Eilebrecht
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean acquireReadLock​(java.lang.String elementId, java.lang.String ownerId)
      Creates a read lock for the given owner
      static boolean acquireWriteLock​(java.lang.String elementId, java.lang.String ownerId)
      Creates a write lock for the given owner
      static InMemoryLockManager.ElementLock getLockInfo​(java.lang.String elementId)
      Returns the lock currently associated with the specified element
      static boolean releaseLock​(java.lang.String elementId, java.lang.String ownerId)
      Releases the lock the given owner has on the specified element
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • acquireReadLock

        public static boolean acquireReadLock​(java.lang.String elementId,
                                              java.lang.String ownerId)
        Creates a read lock for the given owner
        Parameters:
        elementId - global unique identifier of the item to be locked
        ownerId - requester of the lock
        Returns:
        true if lock was set otherwise false
      • acquireWriteLock

        public static boolean acquireWriteLock​(java.lang.String elementId,
                                               java.lang.String ownerId)
        Creates a write lock for the given owner
        Parameters:
        elementId - global unique identifier of the item to be locked
        ownerId - requester of the lock
        Returns:
        true if lock was set otherwise false
      • releaseLock

        public static boolean releaseLock​(java.lang.String elementId,
                                          java.lang.String ownerId)
        Releases the lock the given owner has on the specified element
        Parameters:
        elementId - global unique identifier of the item to be locked
        ownerId - requester of the lock
        Returns:
        true if lock was released, otherwise false (no lock found)
      • getLockInfo

        public static InMemoryLockManager.ElementLock getLockInfo​(java.lang.String elementId)
        Returns the lock currently associated with the specified element
        Parameters:
        elementId - globally unique identifier
        Returns:
        lock meta data object or null if no lock was found