org.apache.camel.component.file.strategy
Class GenericFileRenameExclusiveReadLockStrategy<T>

java.lang.Object
  extended by org.apache.camel.component.file.strategy.GenericFileRenameExclusiveReadLockStrategy<T>
All Implemented Interfaces:
GenericFileExclusiveReadLockStrategy<T>

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
GenericFileRenameExclusiveReadLockStrategy()
           
 
Method Summary
 boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange)
          Acquires exclusive read lock to the file.
 long getTimeout()
           
 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 releaseExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange)
          Releases the exclusive read lock granted by the acquireExclusiveReadLock method.
 void setCheckInterval(long checkInterval)
          Sets the check interval period.
 void setTimeout(long timeout)
          Sets an optional timeout period.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericFileRenameExclusiveReadLockStrategy

public GenericFileRenameExclusiveReadLockStrategy()
Method Detail

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 interface GenericFileExclusiveReadLockStrategy<T>
Parameters:
operations - generic file operations
endpoint - the endpoint
Throws:
Exception - can be thrown in case of errors

acquireExclusiveReadLock

public boolean acquireExclusiveReadLock(GenericFileOperations<T> operations,
                                        GenericFile<T> file,
                                        Exchange exchange)
                                 throws Exception
Description copied from interface: GenericFileExclusiveReadLockStrategy
Acquires exclusive read lock to the file.

Specified by:
acquireExclusiveReadLock in interface GenericFileExclusiveReadLockStrategy<T>
Parameters:
operations - generic file operations
file - the file
exchange - 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

releaseExclusiveReadLock

public void releaseExclusiveReadLock(GenericFileOperations<T> operations,
                                     GenericFile<T> file,
                                     Exchange exchange)
                              throws Exception
Description copied from interface: GenericFileExclusiveReadLockStrategy
Releases the exclusive read lock granted by the acquireExclusiveReadLock method.

Specified by:
releaseExclusiveReadLock in interface GenericFileExclusiveReadLockStrategy<T>
Parameters:
operations - generic file operations
file - the file
exchange - 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 interface GenericFileExclusiveReadLockStrategy<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 interface GenericFileExclusiveReadLockStrategy<T>
Parameters:
checkInterval - interval in millis


Apache CAMEL