Class Invocation
This class enables consistent tagging and correlation of all side effects (e.g. metrics, queries, event sourcing,
message publication) produced during the execution of a handler. Each invocation is assigned a unique
invalid reference
invocation ID
Automatic Invocation Wrapping
The Flux Capacitor client automatically wraps all handler invocations using this class. This includes:- Local handlers (i.e. message handling in the publishing thread)
- Tracked handlers (i.e. message tracking via the Flux platform)
As a result, developers typically do not need to call performInvocation(Callable)
directly,
unless they are manually invoking a handler outside of the Flux infrastructure.
Usage
When used manually, wrap handler logic withperformInvocation(Callable)
to activate an invocation context:
Invocation.performInvocation(() -> {
// handler logic
FluxCapacitor.publishEvent(new SomeEvent());
return result;
});
This ensures:
- A consistent invocation ID is available throughout the thread
- Any emitted messages, metrics, or queries can include that ID as a correlation token
- Callbacks can be registered via
whenHandlerCompletes(BiConsumer)
to react to success/failure
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Invocation
Returns the currentInvocation
bound to this thread, ornull
if none exists.static <V> V
performInvocation
(Callable<V> callable) Wraps the givenCallable
in an invocation context.static Registration
whenHandlerCompletes
(BiConsumer<Object, Throwable> callback) Registers a callback to be executed when the current handler invocation completes.
-
Constructor Details
-
Invocation
public Invocation()
-
-
Method Details
-
performInvocation
Wraps the givenCallable
in an invocation context.This method ensures that callbacks registered via
whenHandlerCompletes(BiConsumer)
are executed upon completion of the callable.- Parameters:
callable
- the task to run- Returns:
- the callable result
-
getCurrent
Returns the currentInvocation
bound to this thread, ornull
if none exists. -
whenHandlerCompletes
Registers a callback to be executed when the current handler invocation completes.If no invocation is active, the callback is executed immediately with
null
values.- Parameters:
callback
- the handler result/error consumer- Returns:
- a
Registration
handle to cancel the callback
-