Class StampedLockManager
- java.lang.Object
-
- org.eclipse.rdf4j.common.concurrent.locks.StampedLockManager
-
- All Implemented Interfaces:
ReadWriteLockManager
@Experimental public class StampedLockManager extends 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.
- Author:
- Håvard M. Ottestad
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StampedLockManager.Cache<T>
static class
StampedLockManager.OptimisticReadLock
-
Constructor Summary
Constructors Constructor Description StampedLockManager()
StampedLockManager(boolean trackLocks)
StampedLockManager(boolean trackLocks, int waitToCollect)
StampedLockManager(String alias, int waitToCollect, LockDiagnostics... lockDiagnostics)
StampedLockManager(String alias, LockDiagnostics... lockDiagnostics)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Lock
convertToReadLock(Lock writeLock)
Convert a write lock to a read lock.StampedLockManager.OptimisticReadLock
getOptimisticReadLock()
Gets an optimistic read lock, if available.Lock
getReadLock()
Gets a read lock.Lock
getWriteLock()
Gets an exclusive write lock.boolean
isReaderActive()
Returnsfalse
if there are no active read locks, otherwise returnstrue
.boolean
isWriterActive()
Returnsfalse
if there are no active write locks, otherwise returnstrue
.Lock
tryReadLock()
Gets a read lock, if available.Lock
tryWriteLock()
Gets an exclusive write lock, if available.void
waitForActiveReaders()
Blocks until all read locks have been released.void
waitForActiveWriter()
Blocks until all write locks have been released.
-
-
-
Constructor Detail
-
StampedLockManager
public StampedLockManager()
-
StampedLockManager
public StampedLockManager(boolean trackLocks)
-
StampedLockManager
public StampedLockManager(boolean trackLocks, int waitToCollect)
-
StampedLockManager
public StampedLockManager(String alias, LockDiagnostics... lockDiagnostics)
-
StampedLockManager
public StampedLockManager(String alias, int waitToCollect, LockDiagnostics... lockDiagnostics)
-
-
Method Detail
-
isWriterActive
public boolean isWriterActive()
Returnsfalse
if there are no active write locks, otherwise returnstrue
.- Specified by:
isWriterActive
in interfaceReadWriteLockManager
-
isReaderActive
public boolean isReaderActive()
Returnsfalse
if there are no active read locks, otherwise returnstrue
.- Specified by:
isReaderActive
in interfaceReadWriteLockManager
-
waitForActiveWriter
public void waitForActiveWriter() throws InterruptedException
Blocks until all write locks have been released.- Specified by:
waitForActiveWriter
in interfaceReadWriteLockManager
- Throws:
InterruptedException
- In case the thread requesting the lock wasinterrupted
.
-
waitForActiveReaders
public void waitForActiveReaders() throws InterruptedException
Blocks until all read locks have been released.- Specified by:
waitForActiveReaders
in interfaceReadWriteLockManager
- Throws:
InterruptedException
- In case the thread requesting the lock wasinterrupted
.
-
getReadLock
public Lock getReadLock() throws InterruptedException
Gets a read lock. This method blocks until the read lock is available.- Specified by:
getReadLock
in interfaceReadWriteLockManager
- Throws:
InterruptedException
- In case the thread requesting the lock wasinterrupted
.
-
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 InterruptedException
Gets an exclusive write lock. This method blocks until the write lock is available.- Specified by:
getWriteLock
in interfaceReadWriteLockManager
- Throws:
InterruptedException
- In case the thread requesting the lock wasinterrupted
.
-
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:
tryReadLock
in interfaceReadWriteLockManager
-
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:
tryWriteLock
in interfaceReadWriteLockManager
-
-