Package io.debezium.util
Class FunctionalReadWriteLock
- java.lang.Object
-
- io.debezium.util.FunctionalReadWriteLock
-
public class FunctionalReadWriteLock extends Object
A form of a read-write lock that has methods that allow lambdas to be performed while the read or write lock is acquired and held.- Author:
- Randall Hauch
-
-
Field Summary
Fields Modifier and Type Field Description private ReadWriteLock
lock
-
Constructor Summary
Constructors Modifier Constructor Description protected
FunctionalReadWriteLock(ReadWriteLock lock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FunctionalReadWriteLock
create(ReadWriteLock lock)
Create a read-write lock around the given standardReadWriteLock
.void
read(Runnable operation)
Obtain a read lock, perform the operation, and release the lock.<T> T
read(Supplier<T> operation)
Obtain a read lock, perform the operation, and release the read lock.static FunctionalReadWriteLock
reentrant()
Create a read-write lock that supports reentrancy.void
write(Runnable operation)
Obtain an exclusive write lock, perform the operation, and release the lock.<T> T
write(Supplier<T> operation)
Obtain an exclusive write lock, perform the operation, and release the lock.
-
-
-
Field Detail
-
lock
private final ReadWriteLock lock
-
-
Constructor Detail
-
FunctionalReadWriteLock
protected FunctionalReadWriteLock(ReadWriteLock lock)
-
-
Method Detail
-
reentrant
public static FunctionalReadWriteLock reentrant()
Create a read-write lock that supports reentrancy.- Returns:
- the functional read-write lock; never null
-
create
public static FunctionalReadWriteLock create(ReadWriteLock lock)
Create a read-write lock around the given standardReadWriteLock
.- Parameters:
lock
- the standard lock; may not be null- Returns:
- the functional read-write lock; never null
-
read
public <T> T read(Supplier<T> operation)
Obtain a read lock, perform the operation, and release the read lock.- Parameters:
operation
- the operation to perform while the read lock is held; may not be null- Returns:
- the result of the operation
-
read
public void read(Runnable operation)
Obtain a read lock, perform the operation, and release the lock.- Parameters:
operation
- the operation to perform while the read lock is held; may not be null
-
write
public <T> T write(Supplier<T> operation)
Obtain an exclusive write lock, perform the operation, and release the lock.- Parameters:
operation
- the operation to perform while the write lock is held; may not be null- Returns:
- the result of the operation
-
write
public void write(Runnable operation)
Obtain an exclusive write lock, perform the operation, and release the lock.- Parameters:
operation
- the operation to perform while the write lock is held; may not be null
-
-