org.objectledge.scheduler
Class CronSchedule

java.lang.Object
  extended by org.objectledge.scheduler.CronSchedule
All Implemented Interfaces:
Schedule

public class CronSchedule
extends Object
implements Schedule

A schedule that follows the configuration syntax of Unix cron utility.

The configuration grammar:

 schedule_config := ( ( minute hour day month weekday ) | special )
 special := ( "@reboot" | "@yearly" | "@annually" | "@monthly" | "@weekly" |
   "@daily" | "@midnight" | "@hourly" )
 minute := value_spec
 hour := value_spec
 day := value_spec
 month := ( value_spec | month_name )
 weekday := ( value_spec | weekday_name )
 month_name := ( "jan" | "feb" | "mar" | "apr" | "may" | "jun" |
   "jul" | "aug" | "sep" | "oct" | "nov" | "dec" )
 weekday_name := ( "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun" )
 value_spec := ( "*" | list_of_values )
 list_of_values := ( value_or_range ( "," value_or_range )* )
 value_or_range := ( number | range )
 range := number "-" number [ "/" number ]
 number := LEXICAL( [0-9]+ )
 

Configuration syntax is compatible with Paul Vixie's cron, version 3.0.


Field Summary
private  String config
          The textual configuration form.
private static int DAY_OF_MONTH
          index of day field.
private static int DAY_OF_WEEK
          index of weekday field.
protected  String eol
          The end of line string for this machine.
private static int HOUR_OF_DAY
          index of hour field.
private  I18n i18n
          I18n component
private static int MINUTE
          index of minute field.
private static int MONTH
          index of month field.
private  int[][] schedule
          The parserd schedule data.
static String TYPE
          The schedule type.
 
Constructor Summary
CronSchedule(I18n i18n)
          Constructor.
 
Method Summary
protected  String addEscapes(String str)
          Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal.
 boolean atStartup()
          Checks if the job should be run at the very startup of the scheduler.
private  void computeDay(Calendar nextRun)
           
private  void computeHour(Calendar nextRun)
           
private  void computeMinute(Calendar nextRun)
           
private  void computeMonth(Calendar nextRunDOM)
           
 String getConfig()
          Return the schedule configuration.
 Date getNextRunTime(Date currentTime, Date lastRunTime)
          Calculates the time of the job's next run.
 String getType()
          Returns the name of the schedule type.
 void init(AbstractScheduler scheduler, String config)
          Initialize the schedule.
private  String localizeParseException(ParseException ex)
          Create a localized message out of ParseException object.
private  String localizeValueOutOrRangeException(ValueOutOfRangeException ex)
          Create a localized message out of ParseException object.
 void setConfig(String config)
          Sets the schedule configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINUTE

private static final int MINUTE
index of minute field.

See Also:
Constant Field Values

HOUR_OF_DAY

private static final int HOUR_OF_DAY
index of hour field.

See Also:
Constant Field Values

DAY_OF_MONTH

private static final int DAY_OF_MONTH
index of day field.

See Also:
Constant Field Values

MONTH

private static final int MONTH
index of month field.

See Also:
Constant Field Values

DAY_OF_WEEK

private static final int DAY_OF_WEEK
index of weekday field.

See Also:
Constant Field Values

TYPE

public static final String TYPE
The schedule type.

See Also:
Constant Field Values

config

private String config
The textual configuration form.


schedule

private int[][] schedule
The parserd schedule data.


i18n

private I18n i18n
I18n component


eol

protected String eol
The end of line string for this machine.

Constructor Detail

CronSchedule

public CronSchedule(I18n i18n)
Constructor.

Parameters:
i18n - the i18n component.
Method Detail

init

public void init(AbstractScheduler scheduler,
                 String config)
          throws InvalidScheduleException
Initialize the schedule.

Specified by:
init in interface Schedule
Parameters:
scheduler - the scheduler.
config - the configuration.
Throws:
InvalidScheduleException - if the specification is invalid.

getType

public String getType()
Returns the name of the schedule type.

Specified by:
getType in interface Schedule
Returns:
the name of the schedule type.

getConfig

public String getConfig()
Return the schedule configuration.

The format of the string is dependant on the nature of the schedule.

Specified by:
getConfig in interface Schedule
Returns:
the schedule configuration.

setConfig

public void setConfig(String config)
               throws InvalidScheduleException
Sets the schedule configuration.

The format of the string is dependant on the nature of the schedule.

Specified by:
setConfig in interface Schedule
Parameters:
config - schedule configuration.
Throws:
InvalidScheduleException - if the specification is invalid

atStartup

public boolean atStartup()
Checks if the job should be run at the very startup of the scheduler.

Specified by:
atStartup in interface Schedule
Returns:
true if the job should be run during the startup of the scheduler.

getNextRunTime

public Date getNextRunTime(Date currentTime,
                           Date lastRunTime)
Calculates the time of the job's next run.

Specified by:
getNextRunTime in interface Schedule
Parameters:
currentTime - the current time.
lastRunTime - the last time the job was run, or null if unknown.
Returns:
job's next execution time of null for never again.

computeMonth

private void computeMonth(Calendar nextRunDOM)

computeDay

private void computeDay(Calendar nextRun)

computeHour

private void computeHour(Calendar nextRun)

computeMinute

private void computeMinute(Calendar nextRun)

localizeParseException

private String localizeParseException(ParseException ex)
Create a localized message out of ParseException object.

Parameters:
ex - the exception.

localizeValueOutOrRangeException

private String localizeValueOutOrRangeException(ValueOutOfRangeException ex)
Create a localized message out of ParseException object.

Parameters:
ex - the exception.

addEscapes

protected String addEscapes(String str)
Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal.

This method was copied from JavaCC generated code.

Parameters:
str - input string.
Returns:
string with escaped sepcial characters.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.