org.apache.camel.component.file
Class GenericFileConsumer<T>

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultConsumer
          extended by org.apache.camel.impl.ScheduledPollConsumer
              extended by org.apache.camel.component.file.GenericFileConsumer<T>
All Implemented Interfaces:
Runnable, Consumer, Service
Direct Known Subclasses:
FileConsumer

public abstract class GenericFileConsumer<T>
extends ScheduledPollConsumer

Base class for remote file consumers.


Field Summary
protected  GenericFileEndpoint<T> endpoint
           
protected  String fileExpressionResult
           
protected  org.apache.commons.logging.Log log
           
protected  boolean loggedIn
           
protected  GenericFileOperations<T> operations
           
 
Constructor Summary
GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations)
           
 
Method Summary
protected  boolean isMatched(GenericFile<T> file, boolean isDirectory)
          Strategy to perform file matching based on endpoint configuration.
protected  boolean isValidFile(GenericFile<T> file, boolean isDirectory)
          Strategy for validating if the given remote file should be included or not
protected  void poll()
          Poll for files
protected abstract  void pollDirectory(String fileName, List<GenericFile<T>> fileList)
          Polls the given directory for files to process
protected  boolean prePollCheck()
          Override if required.
protected  void processExchange(GenericFileExchange<T> exchange)
          Processes the exchange
protected  void processStrategyCommit(GenericFileProcessStrategy<T> processStrategy, GenericFileExchange<T> exchange, GenericFile<T> file)
          Strategy when the file was processed and a commit should be executed.
protected  void processStrategyRollback(GenericFileProcessStrategy<T> processStrategy, GenericFileExchange<T> exchange, GenericFile<T> file)
          Strategy when the file was not processed and a rollback should be executed.
 
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, getStatus, getThreadName, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, notStarting, 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
 

Field Detail

log

protected final transient org.apache.commons.logging.Log log

endpoint

protected GenericFileEndpoint<T> endpoint

operations

protected GenericFileOperations<T> operations

loggedIn

protected boolean loggedIn

fileExpressionResult

protected String fileExpressionResult
Constructor Detail

GenericFileConsumer

public GenericFileConsumer(GenericFileEndpoint<T> endpoint,
                           Processor processor,
                           GenericFileOperations<T> operations)
Method Detail

poll

protected void poll()
             throws Exception
Poll for files

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

prePollCheck

protected boolean prePollCheck()
                        throws Exception
Override if required. Perform some checks (and perhaps actions) before we poll.

Returns:
true to poll, false to skip this poll.
Throws:
Exception

pollDirectory

protected abstract void pollDirectory(String fileName,
                                      List<GenericFile<T>> fileList)
Polls the given directory for files to process

Parameters:
fileName - current directory or file
fileList - current list of files gathered

processExchange

protected void processExchange(GenericFileExchange<T> exchange)
Processes the exchange

Parameters:
exchange - the exchange

processStrategyCommit

protected void processStrategyCommit(GenericFileProcessStrategy<T> processStrategy,
                                     GenericFileExchange<T> exchange,
                                     GenericFile<T> file)
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

processStrategyRollback

protected void processStrategyRollback(GenericFileProcessStrategy<T> processStrategy,
                                       GenericFileExchange<T> exchange,
                                       GenericFile<T> 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(GenericFile<T> file,
                              boolean isDirectory)
Strategy for validating if the given remote file should be included or not

Parameters:
file - the remote file
isDirectory - wether the file is a directory or a file
Returns:
true to include the file, false to skip it

isMatched

protected boolean isMatched(GenericFile<T> file,
                            boolean isDirectory)
Strategy to perform file matching based on endpoint configuration.

Will always return false for certain files/folders:

And then true for directories.

Parameters:
file - the remote file
isDirectory - wether the file is a directory or a file
Returns:
true if the remote file is matched, false if not


Copyright © 2009 Apache Software Foundation. All Rights Reserved.