Interface HandlerRegistry
- All Superinterfaces:
HasLocalHandlers
- All Known Implementing Classes:
HandlerRegistry.MergedHandlerRegistry, HandlerRegistry.NoOpHandlerRegistry, LocalHandlerRegistry
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 usingHasLocalHandlers.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
UseandThen(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
HandlerRegistry.NoOpHandlerRegistry— a stub that does nothing, always returns emptyHandlerRegistry.MergedHandlerRegistry— combines two registries into one
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classCombines twoHandlerRegistryinstances into one.static enumA no-op handler registry that performs no registration or dispatch. -
Method Summary
Modifier and TypeMethodDescriptiondefault HandlerRegistryandThen(HandlerRegistry next) Creates a composite registry that invokes both this and the given registry.handle(DeserializingMessage message) Attempts to handle the given message using local handlers.static HandlerRegistrynoOp()A no-op registry that does not register or invoke any handlers.default HandlerRegistryorThen(HandlerRegistry next) Creates a fallback registry that only invokes the given registry if this one yields no result.Methods inherited from interface HasLocalHandlers
hasLocalHandlers, registerHandler, registerHandler, setSelfHandlerFilter
-
Method Details
-
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
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
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
-