Class NamedLockSupport

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.slf4j.Logger logger  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the lock resource.
      java.util.Map<java.lang.Thread,​java.util.Deque<java.lang.String>> diagnosticState()
      Returns the diagnostic state (if collected) or empty map, never null.
      protected void doClose()  
      protected abstract boolean doLockExclusively​(long time, java.util.concurrent.TimeUnit unit)  
      protected abstract boolean doLockShared​(long time, java.util.concurrent.TimeUnit unit)  
      protected abstract void doUnlock()  
      boolean lockExclusively​(long time, java.util.concurrent.TimeUnit unit)
      Tries to lock exclusively, may block for given time.
      boolean lockShared​(long time, java.util.concurrent.TimeUnit unit)
      Tries to lock shared, may block for given time.
      java.lang.String name()
      Returns this instance name, never null
      java.lang.String toString()  
      void unlock()
      Unlocks the lock, must be invoked by caller after one of the NamedLock.lockShared(long, TimeUnit) or NamedLock.lockExclusively(long, TimeUnit).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
    • Method Detail

      • name

        public java.lang.String name()
        Description copied from interface: NamedLock
        Returns this instance name, never null
        Specified by:
        name in interface NamedLock
      • 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.
        Specified by:
        lockShared in interface NamedLock
        Throws:
        java.lang.InterruptedException
      • doLockShared

        protected abstract boolean doLockShared​(long time,
                                                java.util.concurrent.TimeUnit unit)
                                         throws java.lang.InterruptedException
        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.
        Specified by:
        lockExclusively in interface NamedLock
        Throws:
        java.lang.InterruptedException
      • doLockExclusively

        protected abstract boolean doLockExclusively​(long time,
                                                     java.util.concurrent.TimeUnit unit)
                                              throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • doUnlock

        protected abstract void doUnlock()
      • close

        public void close()
        Description copied from interface: NamedLock
        Closes the lock resource. Lock MUST be unlocked using NamedLock.unlock() in case any locking happened on it. After invoking this method, the lock instance MUST NOT be used anymore. If lock for same name needed, a new instance should be obtained from factory using NamedLockFactory.getLock(String). Ideally, instances are to be used within try-with-resource blocks, so calling this method directly is not really needed, nor advised.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface NamedLock
      • doClose

        protected void doClose()
      • diagnosticState

        public java.util.Map<java.lang.Thread,​java.util.Deque<java.lang.String>> diagnosticState()
        Returns the diagnostic state (if collected) or empty map, never null.
        Since:
        1.9.11
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object