net.i2p.util

## Class SimpleTimer2.TimedEvent

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

- All Implemented Interfaces:
    Runnable
  Direct Known Subclasses:
    ACKTimer, Connection.ResendPacketEvent, Connection.RetransmitEvent, DeadlockDetector, IdleChecker, LoadClientAppsJob.DelayedRunClient, PeerTestEvent, SocketTimeout, TempDirScanner, TunnelGateway.DelayedFlush
  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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected net.i2p.util.SimpleTimer2.TimedEventState` | `_state` state of the current event.
    `protected static int` | `DEFAULT_FUZZ`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TimedEvent(SimpleTimer2 pool)` Create a new timed event.
    `TimedEvent(SimpleTimer2 pool, long timeoutMs)` Create a new timed event and automatically schedules it.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cancel()` Cancel the timed event.
    `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)
    `String` | `toString()` So the critical "please report" message above isn't so ugly

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _state

          protected net.i2p.util.SimpleTimer2.TimedEventState _state

      state of the current event. All access should be under lock.

    - #### DEFAULT_FUZZ

          protected static final int DEFAULT_FUZZ

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TimedEvent

          public TimedEvent(SimpleTimer2 pool)

      Create a new timed event. Must call schedule() later.
      Parameters:
        `pool` - the timer pool

    - #### TimedEvent

          public TimedEvent(SimpleTimer2 pool,
                            long timeoutMs)

      Create a new timed event and automatically schedules it. Don't use this one if you have other things to do first.
      Parameters:
        `pool` - the timer pool
        `timeoutMs` - timeout in milliseconds

  - ### Method Detail

    - #### cancel

          public boolean cancel()

      Cancel the timed event.
      Returns:
        true if cancelled

    - #### forceReschedule

          public void forceReschedule(long timeoutMs)

      Always use the new time - ignores fuzz
      Parameters:
        `timeoutMs` - timeout in milliseconds

    - #### reschedule

          public 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.
      Parameters:
        `timeoutMs` - timeout in milliseconds

    - #### reschedule

          public void reschedule(long timeoutMs,
                                 boolean useEarliestTime)

      May be called from within timeReached(), but schedule() is better there.
      Parameters:
        `timeoutMs` - timeout in milliseconds
        `useEarliestTime` - if its already scheduled, use the earlier of the two timeouts, else use the later

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### schedule

          public void schedule(long timeoutMs)

      Slightly more efficient than reschedule(). Does nothing if already scheduled.
      Parameters:
        `timeoutMs` - the timeout in milliseconds

    - #### 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.
      Parameters:
        `fuzz` - the fuzz value in milliseconds

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

    - #### toString

          public String toString()

      So the critical "please report" message above isn't so ugly
      Overrides:
        `toString` in class `Object`