Class RecursivePublicationGuard

java.lang.Object
io.fluxzero.sdk.publishing.RecursivePublicationGuard
All Implemented Interfaces:
DispatchInterceptor

public class RecursivePublicationGuard extends Object implements DispatchInterceptor
Prevents runaway recursive publication loops by carrying a publication depth in message metadata.
  • Field Details

  • Constructor Details

    • RecursivePublicationGuard

      public RecursivePublicationGuard()
    • RecursivePublicationGuard

      public RecursivePublicationGuard(int maxPublicationDepth)
  • 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
    • prepareLocalDispatch

      public PreparedLocalDispatch prepareLocalDispatch(LocalDispatchDescriptor descriptor)
      Description copied from interface: DispatchInterceptor
      Prepares this interceptor for repeated local dispatches with the same static message characteristics.

      This optional method lets local handling apply an interceptor without creating a complete Message first. Implementations must preserve the observable behavior of DispatchInterceptor.interceptDispatch(Message, MessageType, String). Return null when that is not possible; Fluxzero will then use the regular dispatch path for this payload type.

      The returned policy may be cached and used concurrently. State belonging to a single dispatch must be stored in the supplied LocalExecution, not in the policy itself.

      Specified by:
      prepareLocalDispatch in interface DispatchInterceptor
      Parameters:
      descriptor - payload class, message type, and topic shared by the local dispatches
      Returns:
      a thread-safe prepared policy, or null to use regular message-based dispatch
    • nextDepth

      protected int nextDepth(MessageType messageType)
    • readDepth

      protected int readDepth(Metadata metadata)
    • parseDepth

      protected int parseDepth(String value)