Package org.jivesoftware.smack
Class ReconnectionManager
java.lang.Object
org.jivesoftware.smack.ReconnectionManager
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:
- For the first minute it will attempt to connect once every ten seconds.
- For the next five minutes it will attempt to connect once a minute.
- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumReconnection Policy, whereReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAYis the default policy used by smack andReconnectionManager.ReconnectionPolicy.FIXED_DELAYimplies a fixed amount of time between reconnection attempts. -
Method Summary
Modifier and TypeMethodDescriptionvoidAbort a possibly running reconnection mechanism.booleanaddReconnectionListener(ReconnectionListener listener) Add a new reconnection listener.voidDisable the automatic reconnection mechanism.voidEnable the automatic reconnection mechanism.static booleanGet the current default reconnection mechanism setting for new XMPP connections.static ReconnectionManagergetInstanceFor(AbstractXMPPConnection connection) Get a instance of ReconnectionManager for the given connection.booleanReturns if the automatic reconnection mechanism is enabled.booleanRemove a reconnection listener.static voidsetDefaultFixedDelay(int fixedDelay) Set the default fixed delay in seconds between the reconnection attempts.static voidsetDefaultReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy) Set the default Reconnection Policy to use.static voidsetEnabledPerDefault(boolean enabled) Set if the automatic reconnection mechanism will be enabled per default for new XMPP connections.voidsetFixedDelay(int fixedDelay) Set the fixed delay in seconds between the reconnection attempts Also set the connection policy toReconnectionManager.ReconnectionPolicy.FIXED_DELAY.voidsetReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy) Set the Reconnection Policy to use.
-
Method Details
-
getInstanceFor
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 toReconnectionManager.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
Add a new reconnection listener.- Parameters:
listener- the listener to add- Returns:
trueif the listener was not already added- Since:
- 4.2.2
-
removeReconnectionListener
Remove a reconnection listener.- Parameters:
listener- the listener to remove- Returns:
trueif 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 toReconnectionManager.ReconnectionPolicy.FIXED_DELAY.- Parameters:
fixedDelay- Delay expressed in seconds
-
setReconnectionPolicy
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 withdisableAutomaticReconnection()and enable the mechanism withenableAutomaticReconnection().- Returns:
- true, if the reconnection mechanism is enabled.
-
abortPossiblyRunningReconnection
public void abortPossiblyRunningReconnection()Abort a possibly running reconnection mechanism.- Since:
- 4.2.2
-