Class StripedLock


  • public class StripedLock
    extends java.lang.Object
    Holder for read write locks that provides ability to retrieve them by offset and hashCode Note that locks protect entries
    Since:
    9.0
    Author:
    wburns
    • Constructor Summary

      Constructors 
      Constructor Description
      StripedLock​(int lockCount, org.infinispan.container.offheap.OffsetCalculator offSetCalculator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.locks.ReadWriteLock getLock​(java.lang.Object obj)
      Retrieves the read write lock attributed to the given object using its hashCode for lookup.
      java.util.concurrent.locks.ReadWriteLock getLockFromHashCode​(int hashCode)
      Retrieves the lock associated with the given hashCode
      java.util.concurrent.locks.ReadWriteLock getLockWithOffset​(int offset)
      Retrieves the given lock at a provided offset.
      void lockAll()
      Locks all write locks.
      • Methods inherited from class java.lang.Object

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

      • StripedLock

        public StripedLock​(int lockCount,
                           org.infinispan.container.offheap.OffsetCalculator offSetCalculator)
    • Method Detail

      • getLock

        public java.util.concurrent.locks.ReadWriteLock getLock​(java.lang.Object obj)
        Retrieves the read write lock attributed to the given object using its hashCode for lookup.
        Parameters:
        obj - the object to use to find the lock
        Returns:
        the lock associated with the object
      • getLockFromHashCode

        public java.util.concurrent.locks.ReadWriteLock getLockFromHashCode​(int hashCode)
        Retrieves the lock associated with the given hashCode
        Parameters:
        hashCode - the hashCode to retrieve the lock for
        Returns:
        the lock associated with the given hashCode
      • getLockWithOffset

        public java.util.concurrent.locks.ReadWriteLock getLockWithOffset​(int offset)
        Retrieves the given lock at a provided offset. Note this is not hashCode based. This method requires care and the knowledge of how many locks there are. This is useful when iterating over all locks
        Parameters:
        offset - the offset of the lock to find
        Returns:
        the lock at the given offset
      • lockAll

        public void lockAll()
        Locks all write locks. Ensure that unlockAll() is called in a proper finally block