Class RefCountLockResource

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class RefCountLockResource
    extends RWLockResource
    Reference counted Lock resource, automatically unlocks and decrements the reference count. It contains a lock and a reference count for that lock, and will decrement the lock reference count and unlocking when the resource is closed.
    • Constructor Summary

      Constructors 
      Constructor Description
      RefCountLockResource​(java.util.concurrent.locks.ReentrantReadWriteLock lock, LockMode mode, boolean acquireLock, java.util.concurrent.atomic.AtomicInteger refCount, boolean useTryLock)
      Creates a new instance of LockResource using the given lock and reference counter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Releases the lock and decrement the ref count if a ref counter was provided at construction time.
      • Methods inherited from class java.lang.Object

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

      • RefCountLockResource

        public RefCountLockResource​(java.util.concurrent.locks.ReentrantReadWriteLock lock,
                                    LockMode mode,
                                    boolean acquireLock,
                                    java.util.concurrent.atomic.AtomicInteger refCount,
                                    boolean useTryLock)
        Creates a new instance of LockResource using the given lock and reference counter. The reference counter should have been initialized and incremented outside of this class.
        Parameters:
        lock - the lock to acquire
        mode - the mode to acquire the lock in
        acquireLock - whether to lock the lock
        refCount - ref count for the lock
        useTryLock - applicable only if acquireLock is true. Determines whether or not to use Lock.tryLock() or Lock.lock() to acquire the lock
    • Method Detail

      • close

        public void close()
        Releases the lock and decrement the ref count if a ref counter was provided at construction time.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class LockResource