com.samskivert.util
Class Interval

java.lang.Object
  extended by com.samskivert.util.Interval

public abstract class Interval
extends Object

An interface for doing operations after some delay. Allows expiration to occur on a specific thread, and guarantees that any queued expiration will not run if the Interval has since been cancelled or rescheduled.


Nested Class Summary
protected static class Interval.IntervalTask
          The task that schedules actually runs the interval.
static interface Interval.RunBuddy
          An interface that will be implemented by the runnable posted to a RunQueue that can be used to retrieve the original Interval.
 
Field Summary
protected  RunQueue _runQueue
          If non-null, the RunQueue used to run the expired() method for each Interval.
protected  Interval.IntervalTask _task
          The task that actually schedules our execution with the static Timer.
protected static Timer _timer
          The daemon timer used to schedule all intervals.
 
Constructor Summary
Interval()
          Create a simple interval that does not use a RunQueue to run the expired() method.
Interval(RunQueue runQueue)
          Create an Interval that uses the specified RunQueue to run the expired() method.
 
Method Summary
 void cancel()
          Cancel the current schedule, and ensure that any expirations that are queued up but have not yet run do not run.
protected static Timer createTimer()
           
abstract  void expired()
          The main method where your interval should do its work.
static void resetTimer()
          Deprecated.  
protected  void safelyExpire(Interval.IntervalTask task)
          Safely expire the interval.
 void schedule(Date when)
          Schedules this interval to execute once at when.
 void schedule(long delay)
          Schedule the interval to execute once, after the specified delay.
 void schedule(long delay, boolean repeat)
          Schedule the interval to execute repeatedly with fixed-rate scheduling between repeats, with the same delay.
 void schedule(long initialDelay, long repeatDelay)
          Schedule the interval to execute repeatedly with the specified initial delay and repeat delay with fixed-rate scheduling between repeats.
 void schedule(long initialDelay, long repeatDelay, boolean fixedRate)
          Schedule the interval to execute repeatedly with the specified initial delay and repeat delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_runQueue

protected RunQueue _runQueue
If non-null, the RunQueue used to run the expired() method for each Interval.


_task

protected volatile Interval.IntervalTask _task
The task that actually schedules our execution with the static Timer.


_timer

protected static Timer _timer
The daemon timer used to schedule all intervals.

Constructor Detail

Interval

public Interval()
Create a simple interval that does not use a RunQueue to run the expired() method.


Interval

public Interval(RunQueue runQueue)
Create an Interval that uses the specified RunQueue to run the expired() method. If null is supplied the interval will be run directly on the timer thread.

Method Detail

resetTimer

@Deprecated
public static void resetTimer()
Deprecated. 

This may be removed.


expired

public abstract void expired()
The main method where your interval should do its work.


schedule

public final void schedule(Date when)
Schedules this interval to execute once at when. Supersedes any previous schedule that this Interval may have had.


schedule

public final void schedule(long delay)
Schedule the interval to execute once, after the specified delay. Supersedes any previous schedule that this Interval may have had.


schedule

public final void schedule(long delay,
                           boolean repeat)
Schedule the interval to execute repeatedly with fixed-rate scheduling between repeats, with the same delay. Supersedes any previous schedule that this Interval may have had.


schedule

public final void schedule(long initialDelay,
                           long repeatDelay)
Schedule the interval to execute repeatedly with the specified initial delay and repeat delay with fixed-rate scheduling between repeats. Supersedes any previous schedule that this Interval may have had.


schedule

public final void schedule(long initialDelay,
                           long repeatDelay,
                           boolean fixedRate)
Schedule the interval to execute repeatedly with the specified initial delay and repeat delay. Supersedes any previous schedule that this Interval may have had.

Parameters:
fixedRate - - if true, this interval schedules repeated expirations using Timer.scheduleAtFixedRate(TimerTask, long, long) ensuring that the number of expired calls will match the amount of time elapsed. If false, it uses Timer.schedule(TimerTask, long, long) which ensures that there will be close to repeateDelay milliseconds between expirations.
Throws:
IllegalArgumentException - if fixedRate is false and a RunQueue has been specified. That doesn't make sense because the fixed delay cannot account for the time that the RunBuddy sits on the RunQueue waiting to call expire().

cancel

public final void cancel()
Cancel the current schedule, and ensure that any expirations that are queued up but have not yet run do not run.


safelyExpire

protected final void safelyExpire(Interval.IntervalTask task)
Safely expire the interval.


createTimer

protected static Timer createTimer()


Copyright © 2000-2008 Michael Bayne. All Rights Reserved.