camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch master updated: CAMEL-12850: camel-ftp tries reconnects twice as much as maximumReconnectAttempts (#2545)
Date Wed, 03 Oct 2018 06:31:25 GMT
This is an automated email from the ASF dual-hosted git repository.

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


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

commit cc85db083b6a78631132dd673265fd08da61c34e
Author: Tadayoshi Sato <sato.tadayoshi@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 f4e5c34..8c18751 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 2f4c5b6..38ccdd1 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 332a43c..56b7227 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
@@ -59,9 +59,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]);


Mime
View raw message