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

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


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

commit 7118b29b1879bd77cb7e86d02cbd526f3d75cf94
Author: Tadayoshi Sato <sato.tadayo...@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 b1ae6d7..a96f9c5 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
@@ -55,12 +55,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;
 
@@ -183,37 +178,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 cfea7e0..f37248d 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]);

Reply via email to