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 Details

  • Constructor Details

    • FunctionalReadWriteLock

      protected FunctionalReadWriteLock(ReadWriteLock lock)
  • Method Details

    • 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 standard ReadWriteLock.
      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