Class ItemStoreLockStrategy

java.lang.Object
org.tasktide.itemstore.strategies.ItemStoreLockStrategy

public class ItemStoreLockStrategy extends Object
Class responsible for flexibly owning the Mutex lifecycle for an ItemStore as required. Using the same configured database, hence is tied but a child of AbstractItemStore. Providing an withLock method handle, and explicit lock/release methods
  • Constructor Details

    • ItemStoreLockStrategy

      public ItemStoreLockStrategy(String storeName, Path dbDirectory)
      Targeted constructor using store name under provided directory
      Parameters:
      storeName -
      dbDirectory -
    • ItemStoreLockStrategy

      public ItemStoreLockStrategy(String storeName, Path dbDirectory, Path masterDB)
      AbstractItemStore compatible constructor
      Parameters:
      storeName -
      dbDirectory -
      masterDB -
  • Method Details

    • waitForLock

      public void waitForLock() throws InterruptedException, IOException
      Waits until master is locked
      Throws:
      InterruptedException
      IOException
    • withLock

      public <R> R withLock(String label, ThrowableItemStoreOperation<R> operation) throws ItemStoreCheckedException
      Internal ItemStore method to force database operations under standard lock release pipeline
      Type Parameters:
      R -
      Parameters:
      label -
      operation -
      Returns:
      of operation result
      Throws:
      ItemStoreCheckedException
    • withLockUnchecked

      public <R> R withLockUnchecked(String label, ItemStoreOperation<R> operation) throws ItemStoreUncheckedException
      Internal ItemStore method to force database operations under standard lock release pipeline
      Type Parameters:
      R -
      Parameters:
      label -
      operation -
      Returns:
      of operation result
      Throws:
      ItemStoreUncheckedException
    • withLockNonSynced

      public <R> R withLockNonSynced(String label, ThrowableItemStoreOperation<R> operation) throws ItemStoreCheckedException
      Non-synchronized ItemStore method to force database operations under standard lock release pipeline
      Type Parameters:
      R -
      Parameters:
      label -
      operation -
      Returns:
      of operation result
      Throws:
      ItemStoreCheckedException
    • releaseLock

      public boolean releaseLock(boolean releaseMutex)
      Release lock on master
      Parameters:
      releaseMutex -
      Returns:
      boolean
    • getStoreName

      public String getStoreName()
      Fetch configured store name
      Returns:
      String
    • getDbDirectory

      public Path getDbDirectory()
      Fetch configured DB directory
      Returns:
      Path
    • getMasterDB

      public Path getMasterDB()
      Fetch configured master DB directory
      Returns:
      Path
    • getMasterLock

      public Path getMasterLock()
      Fetch configured master lock directory
      Returns:
      Path
    • getFileChannel

      public FileChannel getFileChannel()
      Fetch active file channel
      Returns:
      FileChannel
    • getFileLock

      public FileLock getFileLock()
      Fetch active OS file lock
      Returns:
      FileLock