Class FileLocks
java.lang.Object
io.goobi.viewer.model.administration.configeditor.FileLocks
Manages per-session exclusive edit leases for configuration files. Each lease carries an expiry; it must be
renewed (heartbeat) before it expires, otherwise it is treated as orphaned and reaped. Prevents concurrent
modification by different HTTP sessions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearLocksForSessionId(String sessionId) getAndClearLocksForSessionId(String sessionId) Atomically collects and removes all locks for the given session.getLockedPathsForSessionId(String sessionId) Returns all file paths locked by the given session id.booleanisFileLockedByOthers(Path file, String sessionId) booleanbooleanAcquires or refreshes the lease for the given session if the file is free or already held by this session.Removes all leases whose expiry time has passed.booleanExtends the lease expiry, but only if the lease is currently held by the given session (heartbeat).booleanunlockFile(Path file, String sessionId) Releases the lease for the given file if it is not held by another session.
-
Constructor Details
-
FileLocks
public FileLocks()Production constructor using the system clock.
-
-
Method Details
-
lockFile
Acquires or refreshes the lease for the given session if the file is free or already held by this session.- Parameters:
file- the file path to locksessionId- the HTTP session identifier acquiring the lock- Returns:
- true if file locked successfully; false otherwise
-
renewLock
Extends the lease expiry, but only if the lease is currently held by the given session (heartbeat).- Parameters:
file- the file path whose lease should be renewedsessionId- the HTTP session identifier that must hold the lease- Returns:
- true if the lease was renewed; false if held by another session or not present
-
unlockFile
Releases the lease for the given file if it is not held by another session.- Parameters:
file- the file path to unlocksessionId- the HTTP session identifier releasing the lock- Returns:
- true if file unlocked successfully; false otherwise
-
isFileLockedByOthers
- Parameters:
file- path to the file to checksessionId- current HTTP session ID to compare against the lock holder- Returns:
- true if a non-expired lease is held by a different session; false otherwise
-
isLocked
- Parameters:
file- path to the file to check- Returns:
- true if any (non-expired) lease currently exists for the file. Used by the reaper to re-check, after removing expired leases, whether a fresh lease was re-acquired before deleting the swap file.
-
removeExpiredLocks
Removes all leases whose expiry time has passed.- Returns:
- map of expired paths to the session id that held them (so callers can clean up owner-tagged artefacts)
-
getLockedPathsForSessionId
Returns all file paths locked by the given session id.- Parameters:
sessionId- aStringobject- Returns:
- set of paths locked by the session
-
clearLocksForSessionId
- Parameters:
sessionId- the HTTP session identifier whose locks should be released
-
getAndClearLocksForSessionId
Atomically collects and removes all locks for the given session.- Parameters:
sessionId- aStringobject- Returns:
- set of paths that were locked by the session and have now been released
-