Class SchedulingInterceptor
- All Implemented Interfaces:
DispatchInterceptor
,HandlerDecorator
,HandlerInterceptor
This interceptor enables powerful scheduling features such as:
- Initial scheduling of @Periodic types: When a handler method or its parameter type is annotated
with
Periodic
, this interceptor will automatically initialize the schedule at startup ifautoStart=true
. - Rescheduling on success or failure: Upon successful or failed invocation of a scheduled handler, this interceptor can reschedule the next invocation based on the result or according to cron/delay rules.
- Metadata injection: Adds the
scheduleId
metadata to outgoing scheduled messages to support correlation and rescheduling. - Dynamic behavior based on handler return value: Supports dynamic rescheduling based on return
types like
TemporalAmount
,TemporalAccessor
,Schedule
, or even a replacement payload object.
Additionally, if the scheduled handler throws a CancelPeriodic
exception,
the schedule is permanently cancelled without logging an error.
This interceptor is registered automatically with FluxCapacitor
.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
HandlerDecorator.MergedDecorator
Nested classes/interfaces inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerInterceptor
HandlerInterceptor.InterceptedHandler
-
Field Summary
Fields inherited from interface io.fluxcapacitor.javaclient.publishing.DispatchInterceptor
noOp
Fields inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
noOp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Instant
firstDeadline
(Periodic periodic, Instant now) protected Object
handleExceptionalResult
(Throwable result, DeserializingMessage schedule, Instant now, Periodic periodic) protected Object
handleResult
(Object result, DeserializingMessage schedule, Instant now, Periodic periodic) protected void
initializePeriodicSchedule
(Class<?> payloadType, Periodic periodic) interceptDispatch
(Message message, MessageType messageType, String topic) Intercepts the dispatch of a message before it is serialized and published or locally handled.interceptHandling
(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Intercepts the message handling logic.protected Instant
nextDeadline
(Periodic periodic, Instant now) wrap
(Handler<DeserializingMessage> handler) Wraps aHandler
with this interceptor, producing an intercepted handler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.publishing.DispatchInterceptor
andThen, modifySerializedMessage, monitorDispatch
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
andThen
-
Constructor Details
-
SchedulingInterceptor
public SchedulingInterceptor()
-
-
Method Details
-
wrap
Description copied from interface:HandlerInterceptor
Wraps aHandler
with this interceptor, producing an intercepted handler.- Specified by:
wrap
in interfaceHandlerDecorator
- Specified by:
wrap
in interfaceHandlerInterceptor
- Parameters:
handler
- the original handler to wrap- Returns:
- an intercepted handler that applies this interceptor to all handled messages
-
initializePeriodicSchedule
-
firstDeadline
-
nextDeadline
-
interceptDispatch
Description copied from interface:DispatchInterceptor
Intercepts the dispatch of a message before it is serialized and published or locally handled.You may modify the message or return
null
to block dispatching. Throwing an exception also prevents dispatching.- Specified by:
interceptDispatch
in interfaceDispatchInterceptor
- Parameters:
message
- the message to be dispatchedmessageType
- the type of the message (e.g., COMMAND, EVENT, etc.)topic
- the target topic or null if not applicable- Returns:
- the modified message, the same message, or
null
to prevent dispatch
-
interceptHandling
public Function<DeserializingMessage,Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Description copied from interface:HandlerInterceptor
Intercepts the message handling logic.The
function
parameter represents the next step in the handling chain— typically the actual message handler. Theinvoker
provides metadata and invocation logic for the underlying handler method.Within this method, an interceptor may:
- Modify the
DeserializingMessage
before passing it to the handler - Bypass the handler entirely and return a value directly
- Wrap the result after the handler is invoked
Note: Interceptors may return a different
DeserializingMessage
, but it must be compatible with a handler method in the same target class. If no suitable handler is found, an exception will be thrown.- Specified by:
interceptHandling
in interfaceHandlerInterceptor
- Parameters:
function
- the next step in the handler chain (typically the handler itself)invoker
- the metadata and execution strategy for the actual handler method- Returns:
- a decorated function that wraps handling behavior
- Modify the
-
handleResult
protected Object handleResult(Object result, DeserializingMessage schedule, Instant now, Periodic periodic) -
handleExceptionalResult
protected Object handleExceptionalResult(Throwable result, DeserializingMessage schedule, Instant now, Periodic periodic)
-