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
Modifier and TypeClassDescriptionstatic enum
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
Modifier and TypeMethodDescriptionvoid
Abort a possibly running reconnection mechanism.boolean
addReconnectionListener
(ReconnectionListener listener) Add a new reconnection listener.void
Disable the automatic reconnection mechanism.void
Enable the automatic reconnection mechanism.static boolean
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
Returns if the automatic reconnection mechanism is enabled.boolean
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 Details
-
getInstanceFor
Get a instance of ReconnectionManager for the given connection.- Parameters:
connection
- TODO javadoc me please- Returns:
- a ReconnectionManager for the connection.
-
setEnabledPerDefault
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
Get the current default reconnection mechanism setting for new XMPP connections.- Returns:
- true if new connection will come with an enabled reconnection mechanism
-
setDefaultFixedDelay
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:
true
if the listener was not already added- Since:
- 4.2.2
-
removeReconnectionListener
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
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
Enable the automatic reconnection mechanism. Does nothing if already enabled. -
disableAutomaticReconnection
Disable the automatic reconnection mechanism. Does nothing if already disabled. -
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
Abort a possibly running reconnection mechanism.- Since:
- 4.2.2
-