APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.quic

public final Class QuicTimerQueue

extends Object
Class Inheritance
Imports
java.util.Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedQueue, .ConcurrentSkipListSet, .Executor, java.util.concurrent.atomic.AtomicLong, jdk.internal.net.http.common.Deadline, .Log, .Logger, .SequentialScheduler, .TimeSource, .Utils

A timer queue that can process events which are due, and possibly reschedule them if needed. An instance of a QuicTimerQueue is usually associated with an instance of QuicSelector which provides the timer/wakeup facility.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private static final QuicTimerQueue.Marker
private volatile boolean
private final Logger
private final ConcurrentLinkedQueue<QuicTimedEvent>
private static final AtomicLong
private static final QuicTimerQueue.Marker
private final Runnable
private final SequentialScheduler
private final Set<QuicTimedEvent>
private volatile Deadline
private final ConcurrentSkipListSet<QuicTimedEvent>
private volatile Deadline

Constructor Summary

AccessConstructor and Description
public
QuicTimerQueue(Runnable
A notifier to wake up the timer thread when new event have been added and the next deadline has changed.
notifier
,
Logger debug)

Creates a new timer queue with the given notifier.

Method Summary

Modifier and TypeMethod and Description
private String
d(Deadline deadline)

private String
d(Deadline now, Deadline deadline)

private Deadline
private static boolean
isDue(final Deadline deadline, final Deadline now)

private Deadline
min(Deadline one, Deadline two)

public static long

Returns:

a unique id for a new QuicTimedEvent
newEventId
()

Returns a unique id for a new QuicTimedEvent.

public Deadline

Returns:

The next deadline, or Deadline.MAX.
nextDeadline
()

The next deadline for this timer queue.

private boolean
notify(Deadline deadline)

public void
offer(QuicTimedEvent
an event to be scheduled
event
)

Schedule the given event by adding it to the timer queue.

public Deadline
private void
public Deadline

Returns:

the next unexpired deadline, or Deadline#MAX if the queue is empty.
processEventsAndReturnNextDeadline
(Deadline
The point in time before which events are considered to be due. Usually, that's now.
now
,
Executor
An executor to process events which are due.
executor
)

Process all events that were due before now, and returns the next deadline.

private int
private int
public void
reschedule(QuicTimedEvent
an event to reschedule
event
)

Reschedule the given QuicTimedEvent.

public void
reschedule(QuicTimedEvent
an event to reschedule
event
,
Deadline
the prospective future deadline at which the event should be rescheduled
deadline
)

Reschedule the given QuicTimedEvent.

private Deadline
scheduled(Deadline deadline)

public void
stop()

Called to clean up the timer queue when it is no longer needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CEILINGback to summary
private static final QuicTimerQueue.Marker CEILING
closedback to summary
private volatile boolean closed
debugback to summary
private final Logger debug
dueback to summary
private final ConcurrentLinkedQueue<QuicTimedEvent> due
EVENTIDSback to summary
private static final AtomicLong EVENTIDS
FLOORback to summary
private static final QuicTimerQueue.Marker FLOOR
notifierback to summary
private final Runnable notifier
processorback to summary
private final SequentialScheduler processor
rescheduledback to summary
private final Set<QuicTimedEvent> rescheduled
returnedDeadlineback to summary
private volatile Deadline returnedDeadline
scheduledback to summary
private final ConcurrentSkipListSet<QuicTimedEvent> scheduled
scheduledDeadlineback to summary
private volatile Deadline scheduledDeadline

Constructor Detail

QuicTimerQueueback to summary
public QuicTimerQueue(Runnable notifier, Logger debug)

Creates a new timer queue with the given notifier. A notifier is used to notify the timer thread that new events have been added to the queue of scheduled event. The notifier should wake up the thread and trigger a call to either processEventsAndReturnNextDeadline(Deadline, Executor) or nextDeadline().

Parameters
notifier:Runnable

A notifier to wake up the timer thread when new event have been added and the next deadline has changed.

Method Detail

dback to summary
private String d(Deadline deadline)
dback to summary
private String d(Deadline now, Deadline deadline)
debugNowback to summary
private Deadline debugNow()
isDueback to summary
private static boolean isDue(final Deadline deadline, final Deadline now)
minback to summary
private Deadline min(Deadline one, Deadline two)
newEventIdback to summary
public static long newEventId()

Returns a unique id for a new QuicTimedEvent. Each new instance of QuicTimedEvent is created with a long ID returned by this method to ensure a total ordering of QuicTimedEvent instances, even when their deadlines are equal.

Returns:long

a unique id for a new QuicTimedEvent

nextDeadlineback to summary
public Deadline nextDeadline()

The next deadline for this timer queue. This is only weakly consistent. If the queue is empty, Deadline#MAX is returned.

Returns:Deadline

The next deadline, or Deadline.MAX.

notifyback to summary
private boolean notify(Deadline deadline)
offerback to summary
public void offer(QuicTimedEvent event)

Schedule the given event by adding it to the timer queue.

Parameters
event:QuicTimedEvent

an event to be scheduled

pendingScheduledDeadlineback to summary
public Deadline pendingScheduledDeadline()
processDueback to summary
private void processDue()
processEventsAndReturnNextDeadlineback to summary
public Deadline processEventsAndReturnNextDeadline(Deadline now, Executor executor)

Process all events that were due before now, and returns the next deadline. The events are processed within an executor's thread, so this method may return before all events have been processed. The events are processed in order, with respect to their deadline. Processing an event involves invoking its handle method. If that method returns a new deadline different from Deadline#MAX the processed event is rescheduled immediately. Otherwise, it will not be rescheduled.

Parameters
now:Deadline

The point in time before which events are considered to be due. Usually, that's now.

executor:Executor

An executor to process events which are due.

Returns:Deadline

the next unexpired deadline, or Deadline#MAX if the queue is empty.

processRescheduledback to summary
private int processRescheduled(Deadline now)
processScheduledback to summary
private int processScheduled(Deadline now)
rescheduleback to summary
public void reschedule(QuicTimedEvent event)

Reschedule the given QuicTimedEvent.

API Note

This method is used if the prospective future deadline at which the event should be scheduled is not known by the caller. This may cause an idle wakeup in the selector thread owning this QuicTimerQueue. Use reschedule(QuicTimedEvent, Deadline) to minimize idle wakeup.

Parameters
event:QuicTimedEvent

an event to reschedule

rescheduleback to summary
public void reschedule(QuicTimedEvent event, Deadline deadline)

Reschedule the given QuicTimedEvent.

API Note

This method should be used in preference of reschedule(QuicTimedEvent) if the prospective future deadline at which the event should be scheduled is already known by the caller. Using this method will minimize idle wakeup of the selector thread, in comparison of reschedule(QuicTimedEvent).

Parameters
event:QuicTimedEvent

an event to reschedule

deadline:Deadline

the prospective future deadline at which the event should be rescheduled

scheduledback to summary
private Deadline scheduled(Deadline deadline)
stopback to summary
public void stop()

Called to clean up the timer queue when it is no longer needed. Makes sure that all pending tasks are cleared from the various lists.

jdk.internal.net.http.quic back to summary

pack-priv final Enum QuicTimerQueue.Marker

extends Enum<QuicTimerQueue.Marker>
implements QuicTimedEvent
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.quic.QuicTimedEvent

Field Summary

Modifier and TypeField and Description
public static final QuicTimerQueue.Marker
CEILING

A Marker event to pass to ConcurrentSkipListSet::floor in order to get the last event in the list, or null.

private final Deadline
private final long
public static final QuicTimerQueue.Marker
FLOOR

A Marker event to pass to ConcurrentSkipListSet::ceiling in order to get the first event in the list, or null.

Constructor Summary

AccessConstructor and Description
private
Marker(Deadline deadline, long eventId)

Method Summary

Modifier and TypeMethod and Description
public Deadline
deadline()

Implements jdk.internal.net.http.quic.QuicTimedEvent.deadline.

Returns the deadline at which the event should be triggered, or Deadline#MAX if the event does not need to be scheduled.

public long
eventId()

Implements jdk.internal.net.http.quic.QuicTimedEvent.eventId.

An event id, obtained at construction time from QuicTimerQueue#newEventId().

public Deadline
handle()

Implements jdk.internal.net.http.quic.QuicTimedEvent.handle.

Handles the triggered event.

public Deadline
refreshDeadline()

Implements jdk.internal.net.http.quic.QuicTimedEvent.refreshDeadline.

Called to cause an event to refresh its deadline.

public static QuicTimerQueue.Marker
public static QuicTimerQueue.Marker[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CEILINGback to summary
public static final QuicTimerQueue.Marker CEILING

A Marker event to pass to ConcurrentSkipListSet::floor in order to get the last event in the list, or null.

API Note

The intended usage is:

var head = scheduled.floor(CEILING);
deadlineback to summary
private final Deadline deadline
eventIdback to summary
private final long eventId
FLOORback to summary
public static final QuicTimerQueue.Marker FLOOR

A Marker event to pass to ConcurrentSkipListSet::ceiling in order to get the first event in the list, or null.

API Note

The intended usage is:

var head = scheduled.ceiling(FLOOR);

Constructor Detail

Markerback to summary
private Marker(Deadline deadline, long eventId)

Method Detail

deadlineback to summary
public Deadline deadline()

Implements jdk.internal.net.http.quic.QuicTimedEvent.deadline.

Doc from jdk.internal.net.http.quic.QuicTimedEvent.deadline.

Returns the deadline at which the event should be triggered, or Deadline#MAX if the event does not need to be scheduled.

Annotations
@Override
eventIdback to summary
public long eventId()

Implements jdk.internal.net.http.quic.QuicTimedEvent.eventId.

Doc from jdk.internal.net.http.quic.QuicTimedEvent.eventId.

An event id, obtained at construction time from QuicTimerQueue#newEventId(). This is used to implement a total order among subclasses.

Annotations
@Override
handleback to summary
public Deadline handle()

Implements jdk.internal.net.http.quic.QuicTimedEvent.handle.

Doc from jdk.internal.net.http.quic.QuicTimedEvent.handle.

Handles the triggered event. Returns a new deadline, if the event needs to be rescheduled, or Deadline.MAX otherwise.

Annotations
@Override
refreshDeadlineback to summary
public Deadline refreshDeadline()

Implements jdk.internal.net.http.quic.QuicTimedEvent.refreshDeadline.

Doc from jdk.internal.net.http.quic.QuicTimedEvent.refreshDeadline.

Called to cause an event to refresh its deadline. This method is called by the QuicTimerQueue when rescheduling an event.

Annotations
@Override
valueOfback to summary
public static QuicTimerQueue.Marker valueOf(String name)
valuesback to summary
public static QuicTimerQueue.Marker[] values()