Class DisableMetrics

java.lang.Object
io.fluxzero.sdk.tracking.metrics.DisableMetrics
All Implemented Interfaces:
DispatchInterceptor, BatchInterceptor, HandlerDecorator, HandlerInterceptor

public class DisableMetrics extends Object implements HandlerInterceptor, BatchInterceptor, DispatchInterceptor
Interceptor that disables the dispatch of outbound MessageType.METRICS messages.

This class implements HandlerInterceptor, BatchInterceptor, and DispatchInterceptor, allowing it to wrap individual message handlers, batch execution by message trackers, or consumer-scoped dispatch interception directly. When applied as a handler or batch interceptor, it uses an AdhocDispatchInterceptor to suppress the publication of metrics within the scope of the handler or batch execution.

Typical usage includes applying this interceptor to consumers that should not emit metrics, such as utility consumers that operate in high-frequency or low-signal environments.

Example Usage

To apply this interceptor, annotate your handler class using @Consumer(batchInterceptors = DisableMetrics.class) or @Consumer(handlerInterceptors = DisableMetrics.class) or @Consumer(dispatchInterceptors = DisableMetrics.class):
@Consumer(handlerInterceptors = DisableMetrics.class)
public class OrderHandler {

    @HandleEvent
    public void on(OrderPlaced event) {
        // Any outbound metrics from this handler will be suppressed
    }
}
See Also:
  • Constructor Details

    • DisableMetrics

      public DisableMetrics()
  • Method Details

    • interceptDispatch

      public Message interceptDispatch(Message message, MessageType messageType, String topic)
      Description copied from interface: DispatchInterceptor
      Intercepts the dispatch of a message before it is serialized and published or locally handled.

      You may modify the message or return null to block dispatching. Throwing an exception also prevents dispatching.

      Specified by:
      interceptDispatch in interface DispatchInterceptor
      Parameters:
      message - the message to be dispatched
      messageType - the type of the message (e.g., COMMAND, EVENT, etc.)
      topic - the target topic or null if not applicable
      Returns:
      the modified message, the same message, or null to prevent dispatch
    • intercept

      public Consumer<MessageBatch> intercept(Consumer<MessageBatch> consumer, Tracker tracker)
      Description copied from interface: BatchInterceptor
      Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.
      Specified by:
      intercept in interface BatchInterceptor
      Parameters:
      consumer - the original consumer that processes the MessageBatch
      tracker - the tracker invoking this interceptor
      Returns:
      a wrapped consumer with additional behavior
    • interceptHandling

      public Function<DeserializingMessage, Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker)
      Description copied from interface: HandlerInterceptor
      Intercepts the message handling logic.

      The function parameter represents the next step in the handling chain— typically the actual message handler. The invoker provides metadata and invocation logic for the underlying handler method.

      Within this method, an interceptor may:

      • Modify the DeserializingMessage before passing it to the handler
      • Bypass the handler entirely and return a value directly
      • Wrap the result after the handler is invoked

      Note: Interceptors may return a different DeserializingMessage, but it must be compatible with a handler method in the same target class. If no suitable handler is found, an exception will be thrown.

      Specified by:
      interceptHandling in interface HandlerInterceptor
      Parameters:
      function - the next step in the handler chain (typically the handler itself)
      invoker - the metadata and execution strategy for the actual handler method
      Returns:
      a decorated function that wraps handling behavior
    • prepare

      Description copied from interface: HandlerInterceptor
      Prepares this interceptor for a specific handler method.

      The returned interceptor is cached and reused concurrently for invocations with the same stable handler metadata. Implementations may use this hook to resolve annotation- or signature-based policy once while keeping message-dependent decisions inside HandlerInterceptor.PreparedHandlerInterceptor.interceptHandling(DeserializingMessage, HandlerDescriptor, BiFunction, HandlerInterceptor.PreparedHandlerFunction).

      The default adapter preserves the existing HandlerInterceptor.interceptHandling(Function, HandlerInvoker) contract and deliberately disables the reusable HandlerMethod path. Custom interceptors therefore retain their current behavior unless they explicitly opt into preparation.

      Specified by:
      prepare in interface HandlerInterceptor
      Parameters:
      handler - stable metadata for the handler method
      Returns:
      a thread-safe prepared interceptor
    • supportsPreparation

      public boolean supportsPreparation()
      Description copied from interface: HandlerInterceptor
      Indicates whether this interceptor opts into the prepared, mergeable handler wrapper.

      The default is false, preserving the exact wrapper behavior of existing custom interceptors. An interceptor should return true only when HandlerInterceptor.prepare(HandlerDescriptor) returns a thread-safe plan that fully represents its handling behavior. If a subclass overrides only the legacy HandlerInterceptor.interceptHandling(Function, HandlerInvoker) method, the legacy wrapper is retained automatically.

      Specified by:
      supportsPreparation in interface HandlerInterceptor
      Returns:
      true when this interceptor may be merged into a prepared wrapper