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 TypeMethodDescriptionprotected 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.booleanIndicates whether any local handlers are currently registered for this gateway.protected booleanlogMessage(HandlerInvoker 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.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, setSelfHandlerFilter
-
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
-
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
-
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 type.
-
logMessage
Determines whether a handler allows its message to be sent to the Fluxzero Runtime.
-