You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/01/18 18:49:00 UTC
svn commit: r1435271 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
main/java/org/apache/camel/component/file/strategy/
test/java/org/apache/camel/component/file/strategy/
Author: davsclaus
Date: Fri Jan 18 17:49:00 2013
New Revision: 1435271
URL: http://svn.apache.org/viewvc?rev=1435271&view=rev
Log:
CAMEL-5590: Moved the prepareOnStatup task to first poll in file/ftp consumer, to avoid blocking starting Camel if the task takes a long time.
Removed:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=1435271&r1=1435270&r2=1435271&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Fri Jan 18 17:49:00 2013
@@ -42,12 +42,13 @@ public abstract class GenericFileConsume
protected final transient Logger log = LoggerFactory.getLogger(getClass());
protected GenericFileEndpoint<T> endpoint;
protected GenericFileOperations<T> operations;
- protected boolean loggedIn;
+ protected volatile boolean loggedIn;
protected String fileExpressionResult;
protected volatile ShutdownRunningTask shutdownRunningTask;
protected volatile int pendingExchanges;
protected Processor customProcessor;
protected boolean eagerLimitMaxMessagesPerPoll = true;
+ protected volatile boolean prepareOnStartup;
public GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations) {
super(endpoint, processor);
@@ -86,6 +87,13 @@ public abstract class GenericFileConsume
* Poll for files
*/
protected int poll() throws Exception {
+ // must prepare on startup the very first time
+ if (!prepareOnStartup) {
+ // prepare on startup
+ endpoint.getGenericFileProcessStrategy().prepareOnStartup(operations, endpoint);
+ prepareOnStartup = true;
+ }
+
// must reset for each poll
fileExpressionResult = null;
shutdownRunningTask = null;
@@ -544,8 +552,11 @@ public abstract class GenericFileConsume
@Override
protected void doStart() throws Exception {
super.doStart();
+ }
- // prepare on startup
- endpoint.getGenericFileProcessStrategy().prepareOnStartup(operations, endpoint);
+ @Override
+ protected void doStop() throws Exception {
+ prepareOnStartup = false;
+ super.doStop();
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java?rev=1435271&r1=1435270&r2=1435271&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java Fri Jan 18 17:49:00 2013
@@ -24,12 +24,12 @@ import org.apache.camel.Exchange;
public interface GenericFileProcessStrategy<T> {
/**
- * Allows custom logic to be run on startup preparing the strategy,
+ * Allows custom logic to be run on first poll preparing the strategy,
* such as removing old lock files etc.
*
* @param operations file operations
* @param endpoint the endpoint
- * @throws Exception can be thrown in case of errors which causes startup to fail
+ * @throws Exception can be thrown in case of errors which causes poll to fail
*/
void prepareOnStartup(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint) throws Exception;
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java?rev=1435271&r1=1435270&r2=1435271&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java Fri Jan 18 17:49:00 2013
@@ -25,6 +25,7 @@ import org.apache.camel.component.file.G
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +42,13 @@ public class MarkerFileExclusiveReadLock
LOG.debug("Prepare on startup by deleting orphaned lock files from: {}", dir);
+ StopWatch watch = new StopWatch();
deleteLockFiles(file, endpoint.isRecursive());
+
+ // log anything that takes more than a second
+ if (watch.taken() > 1000) {
+ LOG.info("Prepared on startup by deleting orphaned lock files from: {} took {} millis to complete.", dir, watch.taken());
+ }
}
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,