Package 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, 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
    Description
    protected net.i2p.util.SimpleTimer2.TimedEventState
    state of the current event.
    protected static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    must call schedule() later
    TimedEvent(SimpleTimer2 pool, long timeoutMs)
    automatically schedules, don't use this one if you have other things to do first
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    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
    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 Details

    • DEFAULT_FUZZ

      protected static final int DEFAULT_FUZZ
      See Also:
    • _state

      protected net.i2p.util.SimpleTimer2.TimedEventState _state
      state of the current event. All access should be under lock.
  • Constructor Details

    • TimedEvent

      public TimedEvent(SimpleTimer2 pool)
      must call schedule() later
    • TimedEvent

      public TimedEvent(SimpleTimer2 pool, long timeoutMs)
      automatically schedules, don't use this one if you have other things to do first
  • Method Details

    • 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)
      Slightly more efficient than reschedule(). Does nothing if already scheduled.
    • 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 -
    • reschedule

      public void reschedule(long timeoutMs, boolean useEarliestTime)
      May be called from within timeReached(), but schedule() is better there.
      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)