Package org.eclipse.aether.named.support
Class NamedLockSupport
java.lang.Object
org.eclipse.aether.named.support.NamedLockSupport
- All Implemented Interfaces:
AutoCloseable,NamedLock
- Direct Known Subclasses:
AdaptedSemaphoreNamedLock,FileLockNamedLock,NoopNamedLockFactory.NoopNamedLock,ReadWriteLockNamedLock
Support class for
NamedLock implementations providing reference counting.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<Thread, Deque<String>> private final NamedLockFactorySupportprotected final org.slf4j.Loggerprivate final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the lock resource.Returns the diagnostic state (if collected) or empty map, nevernull.protected voiddoClose()protected abstract booleandoLockExclusively(long time, TimeUnit unit) protected abstract booleandoLockShared(long time, TimeUnit unit) protected abstract voiddoUnlock()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.name()Returns this instance name, never nulltoString()voidunlock()Unlocks the lock, must be invoked by caller after one of theNamedLock.lockShared(long, TimeUnit)orNamedLock.lockExclusively(long, TimeUnit).
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
name
-
factory
-
diagnosticState
-
-
Constructor Details
-
NamedLockSupport
-
-
Method Details
-
name
Description copied from interface:NamedLockReturns this instance name, never null -
lockExclusively
Description copied from interface:NamedLockTries to lock exclusively, may block for given time. If successful, returnstrue.- Specified by:
lockExclusivelyin interfaceNamedLock- Throws:
InterruptedException
-
doLockExclusively
- Throws:
InterruptedException
-
unlock
public void unlock()Description copied from interface:NamedLockUnlocks the lock, must be invoked by caller after one of theNamedLock.lockShared(long, TimeUnit)orNamedLock.lockExclusively(long, TimeUnit). -
doUnlock
protected abstract void doUnlock() -
close
public void close()Description copied from interface:NamedLockCloses the lock resource. Lock MUST be unlocked usingNamedLock.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 usingNamedLockFactory.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:
closein interfaceAutoCloseable- Specified by:
closein interfaceNamedLock
-
doClose
protected void doClose() -
diagnosticState
Returns the diagnostic state (if collected) or empty map, nevernull.- Since:
- 1.9.11
-
toString
-