Class ReadWriteLockExecutor
java.lang.Object
com.inductiveautomation.historian.gateway.api.util.ReadWriteLockExecutor
Utility class for managing and executing operations within read and write locks.
Provides convenience methods for working with
ReentrantReadWriteLock,
allowing execution of actions or computation of results under various lock conditions.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying ReentrantReadWriteLock for advanced use cases.readLock()Returns the read lock for advanced use cases.<E extends Exception>
booleantryWithReadLock(long timeout, TimeUnit unit, CheckedRunnable<E> action) Attempts to execute the given runnable within a read lock with a timeout.tryWithReadLock(long timeout, TimeUnit unit, CheckedSupplier<T, E> action) Attempts to execute the given supplier within a read lock with a timeout.<E extends Exception>
booleantryWithWriteLock(long timeout, TimeUnit unit, CheckedRunnable<E> action) Attempts to execute the given runnable within a write lock with a timeout.tryWithWriteLock(long timeout, TimeUnit unit, CheckedSupplier<T, E> action) Attempts to execute the given supplier within a write lock with a timeout.<E extends Exception>
voidwithReadLock(CheckedRunnable<E> action) Executes the given runnable within a read lock.<T,E extends Exception>
TwithReadLock(CheckedSupplier<T, E> action) Executes the given supplier within a read lock, returning its result.<E extends Exception>
voidwithReadLockInterruptibly(CheckedRunnable<E> action) Executes the given runnable within an interruptible read lock.<T,E extends Exception>
TwithReadLockInterruptibly(CheckedSupplier<T, E> action) Executes the given supplier within an interruptible read lock, returning its result.<E extends Exception>
voidwithWriteLock(CheckedRunnable<E> action) Executes the given runnable within a write lock.<T,E extends Exception>
TwithWriteLock(CheckedSupplier<T, E> action) Executes the given supplier within a write lock, returning its result.<E extends Exception>
voidwithWriteLockInterruptibly(CheckedRunnable<E> action) Executes the given runnable within an interruptible write lock.<T,E extends Exception>
TwithWriteLockInterruptibly(CheckedSupplier<T, E> action) Executes the given supplier within an interruptible write lock, returning its result.Returns the write lock for advanced use cases.
-
Constructor Details
-
ReadWriteLockExecutor
public ReadWriteLockExecutor() -
ReadWriteLockExecutor
public ReadWriteLockExecutor(boolean fair) -
ReadWriteLockExecutor
-
-
Method Details
-
withReadLock
Executes the given supplier within a read lock, returning its result.- Throws:
E extends Exception
-
withReadLock
Executes the given runnable within a read lock.- Throws:
E extends Exception
-
withWriteLock
Executes the given supplier within a write lock, returning its result.- Throws:
E extends Exception
-
withWriteLock
Executes the given runnable within a write lock.- Throws:
E extends Exception
-
tryWithReadLock
public <T,E extends Exception> Optional<T> tryWithReadLock(long timeout, TimeUnit unit, CheckedSupplier<T, E> action) throws E, InterruptedExceptionAttempts to execute the given supplier within a read lock with a timeout. Returns an Optional containing the result if the lock was acquired, or empty if the timeout elapsed.- Throws:
E extends ExceptionInterruptedException
-
tryWithReadLock
public <E extends Exception> boolean tryWithReadLock(long timeout, TimeUnit unit, CheckedRunnable<E> action) throws E, InterruptedException Attempts to execute the given runnable within a read lock with a timeout. Returns true if the lock was acquired and action executed, false if the timeout elapsed.- Throws:
E extends ExceptionInterruptedException
-
tryWithWriteLock
public <T,E extends Exception> Optional<T> tryWithWriteLock(long timeout, TimeUnit unit, CheckedSupplier<T, E> action) throws E, InterruptedExceptionAttempts to execute the given supplier within a write lock with a timeout. Returns an Optional containing the result if the lock was acquired, or empty if the timeout elapsed.- Throws:
E extends ExceptionInterruptedException
-
tryWithWriteLock
public <E extends Exception> boolean tryWithWriteLock(long timeout, TimeUnit unit, CheckedRunnable<E> action) throws E, InterruptedException Attempts to execute the given runnable within a write lock with a timeout. Returns true if the lock was acquired and action executed, false if the timeout elapsed.- Throws:
E extends ExceptionInterruptedException
-
withReadLockInterruptibly
public <T,E extends Exception> T withReadLockInterruptibly(CheckedSupplier<T, E> action) throws E, InterruptedExceptionExecutes the given supplier within an interruptible read lock, returning its result.- Throws:
E extends ExceptionInterruptedException
-
withReadLockInterruptibly
public <E extends Exception> void withReadLockInterruptibly(CheckedRunnable<E> action) throws E, InterruptedException Executes the given runnable within an interruptible read lock.- Throws:
E extends ExceptionInterruptedException
-
withWriteLockInterruptibly
public <T,E extends Exception> T withWriteLockInterruptibly(CheckedSupplier<T, E> action) throws E, InterruptedExceptionExecutes the given supplier within an interruptible write lock, returning its result.- Throws:
E extends ExceptionInterruptedException
-
withWriteLockInterruptibly
public <E extends Exception> void withWriteLockInterruptibly(CheckedRunnable<E> action) throws E, InterruptedException Executes the given runnable within an interruptible write lock.- Throws:
E extends ExceptionInterruptedException
-
readLock
Returns the read lock for advanced use cases. -
writeLock
Returns the write lock for advanced use cases. -
getUnderlyingLock
Returns the underlying ReentrantReadWriteLock for advanced use cases.
-