Class ReconnectionManager

java.lang.Object
org.jivesoftware.smack.ReconnectionManager

public final class ReconnectionManager extends Object
Handles the automatic reconnection process. Every time a connection is dropped without the application explicitly closing it, the manager automatically tries to reconnect to the server.

There are two possible reconnection policies: ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY - 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.
ReconnectionManager.ReconnectionPolicy.FIXED_DELAY - The reconnection mechanism will try to reconnect after a fixed delay independently from the number of reconnection attempts already performed.

Interrupting the reconnection thread will abort the reconnection mechanism.

  • Method Details

    • getInstanceFor

      public static ReconnectionManager getInstanceFor(AbstractXMPPConnection connection)
      Get a instance of ReconnectionManager for the given connection.
      Parameters:
      connection - TODO javadoc me please
      Returns:
      a ReconnectionManager for the connection.
    • setEnabledPerDefault

      public static void setEnabledPerDefault(boolean enabled)
      Set if the automatic reconnection mechanism will be enabled per default for new XMPP connections. The default is 'false'.
      Parameters:
      enabled - TODO javadoc me please
    • getEnabledPerDefault

      public static boolean getEnabledPerDefault()
      Get the current default reconnection mechanism setting for new XMPP connections.
      Returns:
      true if new connection will come with an enabled reconnection mechanism
    • setDefaultFixedDelay

      public static void setDefaultFixedDelay(int fixedDelay)
      Set the default fixed delay in seconds between the reconnection attempts. Also set the default connection policy to ReconnectionManager.ReconnectionPolicy.FIXED_DELAY
      Parameters:
      fixedDelay - Delay expressed in seconds
    • setDefaultReconnectionPolicy

      public static void setDefaultReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy)
      Set the default Reconnection Policy to use.
      Parameters:
      reconnectionPolicy - TODO javadoc me please
    • addReconnectionListener

      public boolean addReconnectionListener(ReconnectionListener listener)
      Add a new reconnection listener.
      Parameters:
      listener - the listener to add
      Returns:
      true if the listener was not already added
      Since:
      4.2.2
    • removeReconnectionListener

      public boolean removeReconnectionListener(ReconnectionListener listener)
      Remove a reconnection listener.
      Parameters:
      listener - the listener to remove
      Returns:
      true if the listener was active and got removed.
      Since:
      4.2.2
    • setFixedDelay

      public void setFixedDelay(int fixedDelay)
      Set the fixed delay in seconds between the reconnection attempts Also set the connection policy to ReconnectionManager.ReconnectionPolicy.FIXED_DELAY.
      Parameters:
      fixedDelay - Delay expressed in seconds
    • setReconnectionPolicy

      public void setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy)
      Set the Reconnection Policy to use.
      Parameters:
      reconnectionPolicy - TODO javadoc me please
    • enableAutomaticReconnection

      public void enableAutomaticReconnection()
      Enable the automatic reconnection mechanism. Does nothing if already enabled.
    • disableAutomaticReconnection

      public void disableAutomaticReconnection()
      Disable the automatic reconnection mechanism. Does nothing if already disabled.
    • isAutomaticReconnectEnabled

      public boolean isAutomaticReconnectEnabled()
      Returns if the automatic reconnection mechanism is enabled. You can disable the reconnection mechanism with disableAutomaticReconnection() and enable the mechanism with enableAutomaticReconnection().
      Returns:
      true, if the reconnection mechanism is enabled.
    • abortPossiblyRunningReconnection

      public void abortPossiblyRunningReconnection()
      Abort a possibly running reconnection mechanism.
      Since:
      4.2.2