Class NioFileLocker
java.lang.Object
org.springframework.integration.file.filters.AbstractFileListFilter<File>
org.springframework.integration.file.locking.AbstractFileLockerFilter
org.springframework.integration.file.locking.NioFileLocker
- All Implemented Interfaces:
FileLocker,FileListFilter<File>
File locking strategy that uses java.nio. The locks taken by FileChannel are shared with all the threads in a single
JVM, so this locking strategy does not prevent files being picked up multiple times within the same JVM.
FileReadingMessageSources sharing a
Locker will not pick up the same files.
This implementation will acquire or create a FileLock for the given file. Caching locks might be expensive,
so this locking strategy is not recommended for scenarios where many files are accessed in parallel.
- Since:
- 2.0
- Author:
- Iwein Fuld, Mark Fisher, Gary Russell
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisLockable(File file) Checks whether the file passed in can be locked by this locker.booleanTries to lock the given file and returnstrueif it was successful,falseotherwise.voidUnlocks the given file.Methods inherited from class org.springframework.integration.file.locking.AbstractFileLockerFilter
acceptMethods inherited from class org.springframework.integration.file.filters.AbstractFileListFilter
filterFiles, supportsSingleFileFilteringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.integration.file.filters.FileListFilter
isForRecursion
-
Constructor Details
-
NioFileLocker
public NioFileLocker()
-
-
Method Details
-
lock
Description copied from interface:FileLockerTries to lock the given file and returnstrueif it was successful,falseotherwise.- Parameters:
fileToLock- the file that should be locked according to this locker- Returns:
- true if successful.
-
isLockable
Description copied from interface:FileLockerChecks whether the file passed in can be locked by this locker. This method never changes the locked state.- Parameters:
file- The file.- Returns:
- true if the file was locked by another locker than this locker
-
unlock
Description copied from interface:FileLockerUnlocks the given file.- Parameters:
fileToUnlock- the file that should be unlocked according to this locker
-