|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.i2p.util.SimpleTimer2.TimedEvent
public abstract static class SimpleTimer2.TimedEvent
Similar to SimpleTimer.TimedEvent but users must extend instead of implement, and all schedule and cancel methods are through this class rather than SimpleTimer2. To convert over, change implements SimpleTimer.TimedEvent to extends SimpleTimer2.TimedEvent, and be sure to call super(SimpleTimer2.getInstance(), timeoutMs) in the constructor (or super(SimpleTimer2.getInstance()); .... schedule(timeoutMs); if there is other stuff in your constructor) Other porting: SimpleTimer.getInstance().addEvent(new foo(), timeout) => new foo(SimpleTimer2.getInstance(), timeout) SimpleTimer.getInstance().addEvent(this, timeout) => schedule(timeout) SimpleTimer.getInstance().addEvent(foo, timeout) => foo.reschedule(timeout) SimpleTimer.getInstance().removeEvent(foo) => foo.cancel() There's no global locking, but for scheduling, we synchronize on this to reduce the chance of duplicates on the queue. schedule(ms) can get create duplicates reschedule(ms) and reschedule(ms, true) can lose the timer reschedule(ms, false) and forceReschedule(ms) are relatively safe from either
Field Summary | |
---|---|
protected static int |
DEFAULT_FUZZ
|
Constructor Summary | |
---|---|
SimpleTimer2.TimedEvent(SimpleTimer2 pool)
must call schedule() later |
|
SimpleTimer2.TimedEvent(SimpleTimer2 pool,
long timeoutMs)
automatically schedules, don't use this one if you have other things to do first |
Method Summary | |
---|---|
boolean |
cancel()
returns true if cancelled |
void |
forceReschedule(long timeoutMs)
Always use the new time - ignores fuzz |
void |
reschedule(long timeoutMs)
Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there. |
void |
reschedule(long timeoutMs,
boolean useEarliestTime)
May be called from within timeReached(), but schedule() is better there. |
void |
run()
|
void |
schedule(long timeoutMs)
Slightly more efficient than reschedule(). |
void |
setFuzz(int fuzz)
Don't bother rescheduling if +/- this many ms or less. |
abstract void |
timeReached()
Simple interface for events to be queued up and notified on expiration the time requested has been reached (this call should NOT block, otherwise the whole SimpleTimer gets backed up) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int DEFAULT_FUZZ
Constructor Detail |
---|
public SimpleTimer2.TimedEvent(SimpleTimer2 pool)
public SimpleTimer2.TimedEvent(SimpleTimer2 pool, long timeoutMs)
Method Detail |
---|
public void setFuzz(int fuzz)
public void schedule(long timeoutMs)
public void reschedule(long timeoutMs)
timeoutMs
- public void reschedule(long timeoutMs, boolean useEarliestTime)
timeoutMs
- useEarliestTime
- if its already scheduled, use the earlier of the
two timeouts, else use the laterpublic void forceReschedule(long timeoutMs)
timeoutMs
- public boolean cancel()
public void run()
run
in interface Runnable
public abstract void timeReached()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |