Class FluxzeroInterceptor
java.lang.Object
io.fluxzero.sdk.tracking.FluxzeroInterceptor
- All Implemented Interfaces:
BatchInterceptor
A
BatchInterceptor that ensures the correct Fluxzero instance is bound to the current thread for
the duration of a MessageBatch.
This interceptor enables the use of Fluxzero's static convenience methods during message processing. It
ensures that operations like Fluxzero.sendCommand(Object) or Fluxzero.publishEvent(Object)
resolve the correct runtime context even in multithreaded applications.
Thread-Local Binding
- Sets
Fluxzero.instancebefore batch processing begins. - Restores the previous thread-local instance (if any) after processing completes.
- Ensures thread isolation across different trackers and test threads.
Runtime Expectations
- In a typical production application, there is a single
Fluxzeroinstance used throughout the JVM. - This instance is often registered via
Fluxzero.applicationInstanceand used as a fallback when no thread-local binding is available. - Multiple instances may occur in rare cases—such as connecting to multiple Fluxzero Runtimes—or during unit/integration testing scenarios involving multiple test clients or parallel test execution.
- This interceptor ensures that each batch is processed with the appropriate context, even in such edge cases.
Lifecycle
- This interceptor is registered automatically in most Fluxzero configurations.
- In custom or manual configurations (e.g., test setups), it may need to be included explicitly.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface BatchInterceptor
BatchInterceptor.FilterPreserving -
Field Summary
Fields inherited from interface BatchInterceptor
defaultInterceptors -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.fluxzero.common.api.tracking.ConsumerFilterdescribeConsumerFilter(io.fluxzero.common.api.tracking.ConsumerFilter downstream) Describes serialized inputs needed by this interceptor and its downstream consumer.Consumer<io.fluxzero.common.api.tracking.MessageBatch> Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BatchInterceptor
andThen, shutdown
-
Constructor Details
-
FluxzeroInterceptor
public FluxzeroInterceptor()
-
-
Method Details
-
intercept
public Consumer<io.fluxzero.common.api.tracking.MessageBatch> intercept(Consumer<io.fluxzero.common.api.tracking.MessageBatch> consumer, Tracker tracker) Description copied from interface:BatchInterceptorIntercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.- Specified by:
interceptin interfaceBatchInterceptor- Parameters:
consumer- the original consumer that processes theMessageBatchtracker- the tracker invoking this interceptor- Returns:
- a wrapped consumer with additional behavior
-
describeConsumerFilter
public io.fluxzero.common.api.tracking.ConsumerFilter describeConsumerFilter(io.fluxzero.common.api.tracking.ConsumerFilter downstream) Description copied from interface:BatchInterceptorDescribes serialized inputs needed by this interceptor and its downstream consumer. The default is unrestricted because interceptors can transform messages or require inputs that no handler accepts. Implementations may returndownstreamonly when excluded inputs are irrelevant to their behavior and they never transform an excluded input into one the downstream filter admits. Custom inverse projections describe the input side of a transformation; this method runs after serializer/upcaster projection.- Specified by:
describeConsumerFilterin interfaceBatchInterceptor
-