Class RecoveryAttemptRegistry

java.lang.Object
org.mockserver.mock.action.http.RecoveryAttemptRegistry

public class RecoveryAttemptRegistry extends Object
Node-local, stateful per-key attempt counter for the RecoverAfter recovery primitive. When a response's recoverAfter is configured with an idempotencyHeader, the failure window is keyed per (expectationId, header-value) so that each distinct idempotency key gets its own independent 1..K window, while requests sharing a key share one counter (model a single logical retry sequence).

The default (no idempotency header) recovery path does NOT touch this registry — it counts off the expectation's own match count, so it adds zero new state and zero overhead. This registry is only used on the explicit keyed path.

Bounded against memory exhaustion. Idempotency-key values are client-supplied (typically fresh UUIDs), so an unbounded map would grow without limit and exhaust the heap. The registry is therefore a thread-safe bounded registry — a synchronized access-ordered LinkedHashMap that evicts the least-recently-used key once MAX_SIZE (10,000) keys are held, mirroring DnsIntentRegistry. A cold evicted key simply restarts its failure window at attempt 1 on its next request, which matches reset() semantics. nextAttempt(java.lang.String, java.lang.String) remains an atomic per-key increment, safe under concurrent requests.

v1 is node-local (clustering is deferred — like ScenarioManager, the registry can later move behind the StateBackend SPI). State is cleared on server reset (see HttpState.reset()).

  • Constructor Details

    • RecoveryAttemptRegistry

      public RecoveryAttemptRegistry()
  • Method Details

    • getInstance

      public static RecoveryAttemptRegistry getInstance()
    • nextAttempt

      public int nextAttempt(String expectationId, String key)
      Record and return the 1-based attempt number for the given (expectationId, key) pair. The first call for a pair returns 1, the next 2, and so on. If the pair was evicted because the registry was over capacity, counting restarts from 1.
      Parameters:
      expectationId - the matched expectation's id (namespaces the counter so distinct expectations sharing an idempotency-key value do not collide)
      key - the idempotency-key value from the request header
      Returns:
      the 1-based attempt count for this pair
    • reset

      public void reset()
      Clear all attempt state. Called on server reset and for test isolation.