@FunctionalInterface public interface ReconnectionStrategy
Alternatively you can use some of the predefined strategies which you can retrieve by one of the static methods.
E.g.after(long, TimeUnit) always tries to reconnect after a fix amount of time.| Modifier and Type | Method and Description |
|---|---|
static ReconnectionStrategy |
after(long duration,
TimeUnit timeUnit)
Reconnects always after a fix amount of time, e.g. after 10 seconds.
|
long |
getNextReconnectionAttempt(int attempt,
Throwable cause)
Gets the time (in seconds) until the next reconnection is attempted.
|
default boolean |
mayReconnect(Throwable e) |
static ReconnectionStrategy |
truncatedBinaryExponentialBackoffStrategy(int slotTime,
int ceiling)
This is the default reconnection strategy used by the
ReconnectionManager. |
default boolean mayReconnect(Throwable e)
long getNextReconnectionAttempt(int attempt,
Throwable cause)
attempt - The current reconnection attempt. The first attempt is 0, the second attempt is 1, etc...cause - The cause for the disconnection.static ReconnectionStrategy truncatedBinaryExponentialBackoffStrategy(int slotTime, int ceiling)
ReconnectionManager.
It exponentially increases the time span from which a random value for the next reconnection attempt is chosen.
The formula for doing this, is: (2n - 1) * s, where n is the number of reconnection attempt and s is the slot time, which is 60 seconds by default.
In practice this means, the first reconnection attempt occurs after a random period of time between 0 and 60 seconds.
The second attempt chooses a random number between 0 and 180 seconds.
The third attempt chooses a random number between 0 and 420 seconds.
The fourth attempt chooses a random number between 0 and 900 seconds.
The fifth attempt chooses a random number between 0 and 1860 seconds (= 31 minutes)
The strategy is called "truncated", because it won't increase the time span after the nth iteration, which means in the example above, the sixth and any further attempt behaves equally to the fifth attempt.
This "truncated binary exponential backoff" is the recommended reconnection strategy by the XMPP specification.slotTime - The slot time (in seconds), usually 60.ceiling - The ceiling, i.e. when the time is truncated. E.g. if the ceiling is 4, the back off is truncated at the 5th reconnection attempt (it starts at zero).static ReconnectionStrategy after(long duration, TimeUnit timeUnit)
duration - The fix duration after which a reconnection is attempted.timeUnit - The time unit.Copyright © 2014–2015 XMPP.rocks. All rights reserved.