Class BreakpointMatcherRegistry

java.lang.Object
org.mockserver.mock.breakpoint.BreakpointMatcherRegistry

public class BreakpointMatcherRegistry extends Object
Process-wide registry of breakpoint matchers. Each entry describes a request matcher and a set of phases; when a forwarded exchange matches, it is paused at the corresponding phase for interactive inspection/modification.

Thread-safe via a single CopyOnWriteArrayList as the source of truth. This is ideal for the access pattern here: reads (findMatch(org.mockserver.model.RequestDefinition, org.mockserver.mock.breakpoint.BreakpointPhase)) are frequent and on the data plane (including the Netty event loop), while writes (register(org.mockserver.model.RequestDefinition, java.util.Set<org.mockserver.mock.breakpoint.BreakpointPhase>, org.mockserver.configuration.Configuration, org.mockserver.logging.MockServerLogger), remove(java.lang.String), clear()) are rare control-plane operations. A single structure means register/remove/clear are atomic with respect to a concurrent findMatch(org.mockserver.model.RequestDefinition, org.mockserver.mock.breakpoint.BreakpointPhase) — there is no window in which two backing collections can disagree.

Event-loop safety: findMatch(org.mockserver.model.RequestDefinition, org.mockserver.mock.breakpoint.BreakpointPhase) is designed to be called on the Netty event loop for stream-frame phases. When the registry is empty, it returns null immediately via a single CopyOnWriteArrayList.isEmpty() check (zero allocation). When non-empty, it iterates a stable snapshot of the prebuilt matchers without any blocking or allocation beyond the matcher's own match logic.

  • Constructor Details

    • BreakpointMatcherRegistry

      public BreakpointMatcherRegistry()
  • Method Details

    • getInstance

      public static BreakpointMatcherRegistry getInstance()
    • register

      public String register(RequestDefinition matcher, Set<BreakpointPhase> phases, Configuration configuration, MockServerLogger logger)
      Registers a new breakpoint matcher without an owner client (for tests only). In production, the REST endpoint requires a clientId; this overload exists for unit tests that exercise the registry directly.
      Parameters:
      matcher - the request definition to match against
      phases - the set of phases at which matching exchanges should break
      configuration - the active server configuration (passed to MatcherBuilder)
      logger - the server logger (passed to MatcherBuilder)
      Returns:
      the assigned UUID id for the registered breakpoint
    • register

      public String register(RequestDefinition matcher, Set<BreakpointPhase> phases, String clientId, Configuration configuration, MockServerLogger logger)
      Registers a new breakpoint matcher with a required owner clientId.

      The clientId identifies the callback WebSocket client that owns this breakpoint. Matched exchanges are dispatched over the callback WebSocket to that client for interactive resolution.

      Parameters:
      matcher - the request definition to match against
      phases - the set of phases at which matching exchanges should break
      clientId - the callback WS client that owns this breakpoint (required in production)
      configuration - the active server configuration (passed to MatcherBuilder)
      logger - the server logger (passed to MatcherBuilder)
      Returns:
      the assigned UUID id for the registered breakpoint
    • findMatch

      public BreakpointMatcher findMatch(RequestDefinition request, BreakpointPhase phase)
      Finds the first registered breakpoint whose phases contain the given phase AND whose prebuilt matcher matches the given request.

      Returns null if the registry is empty or no matcher matches. This method is allocation-light and safe to call on the Netty event loop.

      Parameters:
      request - the inbound request to match against
      phase - the phase to check
      Returns:
      the first matching BreakpointMatcher, or null
    • remove

      public boolean remove(String id)
      Removes a breakpoint by id.
      Returns:
      true if the breakpoint was found and removed
    • removeByClientId

      public int removeByClientId(String clientId)
      Removes all breakpoints owned by the given callback client. Called when a WebSocket client disconnects so its breakpoints are cleaned up.
      Parameters:
      clientId - the client id whose breakpoints should be removed
      Returns:
      the number of breakpoints removed
    • clear

      public void clear()
      Clears all registered breakpoints.
    • entries

      public List<BreakpointMatcher> entries()
      Returns a snapshot of all registered breakpoints in registration order.
    • size

      public int size()
      Number of currently registered breakpoints.