Package org.apache.camel.component.file
Class FileConsumer
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<File>
org.apache.camel.component.file.FileConsumer
- 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.resume.ResumeAware<org.apache.camel.resume.ResumeStrategy>,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
public class FileConsumer
extends GenericFileConsumer<File>
implements org.apache.camel.resume.ResumeAware<org.apache.camel.resume.ResumeStrategy>
File consumer.
-
Field Summary
Fields inherited from class org.apache.camel.component.file.GenericFileConsumer
customProcessor, eagerLimitMaxMessagesPerPoll, endpoint, operations, pendingExchanges, prepareOnStartup, processStrategy, 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
ConstructorsConstructorDescriptionFileConsumer(FileEndpoint endpoint, org.apache.camel.Processor processor, GenericFileOperations<File> operations, GenericFileProcessStrategy<File> processStrategy) -
Method Summary
Modifier and TypeMethodDescriptionstatic GenericFile<File> asGenericFile(String endpointPath, File file, String charset, boolean probeContentType) Creates a new GenericFilebased on the given file. protected org.apache.camel.ExchangecreateExchange(GenericFile<File> file) Creates the exchange from the polled fileprotected voiddoStart()getRelativeFilePath(String endpointPath, String path, String absolutePath, File file) Geta the relative path from the given file, calculated from the starting path, current path, and current absolute pathorg.apache.camel.resume.ResumeStrategyprotected booleanStrategy to perform file matching based on endpoint configuration in terms of done file name.protected booleanisMatchedHiddenFile(Supplier<GenericFile<File>> file, String name, boolean isDirectory) Strategy to perform hidden file matching based on endpoint configuration.protected booleanpollDirectory(org.apache.camel.Exchange dynamic, String fileName, List<GenericFile<File>> fileList, int depth) Polls the given directory for files to processvoidsetResumeStrategy(org.apache.camel.resume.ResumeStrategy resumeStrategy) protected voidupdateFileHeaders(GenericFile<File> 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.component.file.GenericFileConsumer
afterPoll, beforePoll, canPollMoreFiles, customProcessExchange, doInit, doStop, evaluateFileExpression, getCustomProcessor, hasExtExlusions, hasExtInclusions, ignoreCannotRetrieveFile, isEagerLimitMaxMessagesPerPoll, isMatched, isRetrieveFile, isValidFile, onInit, poll, poll, postPollCheck, prePollCheck, processBatch, processExchange, removeExcessiveInProgressFiles, removeExcessiveInProgressFiles, setCustomProcessor, setEagerLimitMaxMessagesPerPoll, setOperations, setRetrieveFileMethods 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, 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.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
-
Constructor Details
-
FileConsumer
public FileConsumer(FileEndpoint endpoint, org.apache.camel.Processor processor, GenericFileOperations<File> operations, GenericFileProcessStrategy<File> processStrategy)
-
-
Method Details
-
createExchange
Description copied from class:GenericFileConsumerCreates the exchange from the polled file- Specified by:
createExchangein classGenericFileConsumer<File>
-
pollDirectory
protected boolean pollDirectory(org.apache.camel.Exchange dynamic, String fileName, List<GenericFile<File>> fileList, int depth) Description copied from class:GenericFileConsumerPolls the given directory for files to process- Specified by:
pollDirectoryin classGenericFileConsumer<File>- 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
-
isMatched
Description copied from class:GenericFileConsumerStrategy to perform file matching based on endpoint configuration in terms of done file name.- Specified by:
isMatchedin classGenericFileConsumer<File>- 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
-
asGenericFile
public static GenericFile<File> asGenericFile(String endpointPath, File file, String charset, boolean probeContentType) Creates a new GenericFilebased on the given file. - Parameters:
endpointPath- the starting directory the endpoint was configured withfile- the source fileprobeContentType- whether to probe the content type of the file or not- Returns:
- wrapped as a GenericFile
-
getRelativeFilePath
protected Supplier<String> getRelativeFilePath(String endpointPath, String path, String absolutePath, File file) Description copied from class:GenericFileConsumerGeta the relative path from the given file, calculated from the starting path, current path, and current absolute path- Specified by:
getRelativeFilePathin classGenericFileConsumer<File>
-
updateFileHeaders
Description copied from class:GenericFileConsumerUpdates the information onMessageafter we have acquired read-lock and can begin process the file.- Specified by:
updateFileHeadersin classGenericFileConsumer<File>- Parameters:
file- the filemessage- the Camel message to update its headers
-
getEndpoint
- Specified by:
getEndpointin interfaceorg.apache.camel.EndpointAware- Overrides:
getEndpointin classorg.apache.camel.support.DefaultConsumer
-
isMatchedHiddenFile
protected boolean isMatchedHiddenFile(Supplier<GenericFile<File>> file, String name, boolean isDirectory) Description copied from class:GenericFileConsumerStrategy to perform hidden file matching based on endpoint configuration. Will always return false for certain files/folders:- Starting with a dot (hidden)
- Overrides:
isMatchedHiddenFilein classGenericFileConsumer<File>
-
doStart
- Overrides:
doStartin classGenericFileConsumer<File>- Throws:
Exception
-
getResumeStrategy
public org.apache.camel.resume.ResumeStrategy getResumeStrategy()- Specified by:
getResumeStrategyin interfaceorg.apache.camel.resume.ResumeAware<org.apache.camel.resume.ResumeStrategy>
-
setResumeStrategy
public void setResumeStrategy(org.apache.camel.resume.ResumeStrategy resumeStrategy) - Specified by:
setResumeStrategyin interfaceorg.apache.camel.resume.ResumeAware<org.apache.camel.resume.ResumeStrategy>
-
adapterFactoryService
- Specified by:
adapterFactoryServicein interfaceorg.apache.camel.resume.ResumeAware<org.apache.camel.resume.ResumeStrategy>
-