public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsumer
Modifier and Type | Field and Description |
---|---|
protected Processor |
customProcessor |
protected boolean |
eagerLimitMaxMessagesPerPoll |
protected GenericFileEndpoint<T> |
endpoint |
protected String |
fileExpressionResult |
protected org.slf4j.Logger |
log |
protected GenericFileOperations<T> |
operations |
protected int |
pendingExchanges |
protected boolean |
prepareOnStartup |
protected GenericFileProcessStrategy<T> |
processStrategy |
protected ShutdownRunningTask |
shutdownRunningTask |
maxMessagesPerPoll
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
GenericFileConsumer(GenericFileEndpoint<T> endpoint,
Processor processor,
GenericFileOperations<T> operations,
GenericFileProcessStrategy<T> processStrategy) |
Modifier and Type | Method and Description |
---|---|
void |
afterPoll()
Callback invoked after the poll.
|
long |
beforePoll(long timeout)
Callback invoked before the poll.
|
boolean |
canPollMoreFiles(List<?> fileList)
Whether or not we can continue polling for more files
|
protected boolean |
customProcessExchange(Exchange exchange,
Processor processor)
Processes the exchange using a custom processor.
|
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
protected String |
evaluateFileExpression() |
Processor |
getCustomProcessor() |
protected boolean |
ignoreCannotRetrieveFile(String name,
Exchange exchange,
Exception cause)
Whether to ignore if the file cannot be retrieved.
|
boolean |
isEagerLimitMaxMessagesPerPoll() |
protected boolean |
isInProgress(GenericFile<T> file)
Deprecated.
no longer in use, use
GenericFileEndpoint.getInProgressRepository() instead. |
protected boolean |
isMatched(GenericFile<T> file,
boolean isDirectory,
List<T> files)
Strategy to perform file matching based on endpoint configuration.
|
protected abstract boolean |
isMatched(GenericFile<T> file,
String doneFileName,
List<T> files)
Strategy to perform file matching based on endpoint configuration in terms of done file name.
|
protected boolean |
isRetrieveFile()
Override if required.
|
protected boolean |
isValidFile(GenericFile<T> file,
boolean isDirectory,
List<T> files)
Strategy for validating if the given remote file should be included or not
|
void |
onInit()
Callback invoked when the consumer is initialized such as when the
PollingConsumer starts. |
int |
poll()
Poll for files
|
protected abstract boolean |
pollDirectory(String fileName,
List<GenericFile<T>> fileList,
int depth)
Polls the given directory for files to process
|
protected void |
postPollCheck(int polledMessages)
Override if required.
|
protected boolean |
prePollCheck()
Override if required.
|
int |
processBatch(Queue<Object> exchanges)
Processes the list of
Exchange objects in a batch. |
protected boolean |
processExchange(Exchange exchange)
Processes the exchange
|
protected void |
removeExcessiveInProgressFiles(Deque<Exchange> exchanges,
int limit)
Drain any in progress files as we are done with this batch
|
protected void |
removeExcessiveInProgressFiles(List<GenericFile<T>> files)
Drain any in progress files as we are done with the files
|
void |
setCustomProcessor(Processor processor)
Use a custom processor to process the exchange.
|
void |
setEagerLimitMaxMessagesPerPoll(boolean eagerLimitMaxMessagesPerPoll) |
void |
setOperations(GenericFileOperations<T> operations)
Sets the operations to be used.
|
protected abstract void |
updateFileHeaders(GenericFile<T> file,
Message message)
Updates the information on
Message after we have acquired read-lock and
can begin process the file. |
deferShutdown, getMaxMessagesPerPoll, getPendingExchangesSize, isBatchAllowed, prepareShutdown, processEmptyMessage, setMaxMessagesPerPoll
doShutdown, doSuspend, getBackoffCounter, getBackoffErrorThreshold, getBackoffIdleThreshold, getBackoffMultiplier, getDelay, getInitialDelay, getPollStrategy, getRunLoggingLevel, getScheduledExecutorService, getScheduler, getSchedulerProperties, getTimeUnit, isGreedy, isPollAllowed, isPolling, isSchedulerStarted, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, run, setBackoffErrorThreshold, setBackoffIdleThreshold, setBackoffMultiplier, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRunLoggingLevel, setScheduledExecutorService, setScheduler, setSchedulerProperties, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay, startScheduler
createUoW, doneUoW, getAsyncProcessor, getEndpoint, getExceptionHandler, getProcessor, getRoute, handleException, handleException, setExceptionHandler, setRoute, toString
doResume, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getEndpoint
protected final org.slf4j.Logger log
protected GenericFileEndpoint<T> endpoint
protected GenericFileOperations<T> operations
protected GenericFileProcessStrategy<T> processStrategy
protected String fileExpressionResult
protected volatile ShutdownRunningTask shutdownRunningTask
protected volatile int pendingExchanges
protected Processor customProcessor
protected boolean eagerLimitMaxMessagesPerPoll
protected volatile boolean prepareOnStartup
public GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations, GenericFileProcessStrategy<T> processStrategy)
public Processor getCustomProcessor()
public void setCustomProcessor(Processor processor)
processor
- a custom processorpublic boolean isEagerLimitMaxMessagesPerPoll()
public void setEagerLimitMaxMessagesPerPoll(boolean eagerLimitMaxMessagesPerPoll)
public int poll() throws Exception
poll
in class ScheduledPollConsumer
Exception
- can be thrown if an exception occurred during pollingpublic int processBatch(Queue<Object> exchanges)
BatchConsumer
Exchange
objects in a batch.
Each message exchange will be processed individually but the batch
consumer will add properties with the current index and total in the batch.
The items in the Queue may actually be Holder objects that store other
data alongside the Exchange.exchanges
- list of items in this batchprotected void removeExcessiveInProgressFiles(Deque<Exchange> exchanges, int limit)
exchanges
- the exchangeslimit
- the limitprotected void removeExcessiveInProgressFiles(List<GenericFile<T>> files)
files
- the filespublic boolean canPollMoreFiles(List<?> fileList)
fileList
- the current list of gathered filesprotected boolean prePollCheck() throws Exception
Exception
protected void postPollCheck(int polledMessages)
polledMessages
- number of polled messagesprotected abstract boolean pollDirectory(String fileName, List<GenericFile<T>> fileList, int depth)
fileName
- current directory or filefileList
- current list of files gathereddepth
- the current depth of the directory (will start from 0)public void setOperations(GenericFileOperations<T> operations)
operations
- the operationsprotected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause)
GenericFileOperationFailedException
is thrown if the file cannot be retrieved.
This method allows to suppress this and just ignore that.name
- the file nameexchange
- the exchangecause
- optional exception occurred during retrieving fileprotected boolean processExchange(Exchange exchange)
exchange
- the exchangeprotected abstract void updateFileHeaders(GenericFile<T> file, Message message)
Message
after we have acquired read-lock and
can begin process the file.file
- the filemessage
- the Camel message to update its headersprotected boolean isRetrieveFile()
protected boolean customProcessExchange(Exchange exchange, Processor processor)
exchange
- the exchangeprocessor
- the custom processorprotected boolean isValidFile(GenericFile<T> file, boolean isDirectory, List<T> files)
file
- the fileisDirectory
- whether the file is a directory or a filefiles
- files in the directoryprotected boolean isMatched(GenericFile<T> file, boolean isDirectory, List<T> files)
file
- the fileisDirectory
- whether the file is a directory or a filefiles
- files in the directoryprotected abstract boolean isMatched(GenericFile<T> file, String doneFileName, List<T> files)
file
- the filedoneFileName
- the done file name (without any paths)files
- files in the directory@Deprecated protected boolean isInProgress(GenericFile<T> file)
GenericFileEndpoint.getInProgressRepository()
instead.file
- the fileprotected String evaluateFileExpression()
protected void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.doStart
in class ScheduledPollConsumer
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
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.doStop
in class ScheduledPollConsumer
Exception
ServiceSupport.doStart()
public void onInit() throws Exception
PollingConsumerPollingStrategy
PollingConsumer
starts.onInit
in interface PollingConsumerPollingStrategy
onInit
in class ScheduledPollConsumer
Exception
- can be thrown if error initializing.public long beforePoll(long timeout) throws Exception
PollingConsumerPollingStrategy
beforePoll
in interface PollingConsumerPollingStrategy
beforePoll
in class ScheduledPollConsumer
timeout
- the timeoutException
- can be thrown if error occurredpublic void afterPoll() throws Exception
PollingConsumerPollingStrategy
afterPoll
in interface PollingConsumerPollingStrategy
afterPoll
in class ScheduledPollConsumer
Exception
- can be thrown if error occurredApache Camel