Class ReconnectPolicy

java.lang.Object
com.ultikits.ultitools.utils.ReconnectPolicy

final class ReconnectPolicy extends Object
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).
The bounds mirror the backend's contract answer 7 of 2026-10-24 and are aligned with the generated contract together with the provisional table in AgentConnection.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final long
    Upper bound of a long delay.
    (package private) static final long
    Lower bound, and the first ceiling, of a long delay.
    private final long
     
    private final long
     
    (package private) static final long
    Upper bound of a normal delay.
    private static final int
    Past this exponent every ceiling is already capped; also keeps the shift from overflowing.
    private final long
     
    (package private) static final long
    Lower bound, and the attempt-0 ceiling, of a normal delay.
    private final long
     
    private final DoubleSupplier
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    private static long
    ceiling(long base, long max, int exponent)
     
    (package private) long
    delayMillis(int attempt)
    The normal delay before the next attempt.
    private long
    jitter(long low, long high)
     
    (package private) long
    longDelayMillis(int consecutiveLongFailures)
    The long delay before the next attempt.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_DELAY_MS

      static final long MIN_DELAY_MS
      Lower bound, and the attempt-0 ceiling, of a normal delay.
      See Also:
    • MAX_DELAY_MS

      static final long MAX_DELAY_MS
      Upper bound of a normal delay.
      See Also:
    • LONG_MIN_DELAY_MS

      static final long LONG_MIN_DELAY_MS
      Lower bound, and the first ceiling, of a long delay.
      See Also:
    • LONG_MAX_DELAY_MS

      static final long LONG_MAX_DELAY_MS
      Upper bound of a long delay.
      See Also:
    • MAX_EXPONENT

      private static final int MAX_EXPONENT
      Past this exponent every ceiling is already capped; also keeps the shift from overflowing.
      See Also:
    • random

      private final DoubleSupplier 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 with minDelayMs and longMinDelayMs as 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)