Package org.jivesoftware.smack
Class ReconnectionManager
- java.lang.Object
-
- org.jivesoftware.smack.ReconnectionManager
-
public final class ReconnectionManager extends java.lang.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:- 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 Classes Modifier and Type Class Description static class
ReconnectionManager.ReconnectionPolicy
Reconnection Policy, whereReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY
is the default policy used by smack andReconnectionManager.ReconnectionPolicy.FIXED_DELAY
implies a fixed amount of time between reconnection attempts.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortPossiblyRunningReconnection()
Abort a possibly running reconnection mechanism.boolean
addReconnectionListener(ReconnectionListener listener)
Add a new reconnection listener.void
disableAutomaticReconnection()
Disable the automatic reconnection mechanism.void
enableAutomaticReconnection()
Enable the automatic reconnection mechanism.static boolean
getEnabledPerDefault()
Get the current default reconnection mechanism setting for new XMPP connections.static ReconnectionManager
getInstanceFor(AbstractXMPPConnection connection)
Get a instance of ReconnectionManager for the given connection.boolean
isAutomaticReconnectEnabled()
Returns if the automatic reconnection mechanism is enabled.boolean
removeReconnectionListener(ReconnectionListener listener)
Remove a reconnection listener.static void
setDefaultFixedDelay(int fixedDelay)
Set the default fixed delay in seconds between the reconnection attempts.static void
setDefaultReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy)
Set the default Reconnection Policy to use.static void
setEnabledPerDefault(boolean enabled)
Set if the automatic reconnection mechanism will be enabled per default for new XMPP connections.void
setFixedDelay(int fixedDelay)
Set the fixed delay in seconds between the reconnection attempts Also set the connection policy toReconnectionManager.ReconnectionPolicy.FIXED_DELAY
.void
setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy reconnectionPolicy)
Set the Reconnection Policy to use.
-
-
-
Method Detail
-
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 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
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 toReconnectionManager.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 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
-
-