java.lang.Object
io.fluxzero.sdk.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
ConsumerConfigurations based on declared filters - Creating and managing
Trackerinstances 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
HandlerFactoryandHandlerInvoker - Integrating with
ResultGatewayto 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 aFluxzero.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 TypeMethodDescriptionvoidclose()Shuts down all started trackers and waits briefly for asynchronous results (e.g. command responses) to complete.createConsumer(ConsumerConfiguration config, List<io.fluxzero.common.handling.Handler<DeserializingMessage>> handlers) protected Optional<io.fluxzero.common.handling.HandlerInvoker> getInvoker(DeserializingMessage message, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected Objecthandle(DeserializingMessage message, io.fluxzero.common.handling.HandlerInvoker h, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected ObjectprocessError(Throwable e, DeserializingMessage message, io.fluxzero.common.handling.HandlerInvoker h, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) protected voidreportResult(Object result, io.fluxzero.common.handling.HandlerInvoker h, DeserializingMessage message, ConsumerConfiguration config) protected booleanshouldSendResponse(io.fluxzero.common.handling.HandlerInvoker invoker, DeserializingMessage request, Object result, ConsumerConfiguration config) io.fluxzero.common.RegistrationStarts tracking by assigning the given handlers to configured consumers and creating topic-specific or shared trackers.protected io.fluxzero.common.RegistrationstartTracking(ConsumerConfiguration configuration, List<io.fluxzero.common.handling.Handler<DeserializingMessage>> handlers, Fluxzero fluxzero) protected voidstopTracker(DeserializingMessage message, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, Throwable e) protected voidtryHandle(DeserializingMessage message, io.fluxzero.common.handling.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
TrackingExceptionif handlers can't be matched to consumers or if a consumer has already been started previously.- Specified by:
startin interfaceTracking- Parameters:
fluxzero- the owningFluxzeroinstancehandlers- the handler instances to assign and activate- Returns:
- a
Registrationthat 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 io.fluxzero.common.Registration startTracking(ConsumerConfiguration configuration, List<io.fluxzero.common.handling.Handler<DeserializingMessage>> handlers, Fluxzero fluxzero) -
createConsumer
protected Consumer<List<io.fluxzero.common.api.SerializedMessage>> createConsumer(ConsumerConfiguration config, List<io.fluxzero.common.handling.Handler<DeserializingMessage>> handlers) -
tryHandle
protected void tryHandle(DeserializingMessage message, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config, boolean reportResult) -
getInvoker
protected Optional<io.fluxzero.common.handling.HandlerInvoker> getInvoker(DeserializingMessage message, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
handle
protected Object handle(DeserializingMessage message, io.fluxzero.common.handling.HandlerInvoker h, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
processError
protected Object processError(Throwable e, DeserializingMessage message, io.fluxzero.common.handling.HandlerInvoker h, io.fluxzero.common.handling.Handler<DeserializingMessage> handler, ConsumerConfiguration config) -
reportResult
protected void reportResult(Object result, io.fluxzero.common.handling.HandlerInvoker h, DeserializingMessage message, ConsumerConfiguration config) -
shouldSendResponse
protected boolean shouldSendResponse(io.fluxzero.common.handling.HandlerInvoker invoker, DeserializingMessage request, Object result, ConsumerConfiguration config) -
stopTracker
protected void stopTracker(DeserializingMessage message, io.fluxzero.common.handling.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:
closein interfaceAutoCloseable- Specified by:
closein interfaceTracking
-