java.lang.Object
net.i2p.router.tunnel.pool.ThinPoolLogState

public class ThinPoolLogStateextends Object
Decides when a thin-pool warning is worth repeating.

Pure so the repetition policy is unit-testable without a router, and so the policy is stated once rather than implied by wherever a log call happens to sit.

The executor calls into this path on every tick, several times a second, while a pool's healthy count changes on the order of minutes. Warning per call reprinted one unchanged value hundreds of times a minute, which both buries the surrounding build failures and carries no information a single line did not already carry. Logging on change makes the sequence itself the signal: 3/8 -> 2/8 -> 1/3 -> recovered.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Sentinel for "no thin-pool warning emitted yet".
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Per-pool state for rate-limiting the thin-pool warnings.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    static String
    formatThinPool(String poolName, int healthy, int target)
    Format the thin-pool warning body.
    static boolean
    shouldLog(int lastWarned, int healthy)
    Whether a thin-pool warning should be emitted for the observed healthy count.

    Methods inherited from class Object

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

    • NEVER_WARNED

      public static final int NEVER_WARNED
      Sentinel for "no thin-pool warning emitted yet".
      See Also:
  • Constructor Details

    • ThinPoolLogState

      private ThinPoolLogState()
      Per-pool state for rate-limiting the thin-pool warnings.
  • Method Details

    • shouldLog

      public static boolean shouldLog(int lastWarned, int healthy)
      Whether a thin-pool warning should be emitted for the observed healthy count.

      Logs the first observation, then only when the count differs from the last one logged. Returning true for a repeated value would reintroduce the flood; suppressing a genuine return to a previously seen value would hide a regression-then-recovery cycle, so any difference counts as news.

      Parameters:
      lastWarned - value passed to the previous call, or NEVER_WARNED if none has been logged yet
      healthy - current healthy tunnel count, which may be 0
      Returns:
      true if this state has not been logged before
    • formatThinPool

      public static String formatThinPool(String poolName, int healthy, int target)
      Format the thin-pool warning body.

      Pure, so the wording is unit-testable and cannot drift from the counts the policy decides on.

      Parameters:
      poolName - pool name as produced by TunnelPool.toString()
      healthy - current healthy tunnel count
      target - desired healthy tunnel count
      Returns:
      a single-line message suitable for WARN