Class DefaultTracking
java.lang.Object
io.fluxcapacitor.javaclient.tracking.DefaultTracking
- All Implemented Interfaces:
Tracking
,AutoCloseable
Default implementation of the
Tracking
interface that coordinates message tracking for a specific
MessageType
.
This class is responsible for:
- Assigning handler objects to appropriate
ConsumerConfiguration
s based on declared filters - Creating and managing
Tracker
instances for those consumers and their associated topics - Ensuring messages are deserialized, dispatched, and (if applicable) responded to with proper error handling
- Invoking handlers using the provided
HandlerFactory
andHandlerInvoker
- Integrating with
ResultGateway
to send back command/query/web responses when needed
Supports per-consumer batch interceptors and general batch processing logic, including:
- Functional and technical exception management with retry hooks
- Tracking exclusivity to prevent handlers from being assigned to multiple consumers simultaneously
- Internal shutdown coordination and pending message flushes via
close()
Typical Usage
This class is used internally when starting aFluxCapacitor.registerHandlers(List)
invocation
for a given MessageType
, and typically shouldn't be used directly by application developers.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shuts down all started trackers and waits briefly for asynchronous results (e.g. command responses) to complete.protected Consumer
<List<SerializedMessage>> createConsumer
(ConsumerConfiguration config, List<Handler<DeserializingMessage>> handlers) protected Optional
<HandlerInvoker> getInvoker
(DeserializingMessage message, Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected Object
handle
(DeserializingMessage message, HandlerInvoker h, Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected Object
processError
(Throwable e, DeserializingMessage message, HandlerInvoker h, Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected void
reportResult
(Object result, HandlerInvoker h, DeserializingMessage message, ConsumerConfiguration config) protected boolean
shouldSendResponse
(HandlerInvoker invoker, DeserializingMessage request, Object result, ConsumerConfiguration config) start
(FluxCapacitor fluxCapacitor, List<?> handlers) Starts tracking by assigning the given handlers to configured consumers and creating topic-specific or shared trackers.protected Registration
startTracking
(ConsumerConfiguration configuration, List<Handler<DeserializingMessage>> handlers, FluxCapacitor fluxCapacitor) protected void
stopTracker
(DeserializingMessage message, Handler<DeserializingMessage> handler, Throwable e) protected void
tryHandle
(DeserializingMessage message, Handler<DeserializingMessage> handler, ConsumerConfiguration config, boolean reportResult)
-
Constructor Details
-
DefaultTracking
public DefaultTracking()
-
-
Method Details
-
start
Starts tracking by assigning the given handlers to configured consumers and creating topic-specific or shared trackers.Throws a
TrackingException
if handlers can't be matched to consumers or if a consumer has already been started previously.- Specified by:
start
in interfaceTracking
- Parameters:
fluxCapacitor
- the owningFluxCapacitor
instancehandlers
- the handler instances to assign and activate- Returns:
- a
Registration
that can be used to stop all created trackers - Throws:
TrackingException
- if no consumer is found for a handler or if tracking has already been started
-
startTracking
protected Registration startTracking(ConsumerConfiguration configuration, List<Handler<DeserializingMessage>> handlers, FluxCapacitor fluxCapacitor) -
createConsumer
protected Consumer<List<SerializedMessage>> createConsumer(ConsumerConfiguration config, List<Handler<DeserializingMessage>> handlers) -
tryHandle
protected void tryHandle(DeserializingMessage message, Handler<DeserializingMessage> handler, ConsumerConfiguration config, boolean reportResult) -
getInvoker
protected Optional<HandlerInvoker> getInvoker(DeserializingMessage message, Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
handle
protected Object handle(DeserializingMessage message, HandlerInvoker h, Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
processError
protected Object processError(Throwable e, DeserializingMessage message, HandlerInvoker h, Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
reportResult
protected void reportResult(Object result, HandlerInvoker h, DeserializingMessage message, ConsumerConfiguration config) -
shouldSendResponse
protected boolean shouldSendResponse(HandlerInvoker invoker, DeserializingMessage request, Object result, ConsumerConfiguration config) -
stopTracker
protected void stopTracker(DeserializingMessage message, Handler<DeserializingMessage> handler, Throwable e) -
close
public void close()Shuts down all started trackers and waits briefly for asynchronous results (e.g. command responses) to complete.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceTracking
-