Package com.ultikits.ultitools.utils
Class ReconnectPolicy
java.lang.Object
com.ultikits.ultitools.utils.ReconnectPolicy
Reconnect delays for the UltiCloud agent connection, with full jitter (as of 6.3.1).
Two classes of delay, both uniform over their whole range so that servers that lost the gateway at the same moment do not come back at the same moment:
- normal -- attempt
n(0-based) waits a uniform delay in [1 s, min(60 s, 2^n s)]: network loss, gateway restarts, internal errors; - long -- the
k-th consecutive long-class failure (0-based) waits a uniform delay in [60 s, min(15 min, 60 s x 2^k)]: failures that a quick retry only repeats (superseded connection, abuse rate, an invalid hello, HTTP 429).
AgentConnection.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longUpper bound of a long delay.(package private) static final longLower bound, and the first ceiling, of a long delay.private final longprivate final long(package private) static final longUpper bound of a normal delay.private static final intPast this exponent every ceiling is already capped; also keeps the shift from overflowing.private final long(package private) static final longLower bound, and the attempt-0 ceiling, of a normal delay.private final longprivate final DoubleSupplier -
Constructor Summary
ConstructorsConstructorDescriptionReconnectPolicy(DoubleSupplier random) The production policy.ReconnectPolicy(DoubleSupplier random, long minDelayMs, long maxDelayMs, long longMinDelayMs, long longMaxDelayMs) A policy with other bounds, so tests can run the reconnect loop in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionprivate static longceiling(long base, long max, int exponent) (package private) longdelayMillis(int attempt) The normal delay before the next attempt.private longjitter(long low, long high) (package private) longlongDelayMillis(int consecutiveLongFailures) The long delay before the next attempt.
-
Field Details
-
MIN_DELAY_MS
static final long MIN_DELAY_MSLower bound, and the attempt-0 ceiling, of a normal delay.- See Also:
-
MAX_DELAY_MS
static final long MAX_DELAY_MSUpper bound of a normal delay.- See Also:
-
LONG_MIN_DELAY_MS
static final long LONG_MIN_DELAY_MSLower bound, and the first ceiling, of a long delay.- See Also:
-
LONG_MAX_DELAY_MS
static final long LONG_MAX_DELAY_MSUpper bound of a long delay.- See Also:
-
MAX_EXPONENT
private static final int MAX_EXPONENTPast this exponent every ceiling is already capped; also keeps the shift from overflowing.- See Also:
-
random
-
minDelayMs
private final long minDelayMs -
maxDelayMs
private final long maxDelayMs -
longMinDelayMs
private final long longMinDelayMs -
longMaxDelayMs
private final long longMaxDelayMs
-
-
Constructor Details
-
ReconnectPolicy
ReconnectPolicy(DoubleSupplier random) The production policy.- Parameters:
random- a source of uniform values in [0, 1)
-
ReconnectPolicy
ReconnectPolicy(DoubleSupplier random, long minDelayMs, long maxDelayMs, long longMinDelayMs, long longMaxDelayMs) A policy with other bounds, so tests can run the reconnect loop in milliseconds. The formulas are the production ones withminDelayMsandlongMinDelayMsas the bases.
-
-
Method Details
-
delayMillis
long delayMillis(int attempt) The normal delay before the next attempt.- Parameters:
attempt- consecutive normal-class failures so far, 0-based; negative counts as 0- Returns:
- a delay in [1 s, min(60 s, 2^attempt s)]
-
longDelayMillis
long longDelayMillis(int consecutiveLongFailures) The long delay before the next attempt.- Parameters:
consecutiveLongFailures- consecutive long-class failures so far, 0-based; negative counts as 0- Returns:
- a delay in [60 s, min(15 min, 60 s x 2^k)]
-
ceiling
private static long ceiling(long base, long max, int exponent) -
jitter
private long jitter(long low, long high)
-