From f90b43a87c9d7c5c584c1822e2bb6a6982571a8a Mon Sep 17 00:00:00 2001 From: Holger Bergunde Date: Thu, 31 Mar 2011 06:35:59 +0000 Subject: [PATCH] SMACK-325 patched the diff to ReconnectionManager manually. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12219 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smack/ReconnectionManager.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source/org/jivesoftware/smack/ReconnectionManager.java b/source/org/jivesoftware/smack/ReconnectionManager.java index b0119b8b2..514c8235e 100644 --- a/source/org/jivesoftware/smack/ReconnectionManager.java +++ b/source/org/jivesoftware/smack/ReconnectionManager.java @@ -1,7 +1,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.StreamError; - +import java.util.Random; /** * Handles the automatic reconnection process. Every time a connection is dropped without * the application explictly closing it, the manager automatically tries to reconnect to @@ -20,7 +20,9 @@ public class ReconnectionManager implements ConnectionListener { // Holds the connection to the server private Connection connection; - + private Thread reconnectionThread; + private int randomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds + // Holds the state of the reconnection boolean done = false; @@ -61,12 +63,15 @@ public class ReconnectionManager implements ConnectionListener { *
  • Finally it will try indefinitely every 5 minutes. * */ - protected void reconnect() { + synchronized protected void reconnect() { if (this.isReconnectionAllowed()) { // Since there is no thread running, creates a new one to attempt // the reconnection. - Thread reconnectionThread = new Thread() { - + // avoid to run duplicated reconnectionThread -- fd: 16/09/2010 + if (reconnectionThread!=null && reconnectionThread.isAlive()) return; + + reconnectionThread = new Thread() { + /** * Holds the current number of reconnection attempts */ @@ -78,13 +83,14 @@ public class ReconnectionManager implements ConnectionListener { * @return the number of seconds until the next reconnection attempt. */ private int timeDelay() { + attempts++; if (attempts > 13) { - return 60 * 5; // 5 minutes + return randomBase*6*5; // between 2.5 and 7.5 minutes (~5 minutes) } if (attempts > 7) { - return 60; // 1 minute + return randomBase*6; // between 30 and 90 seconds (~1 minutes) } - return 10; // 10 seconds + return randomBase; // 10 seconds } /**