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 Flux platform.
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 Flux platform 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 Flux Platform
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 Flux platform 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 io.fluxcapacitor.javaclient.tracking.handling.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.boolean
Indicates whether any local handlers are currently registered for this gateway.protected boolean
logMessage
(HandlerInvoker invoker) Determines whether a handler allows its message to be sent to the Flux platform.registerHandler
(Object target, HandlerFilter handlerFilter) Registers a handler object, including only those methods that match the providedHandlerFilter
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerRegistry
andThen, orThen
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HasLocalHandlers
registerHandler, setSelfHandlerFilter
-
Constructor Details
-
LocalHandlerRegistry
public LocalHandlerRegistry()
-
-
Method Details
-
hasLocalHandlers
public boolean hasLocalHandlers()Description copied from interface:HasLocalHandlers
Indicates whether any local handlers are currently registered for this gateway.- Specified by:
hasLocalHandlers
in interfaceHasLocalHandlers
- Returns:
true
if local handlers are present,false
otherwise
-
registerHandler
Description copied from interface:HasLocalHandlers
Registers 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:
registerHandler
in interfaceHasLocalHandlers
- Parameters:
target
- the handler object containing annotated methodshandlerFilter
- the filter used to determine which methods should be registered- Returns:
- a
Registration
which can be used to unregister the handlers
-
handle
Description copied from interface:HandlerRegistry
Attempts to handle the given message using local handlers.- Specified by:
handle
in 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 Flux platform.
-