Class TopKeyLockManager

  • All Implemented Interfaces:
    LockManager

    public class TopKeyLockManager
    extends java.lang.Object
    implements LockManager
    Top-key stats about locks.
    Since:
    6.0
    Author:
    Pedro Ruivo
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.infinispan.util.concurrent.locks.impl.InfinispanLock getLock​(java.lang.Object key)  
      int getNumberOfLocksHeld()  
      java.lang.Object getOwner​(java.lang.Object key)
      Retrieves the owner of the lock for the key.
      boolean isLocked​(java.lang.Object key)
      Tests if the key is locked.
      KeyAwareLockPromise lock​(java.lang.Object key, java.lang.Object lockOwner, long time, java.util.concurrent.TimeUnit unit)
      Attempts to lock the key if the lock isn't already held by the lockOwner.
      KeyAwareLockPromise lockAll​(java.util.Collection<?> keys, java.lang.Object lockOwner, long time, java.util.concurrent.TimeUnit unit)
      boolean ownsLock​(java.lang.Object key, java.lang.Object owner)
      Tests if the lockOwner owns a lock on the key.
      java.lang.String printLockInfo()
      Prints lock information for all locks.
      void unlock​(java.lang.Object key, java.lang.Object lockOwner)
      Releases the lock for the key if the lockOwner is the lock owner.
      void unlockAll​(java.util.Collection<?> keys, java.lang.Object lockOwner)
      Same as LockManager.unlock(Object, Object) but for multiple keys.
      void unlockAll​(InvocationContext ctx)
      Same as unlockAll(context.getLockedKeys(), context.getKeyLockOwner();.
      • Methods inherited from class java.lang.Object

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

      • lock

        public KeyAwareLockPromise lock​(java.lang.Object key,
                                        java.lang.Object lockOwner,
                                        long time,
                                        java.util.concurrent.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​(java.util.Collection<?> keys,
                                           java.lang.Object lockOwner,
                                           long time,
                                           java.util.concurrent.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 void unlock​(java.lang.Object key,
                           java.lang.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​(java.util.Collection<?> keys,
                              java.lang.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.
      • unlockAll

        public void unlockAll​(InvocationContext ctx)
        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:
        ctx - the context with the locked keys and the lock owner.
      • ownsLock

        public boolean ownsLock​(java.lang.Object key,
                                java.lang.Object owner)
        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.
        owner - the owner of the lock.
        Returns:
        true if the owner does own the lock on the key, false otherwise.
      • isLocked

        public boolean isLocked​(java.lang.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 java.lang.Object getOwner​(java.lang.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 java.lang.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.
      • getLock

        public org.infinispan.util.concurrent.locks.impl.InfinispanLock getLock​(java.lang.Object key)
        Specified by:
        getLock in interface LockManager