Class DefaultHandler<M>

java.lang.Object
io.fluxzero.common.handling.DefaultHandler<M>
All Implemented Interfaces:
Handler<M>

public class DefaultHandler<M> extends Object implements Handler<M>
Default implementation of the Handler interface.
  • Constructor Details

  • Method Details

    • forTarget

      public static <M> DefaultHandler<M> forTarget(Class<?> targetClass, Object target, HandlerMatcher<Object,M> handlerMatcher)
    • getTargetClass

      public Class<?> getTargetClass()
      Description copied from interface: Handler
      Returns the class of the handler's target object. This may be used for reflective operations, logging, or framework-level behavior.
      Specified by:
      getTargetClass in interface Handler<M>
      Returns:
      the class of the handler's target
    • getInvoker

      public Optional<HandlerInvoker> getInvoker(M message)
      Description copied from interface: Handler
      Returns a HandlerInvoker capable of processing the given message, if available.
      Specified by:
      getInvoker in interface Handler<M>
      Parameters:
      message - the message to be handled
      Returns:
      an optional HandlerInvoker if this handler can handle the message; otherwise Optional.empty()
    • getInvokerOrNull

      public HandlerInvoker getInvokerOrNull(M message)
      Description copied from interface: Handler
      Returns a HandlerInvoker capable of processing the given message, or null when unavailable.

      This is a lower-allocation counterpart to Handler.getInvoker(Object) for internal hot paths. Implementations that can resolve an invoker without creating an Optional should override this method.

      Specified by:
      getInvokerOrNull in interface Handler<M>
      Parameters:
      message - the message to be handled
      Returns:
      an invoker if this handler can handle the message; null otherwise
    • getHandlerMethodOrNull

      public HandlerMethod<M> getHandlerMethodOrNull(M message)
      Description copied from interface: Handler
      Returns a reusable HandlerMethod capable of processing the given message, or null when unavailable.

      This is an optional lower-allocation path for handlers whose target and method plan can be reused across messages. Implementations that cannot expose a stable method should return null and rely on Handler.getInvokerOrNull(Object).

      Specified by:
      getHandlerMethodOrNull in interface Handler<M>
      Parameters:
      message - the message to be handled
      Returns:
      a handler method if this handler can handle the message through a reusable method; null otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object