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

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultEndpoint
          extended by org.apache.camel.impl.ScheduledPollEndpoint
              extended by org.apache.camel.component.file.GenericFileEndpoint<T>
All Implemented Interfaces:
CamelContextAware, Endpoint, IsSingleton, Service, ShutdownableService, BrowsableEndpoint, HasId, StatefulService, SuspendableService
Direct Known Subclasses:
FileEndpoint

public abstract class GenericFileEndpoint<T>
extends ScheduledPollEndpoint
implements BrowsableEndpoint

Base class for file endpoints


Field Summary
protected  boolean allowNullBody
           
protected  AntPathMatcherGenericFileFilter<T> antFilter
           
protected  boolean autoCreate
           
protected  int bufferSize
           
protected  String charset
           
protected  GenericFileConfiguration configuration
           
protected static int DEFAULT_IDEMPOTENT_CACHE_SIZE
           
protected static String DEFAULT_STRATEGYFACTORY_CLASS
           
protected  boolean delete
           
protected  boolean directoryMustExist
           
protected  String doneFileName
           
protected  boolean eagerDeleteTargetFile
           
protected  boolean eagerMaxMessagesPerPoll
           
protected  String exclude
           
protected  GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy
           
protected  GenericFileExist fileExist
           
protected  Expression fileName
           
protected  GenericFileFilter<T> filter
           
protected  boolean flatten
           
protected  Boolean idempotent
           
protected  IdempotentRepository<String> idempotentRepository
           
protected  String include
           
protected  IdempotentRepository<String> inProgressRepository
           
protected  boolean keepLastModified
           
protected  String localWorkDirectory
           
protected  org.slf4j.Logger log
           
protected  int maxDepth
           
protected  int maxMessagesPerPoll
           
protected  int minDepth
           
protected  Expression move
           
protected  Expression moveExisting
           
protected  Expression moveFailed
           
protected  boolean noop
           
protected  Expression preMove
           
protected  GenericFileProcessStrategy<T> processStrategy
           
protected  String readLock
           
protected  long readLockCheckInterval
           
protected  long readLockMinLength
           
protected  long readLockTimeout
           
protected  boolean recursive
           
protected  Comparator<Exchange> sortBy
           
protected  Comparator<GenericFile<T>> sorter
           
protected  boolean startingDirectoryMustExist
           
protected  Expression tempFileName
           
protected  String tempPrefix
           
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
GenericFileEndpoint()
           
GenericFileEndpoint(String endpointUri, Component component)
           
 
Method Summary
 void configureExchange(Exchange exchange)
          Set up the exchange properties with the options of the file endpoint
 void configureMessage(GenericFile<T> file, Message message)
          Configures the given message with the file which sets the body to the file object.
protected  String configureMoveOrPreMoveExpression(String expression)
          Strategy to configure the move, preMove, or moveExisting option based on a String input.
abstract  GenericFileConsumer<T> createConsumer(Processor processor)
          Creates a new Event Driven Consumer which consumes messages from the endpoint using the given processor
protected  String createDoneFileName(String fileName)
          Creates the associated name of the done file based on the given file name.
abstract  Exchange createExchange(GenericFile<T> file)
           
protected  GenericFileProcessStrategy<T> createGenericFileStrategy()
          A strategy method to lazily create the file strategy
abstract  GenericFileProducer<T> createProducer()
          Creates a new producer which is used send messages into the endpoint
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 GenericFileFilter<T> getAntFilter()
           
 int getBufferSize()
           
 String getCharset()
           
 GenericFileConfiguration getConfiguration()
           
 String getDoneFileName()
           
 List<Exchange> getExchanges()
          This implementation will not load the file content.
 String getExclude()
           
 GenericFileExclusiveReadLockStrategy<T> getExclusiveReadLockStrategy()
           
 GenericFileExist getFileExist()
           
 Expression getFileName()
           
abstract  char getFileSeparator()
           
 GenericFileFilter<T> getFilter()
           
 String getGeneratedFileName(Message message)
          Return the file name that will be auto-generated for the given message if none is provided
 GenericFileProcessStrategy<T> getGenericFileProcessStrategy()
           
 IdempotentRepository<String> getIdempotentRepository()
           
 String getInclude()
           
 IdempotentRepository<String> getInProgressRepository()
           
 String getLocalWorkDirectory()
           
 int getMaxDepth()
           
 int getMaxMessagesPerPoll()
           
 int getMinDepth()
           
 Expression getMove()
           
 Expression getMoveExisting()
           
 Expression getMoveFailed()
           
protected  Map<String,Object> getParamsAsMap()
           
 Expression getPreMove()
           
 GenericFileProcessStrategy<T> getProcessStrategy()
           
 String getReadLock()
           
 long getReadLockCheckInterval()
           
 long getReadLockMinLength()
           
 long getReadLockTimeout()
           
abstract  String getScheme()
           
 Comparator<Exchange> getSortBy()
           
 Comparator<GenericFile<T>> getSorter()
           
 Expression getTempFileName()
           
 String getTempPrefix()
           
abstract  boolean isAbsolute(String name)
           
 boolean isAllowNullBody()
           
 boolean isAutoCreate()
           
 boolean isDelete()
           
 boolean isDirectoryMustExist()
           
protected  boolean isDoneFile(String fileName)
          Is the given file a done file?

This method should only be invoked if a done filename property has been set on this endpoint.

 boolean isEagerDeleteTargetFile()
           
 boolean isEagerMaxMessagesPerPoll()
           
 boolean isFlatten()
           
 Boolean isIdempotent()
           
protected  boolean isIdempotentSet()
           
 boolean isKeepLastModified()
           
 boolean isNoop()
           
 boolean isRecursive()
           
 boolean isSingleton()
          Whether this class supports being singleton or not.
 boolean isStartingDirectoryMustExist()
           
 void setAllowNullBody(boolean allowNullBody)
           
 void setAntExclude(String antExclude)
           
 void setAntInclude(String antInclude)
           
 void setAutoCreate(boolean autoCreate)
           
 void setBufferSize(int bufferSize)
           
 void setCharset(String charset)
           
 void setConfiguration(GenericFileConfiguration configuration)
           
 void setDelete(boolean delete)
           
 void setDirectoryMustExist(boolean directoryMustExist)
           
 void setDoneFileName(String doneFileName)
          Sets the done file name.
 void setEagerDeleteTargetFile(boolean eagerDeleteTargetFile)
           
 void setEagerMaxMessagesPerPoll(boolean eagerMaxMessagesPerPoll)
           
 void setExclude(String exclude)
           
 void setExclusiveReadLockStrategy(GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy)
           
 void setFileExist(GenericFileExist fileExist)
           
 void setFileName(Expression fileName)
           
 void setFileName(String fileLanguageExpression)
          Sets the file expression based on SimpleLanguage
 void setFilter(GenericFileFilter<T> filter)
           
 void setFlatten(boolean flatten)
           
 void setIdempotent(Boolean idempotent)
           
 void setIdempotentRepository(IdempotentRepository<String> idempotentRepository)
           
 void setInclude(String include)
           
 void setInProgressRepository(IdempotentRepository<String> inProgressRepository)
           
 void setKeepLastModified(boolean keepLastModified)
           
 void setLocalWorkDirectory(String localWorkDirectory)
           
 void setMaxDepth(int maxDepth)
           
 void setMaxMessagesPerPoll(int maxMessagesPerPoll)
           
 void setMinDepth(int minDepth)
           
 void setMove(Expression move)
           
 void setMove(String fileLanguageExpression)
          Sets the move expression based on SimpleLanguage
 void setMoveExisting(Expression moveExisting)
           
 void setMoveExisting(String fileLanguageExpression)
          Sets the move existing expression based on SimpleLanguage
 void setMoveFailed(Expression moveFailed)
           
 void setMoveFailed(String fileLanguageExpression)
          Sets the move failure expression based on SimpleLanguage
 void setNoop(boolean noop)
           
 void setPreMove(Expression preMove)
           
 void setPreMove(String fileLanguageExpression)
          Sets the pre move expression based on SimpleLanguage
 void setProcessStrategy(GenericFileProcessStrategy<T> processStrategy)
           
 void setReadLock(String readLock)
           
 void setReadLockCheckInterval(long readLockCheckInterval)
           
 void setReadLockMinLength(long readLockMinLength)
           
 void setReadLockTimeout(long readLockTimeout)
           
 void setRecursive(boolean recursive)
           
 void setSortBy(Comparator<Exchange> sortBy)
           
 void setSortBy(String expression)
           
 void setSortBy(String expression, boolean reverse)
           
 void setSorter(Comparator<GenericFile<T>> sorter)
           
 void setStartingDirectoryMustExist(boolean startingDirectoryMustExist)
           
 void setTempFileName(Expression tempFileName)
           
 void setTempFileName(String tempFileNameExpression)
           
 void setTempPrefix(String tempPrefix)
          Enables and uses temporary prefix when writing files, after write it will be renamed to the correct name.
 
Methods inherited from class org.apache.camel.impl.ScheduledPollEndpoint
configureProperties
 
Methods inherited from class org.apache.camel.impl.DefaultEndpoint
configureConsumer, createEndpointConfiguration, createEndpointUri, createExchange, createExchange, createExchange, createPollingConsumer, equals, getCamelContext, getComponent, getConsumerProperties, getEndpointConfiguration, getEndpointKey, getEndpointUri, getExchangePattern, getId, hashCode, isLenientProperties, isSynchronous, setCamelContext, setConsumerProperties, setEndpointConfiguration, setEndpointUri, setEndpointUriIfNotSpecified, setExchangePattern, setSynchronous, toString
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Endpoint
configureProperties, createExchange, createExchange, createExchange, createPollingConsumer, getCamelContext, getEndpointConfiguration, getEndpointKey, getEndpointUri, isLenientProperties, setCamelContext
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Field Detail

DEFAULT_STRATEGYFACTORY_CLASS

protected static final transient String DEFAULT_STRATEGYFACTORY_CLASS
See Also:
Constant Field Values

DEFAULT_IDEMPOTENT_CACHE_SIZE

protected static final transient int DEFAULT_IDEMPOTENT_CACHE_SIZE
See Also:
Constant Field Values

log

protected final transient org.slf4j.Logger log

processStrategy

protected GenericFileProcessStrategy<T> processStrategy

configuration

protected GenericFileConfiguration configuration

inProgressRepository

protected IdempotentRepository<String> inProgressRepository

localWorkDirectory

protected String localWorkDirectory

autoCreate

protected boolean autoCreate

startingDirectoryMustExist

protected boolean startingDirectoryMustExist

directoryMustExist

protected boolean directoryMustExist

bufferSize

protected int bufferSize

fileExist

protected GenericFileExist fileExist

noop

protected boolean noop

recursive

protected boolean recursive

delete

protected boolean delete

flatten

protected boolean flatten

maxMessagesPerPoll

protected int maxMessagesPerPoll

eagerMaxMessagesPerPoll

protected boolean eagerMaxMessagesPerPoll

maxDepth

protected int maxDepth

minDepth

protected int minDepth

tempPrefix

protected String tempPrefix

tempFileName

protected Expression tempFileName

eagerDeleteTargetFile

protected boolean eagerDeleteTargetFile

include

protected String include

exclude

protected String exclude

charset

protected String charset

fileName

protected Expression fileName

move

protected Expression move

moveFailed

protected Expression moveFailed

preMove

protected Expression preMove

moveExisting

protected Expression moveExisting

idempotent

protected Boolean idempotent

idempotentRepository

protected IdempotentRepository<String> idempotentRepository

filter

protected GenericFileFilter<T> filter

antFilter

protected AntPathMatcherGenericFileFilter<T> antFilter

sorter

protected Comparator<GenericFile<T>> sorter

sortBy

protected Comparator<Exchange> sortBy

readLock

protected String readLock

readLockCheckInterval

protected long readLockCheckInterval

readLockTimeout

protected long readLockTimeout

readLockMinLength

protected long readLockMinLength

exclusiveReadLockStrategy

protected GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy

keepLastModified

protected boolean keepLastModified

doneFileName

protected String doneFileName

allowNullBody

protected boolean allowNullBody
Constructor Detail

GenericFileEndpoint

public GenericFileEndpoint()

GenericFileEndpoint

public GenericFileEndpoint(String endpointUri,
                           Component component)
Method Detail

isSingleton

public boolean isSingleton()
Description copied from interface: IsSingleton
Whether this class supports being singleton or not.

Specified by:
isSingleton in interface IsSingleton
Returns:
true to be a single shared instance, false to create new instances.

createConsumer

public abstract GenericFileConsumer<T> createConsumer(Processor processor)
                                               throws Exception
Description copied from interface: Endpoint
Creates a new Event Driven Consumer which consumes messages from the endpoint using the given processor

Specified by:
createConsumer in interface Endpoint
Parameters:
processor - the given processor
Returns:
a newly created consumer
Throws:
Exception - can be thrown

createProducer

public abstract GenericFileProducer<T> createProducer()
                                               throws Exception
Description copied from interface: Endpoint
Creates a new producer which is used send messages into the endpoint

Specified by:
createProducer in interface Endpoint
Returns:
a newly created producer
Throws:
Exception - can be thrown

createExchange

public abstract Exchange createExchange(GenericFile<T> file)

getScheme

public abstract String getScheme()

getFileSeparator

public abstract char getFileSeparator()

isAbsolute

public abstract boolean isAbsolute(String name)

getGeneratedFileName

public String getGeneratedFileName(Message message)
Return the file name that will be auto-generated for the given message if none is provided


getGenericFileProcessStrategy

public GenericFileProcessStrategy<T> getGenericFileProcessStrategy()

getExchanges

public List<Exchange> getExchanges()
This implementation will not load the file content. Any file locking is neither in use by this implementation..

Specified by:
getExchanges in interface BrowsableEndpoint
Returns:
the exchanges on this endpoint

createGenericFileStrategy

protected GenericFileProcessStrategy<T> createGenericFileStrategy()
A strategy method to lazily create the file strategy


isNoop

public boolean isNoop()

setNoop

public void setNoop(boolean noop)

isRecursive

public boolean isRecursive()

setRecursive

public void setRecursive(boolean recursive)

getInclude

public String getInclude()

setInclude

public void setInclude(String include)

getExclude

public String getExclude()

setExclude

public void setExclude(String exclude)

setAntInclude

public void setAntInclude(String antInclude)

setAntExclude

public void setAntExclude(String antExclude)

getAntFilter

public GenericFileFilter<T> getAntFilter()

isDelete

public boolean isDelete()

setDelete

public void setDelete(boolean delete)

isFlatten

public boolean isFlatten()

setFlatten

public void setFlatten(boolean flatten)

getMove

public Expression getMove()

setMove

public void setMove(Expression move)

setMoveFailed

public void setMoveFailed(String fileLanguageExpression)
Sets the move failure expression based on SimpleLanguage


getMoveFailed

public Expression getMoveFailed()

setMoveFailed

public void setMoveFailed(Expression moveFailed)

setMove

public void setMove(String fileLanguageExpression)
Sets the move expression based on SimpleLanguage


getPreMove

public Expression getPreMove()

setPreMove

public void setPreMove(Expression preMove)

setPreMove

public void setPreMove(String fileLanguageExpression)
Sets the pre move expression based on SimpleLanguage


getMoveExisting

public Expression getMoveExisting()

setMoveExisting

public void setMoveExisting(Expression moveExisting)

setMoveExisting

public void setMoveExisting(String fileLanguageExpression)
Sets the move existing expression based on SimpleLanguage


getFileName

public Expression getFileName()

setFileName

public void setFileName(Expression fileName)

setFileName

public void setFileName(String fileLanguageExpression)
Sets the file expression based on SimpleLanguage


getDoneFileName

public String getDoneFileName()

setDoneFileName

public void setDoneFileName(String doneFileName)
Sets the done file name.

Only ${file.name} and ${file.name.noext} is supported as dynamic placeholders.


isIdempotent

public Boolean isIdempotent()

getCharset

public String getCharset()

setCharset

public void setCharset(String charset)

isIdempotentSet

protected boolean isIdempotentSet()

setIdempotent

public void setIdempotent(Boolean idempotent)

getIdempotentRepository

public IdempotentRepository<String> getIdempotentRepository()

setIdempotentRepository

public void setIdempotentRepository(IdempotentRepository<String> idempotentRepository)

getFilter

public GenericFileFilter<T> getFilter()

setFilter

public void setFilter(GenericFileFilter<T> filter)

getSorter

public Comparator<GenericFile<T>> getSorter()

setSorter

public void setSorter(Comparator<GenericFile<T>> sorter)

getSortBy

public Comparator<Exchange> getSortBy()

setSortBy

public void setSortBy(Comparator<Exchange> sortBy)

setSortBy

public void setSortBy(String expression)

setSortBy

public void setSortBy(String expression,
                      boolean reverse)

getTempPrefix

public String getTempPrefix()

setTempPrefix

public void setTempPrefix(String tempPrefix)
Enables and uses temporary prefix when writing files, after write it will be renamed to the correct name.


getTempFileName

public Expression getTempFileName()

setTempFileName

public void setTempFileName(Expression tempFileName)

setTempFileName

public void setTempFileName(String tempFileNameExpression)

isEagerDeleteTargetFile

public boolean isEagerDeleteTargetFile()

setEagerDeleteTargetFile

public void setEagerDeleteTargetFile(boolean eagerDeleteTargetFile)

getConfiguration

public GenericFileConfiguration getConfiguration()

setConfiguration

public void setConfiguration(GenericFileConfiguration configuration)

getExclusiveReadLockStrategy

public GenericFileExclusiveReadLockStrategy<T> getExclusiveReadLockStrategy()

setExclusiveReadLockStrategy

public void setExclusiveReadLockStrategy(GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy)

getReadLock

public String getReadLock()

setReadLock

public void setReadLock(String readLock)

getReadLockCheckInterval

public long getReadLockCheckInterval()

setReadLockCheckInterval

public void setReadLockCheckInterval(long readLockCheckInterval)

getReadLockTimeout

public long getReadLockTimeout()

setReadLockTimeout

public void setReadLockTimeout(long readLockTimeout)

getReadLockMinLength

public long getReadLockMinLength()

setReadLockMinLength

public void setReadLockMinLength(long readLockMinLength)

getBufferSize

public int getBufferSize()

setBufferSize

public void setBufferSize(int bufferSize)

getFileExist

public GenericFileExist getFileExist()

setFileExist

public void setFileExist(GenericFileExist fileExist)

isAutoCreate

public boolean isAutoCreate()

setAutoCreate

public void setAutoCreate(boolean autoCreate)

isStartingDirectoryMustExist

public boolean isStartingDirectoryMustExist()

setStartingDirectoryMustExist

public void setStartingDirectoryMustExist(boolean startingDirectoryMustExist)

isDirectoryMustExist

public boolean isDirectoryMustExist()

setDirectoryMustExist

public void setDirectoryMustExist(boolean directoryMustExist)

getProcessStrategy

public GenericFileProcessStrategy<T> getProcessStrategy()

setProcessStrategy

public void setProcessStrategy(GenericFileProcessStrategy<T> processStrategy)

getLocalWorkDirectory

public String getLocalWorkDirectory()

setLocalWorkDirectory

public void setLocalWorkDirectory(String localWorkDirectory)

getMaxMessagesPerPoll

public int getMaxMessagesPerPoll()

setMaxMessagesPerPoll

public void setMaxMessagesPerPoll(int maxMessagesPerPoll)

isEagerMaxMessagesPerPoll

public boolean isEagerMaxMessagesPerPoll()

setEagerMaxMessagesPerPoll

public void setEagerMaxMessagesPerPoll(boolean eagerMaxMessagesPerPoll)

getMaxDepth

public int getMaxDepth()

setMaxDepth

public void setMaxDepth(int maxDepth)

getMinDepth

public int getMinDepth()

setMinDepth

public void setMinDepth(int minDepth)

getInProgressRepository

public IdempotentRepository<String> getInProgressRepository()

setInProgressRepository

public void setInProgressRepository(IdempotentRepository<String> inProgressRepository)

isKeepLastModified

public boolean isKeepLastModified()

setKeepLastModified

public void setKeepLastModified(boolean keepLastModified)

isAllowNullBody

public boolean isAllowNullBody()

setAllowNullBody

public void setAllowNullBody(boolean allowNullBody)

configureMessage

public void configureMessage(GenericFile<T> file,
                             Message message)
Configures the given message with the file which sets the body to the file object.


configureExchange

public void configureExchange(Exchange exchange)
Set up the exchange properties with the options of the file endpoint


configureMoveOrPreMoveExpression

protected String configureMoveOrPreMoveExpression(String expression)
Strategy to configure the move, preMove, or moveExisting option based on a String input.

Parameters:
expression - the original string input
Returns:
configured string or the original if no modifications is needed

getParamsAsMap

protected Map<String,Object> getParamsAsMap()

createDoneFileName

protected String createDoneFileName(String fileName)
Creates the associated name of the done file based on the given file name.

This method should only be invoked if a done filename property has been set on this endpoint.

Parameters:
fileName - the file name
Returns:
name of the associated done file name

isDoneFile

protected boolean isDoneFile(String fileName)
Is the given file a done file?

This method should only be invoked if a done filename property has been set on this endpoint.

Parameters:
fileName - the file name
Returns:
true if its a done file, false otherwise

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Overrides:
doStart in class DefaultEndpoint
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Overrides:
doStop in class DefaultEndpoint
Throws:
Exception
See Also:
ServiceSupport.doStart()


Apache CAMEL