Class LocalHandlerRegistry
- All Implemented Interfaces:
HandlerRegistry, HasLocalHandlers
HandlerRegistry that manages and dispatches local message handlers — i.e.,
handlers that are invoked directly in the publishing thread without involving the Fluxzero Runtime.
The LocalHandlerRegistry only registers and invokes handlers that meet the criteria for local handling. These
include:
- Methods explicitly annotated with
LocalHandler - Handlers defined inside a message payload class (e.g., query or command) not annotated with
TrackSelf
This mechanism is useful for bypassing asynchronous tracking and Fluxzero Runtime involvement when immediate, in-process execution is preferred — such as for fast local queries, synchronous command handlers, or test scenarios.
Self-Handlers
If a message's payload type defines a handler method (e.g., @HandleQuery) and is not marked
with TrackSelf, then that handler is considered a "self-handler" and is treated as local. These handlers are
lazily constructed by the HandlerFactory and automatically included during message dispatch.
Fallback to Fluxzero Runtime
If no local handlers are found for a given message, it will not be processed in the publishing thread. Instead:- The message will be published to the Fluxzero Runtime using the appropriate gateway
- It will be logged so that remote trackers or consumers can handle it asynchronously
This ensures consistent delivery semantics while giving applications control over what is handled locally.
Thread Safety
Registered handlers are stored in aCopyOnWriteArrayList, making the registry
safe for concurrent usage and dynamic handler registration.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerRegistry
HandlerRegistry.MergedHandlerRegistry, HandlerRegistry.NoOpHandlerRegistry -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanHandle(DeserializingMessage message) Returns whether this registry has a local handler that can process the given message.protected List<Handler<DeserializingMessage>> getLocalHandlers(DeserializingMessage message) Returns the full list of handlers that should be used to process the given message.handle(DeserializingMessage message) Attempts to handle the given message using local handlers.booleanhandleLocal(LocalExecution execution) Attempts payload-first local handling and writes the outcome into the reusable execution frame.handleResult(DeserializingMessage message) Attempts to handle the message locally while preserving a synchronously returned value as a direct value.handleResult(LocalHandlerInput input) Attempts to handle a lazy local input.booleanIndicates whether any local handlers are currently registered for this gateway.protected booleanlogMessage(HandlerDescriptor invoker) Determines whether a handler allows its message to be sent to the Fluxzero Runtime.registerHandler(Object target, HandlerFilter handlerFilter) Registers a handler object, including only those methods that match the providedHandlerFilter.voidsetSelfHandlerFilter(@NonNull HandlerFilter selfHandlerFilter) Sets a custom filter to control whether a handler method is considered a local handler for the current application.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerRegistry
andThen, orThenMethods inherited from interface HasLocalHandlers
registerHandler
-
Constructor Details
-
LocalHandlerRegistry
public LocalHandlerRegistry()
-
-
Method Details
-
hasLocalHandlers
public boolean hasLocalHandlers()Description copied from interface:HasLocalHandlersIndicates whether any local handlers are currently registered for this gateway.- Specified by:
hasLocalHandlersin interfaceHasLocalHandlers- Returns:
trueif local handlers are present,falseotherwise
-
registerHandler
Description copied from interface:HasLocalHandlersRegisters a handler object, including only those methods that match the providedHandlerFilter.This method offers fine-grained control over which handler methods are registered, based on custom logic applied to method annotations and/or signatures.
- Specified by:
registerHandlerin interfaceHasLocalHandlers- Parameters:
target- the handler object containing annotated methodshandlerFilter- the filter used to determine which methods should be registered- Returns:
- a
Registrationwhich can be used to unregister the handlers
-
setSelfHandlerFilter
Description copied from interface:HasLocalHandlersSets a custom filter to control whether a handler method is considered a local handler for the current application. This is typically used internally to ensure that handlers are associated with the correct application or component.- Specified by:
setSelfHandlerFilterin interfaceHasLocalHandlers- Parameters:
selfHandlerFilter- aHandlerFilterto apply to registered handlers
-
handleResult
Description copied from interface:HandlerRegistryAttempts to handle the message locally while preserving a synchronously returned value as a direct value.The default adapts
HandlerRegistry.handle(DeserializingMessage)and therefore represents a handled result as a future. Implementations may override this method when they can retain synchronous completion.- Specified by:
handleResultin interfaceHandlerRegistry- Parameters:
message- the message to dispatch- Returns:
- the local handling result, including an explicit not-handled result when no handler matches
-
handleResult
Description copied from interface:HandlerRegistryAttempts to handle a lazy local input.The default materializes the message and delegates to
HandlerRegistry.handleResult(DeserializingMessage). Implementations that support payload-first handling may override this method.- Specified by:
handleResultin interfaceHandlerRegistry- Parameters:
input- the local handler input- Returns:
- the local handling result
-
handleLocal
Description copied from interface:HandlerRegistryAttempts 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”.- Specified by:
handleLocalin interfaceHandlerRegistry- 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
-
handle
Description copied from interface:HandlerRegistryAttempts to handle the given message using local handlers.- Specified by:
handlein interfaceHandlerRegistry- Parameters:
message- the deserialized message to dispatch- Returns:
- an optional future containing the result, or empty if no handler was found
-
canHandle
Description copied from interface:HandlerRegistryReturns whether this registry has a local handler that can process the given message.- Specified by:
canHandlein interfaceHandlerRegistry- Parameters:
message- the message to inspect- Returns:
trueif a local handler can handle the message,falseotherwise
-
getLocalHandlers
Returns the full list of handlers that should be used to process the given message.This may include a self-handler if the message is a request or schedule type.
-
logMessage
Determines whether a handler allows its message to be sent to the Fluxzero Runtime.
-