Package de.dlr.proseo.storagemgr.utils
Klasse 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.
- Autor:
- Denys Chaykovskiy
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungStorageFileLocker
(String path, long waitTime, long fileCheckMaxCycles) Constructor -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
Acquires a lock on the file.void
unlock()
Releases the lock on the file by removing the file path from the productLockSet.
-
Konstruktordetails
-
StorageFileLocker
Constructor- Parameter:
path
- path of the filewaitTime
- the wait time between each cycle of checking the file lock statusfileCheckMaxCycles
- file check max cycles
-
-
Methodendetails
-
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.- Löst aus:
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.
-