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 2012/08/16 12:56:16 UTC

svn commit: r1373786 - in /camel/branches/camel-2.10.x: ./ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/ components/camel-ftp/src/test/java...

Author: davsclaus
Date: Thu Aug 16 10:56:15 2012
New Revision: 1373786

URL: http://svn.apache.org/viewvc?rev=1373786&view=rev
Log:
CAMEL-5512: Made the readLock=changed faster for ftp component if you enable the fastExistsCheck=true option as well. Notice that not all FTP servers support this.

Added:
    camel/branches/camel-2.10.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockFastExistCheckTest.java
      - copied unchanged from r1373785, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockFastExistCheckTest.java
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpProcessStrategyFactory.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpProcessStrategyFactory.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1373785

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=1373786&r1=1373785&r2=1373786&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java (original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java Thu Aug 16 10:56:15 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote;
 
+import java.util.Map;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.GenericFile;
@@ -109,6 +111,13 @@ public abstract class RemoteFileEndpoint
         ObjectHelper.notEmpty(config.getProtocol(), "protocol");
     }
 
+    @Override
+    protected Map<String, Object> getParamsAsMap() {
+        Map<String, Object> map = super.getParamsAsMap();
+        map.put("fastExistsCheck", fastExistsCheck);
+        return map;
+    }
+
     /**
      * Remote File Endpoints, impl this method to create a custom consumer specific to their "protocol" etc.
      *

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java?rev=1373786&r1=1373785&r2=1373786&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java (original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java Thu Aug 16 10:56:15 2012
@@ -33,6 +33,7 @@ public class FtpChangedExclusiveReadLock
     private long timeout;
     private long checkInterval = 5000;
     private long minLength = 1;
+    private boolean fastExistsCheck;
 
     @Override
     public void prepareOnStartup(GenericFileOperations<FTPFile> tGenericFileOperations, GenericFileEndpoint<FTPFile> tGenericFileEndpoint) throws Exception {
@@ -61,7 +62,18 @@ public class FtpChangedExclusiveReadLock
 
             long newLastModified = 0;
             long newLength = 0;
-            List<FTPFile> files = operations.listFiles(file.getParent());
+            List<FTPFile> files;
+            if (fastExistsCheck) {
+                // use the absolute file path to only pickup the file we want to check, this avoids expensive
+                // list operations if we have a lot of files in the directory
+                LOG.trace("Using fast exists to update file information for {}", file);
+                files = operations.listFiles(file.getAbsoluteFilePath());
+            } else {
+                LOG.trace("Using full directory listing to update file information for {}. Consider enabling fastExistsCheck option.", file);
+                // fast option not enabled, so list the directory and filter the file name
+                files = operations.listFiles(file.getParent());
+            }
+            LOG.trace("List files {} found {} files", file.getAbsoluteFilePath(), files.size());
             for (FTPFile f : files) {
                 if (f.getName().equals(file.getFileName())) {
                     newLastModified = f.getTimestamp().getTimeInMillis();
@@ -130,4 +142,12 @@ public class FtpChangedExclusiveReadLock
     public void setMinLength(long minLength) {
         this.minLength = minLength;
     }
+
+    public boolean isFastExistsCheck() {
+        return fastExistsCheck;
+    }
+
+    public void setFastExistsCheck(boolean fastExistsCheck) {
+        this.fastExistsCheck = fastExistsCheck;
+    }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpProcessStrategyFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpProcessStrategyFactory.java?rev=1373786&r1=1373785&r2=1373786&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpProcessStrategyFactory.java (original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpProcessStrategyFactory.java Thu Aug 16 10:56:15 2012
@@ -126,6 +126,10 @@ public final class FtpProcessStrategyFac
                 if (minLength != null) {
                     readLockStrategy.setMinLength(minLength);
                 }
+                Boolean fastExistsCheck = (Boolean) params.get("fastExistsCheck");
+                if (fastExistsCheck != null) {
+                    readLockStrategy.setFastExistsCheck(fastExistsCheck);
+                }
                 return readLockStrategy;
             }
         }

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java?rev=1373786&r1=1373785&r2=1373786&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java (original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java Thu Aug 16 10:56:15 2012
@@ -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.StopWatch;
+import org.apache.commons.net.ftp.FTPFile;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,6 +34,7 @@ public class SftpChangedExclusiveReadLoc
     private long timeout;
     private long checkInterval = 5000;
     private long minLength = 1;
+    private boolean fastExistsCheck;
 
     @Override
     public void prepareOnStartup(GenericFileOperations<ChannelSftp.LsEntry> tGenericFileOperations, GenericFileEndpoint<ChannelSftp.LsEntry> tGenericFileEndpoint) throws Exception {
@@ -61,7 +63,18 @@ public class SftpChangedExclusiveReadLoc
 
             long newLastModified = 0;
             long newLength = 0;
-            List<ChannelSftp.LsEntry> files = operations.listFiles(file.getParent());
+            List<ChannelSftp.LsEntry> files;
+            if (fastExistsCheck) {
+                // use the absolute file path to only pickup the file we want to check, this avoids expensive
+                // list operations if we have a lot of files in the directory
+                LOG.trace("Using fast exists to update file information for {}", file);
+                files = operations.listFiles(file.getAbsoluteFilePath());
+            } else {
+                LOG.trace("Using full directory listing to update file information for {}. Consider enabling fastExistsCheck option.", file);
+                // fast option not enabled, so list the directory and filter the file name
+                files = operations.listFiles(file.getParent());
+            }
+            LOG.trace("List files {} found {} files", file.getAbsoluteFilePath(), files.size());
             for (ChannelSftp.LsEntry f : files) {
                 if (f.getFilename().equals(file.getFileName())) {
                     newLastModified = f.getAttrs().getMTime();
@@ -130,4 +143,12 @@ public class SftpChangedExclusiveReadLoc
     public void setMinLength(long minLength) {
         this.minLength = minLength;
     }
+
+    public boolean isFastExistsCheck() {
+        return fastExistsCheck;
+    }
+
+    public void setFastExistsCheck(boolean fastExistsCheck) {
+        this.fastExistsCheck = fastExistsCheck;
+    }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpProcessStrategyFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpProcessStrategyFactory.java?rev=1373786&r1=1373785&r2=1373786&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpProcessStrategyFactory.java (original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpProcessStrategyFactory.java Thu Aug 16 10:56:15 2012
@@ -127,6 +127,10 @@ public final class SftpProcessStrategyFa
                 if (minLength != null) {
                     readLockStrategy.setMinLength(minLength);
                 }
+                Boolean fastExistsCheck = (Boolean) params.get("fastExistsCheck");
+                if (fastExistsCheck != null) {
+                    readLockStrategy.setFastExistsCheck(fastExistsCheck);
+                }
                 return readLockStrategy;
             }
         }