Package ghidra.framework.store.local
Class LockFile
java.lang.Object
ghidra.framework.store.local.LockFile
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsLock
(File dir) boolean
Create the lock file using the default timeout.boolean
createLock
(int timeout, boolean hold) Create the lock file.void
dispose()
Cleanup lock resources and tasks.protected void
finalize()
Cleanup during garbage collection.Return the name of the current lock owner or"<Unknown>"
if not locked or could not be determined.boolean
haveLock()
Determine if lock file was successfully created by this instance.boolean
haveLock
(boolean verify) Determine if lock is still in place.static boolean
static boolean
void
Remove the lock file.toString()
-
Field Details
-
nextInstanceId
public static int nextInstanceId
-
-
Constructor Details
-
LockFile
Constructor.- Parameters:
dir
- directory containing lock filename
- unmangled name of entity which this lock is associated with.
-
LockFile
Constructor.- Parameters:
dir
- directory containing lock filename
- unmangled name of entity which this lock is associated with.lockType
- unique lock identifier (may not contain a '.')
-
LockFile
Constructor.- Parameters:
file
- file whose lock state will be controlled with this lock file.
-
-
Method Details
-
isLocked
- Parameters:
dir
- directory containing lock filename
- of entity which this lock is associated with.- Returns:
- true if any lock exists within dir for the given entity name.
-
isLocked
- 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
-
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
Return the name of the current lock owner or"<Unknown>"
if not locked or could not be determined. -
toString
-
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.
-