Class ResyncDetector

java.lang.Object
com.vaadin.observability.micrometer.ResyncDetector

public final class ResyncDetector extends Object
Prototype detector that classifies an incoming UIDL request body as a normal message, a re-sent (duplicate) message, or a full resynchronization request, and records a MeterNames.RESYNC counter for the two recovery cases.

The classification mirrors Flow's own server-side logic in ServerRpcHandler#handleRpc, which is otherwise invisible to the kit because the relevant ClientResentPayloadException and ResynchronizationRequiredException are caught internally by UidlRequestHandler and never surface to a VaadinRequestInterceptor:

  • Resync — the request carries ApplicationConstants.RESYNCHRONIZE_ID= true. This is checked first because a resync request also carries a normally advancing clientId.
  • Resend — the request's ApplicationConstants.CLIENT_TO_SERVER_ID is not greater than the last one seen for the same UI, i.e. the client re-sent a message the server had already processed (Flow compares against lastProcessedClientToServerId + 1).

This is an approximation of Flow's own test. Flow only replays a cached response when clientId == lastProcessedClientToServerId and the message hash matches, discarding still-older ids as out-of-order. The message hash is not exposed to the kit, so we cannot discriminate on it and count every clientId <= previous as a resend; this may over-report relative to what Flow actually replays.

The detector is stateless: the caller supplies the previously seen clientId and stores the ResyncDetector.Result.lastClientId() returned here (e.g. as an HTTP session attribute keyed by UI id), so there is no unbounded per-session state held inside the kit.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Classification of a single UIDL request.
    static final record 
    Result of classifying a request.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    No clientId has been seen yet for a UI.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ResyncDetector(io.micrometer.core.instrument.MeterRegistry registry)
    Creates a detector recording into the given registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    inspect(String requestBody, int previousClientId)
    Classifies a UIDL request body and records a counter for resend/resync events.

    Methods inherited from class java.lang.Object

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

    • NO_CLIENT_ID

      public static final int NO_CLIENT_ID
      No clientId has been seen yet for a UI.
      See Also:
  • Constructor Details

    • ResyncDetector

      public ResyncDetector(io.micrometer.core.instrument.MeterRegistry registry)
      Creates a detector recording into the given registry.
      Parameters:
      registry - the meter registry, not null
  • Method Details

    • inspect

      public ResyncDetector.Result inspect(String requestBody, int previousClientId)
      Classifies a UIDL request body and records a counter for resend/resync events.
      Parameters:
      requestBody - the raw UIDL request body (JSON); may be null or empty
      previousClientId - the last clientId seen for this UI, or NO_CLIENT_ID if none
      Returns:
      the classification and the clientId to remember next