org.apache.camel.component.file
Class FileConsumer

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultConsumer<E>
          extended by org.apache.camel.impl.ScheduledPollConsumer<FileExchange>
              extended by org.apache.camel.component.file.FileConsumer
All Implemented Interfaces:
Runnable, Consumer<FileExchange>, Service

public class FileConsumer
extends ScheduledPollConsumer<FileExchange>

For consuming files.

Version:
$Revision: 63947 $

Constructor Summary
FileConsumer(FileEndpoint endpoint, Processor processor)
           
 
Method Summary
protected  void acquireExclusiveReadLock(File file)
          Acquires exclusive read lock to the given file.
 String getRegexPattern()
           
 int getUnchangedDelay()
           
 boolean isAlwaysConsume()
           
protected  boolean isChanged(File file)
           
 boolean isExclusiveReadLock()
           
 boolean isGenerateEmptyExchangeWhenIdle()
           
protected  boolean isMatched(File file)
           
 boolean isRecursive()
           
 boolean isTimestamp()
           
 boolean isUnchangedSize()
           
protected  boolean isValidFile(File file)
           
protected  void poll()
          The polling method which is invoked periodically to poll this consumer
protected  int pollFile(File target)
          Polls the given file
protected  int pollFileOrDirectory(File fileOrDirectory, boolean processDir)
          Pools the given file or directory for files to process.
protected  void processStrategyCommit(FileProcessStrategy processStrategy, FileExchange exchange, File file, boolean failureHandled)
          Strategy when the file was processed and a commit should be executed.
protected  void processStrategyRollback(FileProcessStrategy processStrategy, FileExchange exchange, File file)
          Strategy when the file was not processed and a rollback should be executed.
 void setAlwaysConsume(boolean alwaysConsume)
          Deprecated. will be removed in Camel 2.0 (not needed when we get rid of last polltimestamp)
 void setExclusiveReadLock(boolean exclusiveReadLock)
           
 void setGenerateEmptyExchangeWhenIdle(boolean generateEmptyExchangeWhenIdle)
          Deprecated. will be removed in Camel 2.0
 void setRecursive(boolean recursive)
           
 void setRegexPattern(String regexPattern)
           
 void setTimestamp(boolean timestamp)
          Deprecated. will be removed in Camel 2.0 (not needed when we get rid of last polltimestamp)
 void setUnchangedDelay(int unchangedDelay)
          Deprecated. will be removed in Camel 2.0
 void setUnchangedSize(boolean unchangedSize)
          Deprecated. will be removed in Camel 2.0
 
Methods inherited from class org.apache.camel.impl.ScheduledPollConsumer
doStart, doStop, getDelay, getInitialDelay, getTimeUnit, isUseFixedDelay, run, setDelay, setInitialDelay, setTimeUnit, setUseFixedDelay
 
Methods inherited from class org.apache.camel.impl.DefaultConsumer
getAsyncProcessor, getEndpoint, getExceptionHandler, getProcessor, handleException, setExceptionHandler, toString
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getThreadName, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

FileConsumer

public FileConsumer(FileEndpoint endpoint,
                    Processor processor)
Method Detail

poll

protected void poll()
             throws Exception
Description copied from class: ScheduledPollConsumer
The polling method which is invoked periodically to poll this consumer

Specified by:
poll in class ScheduledPollConsumer<FileExchange>
Throws:
Exception - can be thrown if an exception occurred during polling

pollFileOrDirectory

protected int pollFileOrDirectory(File fileOrDirectory,
                                  boolean processDir)
Pools the given file or directory for files to process.

Parameters:
fileOrDirectory - file or directory
processDir - recursive
Returns:
the number of files processed or being processed async.

pollFile

protected int pollFile(File target)
Polls the given file

Parameters:
target - the file
Returns:
returns 1 if the file was processed, 0 otherwise.

acquireExclusiveReadLock

protected void acquireExclusiveReadLock(File file)
                                 throws IOException
Acquires exclusive read lock to the given file. Will wait until the lock is granted. After granting the read lock it is realeased, we just want to make sure that when we start consuming the file its not currently in progress of being written by third party.

Throws:
IOException

processStrategyCommit

protected void processStrategyCommit(FileProcessStrategy processStrategy,
                                     FileExchange exchange,
                                     File file,
                                     boolean failureHandled)
Strategy when the file was processed and a commit should be executed.

Parameters:
processStrategy - the strategy to perform the commit
exchange - the exchange
file - the file processed
failureHandled - is false if the exchange was processed succesfully, true if an exception occured during processing but it was handled by the failure processor (usually the DeadLetterChannel).

processStrategyRollback

protected void processStrategyRollback(FileProcessStrategy processStrategy,
                                       FileExchange exchange,
                                       File file)
Strategy when the file was not processed and a rollback should be executed.

Parameters:
processStrategy - the strategy to perform the commit
exchange - the exchange
file - the file processed

isValidFile

protected boolean isValidFile(File file)

isChanged

protected boolean isChanged(File file)

isMatched

protected boolean isMatched(File file)

isRecursive

public boolean isRecursive()

setRecursive

public void setRecursive(boolean recursive)

getRegexPattern

public String getRegexPattern()

setRegexPattern

public void setRegexPattern(String regexPattern)

isGenerateEmptyExchangeWhenIdle

public boolean isGenerateEmptyExchangeWhenIdle()

setGenerateEmptyExchangeWhenIdle

public void setGenerateEmptyExchangeWhenIdle(boolean generateEmptyExchangeWhenIdle)
Deprecated. will be removed in Camel 2.0


getUnchangedDelay

public int getUnchangedDelay()

setUnchangedDelay

public void setUnchangedDelay(int unchangedDelay)
Deprecated. will be removed in Camel 2.0


isUnchangedSize

public boolean isUnchangedSize()

setUnchangedSize

public void setUnchangedSize(boolean unchangedSize)
Deprecated. will be removed in Camel 2.0


isExclusiveReadLock

public boolean isExclusiveReadLock()

setExclusiveReadLock

public void setExclusiveReadLock(boolean exclusiveReadLock)

isAlwaysConsume

public boolean isAlwaysConsume()

setAlwaysConsume

public void setAlwaysConsume(boolean alwaysConsume)
Deprecated. will be removed in Camel 2.0 (not needed when we get rid of last polltimestamp)


isTimestamp

public boolean isTimestamp()

setTimestamp

public void setTimestamp(boolean timestamp)
Deprecated. will be removed in Camel 2.0 (not needed when we get rid of last polltimestamp)



Copyright © 2009 IONA Open Source Community. All Rights Reserved.