|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.impl.agent.ExpirationsTimer
final class ExpirationsTimer
Expiration
timer. Holds the message's expiration state. The cleanup
and thread-safety strategy is to declare state values as final
and create a new timer when the configuration changes. When a timer is no
longer valid, its message
attribute is cleared. This is
preferable to removing the timer from its queue due to the high overhead of
this operation as implemented by PriorityQueue.remove(Object)
. It
also helps minimize the number of times the agent is locked.
The calculation of the expiration time is customized, so the logic and utility methods for these calculations are embedded in this class, too.
Field Summary | |
---|---|
private static long |
BASE
Relative system nanoseconds at the time this class is initialized. |
private long |
expires
Time in nanoseconds when this message expires. |
(package private) Message |
message
Owning message configured for expiration. |
private long |
sequence
Ordered sequence value for this timer. |
Constructor Summary | |
---|---|
ExpirationsTimer(Message message,
long expires,
long sequence)
Constructs a new timer with the given fixed values. |
Method Summary | |
---|---|
int |
compareTo(ExpirationsTimer other)
Returns -1 if this timer expires before the
other timer, 1 if after, or 0 if
they expire at the same time. |
(package private) static long |
expires(long timeout)
Computes the future expiration time in nanoseconds relative to the "current" time. |
(package private) static long |
expires(long timeout,
TimeUnit unit)
Converts the given timeout value to nanoseconds and returns
the future expiration time in nanoseconds relative to the "current" time. |
(package private) static long |
now()
Returns the "current" time in nanoseconds. |
(package private) long |
timeout()
Computes the timeout value in nanoseconds for this timer's expiration time. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
volatile Message message
private final long expires
Long.MIN_VALUE
to Long.MAX_VALUE
.
private final long sequence
expires
value. Each
expiration timer receives a strictly increasing sequence number for each
agent. Values range from Long.MIN_VALUE
to
Long.MAX_VALUE
.
private static final long BASE
Long.MIN_VALUE
to Long.MAX_VALUE
(-9223372036854775808
to
+9223372036854775807
). This value is used to anchor future
System.nanoTime()
values from a known starting point such
that expiration calculations do not overflow.
System.nanoTime()
,
now()
Constructor Detail |
---|
ExpirationsTimer(Message message, long expires, long sequence)
expires
and sequence
attributes are
pre-computed prior to constuction in order to enable computations and
error checking prior to locking the agent.
Method Detail |
---|
static long now()
Long.MIN_VALUE
when this class is first initialized. This
method is for computing future values relative to this initial starting
value. This allows for large timeouts of up to
Long.MAX_VALUE
without overflow (computations of past
values, in contrast, may underflow).
expires(long, TimeUnit)
static long expires(long timeout)
Long.MIN_VALUE
to Long.MAX_VALUE
depending on the current time and the
given timeout
value. For example, if the current time is
-1000
and the timeout value is 100
, the
expiration time is -900
. If the timeout value is
5000
, the expiration time is 4000
(in other
words, the expiration time will have been reached once the value returned
from now()
is 4000
or higher).
now()
static long expires(long timeout, TimeUnit unit)
timeout
value to nanoseconds and returns
the future expiration time in nanoseconds relative to the "current" time.
IllegalArgumentException
- timeout
is negative.
NullPointerException
- unit
is required but
null
. unit
is optional and may be
null
if timeout
is 0
or
Long.MAX_VALUE
.expires(long)
long timeout()
0
if the timer has expired.
public int compareTo(ExpirationsTimer other)
-1
if this timer
expires before the
other
timer, 1
if after, or 0
if
they expire at the same time.
compareTo
in interface Comparable<ExpirationsTimer>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |