Class ReadWriteStripedLocked
java.lang.Object
com.helixframework.concurrency.rwlock.ReadWriteStripedLocked
A thread-safe utility class that provides striped read-write locking capabilities.
Uses Google Guava's Striped class to manage a set of read-write locks, reducing
contention by allowing different threads to acquire locks on different stripes
based on the provided key.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with no name.ReadWriteStripedLocked(String name) Creates a new instance with the specified name. -
Method Summary
Modifier and TypeMethodDescriptiongetName()Returns the name of this instance.<T> Tread(Object key, ValueOperation<T> op) Executes a read operation under a read lock for the given key.voidread(Object key, VoidOperation op) Executes a read operation under a read lock for the given key.<T> Twrite(Object key, ValueOperation<T> op) Executes a write operation under a write lock for the given key.voidwrite(Object key, VoidOperation op) Executes a write operation under a write lock for the given key.
-
Constructor Details
-
ReadWriteStripedLocked
public ReadWriteStripedLocked()Creates a new instance with no name. -
ReadWriteStripedLocked
Creates a new instance with the specified name.- Parameters:
name- the name to identify this instance, can be null
-
-
Method Details
-
read
Executes a read operation under a read lock for the given key.- Type Parameters:
T- the type of value returned by the operation- Parameters:
key- the key to determine which stripe's read lock to useop- the operation to execute that returns a value- Returns:
- the result of the operation
-
read
Executes a read operation under a read lock for the given key.- Parameters:
key- the key to determine which stripe's read lock to useop- the operation to execute
-
write
Executes a write operation under a write lock for the given key.- Type Parameters:
T- the type of value returned by the operation- Parameters:
key- the key to determine which stripe's write lock to useop- the operation to execute that returns a value- Returns:
- the result of the operation
-
write
Executes a write operation under a write lock for the given key.- Parameters:
key- the key to determine which stripe's write lock to useop- the operation to execute
-
getName
Returns the name of this instance.- Returns:
- the name assigned to this instance, may be null
-