Package de.dlr.proseo.storagemgr.utils
Class StorageFileLocker
java.lang.Object
de.dlr.proseo.storagemgr.utils.StorageFileLocker
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.
- Author:
- Denys Chaykovskiy
-
Constructor Summary
ConstructorsConstructorDescriptionStorageFileLocker(String path, long waitTime, long fileCheckMaxCycles) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidAcquires a lock on the file.voidunlock()Releases the lock on the file by removing the file path from the productLockSet.
-
Constructor Details
-
StorageFileLocker
Constructor- Parameters:
path- path of the filewaitTime- the wait time between each cycle of checking the file lock statusfileCheckMaxCycles- file check max cycles
-
-
Method Details
-
lockOrWaitUntilUnlockedAndLock
public void lockOrWaitUntilUnlockedAndLock() throws FileLockedAfterMaxCyclesException, InterruptedExceptionAcquires 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.- Throws:
FileLockedAfterMaxCyclesException- if the file is still locked after a maximum number of checksInterruptedException- 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.
-