Class MutexFilesUtils

java.lang.Object
org.tasktide.mutex.utils.MutexFilesUtils

public class MutexFilesUtils extends Object
File utility for operations with Mutex
  • Constructor Details

    • MutexFilesUtils

      public MutexFilesUtils()
  • Method Details

    • toJson

      public static String toJson(Object data)
      Represents provided data as JSON string
      Parameters:
      data -
      Returns:
      String
    • fetchFiles

      public static Stream<Path> fetchFiles(Path dir)
      Retrieve list of files under target directory under target
      Parameters:
      dir -
      Returns:
      Stream-Path
    • findPosition

      public static int findPosition(Mutex mutex, MutexFileType fileType)
      Returns the full file path of the leader
      Parameters:
      mutex -
      fileType -
      Returns:
      int
    • findPredecessor

      public static Path findPredecessor(Mutex mutex, MutexFileType fileType, int pos)
      Find predecessor path
      Parameters:
      mutex -
      fileType -
      pos -
      Returns:
      Path
    • fetchOldest

      public static Optional<Path> fetchOldest(Path dir)
      Fetch the oldest path
      Parameters:
      dir -
      Returns:
      Optional-Path
    • writeHostFile

      public static boolean writeHostFile(Mutex mutex)
      Enqueue lock request
      Parameters:
      mutex -
      Returns:
      boolean
    • writeElectionFile

      public static boolean writeElectionFile(Mutex mutex)
      Write the election file of Mutex
      Parameters:
      mutex -
      Returns:
      boolean
    • readMutexFromFile

      public static Optional<Mutex> readMutexFromFile(Path mutexFile)
      Fetch nullable Mutex from provided file
      Parameters:
      mutexFile -
      Returns:
      Optional-Mutex
    • removeHostFile

      public static boolean removeHostFile(Mutex mutex)
      Remove host file
      Parameters:
      mutex -
      Returns:
      boolean
    • deleteFile

      public static boolean deleteFile(Path target)
      Delete target flie
      Parameters:
      target -
      Returns:
      boolean
    • writeMutexFile

      public static boolean writeMutexFile(Mutex mutex, Path targetFile)
      Write Mutex
      Parameters:
      mutex -
      targetFile -
      Returns:
      boolean
    • writeMutex

      public static void writeMutex(Mutex mutex, MutexFileType fileType) throws MutexCheckedException
      Write mutex to required MutexFileType
      Parameters:
      mutex -
      fileType -
      Throws:
      MutexCheckedException
    • getLeader

      public static Path getLeader() throws MutexCheckedException
      Fetch leader
      Returns:
      Path
      Throws:
      MutexCheckedException
    • evaluateLeaderTimeToLive

      public static boolean evaluateLeaderTimeToLive(Path leader)
      Evaluates time to live of leader
      Parameters:
      leader -
      Returns:
      boolean
    • clearStaleLeader

      public static boolean clearStaleLeader(Path targetFile)
      Parameters:
      targetFile -
      Returns:
    • writeConfirmatoryBallot

      public static boolean writeConfirmatoryBallot(Mutex mutex, Path confirmDir)
    • removeConfirmatoryBallot

      public static void removeConfirmatoryBallot(Mutex mutex)
    • recastBallot

      public static void recastBallot(Mutex mutex, boolean deleteFlag)