java.lang.Object
io.goobi.viewer.model.administration.configeditor.FileLocks

public class FileLocks extends Object
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 Details

    • FileLocks

      public FileLocks()
      Production constructor using the system clock.
  • Method Details

    • lockFile

      public boolean lockFile(Path file, String sessionId)
      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 lock
      sessionId - the HTTP session identifier acquiring the lock
      Returns:
      true if file locked successfully; false otherwise
    • renewLock

      public boolean renewLock(Path file, String sessionId)
      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 renewed
      sessionId - 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

      public boolean unlockFile(Path file, String sessionId)
      Releases the lease for the given file if it is not held by another session.
      Parameters:
      file - the file path to unlock
      sessionId - the HTTP session identifier releasing the lock
      Returns:
      true if file unlocked successfully; false otherwise
    • isFileLockedByOthers

      public boolean isFileLockedByOthers(Path file, String sessionId)
      Parameters:
      file - path to the file to check
      sessionId - 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

      public boolean isLocked(Path file)
      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

      public Map<Path,String> 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

      public Set<Path> getLockedPathsForSessionId(String sessionId)
      Returns all file paths locked by the given session id.
      Parameters:
      sessionId - a String object
      Returns:
      set of paths locked by the session
    • clearLocksForSessionId

      public void clearLocksForSessionId(String sessionId)
      Parameters:
      sessionId - the HTTP session identifier whose locks should be released
    • getAndClearLocksForSessionId

      public Set<Path> getAndClearLocksForSessionId(String sessionId)
      Atomically collects and removes all locks for the given session.
      Parameters:
      sessionId - a String object
      Returns:
      set of paths that were locked by the session and have now been released