001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.component.file;
018
019import java.util.ArrayList;
020import java.util.Collections;
021import java.util.Deque;
022import java.util.LinkedList;
023import java.util.List;
024import java.util.Queue;
025import java.util.regex.Pattern;
026
027import org.apache.camel.Exchange;
028import org.apache.camel.Message;
029import org.apache.camel.Processor;
030import org.apache.camel.ShutdownRunningTask;
031import org.apache.camel.impl.ScheduledBatchPollingConsumer;
032import org.apache.camel.support.EmptyAsyncCallback;
033import org.apache.camel.util.CastUtils;
034import org.apache.camel.util.ObjectHelper;
035import org.apache.camel.util.StopWatch;
036import org.apache.camel.util.StringHelper;
037import org.apache.camel.util.TimeUtils;
038import org.slf4j.Logger;
039import org.slf4j.LoggerFactory;
040
041/**
042 * Base class for file consumers.
043 */
044public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsumer {
045    protected final Logger log = LoggerFactory.getLogger(getClass());
046    protected GenericFileEndpoint<T> endpoint;
047    protected GenericFileOperations<T> operations;
048    protected String fileExpressionResult;
049    protected volatile ShutdownRunningTask shutdownRunningTask;
050    protected volatile int pendingExchanges;
051    protected Processor customProcessor;
052    protected boolean eagerLimitMaxMessagesPerPoll = true;
053    protected volatile boolean prepareOnStartup;
054    private final Pattern includePattern;
055    private final Pattern excludePattern;
056
057    public GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations) {
058        super(endpoint, processor);
059        this.endpoint = endpoint;
060        this.operations = operations;
061
062        this.includePattern = endpoint.getIncludePattern();
063        this.excludePattern = endpoint.getExcludePattern();
064    }
065
066    public Processor getCustomProcessor() {
067        return customProcessor;
068    }
069
070    /**
071     * Use a custom processor to process the exchange.
072     * <p/>
073     * Only set this if you need to do custom processing, instead of the regular processing.
074     * <p/>
075     * This is for example used to browse file endpoints by leveraging the file consumer to poll
076     * the directory to gather the list of exchanges. But to avoid processing the files regularly
077     * we can use a custom processor.
078     *
079     * @param processor a custom processor
080     */
081    public void setCustomProcessor(Processor processor) {
082        this.customProcessor = processor;
083    }
084
085    public boolean isEagerLimitMaxMessagesPerPoll() {
086        return eagerLimitMaxMessagesPerPoll;
087    }
088
089    public void setEagerLimitMaxMessagesPerPoll(boolean eagerLimitMaxMessagesPerPoll) {
090        this.eagerLimitMaxMessagesPerPoll = eagerLimitMaxMessagesPerPoll;
091    }
092
093    /**
094     * Poll for files
095     */
096    public int poll() throws Exception {
097        // must prepare on startup the very first time
098        if (!prepareOnStartup) {
099            // prepare on startup
100            endpoint.getGenericFileProcessStrategy().prepareOnStartup(operations, endpoint);
101            prepareOnStartup = true;
102        }
103
104        // must reset for each poll
105        fileExpressionResult = null;
106        shutdownRunningTask = null;
107        pendingExchanges = 0;
108
109        // before we poll is there anything we need to check?
110        // such as are we connected to the FTP Server still?
111        if (!prePollCheck()) {
112            log.debug("Skipping poll as pre poll check returned false");
113            return 0;
114        }
115
116        // gather list of files to process
117        List<GenericFile<T>> files = new ArrayList<GenericFile<T>>();
118        String name = endpoint.getConfiguration().getDirectory();
119
120        // time how long it takes to poll
121        StopWatch stop = new StopWatch();
122        boolean limitHit;
123        try {
124            limitHit = !pollDirectory(name, files, 0);
125        } catch (Exception e) {
126            // during poll directory we add files to the in progress repository, in case of any exception thrown after this work
127            // we must then drain the in progress files before rethrowing the exception
128            log.debug("Error occurred during poll directory: {} due {}. Removing {} files marked as in-progress.", name, e.getMessage(), files.size());
129            removeExcessiveInProgressFiles(files);
130            throw e;
131        }
132
133        long delta = stop.taken();
134        if (log.isDebugEnabled()) {
135            log.debug("Took {} to poll: {}", TimeUtils.printDuration(delta), name);
136        }
137
138        // log if we hit the limit
139        if (limitHit) {
140            log.debug("Limiting maximum messages to poll at {} files as there were more messages in this poll.", maxMessagesPerPoll);
141        }
142
143        // sort files using file comparator if provided
144        if (endpoint.getSorter() != null) {
145            files.sort(endpoint.getSorter());
146        }
147
148        // sort using build in sorters so we can use expressions
149        // use a linked list so we can dequeue the exchanges
150        LinkedList<Exchange> exchanges = new LinkedList<Exchange>();
151        for (GenericFile<T> file : files) {
152            Exchange exchange = endpoint.createExchange(file);
153            endpoint.configureExchange(exchange);
154            endpoint.configureMessage(file, exchange.getIn());
155            exchanges.add(exchange);
156        }
157        // sort files using exchange comparator if provided
158        if (endpoint.getSortBy() != null) {
159            exchanges.sort(endpoint.getSortBy());
160        }
161        if (endpoint.isShuffle()) {
162            Collections.shuffle(exchanges);
163        }
164
165        // use a queue for the exchanges
166        Deque<Exchange> q = exchanges;
167
168        // we are not eager limiting, but we have configured a limit, so cut the list of files
169        if (!eagerLimitMaxMessagesPerPoll && maxMessagesPerPoll > 0) {
170            if (files.size() > maxMessagesPerPoll) {
171                log.debug("Limiting maximum messages to poll at {} files as there were more messages in this poll.", maxMessagesPerPoll);
172                // must first remove excessive files from the in progress repository
173                removeExcessiveInProgressFiles(q, maxMessagesPerPoll);
174            }
175        }
176
177        // consume files one by one
178        int total = exchanges.size();
179        if (total > 0) {
180            log.debug("Total {} files to consume", total);
181        }
182
183        int polledMessages = processBatch(CastUtils.cast(q));
184
185        postPollCheck(polledMessages);
186
187        return polledMessages;
188    }
189
190    public int processBatch(Queue<Object> exchanges) {
191        int total = exchanges.size();
192        int answer = total;
193
194        // limit if needed
195        if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) {
196            log.debug("Limiting to maximum messages to poll {} as there were {} messages in this poll.", maxMessagesPerPoll, total);
197            total = maxMessagesPerPoll;
198        }
199
200        for (int index = 0; index < total && isBatchAllowed(); index++) {
201            // only loop if we are started (allowed to run)
202            // use poll to remove the head so it does not consume memory even after we have processed it
203            Exchange exchange = (Exchange) exchanges.poll();
204            // add current index and total as properties
205            exchange.setProperty(Exchange.BATCH_INDEX, index);
206            exchange.setProperty(Exchange.BATCH_SIZE, total);
207            exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
208
209            // update pending number of exchanges
210            pendingExchanges = total - index - 1;
211
212            // process the current exchange
213            boolean started;
214            if (customProcessor != null) {
215                // use a custom processor
216                started = customProcessExchange(exchange, customProcessor);
217            } else {
218                // process the exchange regular
219                started = processExchange(exchange);
220            }
221
222            // if we did not start process the file then decrement the counter
223            if (!started) {
224                answer--;
225            }
226        }
227
228        // drain any in progress files as we are done with this batch
229        removeExcessiveInProgressFiles(CastUtils.cast((Deque<?>) exchanges, Exchange.class), 0);
230
231        return answer;
232    }
233
234    /**
235     * Drain any in progress files as we are done with this batch
236     *
237     * @param exchanges  the exchanges
238     * @param limit      the limit
239     */
240    protected void removeExcessiveInProgressFiles(Deque<Exchange> exchanges, int limit) {
241        // remove the file from the in progress list in case the batch was limited by max messages per poll
242        while (exchanges.size() > limit) {
243            // must remove last
244            Exchange exchange = exchanges.removeLast();
245            GenericFile<?> file = exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE, GenericFile.class);
246            String key = file.getAbsoluteFilePath();
247            endpoint.getInProgressRepository().remove(key);
248        }
249    }
250
251    /**
252     * Drain any in progress files as we are done with the files
253     *
254     * @param files  the files
255     */
256    protected void removeExcessiveInProgressFiles(List<GenericFile<T>> files) {
257        for (GenericFile file : files) {
258            String key = file.getAbsoluteFilePath();
259            endpoint.getInProgressRepository().remove(key);
260        }
261    }
262
263    /**
264     * Whether or not we can continue polling for more files
265     *
266     * @param fileList  the current list of gathered files
267     * @return <tt>true</tt> to continue, <tt>false</tt> to stop due hitting maxMessagesPerPoll limit
268     */
269    public boolean canPollMoreFiles(List<?> fileList) {
270        // at this point we should not limit if we are not eager
271        if (!eagerLimitMaxMessagesPerPoll) {
272            return true;
273        }
274
275        if (maxMessagesPerPoll <= 0) {
276            // no limitation
277            return true;
278        }
279
280        // then only poll if we haven't reached the max limit
281        return fileList.size() < maxMessagesPerPoll;
282    }
283
284    /**
285     * Override if required. Perform some checks (and perhaps actions) before we poll.
286     *
287     * @return <tt>true</tt> to poll, <tt>false</tt> to skip this poll.
288     */
289    protected boolean prePollCheck() throws Exception {
290        return true;
291    }
292
293    /**
294     * Override if required. Perform some checks (and perhaps actions) after we have polled.
295     *
296     * @param polledMessages number of polled messages
297     */
298    protected void postPollCheck(int polledMessages) {
299        // noop
300    }
301
302    /**
303     * Polls the given directory for files to process
304     *
305     * @param fileName current directory or file
306     * @param fileList current list of files gathered
307     * @param depth the current depth of the directory (will start from 0)
308     * @return whether or not to continue polling, <tt>false</tt> means the maxMessagesPerPoll limit has been hit
309     */
310    protected abstract boolean pollDirectory(String fileName, List<GenericFile<T>> fileList, int depth);
311
312    /**
313     * Sets the operations to be used.
314     * <p/>
315     * Can be used to set a fresh operations in case of recovery attempts
316     *
317     * @param operations the operations
318     */
319    public void setOperations(GenericFileOperations<T> operations) {
320        this.operations = operations;
321    }
322
323    /**
324     * Whether to ignore if the file cannot be retrieved.
325     * <p/>
326     * By default an {@link GenericFileOperationFailedException} is thrown if the file cannot be retrieved.
327     * <p/>
328     * This method allows to suppress this and just ignore that.
329     *
330     * @param name        the file name
331     * @param exchange    the exchange
332     * @param cause       optional exception occurred during retrieving file
333     * @return <tt>true</tt> to ignore, <tt>false</tt> is the default.
334     */
335    protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause) {
336        return false;
337    }
338
339    /**
340     * Processes the exchange
341     *
342     * @param exchange the exchange
343     * @return <tt>true</tt> if the file was started to be processed, <tt>false</tt> if the file was not started
344     * to be processed, for some reason (not found, or aborted etc)
345     */
346    protected boolean processExchange(final Exchange exchange) {
347        GenericFile<T> file = getExchangeFileProperty(exchange);
348        log.trace("Processing file: {}", file);
349
350        // must extract the absolute name before the begin strategy as the file could potentially be pre moved
351        // and then the file name would be changed
352        String absoluteFileName = file.getAbsoluteFilePath();
353
354        // check if we can begin processing the file
355        final GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
356
357        Exception beginCause = null;
358        boolean begin = false;
359        try {
360            begin = processStrategy.begin(operations, endpoint, exchange, file);
361        } catch (Exception e) {
362            beginCause = e;
363        }
364
365        if (!begin) {
366            // no something was wrong, so we need to abort and remove the file from the in progress list
367            Exception abortCause = null;
368            log.debug("{} cannot begin processing file: {}", endpoint, file);
369            try {
370                // abort
371                processStrategy.abort(operations, endpoint, exchange, file);
372            } catch (Exception e) {
373                abortCause = e;
374            } finally {
375                // begin returned false, so remove file from the in progress list as its no longer in progress
376                endpoint.getInProgressRepository().remove(absoluteFileName);
377            }
378            if (beginCause != null) {
379                String msg = endpoint + " cannot begin processing file: " + file + " due to: " + beginCause.getMessage();
380                handleException(msg, beginCause);
381            }
382            if (abortCause != null) {
383                String msg2 = endpoint + " cannot abort processing file: " + file + " due to: " + abortCause.getMessage();
384                handleException(msg2, abortCause);
385            }
386            return false;
387        }
388
389        // must use file from exchange as it can be updated due the
390        // preMoveNamePrefix/preMoveNamePostfix options
391        final GenericFile<T> target = getExchangeFileProperty(exchange);
392
393        // we can begin processing the file so update file headers on the Camel message
394        // in case it took some time to acquire read lock, and file size/timestamp has been updated since etc
395        updateFileHeaders(target, exchange.getIn());
396
397        // must use full name when downloading so we have the correct path
398        final String name = target.getAbsoluteFilePath();
399        try {
400            
401            if (isRetrieveFile()) {
402                // retrieve the file using the stream
403                log.trace("Retrieving file: {} from: {}", name, endpoint);
404    
405                // retrieve the file and check it was a success
406                boolean retrieved;
407                Exception cause = null;
408                try {
409                    retrieved = operations.retrieveFile(name, exchange, target.getFileLength());
410                } catch (Exception e) {
411                    retrieved = false;
412                    cause = e;
413                }
414
415                if (!retrieved) {
416                    if (ignoreCannotRetrieveFile(name, exchange, cause)) {
417                        log.trace("Cannot retrieve file {} maybe it does not exists. Ignoring.", name);
418                        // remove file from the in progress list as we could not retrieve it, but should ignore
419                        endpoint.getInProgressRepository().remove(absoluteFileName);
420                        return false;
421                    } else {
422                        // throw exception to handle the problem with retrieving the file
423                        // then if the method return false or throws an exception is handled the same in here
424                        // as in both cases an exception is being thrown
425                        if (cause instanceof GenericFileOperationFailedException) {
426                            throw cause;
427                        } else {
428                            throw new GenericFileOperationFailedException("Cannot retrieve file: " + file + " from: " + endpoint, cause);
429                        }
430                    }
431                }
432    
433                log.trace("Retrieved file: {} from: {}", name, endpoint);                
434            } else {
435                log.trace("Skipped retrieval of file: {} from: {}", name, endpoint);
436                exchange.getIn().setBody(null);
437            }
438
439            // register on completion callback that does the completion strategies
440            // (for instance to move the file after we have processed it)
441            exchange.addOnCompletion(new GenericFileOnCompletion<T>(endpoint, operations, target, absoluteFileName));
442
443            log.debug("About to process file: {} using exchange: {}", target, exchange);
444
445            if (endpoint.isSynchronous()) {
446                // process synchronously
447                getProcessor().process(exchange);
448            } else {
449                // process the exchange using the async consumer to support async routing engine
450                // which can be supported by this file consumer as all the done work is
451                // provided in the GenericFileOnCompletion
452                getAsyncProcessor().process(exchange, EmptyAsyncCallback.get());
453            }
454
455        } catch (Exception e) {
456            // remove file from the in progress list due to failure
457            // (cannot be in finally block due to GenericFileOnCompletion will remove it
458            // from in progress when it takes over and processes the file, which may happen
459            // by another thread at a later time. So its only safe to remove it if there was an exception)
460            endpoint.getInProgressRepository().remove(absoluteFileName);
461
462            String msg = "Error processing file " + file + " due to " + e.getMessage();
463            handleException(msg, e);
464        }
465
466        return true;
467    }
468
469    /**
470     * Updates the information on {@link Message} after we have acquired read-lock and
471     * can begin process the file.
472     *
473     * @param file    the file
474     * @param message the Camel message to update its headers
475     */
476    protected abstract void updateFileHeaders(GenericFile<T> file, Message message);
477
478    /**
479     * Override if required.  Files are retrieved / returns true by default
480     *
481     * @return <tt>true</tt> to retrieve files, <tt>false</tt> to skip retrieval of files.
482     */
483    protected boolean isRetrieveFile() {
484        return true;
485    }
486
487    /**
488     * Processes the exchange using a custom processor.
489     *
490     * @param exchange the exchange
491     * @param processor the custom processor
492     */
493    protected boolean customProcessExchange(final Exchange exchange, final Processor processor) {
494        GenericFile<T> file = getExchangeFileProperty(exchange);
495        log.trace("Custom processing file: {}", file);
496
497        // must extract the absolute name before the begin strategy as the file could potentially be pre moved
498        // and then the file name would be changed
499        String absoluteFileName = file.getAbsoluteFilePath();
500
501        try {
502            // process using the custom processor
503            processor.process(exchange);
504        } catch (Exception e) {
505            if (log.isDebugEnabled()) {
506                log.debug(endpoint + " error custom processing: " + file + " due to: " + e.getMessage() + ". This exception will be ignored.", e);
507            }
508            handleException(e);
509        } finally {
510            // always remove file from the in progress list as its no longer in progress
511            // use the original file name that was used to add it to the repository
512            // as the name can be different when using preMove option
513            endpoint.getInProgressRepository().remove(absoluteFileName);
514        }
515
516        return true;
517    }
518
519    /**
520     * Strategy for validating if the given remote file should be included or not
521     *
522     * @param file        the file
523     * @param isDirectory whether the file is a directory or a file
524     * @param files       files in the directory
525     * @return <tt>true</tt> to include the file, <tt>false</tt> to skip it
526     */
527    protected boolean isValidFile(GenericFile<T> file, boolean isDirectory, List<T> files) {
528        String absoluteFilePath = file.getAbsoluteFilePath();
529
530        if (!isMatched(file, isDirectory, files)) {
531            log.trace("File did not match. Will skip this file: {}", file);
532            return false;
533        }
534
535        // directory is always valid
536        if (isDirectory) {
537            return true;
538        }
539
540        // check if file is already in progress
541        if (endpoint.getInProgressRepository().contains(absoluteFilePath)) {
542            if (log.isTraceEnabled()) {
543                log.trace("Skipping as file is already in progress: {}", file.getFileName());
544            }
545            return false;
546        }
547
548        // if its a file then check we have the file in the idempotent registry already
549        if (endpoint.isIdempotent()) {
550            // use absolute file path as default key, but evaluate if an expression key was configured
551            String key = file.getAbsoluteFilePath();
552            if (endpoint.getIdempotentKey() != null) {
553                Exchange dummy = endpoint.createExchange(file);
554                key = endpoint.getIdempotentKey().evaluate(dummy, String.class);
555            }
556            if (key != null && endpoint.getIdempotentRepository().contains(key)) {
557                log.trace("This consumer is idempotent and the file has been consumed before matching idempotentKey: {}. Will skip this file: {}", key, file);
558                return false;
559            }
560        }
561
562        // okay so final step is to be able to add atomic as in-progress, so we are the
563        // only thread processing this file
564        return endpoint.getInProgressRepository().add(absoluteFilePath);
565    }
566
567    /**
568     * Strategy to perform file matching based on endpoint configuration.
569     * <p/>
570     * Will always return <tt>false</tt> for certain files/folders:
571     * <ul>
572     * <li>Starting with a dot</li>
573     * <li>lock files</li>
574     * </ul>
575     * And then <tt>true</tt> for directories.
576     *
577     * @param file        the file
578     * @param isDirectory whether the file is a directory or a file
579     * @param files       files in the directory
580     * @return <tt>true</tt> if the file is matched, <tt>false</tt> if not
581     */
582    protected boolean isMatched(GenericFile<T> file, boolean isDirectory, List<T> files) {
583        String name = file.getFileNameOnly();
584
585        // folders/names starting with dot is always skipped (eg. ".", ".camel", ".camelLock")
586        if (name.startsWith(".")) {
587            return false;
588        }
589
590        // lock files should be skipped
591        if (name.endsWith(FileComponent.DEFAULT_LOCK_FILE_POSTFIX)) {
592            return false;
593        }
594
595        if (endpoint.getFilter() != null) {
596            if (!endpoint.getFilter().accept(file)) {
597                return false;
598            }
599        }
600
601        if (endpoint.getAntFilter() != null) {
602            if (!endpoint.getAntFilter().accept(file)) {
603                return false;
604            }
605        }
606
607        if (isDirectory && endpoint.getFilterDirectory() != null) {
608            // create a dummy exchange as Exchange is needed for expression evaluation
609            Exchange dummy = endpoint.createExchange(file);
610            boolean matches = endpoint.getFilterDirectory().matches(dummy);
611            if (!matches) {
612                return false;
613            }
614        }
615
616        // directories are regarded as matched if filter accepted them
617        if (isDirectory) {
618            return true;
619        }
620
621        // exclude take precedence over include
622        if (excludePattern != null)  {
623            if (excludePattern.matcher(name).matches()) {
624                return false;
625            }
626        }
627        if (includePattern != null)  {
628            if (!includePattern.matcher(name).matches()) {
629                return false;
630            }
631        }
632
633        // use file expression for a simple dynamic file filter
634        if (endpoint.getFileName() != null) {
635            fileExpressionResult = evaluateFileExpression();
636            if (fileExpressionResult != null) {
637                if (!name.equals(fileExpressionResult)) {
638                    return false;
639                }
640            }
641        }
642
643        if (endpoint.getFilterFile() != null) {
644            // create a dummy exchange as Exchange is needed for expression evaluation
645            Exchange dummy = endpoint.createExchange(file);
646            boolean matches = endpoint.getFilterFile().matches(dummy);
647            if (!matches) {
648                return false;
649            }
650        }
651
652        // if done file name is enabled, then the file is only valid if a done file exists
653        if (endpoint.getDoneFileName() != null) {
654            // done file must be in same path as the file
655            String doneFileName = endpoint.createDoneFileName(file.getAbsoluteFilePath());
656            StringHelper.notEmpty(doneFileName, "doneFileName", endpoint);
657
658            // is it a done file name?
659            if (endpoint.isDoneFile(file.getFileNameOnly())) {
660                log.trace("Skipping done file: {}", file);
661                return false;
662            }
663
664            if (!isMatched(file, doneFileName, files)) {
665                return false;
666            }
667        }
668
669        return true;
670    }
671
672    /**
673     * Strategy to perform file matching based on endpoint configuration in terms of done file name.
674     *
675     * @param file         the file
676     * @param doneFileName the done file name (without any paths)
677     * @param files        files in the directory
678     * @return <tt>true</tt> if the file is matched, <tt>false</tt> if not
679     */
680    protected abstract boolean isMatched(GenericFile<T> file, String doneFileName, List<T> files);
681
682    /**
683     * Is the given file already in progress.
684     *
685     * @param file the file
686     * @return <tt>true</tt> if the file is already in progress
687     * @deprecated no longer in use, use {@link org.apache.camel.component.file.GenericFileEndpoint#getInProgressRepository()} instead.
688     */
689    @Deprecated
690    protected boolean isInProgress(GenericFile<T> file) {
691        String key = file.getAbsoluteFilePath();
692        // must use add, to have operation as atomic
693        return !endpoint.getInProgressRepository().add(key);
694    }
695
696    protected String evaluateFileExpression() {
697        if (fileExpressionResult == null && endpoint.getFileName() != null) {
698            // create a dummy exchange as Exchange is needed for expression evaluation
699            Exchange dummy = endpoint.createExchange();
700            fileExpressionResult = endpoint.getFileName().evaluate(dummy, String.class);
701            if (dummy.getException() != null) {
702                throw ObjectHelper.wrapRuntimeCamelException(dummy.getException());
703            }
704        }
705        return fileExpressionResult;
706    }
707
708    @SuppressWarnings("unchecked")
709    private GenericFile<T> getExchangeFileProperty(Exchange exchange) {
710        return (GenericFile<T>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
711    }
712
713    @Override
714    protected void doStart() throws Exception {
715        super.doStart();
716    }
717
718    @Override
719    protected void doStop() throws Exception {
720        prepareOnStartup = false;
721        super.doStop();
722    }
723
724    @Override
725    public void onInit() throws Exception {
726        // noop as we do a manual on-demand poll with GenericFilePolllingConsumer
727    }
728
729    @Override
730    public long beforePoll(long timeout) throws Exception {
731        // noop as we do a manual on-demand poll with GenericFilePolllingConsumer
732        return timeout;
733    }
734
735    @Override
736    public void afterPoll() throws Exception {
737        // noop as we do a manual on-demand poll with GenericFilePolllingConsumer
738    }
739
740}