Class DefaultLockManager

java.lang.Object
org.infinispan.util.concurrent.locks.impl.DefaultLockManager
All Implemented Interfaces:
LockManager

@MBean(objectName="LockManager", description="Manager that handles MVCC locks for entries") public class DefaultLockManager extends Object implements LockManager
The default LockManager implementation for transactional and non-transactional caches.
Since:
8.0
Author:
Pedro Ruivo
  • Constructor Details

    • DefaultLockManager

      public DefaultLockManager()
  • Method Details

    • lock

      public KeyAwareLockPromise lock(Object key, Object lockOwner, long time, TimeUnit unit)
      Description copied from interface: LockManager
      Attempts to lock the key if the lock isn't already held by the lockOwner.

      This method is non-blocking and return immediately a LockPromise. The LockPromise can (and should) be used by the invoker to check when the lock is really acquired by invoking LockPromise.lock().

      Specified by:
      lock in interface LockManager
      Parameters:
      key - key to lock.
      lockOwner - the owner of the lock.
      time - the maximum time to wait for the lock
      unit - the time unit of the time argument
      Returns:
      the KeyAwareLockPromise associated to this keys.
    • lockAll

      public KeyAwareLockPromise lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit)
      Description copied from interface: LockManager
      Same as LockManager.lock(Object, Object, long, TimeUnit) but for multiple keys.

      It ensures no deadlocks if the method is invoked by different lock owners for the same set (or subset) of keys.

      Specified by:
      lockAll in interface LockManager
      Parameters:
      keys - keys to lock.
      lockOwner - the owner of the lock.
      time - the maximum time to wait for the lock
      unit - the time unit of the time argument
      Returns:
      the KeyAwareLockPromise associated to this keys.
    • unlock

      public Collection<Supplier<CompletionStage<Void>>> unlock(Object key, Object lockOwner)
      Description copied from interface: LockManager
      Releases the lock for the key if the lockOwner is the lock owner.

      Note this method will unlock a lock where the key is the lockOwner

      Specified by:
      unlock in interface LockManager
      Parameters:
      key - key to unlock.
      lockOwner - the owner of the lock.
      Returns:
      any post-unlock listener suppliers that were registered for the lock owner.
    • unlockAll

      public Collection<Supplier<CompletionStage<Void>>> unlockAll(Collection<?> keys, Object lockOwner)
      Description copied from interface: LockManager
      Same as LockManager.unlock(Object, Object) but for multiple keys.

      Note this method will not unlock a lock where the key is the lockOwner

      Specified by:
      unlockAll in interface LockManager
      Parameters:
      keys - keys to unlock.
      lockOwner - the owner of the lock.
      Returns:
      any post-unlock listener suppliers that were registered for the unlocked keys.
    • unlockAll

      public Collection<Supplier<CompletionStage<Void>>> unlockAll(InvocationContext context)
      Description copied from interface: LockManager
      Same as unlockAll(context.getLockedKeys(), context.getKeyLockOwner();.

      Note this method will not unlock a lock where the key is the lockOwner

      Specified by:
      unlockAll in interface LockManager
      Parameters:
      context - the context with the locked keys and the lock owner.
      Returns:
      any post-unlock listener suppliers that were registered for the unlocked keys.
    • addPostUnlockListener

      public void addPostUnlockListener(Object key, Supplier<CompletionStage<Void>> listener)
      Description copied from interface: LockManager
      Registers a listener that will be returned when the current lock owner releases its locks via LockManager.unlock(Object, Object), LockManager.unlockAll(Collection, Object), or LockManager.unlockAll(InvocationContext).

      The key must currently be locked. If it is not, an IllegalStateException is thrown. The listener is associated with the current lock owner and will only be returned when that owner's locks are released.

      Note: registered listeners are not invoked when the operation that acquired the lock completes with an exception. In that case, the listeners are still drained from the map but are discarded by the interceptor chain.

      Specified by:
      addPostUnlockListener in interface LockManager
      Parameters:
      key - the key that must be currently locked.
      listener - a supplier that produces a CompletionStage to be awaited after unlock.
    • ownsLock

      public boolean ownsLock(Object key, Object lockOwner)
      Description copied from interface: LockManager
      Tests if the lockOwner owns a lock on the key.
      Specified by:
      ownsLock in interface LockManager
      Parameters:
      key - key to test.
      lockOwner - the owner of the lock.
      Returns:
      true if the owner does own the lock on the key, false otherwise.
    • isLocked

      public boolean isLocked(Object key)
      Description copied from interface: LockManager
      Tests if the key is locked.
      Specified by:
      isLocked in interface LockManager
      Parameters:
      key - key to test.
      Returns:
      true if the key is locked, false otherwise.
    • getOwner

      public Object getOwner(Object key)
      Description copied from interface: LockManager
      Retrieves the owner of the lock for the key.
      Specified by:
      getOwner in interface LockManager
      Returns:
      the owner of the lock, or null if not locked.
    • printLockInfo

      public String printLockInfo()
      Description copied from interface: LockManager
      Prints lock information for all locks.
      Specified by:
      printLockInfo in interface LockManager
      Returns:
      the lock information
    • getNumberOfLocksHeld

      @ManagedAttribute(description="The number of exclusive locks that are held.", displayName="Number of locks held") public int getNumberOfLocksHeld()
      Specified by:
      getNumberOfLocksHeld in interface LockManager
      Returns:
      the number of locks held.
    • getConcurrencyLevel

      @ManagedAttribute(description="The concurrency level that the MVCC Lock Manager has been configured with.", displayName="Concurrency level", dataType=TRAIT) public int getConcurrencyLevel()
    • getNumberOfLocksAvailable

      @ManagedAttribute(description="The number of exclusive locks that are available.", displayName="Number of locks available") public int getNumberOfLocksAvailable()
    • getLock

      public InfinispanLock getLock(Object key)
      Specified by:
      getLock in interface LockManager