com.ccg.util
Class ScheduleEntry

java.lang.Object
  extended by com.ccg.util.ScheduleEntry
All Implemented Interfaces:
Schedulable, Runnable

public abstract class ScheduleEntry
extends Object
implements Schedulable

Base implementation of a Schedulable entry. This class implements all of the basic functions necessary of a Schedulable interface. It simplifies the task of creating a periodic event. You simply extend this class, implement the run() method and add it to a Scheduler. The Scheduler will then take care of invoking your method on a periodic basis (note, your run() method should run rather quickly - if it might block, or take a long time, you should consider running it as its own separate thread).

Since:
1.0
Version:
$Revision: 1.4 $
Author:
$Author: pkb $
See Also:
Scheduler

Constructor Summary
ScheduleEntry()
          Default constructor.
ScheduleEntry(int delayMillis)
          Construct a ScheduleEntry object with a initial delay.
 
Method Summary
 int getDelayMillis()
          Get delay (in milliseconds) between runs.
abstract  void run()
          What should be done periodically.
 void setDelayMillis(int delayMillis)
          Set the delay time until the run() method is invoked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduleEntry

public ScheduleEntry()
Default constructor. This method creates a ScheduleEntry object initializing its delay time to 1000 milliseconds. If the object is added to a Scheduler its run() method will be invoked once a second (approximately).

Since:
1.0
See Also:
setDelayMillis(int), ScheduleEntry(int)

ScheduleEntry

public ScheduleEntry(int delayMillis)
Construct a ScheduleEntry object with a initial delay. This method creates a ScheduleEntry object initializing its delay time to the number of milliseconds specified. If the object is added to a Scheduler its run() method will be invoked once the specified number of milliseconds have elapsed (approximately).

Parameters:
delayMillis - How long in milliseconds before the run() method should be invoked.
Since:
1.0
See Also:
setDelayMillis(int), ScheduleEntry()
Method Detail

getDelayMillis

public int getDelayMillis()
Get delay (in milliseconds) between runs. All Schedulable objects must provide a run() method. These run() methods are similar to threads except the run() method should never block or run indefinitely (it should do something fairly quickly and then exit). This method indicates how much of a delay (in milliseconds) there should be before the Scheduler invokes the run() method. This allows one to control how often the Schedulable item is run. This time should remain constant until the setDelayMillis(int) method is invoked.

Specified by:
getDelayMillis in interface Schedulable
Returns:
How many milliseconds to wait before invoking the Schedulable objects run method. Return 0 if you no longer need to continue running (you will then be removed from the Scheduler's table of Schedulable objects).
Since:
1.0
See Also:
setDelayMillis(int), Scheduler

setDelayMillis

public void setDelayMillis(int delayMillis)
Set the delay time until the run() method is invoked. This method is used to set the delay (in milliseconds) that the Scheduler will wait to invoke the run() method of this object. It should be noted, that if you adjust this value from a thread outside of the Scheduler, the value won't take affect until after the schedular next invokes your run() method.

Parameters:
delayMillis - How long in milliseconds before the run() method should be invoked.
Since:
1.0
See Also:
getDelayMillis()

run

public abstract void run()
What should be done periodically. This is the whole point of the Schedulable interface and ScheduleEntry classes. After this item has been added to a Scheduler, the Scheduler will periodically invoke this method. The delays between invocations are determined by getDelayMillis().

NOTE: Since the Scheduler object may manage many Schedulable objects, it is important that this method execute as quickly as possible - since it blocks the execution of all other objects maintained by the Scheduler. If your object might block indefinitely (say waiting for input), or loop indefinitely, or do anything else which might cause it to take a long time, it should not be added to a shared Scheduler.

Specified by:
run in interface Runnable
Since:
1.0
See Also:
Scheduler


Copyright 1998-1998-2006 null. All Rights Reserved.