Class StubDeadlineManager

java.lang.Object
org.axonframework.test.deadline.StubDeadlineManager
All Implemented Interfaces:
DeadlineManager, MessageDispatchInterceptorSupport<DeadlineMessage<?>>, MessageHandlerInterceptorSupport<DeadlineMessage<?>>

public class StubDeadlineManager extends Object implements DeadlineManager
Stub implementation of DeadlineManager. Records all scheduled, canceled and met deadlines.
Since:
3.3
Author:
Milan Savic, Steven van Beelen
  • Constructor Details

    • StubDeadlineManager

      public StubDeadlineManager()
      Initializes the manager with ZonedDateTime.now() as current time.
    • StubDeadlineManager

      public StubDeadlineManager(TemporalAccessor currentDateTime)
      Initializes the manager with provided currentDateTime as current time.
      Parameters:
      currentDateTime - The instance to use as current date and time
  • Method Details

    • initializeAt

      public void initializeAt(TemporalAccessor currentDateTime) throws IllegalStateException
      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: DeadlineManager
      Schedules a deadline at given triggerDateTime with provided context. The returned scheduleId and provided deadlineName combination can be used to cancel the scheduled deadline.

      The given messageOrPayload may be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload and MetaData of the actual deadline being used. In the former case, the given messageOrPayload will be wrapped as the payload of a DeadlineMessage.

      Specified by:
      schedule in interface DeadlineManager
      Parameters:
      triggerDateTime - A Instant denoting the moment to trigger the deadline handling
      deadlineName - A String representing the name of the deadline to schedule
      payloadOrMessage - A Message or payload for a message as an Object
      deadlineScope - A ScopeDescriptor describing the scope within which the deadline was scheduled
      Returns:
      the scheduleId as a String to 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: DeadlineManager
      Schedules a deadline after the given triggerDuration with provided context. The provided deadlineName / scheduleId combination can be used to cancel the scheduled deadline.

      The given messageOrPayload may be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload and MetaData of the actual deadline being used. In the former case, the given messageOrPayload will be wrapped as the payload of a DeadlineMessage.

      Specified by:
      schedule in interface DeadlineManager
      Parameters:
      triggerDuration - A Duration describing the waiting period before handling the deadline
      deadlineName - A String representing the name of the deadline to schedule
      payloadOrMessage - A Message or payload for a message as an Object
      deadlineScope - A ScopeDescriptor describing the scope within which the deadline was scheduled
      Returns:
      the scheduleId as a String to use when cancelling the schedule
    • cancelSchedule

      public void cancelSchedule(@Nonnull String deadlineName, @Nonnull String scheduleId)
      Description copied from interface: DeadlineManager
      Cancels the deadline corresponding to the given deadlineName / scheduleId combination. This method has no impact on deadlines which have already been triggered.
      Specified by:
      cancelSchedule in interface DeadlineManager
      Parameters:
      deadlineName - a String representing the name of the deadline to cancel
      scheduleId - the String denoting the scheduled deadline to cancel
    • cancelAll

      public void cancelAll(@Nonnull String deadlineName)
      Description copied from interface: DeadlineManager
      Cancels all the deadlines corresponding to the given deadlineName. This method has no impact on deadlines which have already been triggered.
      Specified by:
      cancelAll in interface DeadlineManager
      Parameters:
      deadlineName - a String representing the name of the deadlines to cancel
    • cancelAllWithinScope

      public void cancelAllWithinScope(@Nonnull String deadlineName, @Nonnull ScopeDescriptor scope)
      Description copied from interface: DeadlineManager
      Cancels all deadlines corresponding to the given deadlineName and scope. This method has no impact on deadlines which have already been triggered.
      Specified by:
      cancelAllWithinScope in interface DeadlineManager
      Parameters:
      deadlineName - a String representing the name of the deadlines to cancel
      scope - a ScopeDescriptor describing the scope within which the deadline was scheduled
    • getScheduledDeadlines

      public List<ScheduledDeadlineInfo> getScheduledDeadlines()
      Return all scheduled deadlines which have not been met (yet).
      Returns:
      all scheduled deadlines which have not been met (yet)
    • getDeadlinesMet

      @Deprecated public List<ScheduledDeadlineInfo> getDeadlinesMet()
      Deprecated.
      Return all deadlines which have been met.
      Returns:
      all deadlines which have been met
    • getTriggeredDeadlines

      public List<ScheduledDeadlineInfo> getTriggeredDeadlines()
      Return all triggered deadlines.
      Returns:
      all triggered deadlines
    • getCurrentDateTime

      public Instant getCurrentDateTime()
      Return the current date and time as an Instant as is being used by this DeadlineManager.
      Returns:
      the current date and time used by the manager
    • advanceToNextTrigger

      public ScheduledDeadlineInfo 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:
      ScheduledDeadlineInfo of the first scheduled deadline
    • advanceTimeTo

      public void advanceTimeTo(Instant newDateTime, DeadlineConsumer deadlineConsumer)
      Advances time to the given newDateTime and invokes the given deadlineConsumer for each deadline scheduled until that time.
      Parameters:
      newDateTime - the time to advance the "current time" of the manager to
      deadlineConsumer - the consumer to invoke for each deadline to trigger
    • advanceTimeBy

      public void advanceTimeBy(Duration duration, DeadlineConsumer deadlineConsumer)
      Advances time by the given duration and invokes the given deadlineConsumer for each deadline scheduled until that time.
      Parameters:
      duration - the amount of time to advance the "current time" of the manager with
      deadlineConsumer - the consumer to invoke for each deadline to trigger
    • registerDispatchInterceptor

      @Nonnull public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super DeadlineMessage<?>> dispatchInterceptor)
      Description copied from interface: MessageDispatchInterceptorSupport
      Register 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:
      registerDispatchInterceptor in interface MessageDispatchInterceptorSupport<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: MessageHandlerInterceptorSupport
      Register the given handlerInterceptor. 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:
      registerHandlerInterceptor in interface MessageHandlerInterceptorSupport<DeadlineMessage<?>>
      Parameters:
      handlerInterceptor - The interceptor to register
      Returns:
      A Registration, which may be used to deregister the interceptor.