public class StubDeadlineManager extends Object implements DeadlineManager
DeadlineManager
. Records all scheduled and met deadlines.Constructor and Description |
---|
StubDeadlineManager()
Initializes the manager with
ZonedDateTime.now() as current time. |
StubDeadlineManager(TemporalAccessor currentDateTime)
Initializes the manager with provided
currentDateTime as current time. |
Modifier and Type | Method and Description |
---|---|
void |
advanceTimeBy(Duration duration,
DeadlineConsumer deadlineConsumer)
Advances time by the given
duration and invokes the given deadlineConsumer for each deadline
scheduled until that time. |
void |
advanceTimeTo(Instant newDateTime,
DeadlineConsumer deadlineConsumer)
Advances time to the given
newDateTime and invokes the given deadlineConsumer for each deadline
scheduled until that time. |
ScheduledDeadlineInfo |
advanceToNextTrigger()
Advances the "current time" of the manager to the next scheduled deadline, and returns that deadline.
|
void |
cancelAll(String deadlineName)
Cancels all the deadlines corresponding to the given
deadlineName . |
void |
cancelSchedule(String deadlineName,
String scheduleId)
Cancels the deadline corresponding to the given
deadlineName / scheduleId combination. |
Instant |
getCurrentDateTime() |
List<ScheduledDeadlineInfo> |
getDeadlinesMet() |
List<ScheduledDeadlineInfo> |
getScheduledDeadlines() |
void |
initializeAt(TemporalAccessor currentDateTime)
Resets the initial "current time" of this manager.
|
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> dispatchInterceptor)
Register the given DispatchInterceptor.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> handlerInterceptor)
Register the given
handlerInterceptor . |
String |
schedule(Duration triggerDuration,
String deadlineName,
Object payloadOrMessage,
ScopeDescriptor deadlineScope)
Schedules a deadline after the given
triggerDuration with provided context. |
String |
schedule(Instant triggerDateTime,
String deadlineName,
Object payloadOrMessage,
ScopeDescriptor deadlineScope)
Schedules a deadline at given
triggerDateTime with provided context. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
schedule, schedule, schedule, schedule
public StubDeadlineManager()
ZonedDateTime.now()
as current time.public StubDeadlineManager(TemporalAccessor currentDateTime)
currentDateTime
as current time.currentDateTime
- The instance to use as current date and timepublic void initializeAt(TemporalAccessor currentDateTime) throws IllegalStateException
currentDateTime
- The instant to use as the current date and timeIllegalStateException
- when calling this method after deadlines are scheduledpublic String schedule(Instant triggerDateTime, String deadlineName, Object payloadOrMessage, ScopeDescriptor deadlineScope)
DeadlineManager
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
.
schedule
in interface DeadlineManager
triggerDateTime
- A Instant
denoting the moment to trigger the deadline handlingdeadlineName
- A String
representing the name of the deadline to schedulepayloadOrMessage
- A Message
or payload for a message as an
Object
deadlineScope
- A ScopeDescriptor
describing the scope within which the deadline was scheduledscheduleId
as a String
to use when cancelling the schedulepublic String schedule(Duration triggerDuration, String deadlineName, Object payloadOrMessage, ScopeDescriptor deadlineScope)
DeadlineManager
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
.
Scheduling a deadline with the same deadlineName
and scheduleId
will replace the previous
schedule with the new one.
schedule
in interface DeadlineManager
triggerDuration
- A Duration
describing the waiting period before handling the deadlinedeadlineName
- A String
representing the name of the deadline to schedulepayloadOrMessage
- A Message
or payload for a message as an
Object
deadlineScope
- A ScopeDescriptor
describing the scope within which the deadline was scheduledpublic void cancelSchedule(String deadlineName, String scheduleId)
DeadlineManager
deadlineName
/ scheduleId
combination.
This method has no impact on deadlines which have already been triggered.cancelSchedule
in interface DeadlineManager
deadlineName
- A String
representing the name of the deadline to cancelscheduleId
- The String
denoting the scheduled deadline to cancelpublic void cancelAll(String deadlineName)
DeadlineManager
deadlineName
.
This method has no impact on deadlines which have already been triggered.cancelAll
in interface DeadlineManager
deadlineName
- A String
representing the name of the deadlines to cancelpublic List<ScheduledDeadlineInfo> getScheduledDeadlines()
public List<ScheduledDeadlineInfo> getDeadlinesMet()
public Instant getCurrentDateTime()
public ScheduledDeadlineInfo advanceToNextTrigger()
ScheduledDeadlineInfo
of the first scheduled deadlinepublic void advanceTimeTo(Instant newDateTime, DeadlineConsumer deadlineConsumer)
newDateTime
and invokes the given deadlineConsumer
for each deadline
scheduled until that time.newDateTime
- The time to advance the "current time" of the manager todeadlineConsumer
- The consumer to invoke for each deadline to triggerpublic void advanceTimeBy(Duration duration, DeadlineConsumer deadlineConsumer)
duration
and invokes the given deadlineConsumer
for each deadline
scheduled until that time.duration
- The amount of time to advance the "current time" of the manager withdeadlineConsumer
- The consumer to invoke for each deadline to triggerpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> dispatchInterceptor)
MessageDispatchInterceptorSupport
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<DeadlineMessage<?>>
dispatchInterceptor
- The interceptor to registerpublic Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> handlerInterceptor)
MessageHandlerInterceptorSupport
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.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<DeadlineMessage<?>>
handlerInterceptor
- The interceptor to registerCopyright © 2010–2019. All rights reserved.