Class DefaultLockManager

  • All Implemented Interfaces:
    LockManager

    public class DefaultLockManager
    extends Object
    implements LockManager
    The default LockManager implementation for transactional and non-transactional caches.
    Since:
    8.0
    Author:
    Pedro Ruivo
    • Constructor Detail

      • DefaultLockManager

        public DefaultLockManager()
    • Method Detail

      • 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.
      • unlock

        public 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.
      • unlockAll

        public 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.
      • 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

        public int getNumberOfLocksHeld()
        Specified by:
        getNumberOfLocksHeld in interface LockManager
        Returns:
        the number of locks held.
      • getConcurrencyLevel

        public int getConcurrencyLevel()
      • getNumberOfLocksAvailable

        public int getNumberOfLocksAvailable()