Class LockFile

java.lang.Object
ghidra.framework.store.local.LockFile

public class LockFile extends Object
Provides for the creation and management of a named lock file. Keep in mind that if a lock expires it may be removed without notice. Care should be taken to renew a lock file in a timely manner.
  • Field Details

    • nextInstanceId

      public static int nextInstanceId
  • Constructor Details

    • LockFile

      public LockFile(File dir, String name)
      Constructor.
      Parameters:
      dir - directory containing lock file
      name - unmangled name of entity which this lock is associated with.
    • LockFile

      public LockFile(File dir, String name, String lockType)
      Constructor.
      Parameters:
      dir - directory containing lock file
      name - unmangled name of entity which this lock is associated with.
      lockType - unique lock identifier (may not contain a '.')
    • LockFile

      public LockFile(File file)
      Constructor.
      Parameters:
      file - file whose lock state will be controlled with this lock file.
  • Method Details

    • isLocked

      public static boolean isLocked(File dir, String name)
      Parameters:
      dir - directory containing lock file
      name - of entity which this lock is associated with.
      Returns:
      true if any lock exists within dir for the given entity name.
    • isLocked

      public static boolean isLocked(File file)
      Parameters:
      file - file whose lock state is controlled with this lock file.
      Returns:
      true if any lock exists within dir for the given entity name.
    • containsLock

      public static boolean containsLock(File dir)
    • haveLock

      public boolean haveLock()
      Determine if lock file was successfully created by this instance. This does not quarentee that the lock is still present if more than MAX_LOCK_LEASE_PERIOD has lapsed since lock was created.
      Returns:
      true if lock has been created, otherwise false.
    • haveLock

      public boolean haveLock(boolean verify)
      Determine if lock is still in place. Verifying the lock may be necessary when slow processes are holding the lock without timely renewals.
      Returns:
      true if lock is still in place, otherwise false.
    • getLockOwner

      public String getLockOwner()
      Return the name of the current lock owner or "<Unknown>" if not locked or could not be determined.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • removeLock

      public void removeLock()
      Remove the lock file. This method should be invoked when the corresponding transaction is complete.
    • createLock

      public boolean createLock()
      Create the lock file using the default timeout. Lock is guaranteed for MAX_LOCK_LEASE_PERIOD seconds.
      Returns:
      true if lock creation was successful.
    • createLock

      public boolean createLock(int timeout, boolean hold)
      Create the lock file. If another lock file already exists, wait for it to expire within the specified timeout period. Method will block until either the lock is obtained or the timeout period lapses.
      Parameters:
      timeout - maximum time in milliseconds to wait for lock.
      hold - if true the lock will be held and maintained until removed, otherwise it is only guaranteed for MAX_LOCK_LEASE_PERIOD seconds.
      Returns:
      true if lock creation was successful.
    • dispose

      public void dispose()
      Cleanup lock resources and tasks. Invoking this method could prevent stale locks from being removed if createLock was invoked with a very short timeout. Use of dispose is optional - the associated wait task should stop by it self allowing the LockFile object to be finalized.
    • finalize

      protected void finalize()
      Cleanup during garbage collection.
      Overrides:
      finalize in class Object