Package org.apache.camel.component.file
Class GenericFileConsumer<T>
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultConsumer
org.apache.camel.support.ScheduledPollConsumer
org.apache.camel.support.ScheduledBatchPollingConsumer
org.apache.camel.component.file.GenericFileConsumer<T>
- All Implemented Interfaces:
AutoCloseable,Runnable,org.apache.camel.BatchConsumer,org.apache.camel.Consumer,org.apache.camel.EndpointAware,org.apache.camel.health.HealthCheckAware,org.apache.camel.PollingConsumerPollingStrategy,org.apache.camel.RouteAware,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.HostedService,org.apache.camel.spi.RouteIdAware,org.apache.camel.spi.ShutdownAware,org.apache.camel.spi.ShutdownPrepared,org.apache.camel.StatefulService,org.apache.camel.Suspendable,org.apache.camel.SuspendableService
- Direct Known Subclasses:
FileConsumer
public abstract class GenericFileConsumer<T>
extends org.apache.camel.support.ScheduledBatchPollingConsumer
Base class for file consumers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.camel.Processorprotected booleanprotected GenericFileEndpoint<T> protected GenericFileOperations<T> protected intprotected booleanprotected GenericFileProcessStrategy<T> protected org.apache.camel.ShutdownRunningTaskFields inherited from class org.apache.camel.support.ScheduledBatchPollingConsumer
maxMessagesPerPollFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGenericFileConsumer(GenericFileEndpoint<T> endpoint, org.apache.camel.Processor processor, GenericFileOperations<T> operations, GenericFileProcessStrategy<T> processStrategy) -
Method Summary
Modifier and TypeMethodDescriptionvoidlongbeforePoll(long timeout) booleancanPollMoreFiles(List<?> fileList) Whether or not we can continue polling for more filesprotected abstract org.apache.camel.ExchangecreateExchange(GenericFile<T> file) Creates the exchange from the polled fileprotected booleancustomProcessExchange(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor) Processes the exchange using a custom processor.protected voiddoInit()protected voiddoStart()protected voiddoStop()protected StringevaluateFileExpression(org.apache.camel.Exchange exchange) org.apache.camel.ProcessorgetRelativeFilePath(String endpointPath, String path, String absolutePath, T file) Geta the relative path from the given file, calculated from the starting path, current path, and current absolute pathprotected booleanhasExtExlusions(String fname) protected booleanhasExtInclusions(String fname) protected booleanignoreCannotRetrieveFile(String name, org.apache.camel.Exchange exchange, Exception cause) Whether to ignore if the file cannot be retrieved.booleanprotected abstract booleanStrategy to perform file matching based on endpoint configuration in terms of done file name.protected booleanisMatched(org.apache.camel.Exchange dynamic, Supplier<GenericFile<T>> file, String name, String absoluteFilePath, Supplier<String> relativeFilePath, boolean isDirectory, T[] files) Strategy to perform file matching based on endpoint configuration.protected booleanisMatchedHiddenFile(Supplier<GenericFile<T>> file, String name, boolean isDirectory) Strategy to perform hidden file matching based on endpoint configuration.booleanWhether the consumer should retrieve/download files.protected booleanisValidFile(org.apache.camel.Exchange dynamic, Supplier<GenericFile<T>> file, String name, String absoluteFilePath, Supplier<String> relativeFilePath, boolean isDirectory, T[] files) Strategy for validating if the given remote file should be included or notvoidonInit()protected intpoll()protected intpoll(org.apache.camel.Exchange dynamic) Poll for filesprotected abstract booleanpollDirectory(org.apache.camel.Exchange dynamic, String fileName, List<GenericFile<T>> fileList, int depth) Polls the given directory for files to processprotected voidpostPollCheck(int polledMessages) Override if required.protected booleanOverride if required.intprocessBatch(Queue<Object> exchanges) protected booleanprocessExchange(org.apache.camel.Exchange exchange) Processes the exchangeprotected voidremoveExcessiveInProgressFiles(Deque<org.apache.camel.Exchange> exchanges, int limit) Drain any in progress files as we are done with this batchprotected voidremoveExcessiveInProgressFiles(List<GenericFile<T>> files) Drain any in progress files as we are done with the filesvoidsetCustomProcessor(org.apache.camel.Processor processor) Use a custom processor to process the exchange.voidsetEagerLimitMaxMessagesPerPoll(boolean eagerLimitMaxMessagesPerPoll) voidsetOperations(GenericFileOperations<T> operations) Sets the operations to be used.voidsetRetrieveFile(boolean retrieveFile) Whether the consumer should retrieve/download files.protected abstract voidupdateFileHeaders(GenericFile<T> file, org.apache.camel.Message message) Updates the information onMessageafter we have acquired read-lock and can begin process the file.Methods inherited from class org.apache.camel.support.ScheduledBatchPollingConsumer
deferShutdown, getMaxMessagesPerPoll, getPendingExchangesSize, isBatchAllowed, prepareShutdown, processEmptyMessage, setMaxMessagesPerPollMethods inherited from class org.apache.camel.support.ScheduledPollConsumer
addLastErrorDetail, afterConfigureScheduler, doBuild, doShutdown, doSuspend, forceConsumerAsReady, getBackoffCounter, getBackoffErrorThreshold, getBackoffIdleThreshold, getBackoffMultiplier, getCounter, getDelay, getErrorCounter, getInitialDelay, getLastError, getLastErrorDetails, getPollStrategy, getRepeatCount, getRunLoggingLevel, getScheduledExecutorService, getScheduler, getSchedulerProperties, getSuccessCounter, getTimeUnit, initialHealthCheckState, isConsumerReady, isFirstPollDone, isGreedy, isPollAllowed, isPolling, isSchedulerStarted, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, run, setBackoffErrorThreshold, setBackoffIdleThreshold, setBackoffMultiplier, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRepeatCount, setRunLoggingLevel, setScheduledExecutorService, setScheduler, setSchedulerProperties, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay, startSchedulerMethods inherited from class org.apache.camel.support.DefaultConsumer
createExchange, createUoW, defaultConsumerCallback, doneUoW, getAsyncProcessor, getEndpoint, getExceptionHandler, getHealthCheck, getProcessor, getRoute, getRouteId, handleException, handleException, handleException, isHostedService, releaseExchange, setExceptionHandler, setHealthCheck, setRoute, setRouteId, toStringMethods inherited from class org.apache.camel.support.service.BaseService
build, doFail, doLifecycleChange, doResume, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.camel.Consumer
createExchange, defaultConsumerCallback, getProcessor, releaseExchangeMethods inherited from interface org.apache.camel.EndpointAware
getEndpointMethods inherited from interface org.apache.camel.health.HealthCheckAware
getHealthCheck, setHealthCheckMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
endpoint
-
operations
-
processStrategy
-
shutdownRunningTask
protected volatile org.apache.camel.ShutdownRunningTask shutdownRunningTask -
pendingExchanges
protected volatile int pendingExchanges -
customProcessor
protected org.apache.camel.Processor customProcessor -
eagerLimitMaxMessagesPerPoll
protected boolean eagerLimitMaxMessagesPerPoll -
prepareOnStartup
protected volatile boolean prepareOnStartup
-
-
Constructor Details
-
GenericFileConsumer
protected GenericFileConsumer(GenericFileEndpoint<T> endpoint, org.apache.camel.Processor processor, GenericFileOperations<T> operations, GenericFileProcessStrategy<T> processStrategy)
-
-
Method Details
-
getCustomProcessor
public org.apache.camel.Processor getCustomProcessor() -
setCustomProcessor
public void setCustomProcessor(org.apache.camel.Processor processor) Use a custom processor to process the exchange. Only set this if you need to do custom processing, instead of the regular processing. This is for example used to browse file endpoints by leveraging the file consumer to poll the directory to gather the list of exchanges. But to avoid processing the files regularly we can use a custom processor.- Parameters:
processor- a custom processor
-
isEagerLimitMaxMessagesPerPoll
public boolean isEagerLimitMaxMessagesPerPoll() -
setEagerLimitMaxMessagesPerPoll
public void setEagerLimitMaxMessagesPerPoll(boolean eagerLimitMaxMessagesPerPoll) -
createExchange
Creates the exchange from the polled file -
poll
- Specified by:
pollin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
poll
Poll for files- Overrides:
pollin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
processBatch
-
removeExcessiveInProgressFiles
protected void removeExcessiveInProgressFiles(Deque<org.apache.camel.Exchange> exchanges, int limit) Drain any in progress files as we are done with this batch- Parameters:
exchanges- the exchangeslimit- the limit
-
removeExcessiveInProgressFiles
Drain any in progress files as we are done with the files- Parameters:
files- the files
-
canPollMoreFiles
Whether or not we can continue polling for more files- Parameters:
fileList- the current list of gathered files- Returns:
- true to continue, false to stop due hitting maxMessagesPerPoll limit
-
prePollCheck
Override if required. Perform some checks (and perhaps actions) before we poll.- Returns:
- true to poll, false to skip this poll.
- Throws:
Exception
-
postPollCheck
protected void postPollCheck(int polledMessages) Override if required. Perform some checks (and perhaps actions) after we have polled.- Parameters:
polledMessages- number of polled messages
-
pollDirectory
protected abstract boolean pollDirectory(org.apache.camel.Exchange dynamic, String fileName, List<GenericFile<T>> fileList, int depth) Polls the given directory for files to process- Parameters:
fileName- current directory or filefileList- current list of files gathereddepth- the current depth of the directory (will start from 0)- Returns:
- whether or not to continue polling, false means the maxMessagesPerPoll limit has been hit
-
setOperations
Sets the operations to be used. Can be used to set a fresh operations in case of recovery attempts- Parameters:
operations- the operations
-
ignoreCannotRetrieveFile
protected boolean ignoreCannotRetrieveFile(String name, org.apache.camel.Exchange exchange, Exception cause) Whether to ignore if the file cannot be retrieved. By default anGenericFileOperationFailedExceptionis thrown if the file cannot be retrieved. This method allows to suppress this and just ignore that.- Parameters:
name- the file nameexchange- the exchangecause- optional exception occurred during retrieving file- Returns:
- true to ignore, false is the default.
-
processExchange
protected boolean processExchange(org.apache.camel.Exchange exchange) Processes the exchange- Parameters:
exchange- the exchange- Returns:
- true if the file was started to be processed, false if the file was not started to be processed, for some reason (not found, or aborted etc)
-
updateFileHeaders
Updates the information onMessageafter we have acquired read-lock and can begin process the file.- Parameters:
file- the filemessage- the Camel message to update its headers
-
isRetrieveFile
public boolean isRetrieveFile()Whether the consumer should retrieve/download files. If false then the message body is null as no file is retrieved. -
setRetrieveFile
public void setRetrieveFile(boolean retrieveFile) Whether the consumer should retrieve/download files. If false then the message body is null as no file is retrieved. -
customProcessExchange
protected boolean customProcessExchange(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor) Processes the exchange using a custom processor.- Parameters:
exchange- the exchangeprocessor- the custom processor
-
isValidFile
protected boolean isValidFile(org.apache.camel.Exchange dynamic, Supplier<GenericFile<T>> file, String name, String absoluteFilePath, Supplier<String> relativeFilePath, boolean isDirectory, T[] files) Strategy for validating if the given remote file should be included or not- Parameters:
file- the filename- the file nameisDirectory- whether the file is a directory or a filefiles- files in the directory- Returns:
- true to include the file, false to skip it
-
isMatchedHiddenFile
protected boolean isMatchedHiddenFile(Supplier<GenericFile<T>> file, String name, boolean isDirectory) Strategy to perform hidden file matching based on endpoint configuration. Will always return false for certain files/folders:- Starting with a dot (hidden)
-
getRelativeFilePath
protected abstract Supplier<String> getRelativeFilePath(String endpointPath, String path, String absolutePath, T file) Geta the relative path from the given file, calculated from the starting path, current path, and current absolute path -
isMatched
protected boolean isMatched(org.apache.camel.Exchange dynamic, Supplier<GenericFile<T>> file, String name, String absoluteFilePath, Supplier<String> relativeFilePath, boolean isDirectory, T[] files) Strategy to perform file matching based on endpoint configuration. Will always return false for certain files/folders:- Starting with a dot
- lock files
- Parameters:
file- the filename- the file nameabsoluteFilePath- the absolute file namerelativeFilePath- the relative file nameisDirectory- whether the file is a directory or a filefiles- files in the directory- Returns:
- true if the file is matched, false if not
-
hasExtInclusions
-
hasExtExlusions
-
isMatched
Strategy to perform file matching based on endpoint configuration in terms of done file name.- Parameters:
file- the filedoneFileName- the done file name (without any paths)files- files in the directory- Returns:
- true if the file is matched, false if not
-
evaluateFileExpression
-
doInit
- Overrides:
doInitin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
doStart
- Overrides:
doStartin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
doStop
- Overrides:
doStopin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
onInit
- Specified by:
onInitin interfaceorg.apache.camel.PollingConsumerPollingStrategy- Overrides:
onInitin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
beforePoll
- Specified by:
beforePollin interfaceorg.apache.camel.PollingConsumerPollingStrategy- Overrides:
beforePollin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-
afterPoll
- Specified by:
afterPollin interfaceorg.apache.camel.PollingConsumerPollingStrategy- Overrides:
afterPollin classorg.apache.camel.support.ScheduledPollConsumer- Throws:
Exception
-