Class AdaptedSemaphoreNamedLock

  • All Implemented Interfaces:
    java.lang.AutoCloseable, NamedLock

    public class AdaptedSemaphoreNamedLock
    extends NamedLockSupport
    Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common API).
    • Field Detail

      • NONE

        private static final int NONE
        Count of permissions involved with "nop" locking. When required lock step is preceded with a step that already fulfills currently requested locking, no locking is needed. In other words, caller already possesses the access to lock protected resource. The "nop" locking is used to track proper "boxing" of lock/unlock calls.
        See Also:
        Constant Field Values
      • SHARED

        private static final int SHARED
        Count of permissions involved with shared locking
        See Also:
        Constant Field Values
      • EXCLUSIVE

        private static final int EXCLUSIVE
        Count of permissions involved with exclusive locking
        See Also:
        Constant Field Values
      • threadPerms

        private final java.lang.ThreadLocal<java.util.Deque<java.lang.Integer>> threadPerms
    • Method Detail

      • lockShared

        public boolean lockShared​(long time,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.lang.InterruptedException
        Description copied from interface: NamedLock
        Tries to lock shared, may block for given time. If successful, returns true.
        Throws:
        java.lang.InterruptedException
      • lockExclusively

        public boolean lockExclusively​(long time,
                                       java.util.concurrent.TimeUnit unit)
                                throws java.lang.InterruptedException
        Description copied from interface: NamedLock
        Tries to lock exclusively, may block for given time. If successful, returns true.
        Throws:
        java.lang.InterruptedException