Smack

org.jivesoftware.smack
Class ReconnectionManager

java.lang.Object
  extended by org.jivesoftware.smack.ReconnectionManager
All Implemented Interfaces:
ConnectionListener

public class ReconnectionManager
extends java.lang.Object
implements ConnectionListener

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 server.

The reconnection mechanism will try to reconnect periodically:

  1. For the first minute it will attempt to connect once every ten seconds.
  2. For the next five minutes it will attempt to connect once a minute.
  3. If that fails it will indefinitely try to connect once every five minutes.

Author:
Francisco Vives

Method Summary
 void connectionClosed()
          Notification that the connection was closed normally or that the reconnection process has been aborted.
 void connectionClosedOnError(java.lang.Exception e)
          Notification that the connection was closed due to an exception.
protected  void notifyAttemptToReconnectIn(int seconds)
          Fires listeners when The Connection will retry a reconnection.
protected  void notifyReconnectionFailed(java.lang.Exception exception)
          Fires listeners when a reconnection attempt has failed.
protected  void reconnect()
          Starts a reconnection mechanism if it was configured to do that.
 void reconnectingIn(int seconds)
          The connection will retry to reconnect in the specified number of seconds.
 void reconnectionFailed(java.lang.Exception e)
          An attempt to connect to the server has failed.
 void reconnectionSuccessful()
          The connection has successfull gotten connected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reconnect

protected void reconnect()
Starts a reconnection mechanism if it was configured to do that. The algorithm is been executed when the first connection error is detected.

The reconnection mechanism will try to reconnect periodically in this way:

  1. First it will try 6 times every 10 seconds.
  2. Then it will try 10 times every 1 minute.
  3. Finally it will try indefinitely every 5 minutes.


notifyReconnectionFailed

protected void notifyReconnectionFailed(java.lang.Exception exception)
Fires listeners when a reconnection attempt has failed.

Parameters:
exception - the exception that occured.

notifyAttemptToReconnectIn

protected void notifyAttemptToReconnectIn(int seconds)
Fires listeners when The Connection will retry a reconnection. Expressed in seconds.

Parameters:
seconds - the number of seconds that a reconnection will be attempted in.

connectionClosed

public void connectionClosed()
Description copied from interface: ConnectionListener
Notification that the connection was closed normally or that the reconnection process has been aborted.

Specified by:
connectionClosed in interface ConnectionListener

connectionClosedOnError

public void connectionClosedOnError(java.lang.Exception e)
Description copied from interface: ConnectionListener
Notification that the connection was closed due to an exception. When abruptly disconnected it is possible for the connection to try reconnecting to the server.

Specified by:
connectionClosedOnError in interface ConnectionListener
Parameters:
e - the exception.

reconnectingIn

public void reconnectingIn(int seconds)
Description copied from interface: ConnectionListener
The connection will retry to reconnect in the specified number of seconds.

Specified by:
reconnectingIn in interface ConnectionListener
Parameters:
seconds - remaining seconds before attempting a reconnection.

reconnectionFailed

public void reconnectionFailed(java.lang.Exception e)
Description copied from interface: ConnectionListener
An attempt to connect to the server has failed. The connection will keep trying reconnecting to the server in a moment.

Specified by:
reconnectionFailed in interface ConnectionListener
Parameters:
e - the exception that caused the reconnection to fail.

reconnectionSuccessful

public void reconnectionSuccessful()
The connection has successfull gotten connected.

Specified by:
reconnectionSuccessful in interface ConnectionListener

Smack

Copyright © 2003-2007 Jive Software.