Package org.apache.camel.component.file
Interface GenericFileExclusiveReadLockStrategy<T>
-
- All Known Implementing Classes:
FileChangedExclusiveReadLockStrategy
,FileIdempotentChangedRepositoryReadLockStrategy
,FileIdempotentRenameRepositoryReadLockStrategy
,FileIdempotentRepositoryReadLockStrategy
,FileLockExclusiveReadLockStrategy
,FileRenameExclusiveReadLockStrategy
,GenericFileRenameExclusiveReadLockStrategy
,MarkerFileExclusiveReadLockStrategy
public interface GenericFileExclusiveReadLockStrategy<T>
Strategy for acquiring exclusive read locks for files to be consumed. After granting the read lock it is released, we just want to make sure that when we start consuming the file its not currently in progress of being written by third party. Camel supports out of the box the following strategies:- FileRenameExclusiveReadLockStrategy waiting until its possible to rename the file.
- FileLockExclusiveReadLockStrategy acquiring a RW file lock for the duration of the processing.
- MarkerFileExclusiveReadLockStrategy using a marker file for acquiring read lock.
- FileChangedExclusiveReadLockStrategy using a file changed detection for acquiring read lock.
- FileIdempotentRepositoryReadLockStrategy using a
IdempotentRepository
to hold the read locks which allows to support clustering.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange)
Acquires exclusive read lock to the file.void
prepareOnStartup(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint)
Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.void
releaseExclusiveReadLockOnAbort(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange)
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).void
releaseExclusiveReadLockOnCommit(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange)
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)void
releaseExclusiveReadLockOnRollback(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange)
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)void
setCheckInterval(long checkInterval)
Sets the check interval period.void
setDeleteOrphanLockFiles(boolean deleteOrphanLockFiles)
Sets whether orphan marker files should be deleted upon startupvoid
setMarkerFiler(boolean markerFile)
Sets whether marker file should be used or not.void
setReadLockLoggingLevel(org.apache.camel.LoggingLevel readLockLoggingLevel)
Sets logging level used when a read lock could not be acquired.void
setTimeout(long timeout)
Sets an optional timeout period.
-
-
-
Method Detail
-
prepareOnStartup
void prepareOnStartup(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint) throws Exception
Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.- Parameters:
operations
- generic file operationsendpoint
- the endpoint- Throws:
Exception
- can be thrown in case of errors
-
acquireExclusiveReadLock
boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception
Acquires exclusive read lock to the file.- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Returns:
- true if read lock was acquired. If false Camel will skip the file and try it on the next poll
- Throws:
Exception
- can be thrown in case of errors
-
releaseExclusiveReadLockOnAbort
void releaseExclusiveReadLockOnAbort(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
releaseExclusiveReadLockOnRollback
void releaseExclusiveReadLockOnRollback(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
releaseExclusiveReadLockOnCommit
void releaseExclusiveReadLockOnCommit(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
setTimeout
void setTimeout(long timeout)
Sets an optional timeout period. If the readlock could not be granted within the time period then the wait is stopped and the acquireExclusiveReadLock method returns false.- Parameters:
timeout
- period in millis
-
setCheckInterval
void setCheckInterval(long checkInterval)
Sets the check interval period. The check interval is used for sleeping between attempts to acquire read lock. Setting a high value allows to cater for slow writes in case the producer of the file is slow. The default period is 1000 millis.- Parameters:
checkInterval
- interval in millis
-
setReadLockLoggingLevel
void setReadLockLoggingLevel(org.apache.camel.LoggingLevel readLockLoggingLevel)
Sets logging level used when a read lock could not be acquired. Logging level used when a read lock could not be acquired. The default logging level is WARN- Parameters:
readLockLoggingLevel
- LoggingLevel
-
setMarkerFiler
void setMarkerFiler(boolean markerFile)
Sets whether marker file should be used or not.- Parameters:
markerFile
- true to use marker files.
-
setDeleteOrphanLockFiles
void setDeleteOrphanLockFiles(boolean deleteOrphanLockFiles)
Sets whether orphan marker files should be deleted upon startup- Parameters:
deleteOrphanLockFiles
- true to delete files, false to skip this check
-
-