Package org.axonframework.test.deadline
Class StubDeadlineManager
java.lang.Object
org.axonframework.test.deadline.StubDeadlineManager
- All Implemented Interfaces:
DeadlineManager,MessageDispatchInterceptorSupport<DeadlineMessage<?>>,MessageHandlerInterceptorSupport<DeadlineMessage<?>>
Stub implementation of
DeadlineManager. Records all scheduled, canceled and met deadlines.- Since:
- 3.3
- Author:
- Milan Savic, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes the manager withZonedDateTime.now()as current time.StubDeadlineManager(TemporalAccessor currentDateTime) Initializes the manager with providedcurrentDateTimeas current time. -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceTimeBy(Duration duration, DeadlineConsumer deadlineConsumer) Advances time by the givendurationand invokes the givendeadlineConsumerfor each deadline scheduled until that time.voidadvanceTimeTo(Instant newDateTime, DeadlineConsumer deadlineConsumer) Advances time to the givennewDateTimeand invokes the givendeadlineConsumerfor each deadline scheduled until that time.Advances the "current time" of the manager to the next scheduled deadline, and returns that deadline.voidCancels all the deadlines corresponding to the givendeadlineName.voidcancelAllWithinScope(String deadlineName, ScopeDescriptor scope) Cancels all deadlines corresponding to the givendeadlineNameandscope.voidcancelSchedule(String deadlineName, String scheduleId) Cancels the deadline corresponding to the givendeadlineName/scheduleIdcombination.Return the current date and time as anInstantas is being used by thisDeadlineManager.Deprecated.Return all scheduled deadlines which have not been met (yet).Return all triggered deadlines.voidinitializeAt(TemporalAccessor currentDateTime) Resets the initial "current time" of this manager.registerDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> dispatchInterceptor) Register the given DispatchInterceptor.registerHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> handlerInterceptor) Register the givenhandlerInterceptor.schedule(Duration triggerDuration, String deadlineName, Object payloadOrMessage, ScopeDescriptor deadlineScope) Schedules a deadline after the giventriggerDurationwith provided context.schedule(Instant triggerDateTime, String deadlineName, Object payloadOrMessage, ScopeDescriptor deadlineScope) Schedules a deadline at giventriggerDateTimewith provided context.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.deadline.DeadlineManager
cancelAllWithinScope, schedule, schedule, schedule, schedule, shutdown
-
Constructor Details
-
StubDeadlineManager
public StubDeadlineManager()Initializes the manager withZonedDateTime.now()as current time. -
StubDeadlineManager
Initializes the manager with providedcurrentDateTimeas current time.- Parameters:
currentDateTime- The instance to use as current date and time
-
-
Method Details
-
initializeAt
Resets the initial "current time" of this manager. Must be called before any deadlines are scheduled.- Parameters:
currentDateTime- The instant to use as the current date and time- Throws:
IllegalStateException- when calling this method after deadlines are scheduled
-
schedule
@Nonnull public String schedule(@Nonnull Instant triggerDateTime, @Nonnull String deadlineName, Object payloadOrMessage, @Nonnull ScopeDescriptor deadlineScope) Description copied from interface:DeadlineManagerSchedules a deadline at giventriggerDateTimewith provided context. The returnedscheduleIdand provideddeadlineNamecombination can be used to cancel the scheduled deadline.The given
messageOrPayloadmay be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload andMetaDataof the actual deadline being used. In the former case, the givenmessageOrPayloadwill be wrapped as the payload of aDeadlineMessage.- Specified by:
schedulein interfaceDeadlineManager- Parameters:
triggerDateTime- AInstantdenoting the moment to trigger the deadline handlingdeadlineName- AStringrepresenting the name of the deadline to schedulepayloadOrMessage- AMessageor payload for a message as anObjectdeadlineScope- AScopeDescriptordescribing the scope within which the deadline was scheduled- Returns:
- the
scheduleIdas aStringto use when cancelling the schedule
-
schedule
@Nonnull public String schedule(@Nonnull Duration triggerDuration, @Nonnull String deadlineName, Object payloadOrMessage, @Nonnull ScopeDescriptor deadlineScope) Description copied from interface:DeadlineManagerSchedules a deadline after the giventriggerDurationwith provided context. The provideddeadlineName/scheduleIdcombination can be used to cancel the scheduled deadline.The given
messageOrPayloadmay be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload andMetaDataof the actual deadline being used. In the former case, the givenmessageOrPayloadwill be wrapped as the payload of aDeadlineMessage.- Specified by:
schedulein interfaceDeadlineManager- Parameters:
triggerDuration- ADurationdescribing the waiting period before handling the deadlinedeadlineName- AStringrepresenting the name of the deadline to schedulepayloadOrMessage- AMessageor payload for a message as anObjectdeadlineScope- AScopeDescriptordescribing the scope within which the deadline was scheduled- Returns:
- the
scheduleIdas aStringto use when cancelling the schedule
-
cancelSchedule
Description copied from interface:DeadlineManagerCancels the deadline corresponding to the givendeadlineName/scheduleIdcombination. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelSchedulein interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadline to cancelscheduleId- theStringdenoting the scheduled deadline to cancel
-
cancelAll
Description copied from interface:DeadlineManagerCancels all the deadlines corresponding to the givendeadlineName. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelAllin interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancel
-
cancelAllWithinScope
Description copied from interface:DeadlineManagerCancels all deadlines corresponding to the givendeadlineNameandscope. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelAllWithinScopein interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancelscope- aScopeDescriptordescribing the scope within which the deadline was scheduled
-
getScheduledDeadlines
Return all scheduled deadlines which have not been met (yet).- Returns:
- all scheduled deadlines which have not been met (yet)
-
getDeadlinesMet
Deprecated.in favor ofgetTriggeredDeadlines()Return all deadlines which have been met.- Returns:
- all deadlines which have been met
-
getTriggeredDeadlines
Return all triggered deadlines.- Returns:
- all triggered deadlines
-
getCurrentDateTime
Return the current date and time as anInstantas is being used by thisDeadlineManager.- Returns:
- the current date and time used by the manager
-
advanceToNextTrigger
Advances the "current time" of the manager to the next scheduled deadline, and returns that deadline. In theory, this may cause "current time" to move backwards.- Returns:
ScheduledDeadlineInfoof the first scheduled deadline
-
advanceTimeTo
Advances time to the givennewDateTimeand invokes the givendeadlineConsumerfor each deadline scheduled until that time.- Parameters:
newDateTime- the time to advance the "current time" of the manager todeadlineConsumer- the consumer to invoke for each deadline to trigger
-
advanceTimeBy
Advances time by the givendurationand invokes the givendeadlineConsumerfor each deadline scheduled until that time.- Parameters:
duration- the amount of time to advance the "current time" of the manager withdeadlineConsumer- the consumer to invoke for each deadline to trigger
-
registerDispatchInterceptor
@Nonnull public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super DeadlineMessage<?>> dispatchInterceptor) Description copied from interface:MessageDispatchInterceptorSupportRegister the given DispatchInterceptor. After registration, the interceptor will be invoked for each Message dispatched on the messaging component that it was registered to.- Specified by:
registerDispatchInterceptorin interfaceMessageDispatchInterceptorSupport<DeadlineMessage<?>>- Parameters:
dispatchInterceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
registerHandlerInterceptor
@Nonnull public Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super DeadlineMessage<?>> handlerInterceptor) Description copied from interface:MessageHandlerInterceptorSupportRegister the givenhandlerInterceptor. After registration, the interceptor will be invoked for each handled Message on the messaging component that it was registered to, prior to invoking the message's handler.- Specified by:
registerHandlerInterceptorin interfaceMessageHandlerInterceptorSupport<DeadlineMessage<?>>- Parameters:
handlerInterceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
getTriggeredDeadlines()