Class BreakpointMatcherRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all registered breakpoints.entries()Returns a snapshot of all registered breakpoints in registration order.findMatch(RequestDefinition request, BreakpointPhase phase) Finds the first registered breakpoint whose phases contain the given phase AND whose prebuilt matcher matches the given request.static BreakpointMatcherRegistryregister(RequestDefinition matcher, Set<BreakpointPhase> phases, String clientId, Configuration configuration, MockServerLogger logger) Registers a new breakpoint matcher with a required owner clientId.register(RequestDefinition matcher, Set<BreakpointPhase> phases, Configuration configuration, MockServerLogger logger) Registers a new breakpoint matcher without an owner client (for tests only).booleanRemoves a breakpoint by id.intremoveByClientId(String clientId) Removes all breakpoints owned by the given callback client.intsize()Number of currently registered breakpoints.
-
Constructor Details
-
BreakpointMatcherRegistry
public BreakpointMatcherRegistry()
-
-
Method Details
-
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 againstphases- the set of phases at which matching exchanges should breakconfiguration- 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
clientIdidentifies 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 againstphases- the set of phases at which matching exchanges should breakclientId- 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
Finds the first registered breakpoint whose phases contain the given phase AND whose prebuilt matcher matches the given request.Returns
nullif 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 againstphase- the phase to check- Returns:
- the first matching
BreakpointMatcher, ornull
-
remove
Removes a breakpoint by id.- Returns:
- true if the breakpoint was found and removed
-
removeByClientId
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
Returns a snapshot of all registered breakpoints in registration order. -
size
public int size()Number of currently registered breakpoints.
-