Interface HandlerRegistry
- All Superinterfaces:
HasLocalHandlers
- All Known Implementing Classes:
HandlerRegistry.MergedHandlerRegistry, HandlerRegistry.NoOpHandlerRegistry, LocalHandlerRegistry
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.default booleancanHandle(DeserializingMessage message) Returns whether this registry has a local handler that can process the given message.handle(DeserializingMessage message) Attempts to handle the given message using local handlers.default Optional<CompletableFuture<Object>> handle(DeserializingMessage message, boolean allowExternalPublication) Attempts to handle the message locally while controlling optional SDK-managed external publication.default booleanhandleLocal(LocalExecution execution) Attempts payload-first local handling and writes the outcome into the reusable execution frame.default LocalHandlerResulthandleResult(DeserializingMessage message) Attempts to handle the message locally while preserving a synchronously returned value as a direct value.default LocalHandlerResulthandleResult(DeserializingMessage message, boolean allowExternalPublication) Attempts to handle the message locally while controlling optional SDK-managed external publication.default LocalHandlerResulthandleResult(LocalHandlerInput input) Attempts to handle a lazy local input.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.default booleanReturns whether this registry supports messages whose external-only dispatch side effects are deferred until local handler selection has completed.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
-
handle
default Optional<CompletableFuture<Object>> handle(DeserializingMessage message, boolean allowExternalPublication) Attempts to handle the message locally while controlling optional SDK-managed external publication.The default delegates to
handle(DeserializingMessage)because custom registries are assumed to invoke local handlers only. Registries that optionally mirror locally handled messages externally should honorallowExternalPublication.- Parameters:
message- the deserialized message to dispatchallowExternalPublication- whether SDK-managed mirroring may publish the message externally- Returns:
- an optional future containing the result, or empty if no handler was found
-
handleResult
Attempts to handle the message locally while preserving a synchronously returned value as a direct value.The default adapts
handle(DeserializingMessage)and therefore represents a handled result as a future. Implementations may override this method when they can retain synchronous completion.- Parameters:
message- the message to dispatch- Returns:
- the local handling result, including an explicit not-handled result when no handler matches
-
handleResult
default LocalHandlerResult handleResult(DeserializingMessage message, boolean allowExternalPublication) Attempts to handle the message locally while controlling optional SDK-managed external publication.- Parameters:
message- the message to dispatchallowExternalPublication- whether SDK-managed mirroring may publish the message externally- Returns:
- the local handling result
-
handleResult
Attempts to handle a lazy local input.The default materializes the message and delegates to
handleResult(DeserializingMessage). Implementations that support payload-first handling may override this method.- Parameters:
input- the local handler input- Returns:
- the local handling result
-
supportsDeferredExternalization
default boolean supportsDeferredExternalization()Returns whether this registry supports messages whose external-only dispatch side effects are deferred until local handler selection has completed.The default is
falseto preserve the contract of custom registries. Fluxzero's local registry overrides this because its handler and dispatch interceptor chains coordinate deferred externalization. -
handleLocal
Attempts payload-first local handling and writes the outcome into the reusable execution frame. Implementations that cannot preserve the lazy input returnfalse, causing the caller to use the canonical message-based path.This method is intended for Fluxzero registry implementations. A
falseresult means “use the regular path”, not “no handler exists”.- Parameters:
execution- the current local dispatch and destination for its result- Returns:
trueif this registry completed handler selection on the payload-first path;falseto use regular message-based handling
-
canHandle
Returns whether this registry has a local handler that can process the given message.- Parameters:
message- the message to inspect- Returns:
trueif a local handler can handle the message,falseotherwise
-
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
-