Class MutableHandler<M>
java.lang.Object
io.fluxcapacitor.javaclient.tracking.handling.MutableHandler<M>
- Type Parameters:
M
- the message type this handler supports
- All Implemented Interfaces:
Handler<M>
A specialized
Handler
that maintains and mutates an internal delegate instance.
This handler is designed for use cases where the state of the handler may evolve dynamically across message invocations. It is particularly suited for temporarily scoped objects (e.g. sagas, user sessions).
Behavior
When a handler method returns an instance of the handler’s target class, this instance is stored as the new delegate:
Object result = method.invoke(target);
if (result instanceof MyHandler) {
target = result; // promote new version
}
If the method returns null
and the method's return type matches the target class, the internal
target is cleared, and any registered delete callbacks are triggered.
Lifecycle Hooks
A delete callback can be registered usingonDelete(Runnable)
to perform cleanup when
the handler deletes its state (i.e., returns null
).-
Nested Class Summary
Nested classes/interfaces inherited from interface io.fluxcapacitor.common.handling.Handler
Handler.DelegatingHandler<M>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetInvoker
(M message) Returns aHandlerInvoker
capable of processing the given message, if available.boolean
isEmpty()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.handling.Handler
getTargetClass, or
-
Constructor Details
-
MutableHandler
public MutableHandler()
-
-
Method Details
-
getInvoker
Description copied from interface:Handler
Returns aHandlerInvoker
capable of processing the given message, if available.- Specified by:
getInvoker
in interfaceHandler<M>
- Parameters:
message
- the message to be handled- Returns:
- an optional
HandlerInvoker
if this handler can handle the message; otherwiseOptional.empty()
-
instantiateTarget
-
isEmpty
public boolean isEmpty() -
onDelete
-