public final class TruncatedBinaryExponentialBackoffStrategy extends Object implements ReconnectionStrategy
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.
This class is immutable.
| Constructor and Description |
|---|
TruncatedBinaryExponentialBackoffStrategy(int slotTime,
int ceiling) |
public TruncatedBinaryExponentialBackoffStrategy(int slotTime,
int ceiling)
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).public int getNextReconnectionAttempt(int attempt)
ReconnectionStrategygetNextReconnectionAttempt in interface ReconnectionStrategyattempt - The current reconnection attempt. The first attempt is 0, the second attempt is 1, etc...Copyright © 2014–2015 XMPP.rocks. All rights reserved.