Class FileLockExclusiveReadLockStrategy
- java.lang.Object
-
- org.apache.camel.component.file.strategy.MarkerFileExclusiveReadLockStrategy
-
- org.apache.camel.component.file.strategy.FileLockExclusiveReadLockStrategy
-
- All Implemented Interfaces:
GenericFileExclusiveReadLockStrategy<File>
public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLockStrategy
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
Constructors Constructor Description FileLockExclusiveReadLockStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange)
Acquires exclusive read lock to the file.protected void
doReleaseExclusiveReadLock(GenericFile<File> file, org.apache.camel.Exchange exchange)
long
getTimeout()
void
prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint)
Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.void
setCheckInterval(long checkInterval)
Sets the check interval period.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.-
Methods inherited from class org.apache.camel.component.file.strategy.MarkerFileExclusiveReadLockStrategy
releaseExclusiveReadLockOnAbort, releaseExclusiveReadLockOnCommit, releaseExclusiveReadLockOnRollback, setDeleteOrphanLockFiles, setMarkerFiler
-
-
-
-
Method Detail
-
prepareOnStartup
public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint)
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<File>
- Overrides:
prepareOnStartup
in classMarkerFileExclusiveReadLockStrategy
- 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:GenericFileExclusiveReadLockStrategy
Acquires exclusive read lock to the file.- Specified by:
acquireExclusiveReadLock
in interfaceGenericFileExclusiveReadLockStrategy<File>
- Overrides:
acquireExclusiveReadLock
in classMarkerFileExclusiveReadLockStrategy
- 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
-
doReleaseExclusiveReadLock
protected void doReleaseExclusiveReadLock(GenericFile<File> file, org.apache.camel.Exchange exchange) throws Exception
- Overrides:
doReleaseExclusiveReadLock
in classMarkerFileExclusiveReadLockStrategy
- Throws:
Exception
-
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<File>
- Overrides:
setTimeout
in classMarkerFileExclusiveReadLockStrategy
- 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<File>
- Overrides:
setCheckInterval
in classMarkerFileExclusiveReadLockStrategy
- 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<File>
- Overrides:
setReadLockLoggingLevel
in classMarkerFileExclusiveReadLockStrategy
- Parameters:
readLockLoggingLevel
- LoggingLevel
-
-