Interface HandlerRegistry

All Superinterfaces:
HasLocalHandlers
All Known Implementing Classes:
HandlerRegistry.MergedHandlerRegistry, HandlerRegistry.NoOpHandlerRegistry, LocalHandlerRegistry

public interface HandlerRegistry extends HasLocalHandlers
Interface for registering and invoking local message handlers.

A HandlerRegistry is responsible for managing one or more message handlers — including discovery, invocation, and filtering logic. It is a central abstraction in scenarios where handlers are registered programmatically (e.g. embedded services, tests, functional configurations).

Responsibilities

  • Registering local handler instances (e.g. beans, stateful components)
  • Dispatching messages to matching handlers
  • Composing multiple registries to form a combined resolution chain
  • Delegating filtering behavior via HandlerFilter

Usage

Handlers can be registered using HasLocalHandlers.registerHandler(Object) or HasLocalHandlers.registerHandler(Object, HandlerFilter). Message handling can be triggered manually via handle(DeserializingMessage).

 HandlerRegistry registry = ...;
 registry.registerHandler(new MyCommandHandler());

 registry.handle(myMessage).ifPresent(resultFuture -> {
     Object result = resultFuture.join();
     ...
 });
 

Composing Registries

Use andThen(HandlerRegistry) or orThen(HandlerRegistry) to chain multiple registries:
  • andThen: invokes both registries and merges results (e.g. for broadcasting)
  • orThen: invokes the second only if the first produces no result

 HandlerRegistry composite = registry1.orThen(registry2);
 

Built-in Implementations

See Also:
  • Method Details

    • noOp

      static HandlerRegistry noOp()
      A no-op registry that does not register or invoke any handlers.
    • handle

      Attempts to handle the given message using local handlers.
      Parameters:
      message - the deserialized message to dispatch
      Returns:
      an optional future containing the result, or empty if no handler was found
    • andThen

      default HandlerRegistry andThen(HandlerRegistry next)
      Creates a composite registry that invokes both this and the given registry.

      Results are merged via thenCombine() if both registries handle the message.

      Parameters:
      next - the registry to invoke second
      Returns:
      a combined registry
    • orThen

      default HandlerRegistry orThen(HandlerRegistry next)
      Creates a fallback registry that only invokes the given registry if this one yields no result.
      Parameters:
      next - the fallback registry
      Returns:
      a combined registry with short-circuiting behavior