Package io.ocfl.core
Class FileLocker
java.lang.Object
io.ocfl.core.FileLocker
Provides locks for logical paths, so that an object may be safely modified by multiple threads.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a lock on the specified logical path or throws aLockException
if a lock was unable to be acquired.<T> T
withLock
(String logicalPath, UncheckedCallable<T> callable) Executes the callable after acquire a lock on the specified logical path.void
Executes the runnable after acquire a lock on the specified logical path.
-
Constructor Details
-
FileLocker
- Parameters:
timeoutDuration
- the max amount of time to wait for a file lock
-
-
Method Details
-
lock
Returns a lock on the specified logical path or throws aLockException
if a lock was unable to be acquired. This lock MUST be released in a finally block.- Parameters:
logicalPath
- the path to lock- Returns:
- the lock
- Throws:
LockException
- when unable to acquire a lock
-
withLock
Executes the runnable after acquire a lock on the specified logical path. If the lock cannot be acquired, aLockException
is thrown.- Parameters:
logicalPath
- the path to lock- Throws:
LockException
- when unable to acquire a lock
-
withLock
Executes the callable after acquire a lock on the specified logical path. If the lock cannot be acquired, aLockException
is thrown.- Parameters:
logicalPath
- the path to lock- Returns:
- the output of the callable
- Throws:
LockException
- when unable to acquire a lock
-