mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
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
This commit is contained in:
parent
750cfa64b0
commit
f90b43a87c
1 changed files with 14 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.StreamError;
|
import org.jivesoftware.smack.packet.StreamError;
|
||||||
|
import java.util.Random;
|
||||||
/**
|
/**
|
||||||
* Handles the automatic reconnection process. Every time a connection is dropped without
|
* Handles the automatic reconnection process. Every time a connection is dropped without
|
||||||
* the application explictly closing it, the manager automatically tries to reconnect to
|
* 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
|
// Holds the connection to the server
|
||||||
private Connection connection;
|
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
|
// Holds the state of the reconnection
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
||||||
|
@ -61,12 +63,15 @@ public class ReconnectionManager implements ConnectionListener {
|
||||||
* <li>Finally it will try indefinitely every 5 minutes.
|
* <li>Finally it will try indefinitely every 5 minutes.
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
protected void reconnect() {
|
synchronized protected void reconnect() {
|
||||||
if (this.isReconnectionAllowed()) {
|
if (this.isReconnectionAllowed()) {
|
||||||
// Since there is no thread running, creates a new one to attempt
|
// Since there is no thread running, creates a new one to attempt
|
||||||
// the reconnection.
|
// 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
|
* 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.
|
* @return the number of seconds until the next reconnection attempt.
|
||||||
*/
|
*/
|
||||||
private int timeDelay() {
|
private int timeDelay() {
|
||||||
|
attempts++;
|
||||||
if (attempts > 13) {
|
if (attempts > 13) {
|
||||||
return 60 * 5; // 5 minutes
|
return randomBase*6*5; // between 2.5 and 7.5 minutes (~5 minutes)
|
||||||
}
|
}
|
||||||
if (attempts > 7) {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue