Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.i2p.util
Class SimpleTimer2.TimedEvent

    java.lang.Object
      net.i2p.util.SimpleTimer2.TimedEvent

All Implemented Interfaces:
  Runnable

Direct Known Subclasses:
  Connection.ResendPacketEvent

Enclosing class:
  SimpleTimer2

    public abstract static class SimpleTimer2.TimedEvent

extends Object
implements Runnable

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 Do not call from within timeReached()
`void` | `reschedule(long timeoutMs, boolean useEarliestTime)` useEarliestTime must be false if called from within timeReached(), as it won't be rescheduled, in favor of the currently running task
`void` | `run()`
`void` | `schedule(long timeoutMs)` 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

### DEFAULT_FUZZ

    protected static final int DEFAULT_FUZZ

See Also:
  Constant Field Values

Constructor Detail

### SimpleTimer2.TimedEvent

    public SimpleTimer2.TimedEvent(SimpleTimer2 pool)

  must call schedule() later

### SimpleTimer2.TimedEvent

    public SimpleTimer2.TimedEvent(SimpleTimer2 pool,
                                   long timeoutMs)

  automatically schedules, don't use this one if you have other things to do first

Method Detail

### setFuzz

    public void setFuzz(int fuzz)

  Don't bother rescheduling if +/- this many ms or less. Use this to reduce timer queue and object churn for a sloppy timer like an inactivity timer. Default 3 ms.

### schedule

    public void schedule(long timeoutMs)

  More efficient than reschedule(). Only call this after calling the non-scheduling constructor, or from within timeReached(), or you will get duplicates on the queue. Otherwise use reschedule().

### reschedule

    public void reschedule(long timeoutMs)

  Use the earliest of the new time and the old time Do not call from within timeReached()

  Parameters:
    `timeoutMs` -

### reschedule

    public void reschedule(long timeoutMs,
                           boolean useEarliestTime)

  useEarliestTime must be false if called from within timeReached(), as it won't be rescheduled, in favor of the currently running task

  Parameters:
    `timeoutMs` -
    `useEarliestTime` - if its already scheduled, use the earlier of the two timeouts, else use the later

### forceReschedule

    public void forceReschedule(long timeoutMs)

  Always use the new time - ignores fuzz

  Parameters:
    `timeoutMs` -

### cancel

    public boolean cancel()

  returns true if cancelled

### run

    public void run()

  Specified by:
    `run` in interface `Runnable`

### timeReached

    public 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)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD