Class GenericFileRenameExclusiveReadLockStrategy<T>
java.lang.Object
org.apache.camel.component.file.strategy.GenericFileRenameExclusiveReadLockStrategy<T>
- All Implemented Interfaces:
GenericFileExclusiveReadLockStrategy<T>
- Direct Known Subclasses:
FileRenameExclusiveReadLockStrategy
public class GenericFileRenameExclusiveReadLockStrategy<T>
extends Object
implements GenericFileExclusiveReadLockStrategy<T>
Acquires exclusive read lock to the given file. Will wait until the lock is granted. 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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acquireExclusiveReadLock
(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) Acquires exclusive read lock to the file.long
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.
-
Constructor Details
-
GenericFileRenameExclusiveReadLockStrategy
public GenericFileRenameExclusiveReadLockStrategy()
-
-
Method Details
-
prepareOnStartup
public void prepareOnStartup(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategy
Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.- Specified by:
prepareOnStartup
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
operations
- generic file operationsendpoint
- the endpoint- Throws:
Exception
- can be thrown in case of errors
-
acquireExclusiveReadLock
public boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategy
Acquires exclusive read lock to the file.- Specified by:
acquireExclusiveReadLock
in interfaceGenericFileExclusiveReadLockStrategy<T>
- 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
public void releaseExclusiveReadLockOnAbort(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategy
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).- Specified by:
releaseExclusiveReadLockOnAbort
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
releaseExclusiveReadLockOnRollback
public void releaseExclusiveReadLockOnRollback(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategy
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)- Specified by:
releaseExclusiveReadLockOnRollback
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
releaseExclusiveReadLockOnCommit
public void releaseExclusiveReadLockOnCommit(GenericFileOperations<T> operations, GenericFile<T> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategy
Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)- Specified by:
releaseExclusiveReadLockOnCommit
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
operations
- generic file operationsfile
- the fileexchange
- the exchange- Throws:
Exception
- can be thrown in case of errors
-
getTimeout
public long getTimeout() -
setTimeout
public void setTimeout(long timeout) Description copied from interface:GenericFileExclusiveReadLockStrategy
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.- Specified by:
setTimeout
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
timeout
- period in millis
-
setCheckInterval
public void setCheckInterval(long checkInterval) Description copied from interface:GenericFileExclusiveReadLockStrategy
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.- Specified by:
setCheckInterval
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
checkInterval
- interval in millis
-
setReadLockLoggingLevel
public void setReadLockLoggingLevel(org.apache.camel.LoggingLevel readLockLoggingLevel) Description copied from interface:GenericFileExclusiveReadLockStrategy
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- Specified by:
setReadLockLoggingLevel
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
readLockLoggingLevel
- LoggingLevel
-
setMarkerFiler
public void setMarkerFiler(boolean markerFile) Description copied from interface:GenericFileExclusiveReadLockStrategy
Sets whether marker file should be used or not.- Specified by:
setMarkerFiler
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
markerFile
- true to use marker files.
-
setDeleteOrphanLockFiles
public void setDeleteOrphanLockFiles(boolean deleteOrphanLockFiles) Description copied from interface:GenericFileExclusiveReadLockStrategy
Sets whether orphan marker files should be deleted upon startup- Specified by:
setDeleteOrphanLockFiles
in interfaceGenericFileExclusiveReadLockStrategy<T>
- Parameters:
deleteOrphanLockFiles
- true to delete files, false to skip this check
-