Class MarkerFileExclusiveReadLockStrategy
java.lang.Object
org.apache.camel.component.file.strategy.MarkerFileExclusiveReadLockStrategy
- All Implemented Interfaces:
GenericFileExclusiveReadLockStrategy<File>
- Direct Known Subclasses:
FileChangedExclusiveReadLockStrategy,FileLockExclusiveReadLockStrategy
public class MarkerFileExclusiveReadLockStrategy
extends Object
implements GenericFileExclusiveReadLockStrategy<File>
Acquires read lock to the given file using a marker file so other Camel consumers wont acquire the same file. This is
the default behavior in Camel 1.x.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) Acquires exclusive read lock to the file.protected voiddoReleaseExclusiveReadLock(GenericFile<File> file, org.apache.camel.Exchange exchange) Perform the releases of the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation.protected static booleanisTimedOut(org.apache.camel.util.StopWatch watch, File target, long timeout, org.apache.camel.LoggingLevel readLockLoggingLevel) voidprepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint) Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.voidreleaseExclusiveReadLockOnAbort(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) Releases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).voidreleaseExclusiveReadLockOnCommit(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)voidreleaseExclusiveReadLockOnRollback(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)voidsetCheckInterval(long checkInterval) Sets the check interval period.voidsetDeleteOrphanLockFiles(boolean deleteOrphanLockFiles) Sets whether orphan marker files should be deleted upon startupvoidsetMarkerFiler(boolean markerFile) Sets whether marker file should be used or not.voidsetReadLockLoggingLevel(org.apache.camel.LoggingLevel readLockLoggingLevel) Sets logging level used when a read lock could not be acquired.voidsetTimeout(long timeout) Sets an optional timeout period.
-
Constructor Details
-
MarkerFileExclusiveReadLockStrategy
public MarkerFileExclusiveReadLockStrategy()
-
-
Method Details
-
prepareOnStartup
public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint) Description copied from interface:GenericFileExclusiveReadLockStrategyAllows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.- Specified by:
prepareOnStartupin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
operations- generic file operationsendpoint- the endpoint
-
acquireExclusiveReadLock
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategyAcquires exclusive read lock to the file.- Specified by:
acquireExclusiveReadLockin interfaceGenericFileExclusiveReadLockStrategy<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
public void releaseExclusiveReadLockOnAbort(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategyReleases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).- Specified by:
releaseExclusiveReadLockOnAbortin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
operations- generic file operationsfile- the fileexchange- the exchange- Throws:
Exception- can be thrown in case of errors
-
releaseExclusiveReadLockOnRollback
public void releaseExclusiveReadLockOnRollback(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategyReleases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)- Specified by:
releaseExclusiveReadLockOnRollbackin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
operations- generic file operationsfile- the fileexchange- the exchange- Throws:
Exception- can be thrown in case of errors
-
releaseExclusiveReadLockOnCommit
public void releaseExclusiveReadLockOnCommit(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception Description copied from interface:GenericFileExclusiveReadLockStrategyReleases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)- Specified by:
releaseExclusiveReadLockOnCommitin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
operations- generic file operationsfile- the fileexchange- the exchange- Throws:
Exception- can be thrown in case of errors
-
doReleaseExclusiveReadLock
protected void doReleaseExclusiveReadLock(GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception Perform the releases of the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation.- Parameters:
file- the fileexchange- the exchange- Throws:
Exception- can be thrown in case of errors- See Also:
-
setTimeout
public void setTimeout(long timeout) Description copied from interface:GenericFileExclusiveReadLockStrategySets 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:
setTimeoutin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
timeout- period in millis
-
setCheckInterval
public void setCheckInterval(long checkInterval) Description copied from interface:GenericFileExclusiveReadLockStrategySets 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:
setCheckIntervalin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
checkInterval- interval in millis
-
setReadLockLoggingLevel
public void setReadLockLoggingLevel(org.apache.camel.LoggingLevel readLockLoggingLevel) Description copied from interface:GenericFileExclusiveReadLockStrategySets 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:
setReadLockLoggingLevelin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
readLockLoggingLevel- LoggingLevel
-
setMarkerFiler
public void setMarkerFiler(boolean markerFile) Description copied from interface:GenericFileExclusiveReadLockStrategySets whether marker file should be used or not.- Specified by:
setMarkerFilerin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
markerFile- true to use marker files.
-
setDeleteOrphanLockFiles
public void setDeleteOrphanLockFiles(boolean deleteOrphanLockFiles) Description copied from interface:GenericFileExclusiveReadLockStrategySets whether orphan marker files should be deleted upon startup- Specified by:
setDeleteOrphanLockFilesin interfaceGenericFileExclusiveReadLockStrategy<File>- Parameters:
deleteOrphanLockFiles- true to delete files, false to skip this check
-
isTimedOut
protected static boolean isTimedOut(org.apache.camel.util.StopWatch watch, File target, long timeout, org.apache.camel.LoggingLevel readLockLoggingLevel)
-