Package org.eclipse.aether.named.support
Class NamedLockSupport
- java.lang.Object
-
- org.eclipse.aether.named.support.NamedLockSupport
-
- All Implemented Interfaces:
java.lang.AutoCloseable,NamedLock
- Direct Known Subclasses:
AdaptedSemaphoreNamedLock,FileLockNamedLock,ReadWriteLockNamedLock
public abstract class NamedLockSupport extends java.lang.Object implements NamedLock
Support class forNamedLockimplementations providing reference counting.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogger
-
Constructor Summary
Constructors Constructor Description NamedLockSupport(java.lang.String name, NamedLockFactorySupport factory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()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, nevernull.protected voiddoClose()protected abstract booleandoLockExclusively(long time, java.util.concurrent.TimeUnit unit)protected abstract booleandoLockShared(long time, java.util.concurrent.TimeUnit unit)protected abstract voiddoUnlock()booleanlockExclusively(long time, java.util.concurrent.TimeUnit unit)Tries to lock exclusively, may block for given time.booleanlockShared(long time, java.util.concurrent.TimeUnit unit)Tries to lock shared, may block for given time.java.lang.Stringname()Returns this instance name, never nulljava.lang.StringtoString()voidunlock()Unlocks the lock, must be invoked by caller after one of theNamedLock.lockShared(long, TimeUnit)orNamedLock.lockExclusively(long, TimeUnit).
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Detail
-
NamedLockSupport
public NamedLockSupport(java.lang.String name, NamedLockFactorySupport factory)
-
-
Method Detail
-
name
public java.lang.String name()
Description copied from interface:NamedLockReturns this instance name, never null
-
lockShared
public boolean lockShared(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Description copied from interface:NamedLockTries to lock shared, may block for given time. If successful, returnstrue.- Specified by:
lockSharedin interfaceNamedLock- 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:NamedLockTries to lock exclusively, may block for given time. If successful, returnstrue.- Specified by:
lockExclusivelyin interfaceNamedLock- Throws:
java.lang.InterruptedException
-
doLockExclusively
protected abstract boolean doLockExclusively(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Throws:
java.lang.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.
-
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, nevernull.- Since:
- 1.9.11
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-