Klasse StorageFileLocker

java.lang.Object
de.dlr.proseo.storagemgr.utils.StorageFileLocker

public class StorageFileLocker extends Object
A mechanism to lock and unlock files during the download process. It helps manage concurrent access to files by ensuring that only one process or thread can access a file at a time.
Autor:
Denys Chaykovskiy
  • Konstruktordetails

    • StorageFileLocker

      public StorageFileLocker(String path, long waitTime, long fileCheckMaxCycles)
      Constructor
      Parameter:
      path - path of the file
      waitTime - the wait time between each cycle of checking the file lock status
      fileCheckMaxCycles - file check max cycles
  • Methodendetails

    • lockOrWaitUntilUnlockedAndLock

      public void lockOrWaitUntilUnlockedAndLock() throws FileLockedAfterMaxCyclesException, InterruptedException
      Acquires a lock on the file. The method checks if the file is already locked by checking if it exists in the productLockSet. If it's not locked, it adds the file path to the set and breaks out of the loop. Otherwise, it waits for the specified waitTime and checks again. This process continues for a maximum of fileCheckMaxCycles cycles.
      Löst aus:
      FileLockedAfterMaxCyclesException - if the file is still locked after a maximum number of checks
      InterruptedException - if the thread is interrupted while waiting for the concurrent access to terminate
    • unlock

      public void unlock()
      Releases the lock on the file by removing the file path from the productLockSet.