camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r654567 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/FileConsumer.java test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
Date Thu, 08 May 2008 16:01:02 GMT
Author: jstrachan
Date: Thu May  8 09:01:02 2008
New Revision: 654567

URL: http://svn.apache.org/viewvc?rev=654567&view=rev
Log:
further fix for http://issues.apache.org/activemq/browse/CAMEL-498 to avoid repeatedly processing
the same file with noop=true

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=654567&r1=654566&r2=654567&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Thu May  8 09:01:02 2008
@@ -106,24 +106,7 @@
         }
         // we only care about file modified times if we are not deleting/moving
         // files
-        if (endpoint.isNoop()) {
-            // do nothing now as isValidFile() filters unmodified files
-/*
-            long fileModified = file.lastModified();
-            Long previousModified = noopMap.get(file);
-            noopMap.put(file, fileModified);
-            if (previousModified == null || fileModified > previousModified) {
-                return 1;
-            }
-            else {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Ignoring file: " + file + " as modified time: " + fileModified
-                              + " less than the previous modified time: " + previousModified);
-                }
-                return 0;
-            }
-*/
-        } else {
+        if (!endpoint.isNoop()) {
             if (filesBeingProcessed.contains(file)) {
                 return 1;
             }
@@ -172,7 +155,7 @@
         boolean result = false;
         if (file != null && file.exists()) {
             // TODO: maybe use a configurable strategy instead of the hardcoded one based
on last file change
-            if (isMatched(file) && isUnchanged(file)) {
+            if (isMatched(file) && isChanged(file)) {
                 result = true;
             }
         }
@@ -180,7 +163,7 @@
     }
 
 
-    protected boolean isUnchanged(File file) {
+    protected boolean isChanged(File file) {
         if (file == null) {
             // Sanity check
             return false;
@@ -188,7 +171,7 @@
             // Allow recursive polling to descend into this directory
             return true;
         } else {
-            boolean lastModifiedCheck = true;
+            boolean lastModifiedCheck = false;
             long modifiedDuration = 0;
             if (getUnchangedDelay() > 0) {
                 modifiedDuration = System.currentTimeMillis() - file.lastModified();
@@ -198,31 +181,35 @@
             long fileModified = file.lastModified();
             Long previousModified = noopMap.get(file);
             noopMap.put(file, fileModified);
-            boolean modifiedChanged = previousModified == null || fileModified > previousModified;
-
-
+            if (previousModified == null || fileModified > previousModified) {
+                lastModifiedCheck = true;
+            }
 
-            boolean sizeCheck = true;
+            boolean sizeCheck = false;
             long sizeDifference = 0;
             if (isUnchangedSize()) {
-                long prevFileSize = (fileSizes.get(file) == null) ? 0 : fileSizes.get(file).longValue();
-                sizeDifference = file.length() - prevFileSize;
-                sizeCheck = sizeDifference == 0;
+                Long value = fileSizes.get(file);
+                if (value == null) {
+                    sizeCheck = true;
+                }
+                else {
+                    sizeCheck = file.length() != value;
+                }
             }
 
-            boolean answer = lastModifiedCheck && sizeCheck && !modifiedChanged;
+            boolean answer = lastModifiedCheck || sizeCheck;
 
             if (LOG.isDebugEnabled()) {
-                LOG.debug("file:" + file + " isUnchanged:" + answer + " " + "sizeCheck:"
+ sizeCheck + "("
+                LOG.debug("file:" + file + " isChanged:" + answer + " " + "sizeCheck:" +
sizeCheck + "("
                           + sizeDifference + ") " + "lastModifiedCheck:" + lastModifiedCheck
+ "("
                           + modifiedDuration + ")");
             }
 
             if (isUnchangedSize()) {
                 if (answer) {
-                    fileSizes.remove(file);
-                } else {
                     fileSizes.put(file, file.length());
+                } else {
+                    fileSizes.remove(file);
                 }
             }
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java?rev=654567&r1=654566&r2=654567&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
Thu May  8 09:01:02 2008
@@ -65,6 +65,9 @@
         assertFileNotExists(file);
         assertFileExists(newFile);
 
+        // now lets wait for multiple polls to check we only process it once
+        Thread.sleep(5000);
+
         assertMockEndpointsSatisifed();
     }
 



Mime
View raw message