atg.service.scheduler
Class PeriodicSchedule

java.lang.Object
  extended by atg.service.scheduler.PeriodicSchedule
All Implemented Interfaces:
Schedule, java.io.Serializable

public class PeriodicSchedule
extends java.lang.Object
implements Schedule, java.io.Serializable

This implementation of Schedule represents a Schedule for an job that repeats at regular intervals. There are three parameters for this Schedule. The first is the delay between the current time and the time that the first job should occur. The second parameter is the period between jobs. Both are expressed in milliseconds.

The third parameter determines whether or not the Schedule should attempt to "catch up" if it misses jobs. For example, say that the period is 2 seconds. Now assume that the job occurs at time A. Another job should occur at time A+2. But say that the Scheduler doesn't get around to handling the job until time A+5. This might happen if the polling interval is greater than the job's period (technically, this will occur if the polling interval is greater than half the period). The next time it will schedule for the job is A+6, which means that the job at A+4 is missed.

If the Schedule is instructed to "catch up", then at time A+5, the job will occur twice, once for A+2, and once for A+4. The next job will occur at A+6.

If the Schedule is not instructed to "catch up", then the job that would have occurred at A+4 will be discarded.

See Also:
Serialized Form

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
PeriodicSchedule(long pPeriod)
          Constructs a new PeriodicSchedule for a job that will occur at regular intervals.
PeriodicSchedule(long pDelay, long pPeriod, boolean pShouldCatchUp)
          Constructs a new PeriodicSchedule for a job that will occur at regular intervals.
PeriodicSchedule(java.lang.String pValue, java.util.Locale pLocale)
          Creates a new PeriodicSchedule instance from the string pValue passed in.
 
Method Summary
 boolean equals(java.lang.Object pObject)
          Returns true if the given object is a PeriodicSchedule with the same settings as this schedule.
 long getNextJobTime(long pLastOccurrenceTime)
          Returns the next time that the job Scheduled by this will take place.
 long getPeriod()
          Returns the defined period (in msec) between jobs.
static java.util.ResourceBundle getResources(java.util.Locale pLocale)
          Returns a locale-specific version of the resources for this class
protected  int getUnitOfTimeIndex(java.lang.String pStr)
          Returns the index into the units of time arrays for the specified unit of time.
 int hashCode()
          Returns a hash code value for this object.
protected  void initUnitOfTimeValues(java.util.ResourceBundle pBundle)
          Initialize the arrays holding the units of time and their conversion factors.
 boolean isCatchUp()
           
 boolean isRepeating()
          Returns true if this is a repeating job, false if this is a one-shot job.
static java.lang.String msecToString(long t, java.util.Locale pLocale)
          Return a quantity in milliseconds as a parseable English phrase
 boolean mustKnowFirstTime()
          If true, then the first time getNextJobTime is called it will be called with -1.
 java.lang.String scheduleString()
          Returns a Parseable representation of this Schedule.
 java.lang.String scheduleString(java.util.Locale pLocale)
          Returns a Parseable representation of this Schedule.
 java.lang.String toString()
          Returns a String value of this
 java.lang.String toString(java.util.Locale pLocale)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

PeriodicSchedule

public PeriodicSchedule(java.lang.String pValue,
                        java.util.Locale pLocale)
                 throws java.lang.IllegalArgumentException
Creates a new PeriodicSchedule instance from the string pValue passed in.

Parameters:
pValue - a String value
pLocale - a Locale value
Throws:
java.lang.IllegalArgumentException - if the strig can not be parsed

PeriodicSchedule

public PeriodicSchedule(long pDelay,
                        long pPeriod,
                        boolean pShouldCatchUp)
Constructs a new PeriodicSchedule for a job that will occur at regular intervals.

Parameters:
pDelay - the delay (in msec) before the first job
pPeriod - the period (in msec) between jobs
pShouldCatchUp - flag indicating if the Schedule should catch up for missed jobs.

PeriodicSchedule

public PeriodicSchedule(long pPeriod)
Constructs a new PeriodicSchedule for a job that will occur at regular intervals. The job will start immediately, and will not attempt to catch up missed jobs.

Parameters:
pPeriod - the period (in msec) between jobs
Method Detail

getResources

public static java.util.ResourceBundle getResources(java.util.Locale pLocale)
Returns a locale-specific version of the resources for this class

Parameters:
Locale - the specified locale

getPeriod

public long getPeriod()
Returns the defined period (in msec) between jobs.


isCatchUp

public boolean isCatchUp()

getNextJobTime

public long getNextJobTime(long pLastOccurrenceTime)
Returns the next time that the job Scheduled by this will take place.

Specified by:
getNextJobTime in interface Schedule
Parameters:
pLastOccurrenceTime - the last time the job occurred, or -1 if it has not yet occurred.
Returns:
the next time that the job will occur, or -1 if the job's next time could not be calculated.

mustKnowFirstTime

public boolean mustKnowFirstTime()
If true, then the first time getNextJobTime is called it will be called with -1. Otherwise, the first time getNextJobTime is called it will be called with the current time.

Specified by:
mustKnowFirstTime in interface Schedule

isRepeating

public boolean isRepeating()
Returns true if this is a repeating job, false if this is a one-shot job.

Specified by:
isRepeating in interface Schedule

toString

public java.lang.String toString()
Returns a String value of this

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.util.Locale pLocale)

scheduleString

public java.lang.String scheduleString()
Description copied from interface: Schedule
Returns a Parseable representation of this Schedule.

Specified by:
scheduleString in interface Schedule

scheduleString

public java.lang.String scheduleString(java.util.Locale pLocale)
Returns a Parseable representation of this Schedule.

Specified by:
scheduleString in interface Schedule

msecToString

public static java.lang.String msecToString(long t,
                                            java.util.Locale pLocale)
Return a quantity in milliseconds as a parseable English phrase


equals

public boolean equals(java.lang.Object pObject)
Returns true if the given object is a PeriodicSchedule with the same settings as this schedule.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class java.lang.Object

initUnitOfTimeValues

protected void initUnitOfTimeValues(java.util.ResourceBundle pBundle)
Initialize the arrays holding the units of time and their conversion factors.

Parameters:
ResourceBundle - the locale-specific bundle to use

getUnitOfTimeIndex

protected int getUnitOfTimeIndex(java.lang.String pStr)
Returns the index into the units of time arrays for the specified unit of time.

Parameters:
String - the unit of time
Returns:
int the index into the arrays for the unit of time