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 2018/10/03 07:25:25 UTC

[camel] branch camel-2.21.x updated: CAMEL-12850: camel-ftp tries reconnects twice as much as maximumReconnectAttempts (#2545)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.21.x by this push:
     new 781cd15  CAMEL-12850: camel-ftp tries reconnects twice as much as maximumReconnectAttempts (#2545)
781cd15 is described below

commit 781cd150ce00d13cce5ba4bedf1018368c5a207d
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Wed Oct 3 15:31:20 2018 +0900

    CAMEL-12850: camel-ftp tries reconnects twice as much as maximumReconnectAttempts (#2545)
---
 .../component/file/remote/RemoteFileConsumer.java  | 38 +----------------
 .../component/file/remote/RemoteFileProducer.java  | 49 +---------------------
 .../FtpBadLoginInProducerConnectionLeakTest.java   |  4 +-
 3 files changed, 3 insertions(+), 88 deletions(-)

diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
index a676732..0d4bf8d 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
@@ -54,12 +54,7 @@ public abstract class RemoteFileConsumer<T> extends GenericFileConsumer<T> {
             log.trace("prePollCheck on " + getEndpoint().getConfiguration().remoteServerInformation());
         }
         try {
-            if (getEndpoint().getMaximumReconnectAttempts() > 0) {
-                // only use recoverable if we are allowed any re-connect attempts
-                recoverableConnectIfNecessary();
-            } else {
-                connectIfNecessary();
-            }
+            connectIfNecessary();
         } catch (Exception e) {
             loggedIn = false;
 
@@ -182,37 +177,6 @@ public abstract class RemoteFileConsumer<T> extends GenericFileConsumer<T> {
         }
     }
 
-    protected void recoverableConnectIfNecessary() throws Exception {
-        try {
-            connectIfNecessary();
-        } catch (Exception e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Could not connect to: " + getEndpoint() + ". Will try to recover.", e);
-            }
-            loggedIn = false;
-        }
-
-        // recover by re-creating operations which should most likely be able to recover
-        if (!loggedIn) {
-            log.debug("Trying to recover connection to: {} with a fresh client.", getEndpoint());
-            // we want to preserve last FTP activity listener when we set a new operations
-            if (operations instanceof FtpOperations) {
-                FtpOperations ftpOperations = (FtpOperations) operations;
-                FtpClientActivityListener listener = ftpOperations.getClientActivityListener();
-                setOperations(getEndpoint().createRemoteFileOperations());
-                getOperations().setEndpoint(getEndpoint());
-                if (listener != null) {
-                    ftpOperations = (FtpOperations) getOperations();
-                    ftpOperations.setClientActivityListener(listener);
-                }
-            } else {
-                setOperations(getEndpoint().createRemoteFileOperations());
-                getOperations().setEndpoint(getEndpoint());
-            }
-            connectIfNecessary();
-        }
-    }
-
     protected void connectIfNecessary() throws IOException {
         // We need to send a noop first to check if the connection is still open 
         boolean isConnected = false;
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
index ebe5b20..53ad199 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
@@ -20,7 +20,6 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ServicePoolAware;
 import org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.apache.camel.component.file.GenericFileProducer;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
 
 /**
@@ -128,12 +127,7 @@ public class RemoteFileProducer<T> extends GenericFileProducer<T> implements Ser
         // if not alive then reconnect
         if (!noop) {
             try {
-                if (getEndpoint().getMaximumReconnectAttempts() > 0) {
-                    // only use recoverable if we are allowed any re-connect attempts
-                    recoverableConnectIfNecessary();
-                } else {
-                    connectIfNecessary();
-                }
+                connectIfNecessary();
             } catch (Exception e) {
                 loggedIn = false;
 
@@ -179,47 +173,6 @@ public class RemoteFileProducer<T> extends GenericFileProducer<T> implements Ser
         super.doStop();
     }
 
-    protected void recoverableConnectIfNecessary() throws Exception {
-        try {
-            connectIfNecessary();
-        } catch (Exception e) {
-            loggedIn = false;
-
-            // are we interrupted
-            InterruptedException ie = ObjectHelper.getException(InterruptedException.class, e);
-            if (ie != null) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Interrupted during connect to: " + getEndpoint(), ie);
-                }
-                throw ie;
-            }
-
-            if (log.isDebugEnabled()) {
-                log.debug("Could not connect to: " + getEndpoint() + ". Will try to recover.", e);
-            }
-        }
-
-        // recover by re-creating operations which should most likely be able to recover
-        if (!loggedIn) {
-            log.debug("Trying to recover connection to: {} with a new FTP client.", getEndpoint());
-            // we want to preserve last FTP activity listener when we set a new operations
-            if (operations instanceof FtpOperations) {
-                FtpOperations ftpOperations = (FtpOperations) operations;
-                FtpClientActivityListener listener = ftpOperations.getClientActivityListener();
-                setOperations(getEndpoint().createRemoteFileOperations());
-                getOperations().setEndpoint(getEndpoint());
-                if (listener != null) {
-                    ftpOperations = (FtpOperations) getOperations();
-                    ftpOperations.setClientActivityListener(listener);
-                }
-            } else {
-                setOperations(getEndpoint().createRemoteFileOperations());
-                getOperations().setEndpoint(getEndpoint());
-            }
-            connectIfNecessary();
-        }
-    }
-
     protected void connectIfNecessary() throws GenericFileOperationFailedException {
         if (!loggedIn || !getOperations().isConnected()) {
             log.debug("Not already connected/logged in. Connecting to: {}", getEndpoint());
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpBadLoginInProducerConnectionLeakTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpBadLoginInProducerConnectionLeakTest.java
index 0d61331..b87e9a4 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpBadLoginInProducerConnectionLeakTest.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpBadLoginInProducerConnectionLeakTest.java
@@ -58,9 +58,7 @@ public class FtpBadLoginInProducerConnectionLeakTest extends FtpServerTestSuppor
             }
         }
 
-        // maximumReconnectAttempts is related to TCP connects, not to FTP login attempts
-        // but having this parameter > 0 leads to two connection attempts
-        assertEquals("Expected 4 socket connections to be created", 4, socketAudits.size());
+        assertEquals("Expected 2 socket connections to be created", 2, socketAudits.size());
 
         for (Map.Entry<Integer, boolean[]> socketStats : socketAudits.entrySet()) {
             assertTrue("Socket should be connected", socketStats.getValue()[0]);