Class LockManager

java.lang.Object
org.openspaces.core.map.LockManager

public class LockManager extends Object
The lock manager is built on top of IMap and supports the ability to lock and unlock certain keys within the map.
Author:
kimchy
  • Field Details

    • EMPTY_LOCK_VALUE

      public static final Object EMPTY_LOCK_VALUE
      A empty lock value written to indicate a lock when there is no value to lock on (i.e. calling lock on a key where there is no value in the cache).
  • Constructor Details

    • LockManager

      public LockManager(IMap map)
      Creates a new Lock Manager based on the IMap.
  • Method Details

    • isEmptyLockValue

      public static boolean isEmptyLockValue(Object value)
    • lock

      public LockHandle lock(Object key, long lockTimeToLive, long timeoutWaitingForLock)
      Locks the given key for any updates. Retruns a LockHandle that can be used to perform specific updates under the same lock (by using the transaction object stored within it).

      Might create an empty value if there is no value in order to lock on. The empty value can be checked using isEmptyLockValue(Object).

      Parameters:
      key - The key to lock
      lockTimeToLive - The lock time to live (in milliseconds)
      timeoutWaitingForLock - The time to wait for an already locked lock
      Returns:
      LockHandle that can be used to perfrom operations under the given lock
    • putAndUnlock

      public void putAndUnlock(Object key, Object value)
      Unlocks the given key and puts the given value in a single operation.
      Parameters:
      key - The key to unlock and put the value in
      value - The value to put after unlocking the key
    • islocked

      public boolean islocked(Object key)
      Returns true if the given key is locked. Otherwise returns false.
      Parameters:
      key - The key to check if it locked or not.
      Returns:
      true if the given key is locked or not.
    • unlock

      public void unlock(Object key)
      Unlocks the given lock on the key
      Parameters:
      key - The key to unlock