Package org.eclipse.aether.named
Interface NamedLock
- All Superinterfaces:
- AutoCloseable
- All Known Implementing Classes:
- AdaptedSemaphoreNamedLock,- CompositeNamedLock,- FileLockNamedLock,- NamedLockSupport,- ReadWriteLockNamedLock
A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
 no lock upgrade is supported. The lock instance obtained from lock factory must be treated as a resource, best in
 try-with-resource block. Usual pattern to use this lock:
 
   try (NamedLock lock = factory.getLock("resourceName")) {
     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
       try {
         ... exclusive access to "resourceName" resource gained here
       }
       finally {
         lock.unlock();
       }
     }
     else {
       ... failed to gain access within specified time, handle it
     }
   }
 - 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes the lock resource.key()Returns this instance key, nevernull.booleanlockExclusively(long time, TimeUnit unit) Tries to lock exclusively, may block for given time.booleanlockShared(long time, TimeUnit unit) Tries to lock shared, may block for given time.voidunlock()Unlocks the lock, must be invoked by caller after one of thelockShared(long, TimeUnit)orlockExclusively(long, TimeUnit).
- 
Method Details- 
keyReturns this instance key, nevernull.
- 
lockExclusivelyTries to lock exclusively, may block for given time. If successful, returnstrue.- Throws:
- InterruptedException
 
- 
unlockvoid unlock()Unlocks the lock, must be invoked by caller after one of thelockShared(long, TimeUnit)orlockExclusively(long, TimeUnit).
- 
closevoid close()Closes the lock resource. Lock MUST be unlocked usingunlock()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 usingNamedLockFactory.getLock(java.util.Collection). Ideally, instances are to be used within try-with-resource blocks, so calling this method directly is not really needed, nor advised.- Specified by:
- closein interface- AutoCloseable
 
 
-