1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

SMACK-279: The XMPPConnection extends the new abstract Connection class

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11613 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Günther Niess 2010-02-09 11:55:56 +00:00 committed by niess
parent 11a41e79ca
commit 127319a821
102 changed files with 1420 additions and 1194 deletions

View file

@ -19,7 +19,7 @@ import org.jivesoftware.smack.packet.StreamError;
public class ReconnectionManager implements ConnectionListener {
// Holds the connection to the server
private XMPPConnection connection;
private Connection connection;
// Holds the state of the reconnection
boolean done = false;
@ -28,14 +28,14 @@ public class ReconnectionManager implements ConnectionListener {
// Create a new PrivacyListManager on every established connection. In the init()
// method of PrivacyListManager, we'll add a listener that will delete the
// instance when the connection is closed.
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
connection.addConnectionListener(new ReconnectionManager(connection));
}
});
}
private ReconnectionManager(XMPPConnection connection) {
private ReconnectionManager(Connection connection) {
this.connection = connection;
}
@ -46,9 +46,8 @@ public class ReconnectionManager implements ConnectionListener {
* @return true if automatic reconnections are allowed.
*/
private boolean isReconnectionAllowed() {
return !done && !connection.isConnected()
&& connection.getConfiguration().isReconnectionAllowed()
&& connection.packetReader != null;
return !done && !connection.isConnected()
&& connection.isReconnectionAllowed();
}
/**
@ -94,7 +93,7 @@ public class ReconnectionManager implements ConnectionListener {
*/
public void run() {
// The process will try to reconnect until the connection is established or
// the user cancel the reconnection process {@link XMPPConnection#disconnect()}
// the user cancel the reconnection process {@link Connection#disconnect()}
while (ReconnectionManager.this.isReconnectionAllowed()) {
// Find how much time we should wait until the next reconnection
int remainingSeconds = timeDelay();
@ -142,21 +141,21 @@ public class ReconnectionManager implements ConnectionListener {
* @param exception the exception that occured.
*/
protected void notifyReconnectionFailed(Exception exception) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.packetReader.connectionListeners) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectionFailed(exception);
}
}
}
/**
* Fires listeners when The XMPPConnection will retry a reconnection. Expressed in seconds.
* Fires listeners when The Connection will retry a reconnection. Expressed in seconds.
*
* @param seconds the number of seconds that a reconnection will be attempted in.
*/
protected void notifyAttemptToReconnectIn(int seconds) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.packetReader.connectionListeners) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectingIn(seconds);
}
}