public interface EventQueue extends AutoCloseable
Modifier and Type | Interface and Description |
---|---|
static class |
EventQueue.DeadlineFunction |
static class |
EventQueue.EarliestDeadlineFunction |
static interface |
EventQueue.Event |
static class |
EventQueue.EventInsertionType |
static class |
EventQueue.FailureLoggingEvent |
static class |
EventQueue.NoDeadlineFunction |
static class |
EventQueue.VoidEvent |
Modifier and Type | Method and Description |
---|---|
default void |
append(EventQueue.Event event)
Add an element to the end of the queue.
|
default void |
appendWithDeadline(long deadlineNs,
EventQueue.Event event)
Add an event to the end of the queue.
|
void |
beginShutdown(String source)
Asynchronously shut down the event queue.
|
void |
cancelDeferred(String tag)
Cancel a deferred event.
|
void |
close()
Synchronously close the event queue and wait for any threads to be joined.
|
void |
enqueue(EventQueue.EventInsertionType insertionType,
String tag,
Function<OptionalLong,OptionalLong> deadlineNsCalculator,
EventQueue.Event event)
Add an event to the queue.
|
default boolean |
isEmpty() |
default void |
prepend(EventQueue.Event event)
Add an element to the front of the queue.
|
default void |
scheduleDeferred(String tag,
Function<OptionalLong,OptionalLong> deadlineNsCalculator,
EventQueue.Event event)
Schedule an event to be run at a specific time.
|
int |
size() |
default void |
wakeup()
This method is used during unit tests where MockTime is in use.
|
default void prepend(EventQueue.Event event)
event
- The mandatory event to prepend.default void append(EventQueue.Event event)
event
- The event to append.default void appendWithDeadline(long deadlineNs, EventQueue.Event event)
deadlineNs
- The deadline for starting the event, in monotonic
nanoseconds. If the event has not started by this
deadline, handleException is called with a
TimeoutException
,
and the event is cancelled.event
- The event to append.default void scheduleDeferred(String tag, Function<OptionalLong,OptionalLong> deadlineNsCalculator, EventQueue.Event event)
tag
- If this is non-null, the unique tag to use for this
event. If an event with this tag already exists, it
will be cancelled.deadlineNsCalculator
- A function which takes as an argument the existing
deadline for the event with this tag (or empty if the
event has no tag, or if there is none such), and
produces the deadline to use for this event.
Once the deadline has arrived, the event will be
run. Events whose deadlines are only a few nanoseconds
apart may be executed in any order.event
- The event to schedule.void cancelDeferred(String tag)
tag
- The unique tag for the event to be cancelled. Must be
non-null. If the event with the tag has not been
scheduled, this call will be ignored.void enqueue(EventQueue.EventInsertionType insertionType, String tag, Function<OptionalLong,OptionalLong> deadlineNsCalculator, EventQueue.Event event)
insertionType
- How to insert the event.
PREPEND means insert the event as the first thing
to run. APPEND means insert the event as the last
thing to run. DEFERRED means insert the event to
run after a delay.tag
- If this is non-null, the unique tag to use for
this event. If an event with this tag already
exists, it will be cancelled.deadlineNsCalculator
- If this is non-null, it is a function which takes
as an argument the existing deadline for the
event with this tag (or null if the event has no
tag, or if there is none such), and produces the
deadline to use for this event (or empty to use
none.) Events whose deadlines are only a few
nanoseconds apart may be executed in any order.event
- The event to enqueue.void beginShutdown(String source)
source
- The source of the shutdown.int size()
default boolean isEmpty()
default void wakeup()
void close() throws InterruptedException
close
in interface AutoCloseable
InterruptedException