Class StampedLockManager
- java.lang.Object
-
- org.eclipse.rdf4j.common.concurrent.locks.StampedLockManager
-
- All Implemented Interfaces:
ReadWriteLockManager
@Experimental public class StampedLockManager extends java.lang.Object implements ReadWriteLockManager
A read/write-lock manager backed by a StampedLock.This class is in an experimental state: its existence, signature or behavior may change without warning from one release to the next.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStampedLockManager.Cache<T>static classStampedLockManager.OptimisticReadLockprivate static classStampedLockManager.ReadLockprivate static classStampedLockManager.WriteLock
-
Field Summary
Fields Modifier and Type Field Description private LockMonitoring<StampedLockManager.ReadLock>readLockMonitoring(package private) java.util.concurrent.locks.StampedLockstampedLockprivate inttryWriteLockMillisprivate LockMonitoring<StampedLockManager.WriteLock>writeLockMonitoring
-
Constructor Summary
Constructors Constructor Description StampedLockManager()StampedLockManager(boolean trackLocks)StampedLockManager(boolean trackLocks, int waitToCollect)StampedLockManager(java.lang.String alias, int waitToCollect, LockDiagnostics... lockDiagnostics)StampedLockManager(java.lang.String alias, LockDiagnostics... lockDiagnostics)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LockconvertToReadLock(Lock writeLock)Convert a write lock to a read lock.private StampedLockManager.ReadLockcreateReadLockInner()private StampedLockManager.WriteLockcreateWriteLockInner()StampedLockManager.OptimisticReadLockgetOptimisticReadLock()Gets an optimistic read lock, if available.LockgetReadLock()Gets a read lock.LockgetWriteLock()Gets an exclusive write lock.booleanisReaderActive()Returnsfalseif there are no active read locks, otherwise returnstrue.booleanisWriterActive()Returnsfalseif there are no active write locks, otherwise returnstrue.private voidspinWait()LocktryReadLock()Gets a read lock, if available.private StampedLockManager.ReadLocktryReadLockInner()LocktryWriteLock()Gets an exclusive write lock, if available.private StampedLockManager.WriteLocktryWriteLockInner()voidwaitForActiveReaders()Blocks until all read locks have been released.voidwaitForActiveWriter()Blocks until all write locks have been released.private longwriteLockInterruptibly()
-
-
-
Field Detail
-
readLockMonitoring
private final LockMonitoring<StampedLockManager.ReadLock> readLockMonitoring
-
writeLockMonitoring
private final LockMonitoring<StampedLockManager.WriteLock> writeLockMonitoring
-
stampedLock
final java.util.concurrent.locks.StampedLock stampedLock
-
tryWriteLockMillis
private final int tryWriteLockMillis
-
-
Constructor Detail
-
StampedLockManager
public StampedLockManager()
-
StampedLockManager
public StampedLockManager(boolean trackLocks)
-
StampedLockManager
public StampedLockManager(boolean trackLocks, int waitToCollect)
-
StampedLockManager
public StampedLockManager(java.lang.String alias, LockDiagnostics... lockDiagnostics)
-
StampedLockManager
public StampedLockManager(java.lang.String alias, int waitToCollect, LockDiagnostics... lockDiagnostics)
-
-
Method Detail
-
isWriterActive
public boolean isWriterActive()
Returnsfalseif there are no active write locks, otherwise returnstrue.- Specified by:
isWriterActivein interfaceReadWriteLockManager
-
isReaderActive
public boolean isReaderActive()
Returnsfalseif there are no active read locks, otherwise returnstrue.- Specified by:
isReaderActivein interfaceReadWriteLockManager
-
waitForActiveWriter
public void waitForActiveWriter() throws java.lang.InterruptedExceptionBlocks until all write locks have been released.- Specified by:
waitForActiveWriterin interfaceReadWriteLockManager- Throws:
java.lang.InterruptedException- In case the thread requesting the lock wasinterrupted.
-
waitForActiveReaders
public void waitForActiveReaders() throws java.lang.InterruptedExceptionBlocks until all read locks have been released.- Specified by:
waitForActiveReadersin interfaceReadWriteLockManager- Throws:
java.lang.InterruptedException- In case the thread requesting the lock wasinterrupted.
-
getReadLock
public Lock getReadLock() throws java.lang.InterruptedException
Gets a read lock. This method blocks until the read lock is available.- Specified by:
getReadLockin interfaceReadWriteLockManager- Throws:
java.lang.InterruptedException- In case the thread requesting the lock wasinterrupted.
-
createReadLockInner
private StampedLockManager.ReadLock createReadLockInner() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
getOptimisticReadLock
public StampedLockManager.OptimisticReadLock getOptimisticReadLock()
Gets an optimistic read lock, if available. This method will return null if the optimistic read lock is not immediately available.
-
convertToReadLock
public Lock convertToReadLock(Lock writeLock)
Convert a write lock to a read lock.
-
getWriteLock
public Lock getWriteLock() throws java.lang.InterruptedException
Gets an exclusive write lock. This method blocks until the write lock is available.- Specified by:
getWriteLockin interfaceReadWriteLockManager- Throws:
java.lang.InterruptedException- In case the thread requesting the lock wasinterrupted.
-
createWriteLockInner
private StampedLockManager.WriteLock createWriteLockInner() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
writeLockInterruptibly
private long writeLockInterruptibly() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
tryReadLock
public Lock tryReadLock()
Gets a read lock, if available. This method will return null if the read lock is not immediately available.- Specified by:
tryReadLockin interfaceReadWriteLockManager
-
tryReadLockInner
private StampedLockManager.ReadLock tryReadLockInner()
-
tryWriteLock
public Lock tryWriteLock()
Gets an exclusive write lock, if available. This method will return null if the write lock is not immediately available.- Specified by:
tryWriteLockin interfaceReadWriteLockManager
-
tryWriteLockInner
private StampedLockManager.WriteLock tryWriteLockInner()
-
spinWait
private void spinWait() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
-