Class LockManager

java.lang.Object
de.calamanari.pk.pessimisticofflinelock.LockManager

public final class LockManager
extends java.lang.Object
Lock Manager - manages locks in this PESSIMISTIC OFFLINE LOCK example
This one uses a global lock table in the database
Author:
Karl Eilebrecht
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  LockManager.LockInfo
    In-memory representation of lock data
    static class  LockManager.LockType
    Enumeration of supported lock types
  • Method Summary

    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 LockManager.LockInfo getLockInfo​(java.lang.String elementId)
    Returns the current lock information related to the given 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 Details

    • 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 - identifier of the element which was locked
      ownerId - owner of the lock to be released
      Returns:
      true if lock was released, otherwise false (no lock found)
    • getLockInfo

      public static LockManager.LockInfo getLockInfo​(java.lang.String elementId)
      Returns the current lock information related to the given element
      Parameters:
      elementId - identifier of an element which might be locked
      Returns:
      lock info