1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

Added ability to force an immediate reconnection. Not sure I'm fond of it, but it's doing the trick.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@9669 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Daniel Henninger 2007-12-23 23:25:02 +00:00 committed by dhenninger
parent 882d47fb6c
commit e5791ee5c6

View file

@ -2,9 +2,6 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.StreamError;
import java.util.ArrayList;
import java.util.List;
/**
* Handles the automatic reconnection process. Every time a connection is dropped without
* the application explicitly closing it, the manager automatically tries to reconnect to
@ -25,7 +22,7 @@ public class ReconnectionManager implements ConnectionListener {
private int secondBetweenReconnection = 5 * 60; // 5 minutes
// Holds the thread that produces a periodical reconnection.
private Thread reconnectionThread;
static private Thread reconnectionThread;
// Holds the connection to the server
private XMPPConnection connection;
@ -84,6 +81,17 @@ public class ReconnectionManager implements ConnectionListener {
this.secondBetweenReconnection = secondBetweenReconnection;
}
/**
* Forces an immediate reconnection and attempts an immediate reconnection.
*
* Interrupts the existing reconnection thread so that it can try an immediate connection attempt.
*/
static public void forceReconnection() {
if (reconnectionThread != null) {
reconnectionThread.interrupt();
}
}
/**
* Starts a reconnection mechanism if it was configured to do that.
* The algorithm is been executed when the first connection error is detected.
@ -149,9 +157,12 @@ public class ReconnectionManager implements ConnectionListener {
.notifyAttemptToReconnectIn(remainingSeconds);
}
catch (InterruptedException e1) {
e1.printStackTrace();
// We want to be able to legitimately interrupt this thread so we can
// force a reconnection.
remainingSeconds = 0;
// e1.printStackTrace();
// Notify the reconnection has failed
ReconnectionManager.this.notifyReconnectionFailed(e1);
// ReconnectionManager.this.notifyReconnectionFailed(e1);
}
}
// Waiting time have finished
@ -182,7 +193,6 @@ public class ReconnectionManager implements ConnectionListener {
* @param exception the exception that occured.
*/
protected void notifyReconnectionFailed(Exception exception) {
List<ConnectionListener> listenersCopy;
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.packetReader.connectionListeners) {
listener.reconnectionFailed(exception);