Class ReadWriteStripedLocked

java.lang.Object
com.helixframework.concurrency.rwlock.ReadWriteStripedLocked

public final class ReadWriteStripedLocked extends Object
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 Details

    • ReadWriteStripedLocked

      public ReadWriteStripedLocked()
      Creates a new instance with no name.
    • ReadWriteStripedLocked

      public ReadWriteStripedLocked(String name)
      Creates a new instance with the specified name.
      Parameters:
      name - the name to identify this instance, can be null
  • Method Details

    • read

      public <T> T read(Object key, ValueOperation<T> op)
      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 use
      op - the operation to execute that returns a value
      Returns:
      the result of the operation
    • read

      public void read(Object key, VoidOperation op)
      Executes a read operation under a read lock for the given key.
      Parameters:
      key - the key to determine which stripe's read lock to use
      op - the operation to execute
    • write

      public <T> T write(Object key, ValueOperation<T> op)
      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 use
      op - the operation to execute that returns a value
      Returns:
      the result of the operation
    • write

      public void write(Object key, VoidOperation op)
      Executes a write operation under a write lock for the given key.
      Parameters:
      key - the key to determine which stripe's write lock to use
      op - the operation to execute
    • getName

      public String getName()
      Returns the name of this instance.
      Returns:
      the name assigned to this instance, may be null