org.openeai.afa
Class Schedule

java.lang.Object
  extended by org.openeai.OpenEaiObject
      extended by org.openeai.afa.Schedule

public class Schedule
extends OpenEaiObject

This is a class that wraps the execution details of a set of commands. It keeps track of when a particular command(s) should execute. The ScheduledApp class will use these objects to determine when commands associated to this Schedule should run. Then the ScheduledApp will execute the command(s) associated with this Schedule.

The Schedule object allows a flexible mechanism to associate certain times, days or intervals at which the ScheduledCommands associated to this schedule should run. By querying this information the ScheduledApp component can determine if the ScheduledCommands associated to this Schedule should run and if so, execute them.

Version:
4.0 - 27 April 2005
Author:
Tod Jackson (tod@openeai.org), Steve Wheat (steve@openeai.org)

Field Summary
static java.lang.String FRIDAY
           
static java.lang.String MONDAY
           
static java.lang.String SATURDAY
           
static java.lang.String SUNDAY
           
static java.lang.String THURSDAY
           
static java.lang.String TUESDAY
           
static java.lang.String WEDNESDAY
           
 
Fields inherited from class org.openeai.OpenEaiObject
logger
 
Constructor Summary
Schedule(ScheduleConfig sConfig)
          Constructs the Schedule object with a ScheduleConfig object which wraps the Schedules information found in the ScheduledApp's deployment document.
 
Method Summary
 void addCommand(java.lang.String name, CommandConfig cConfig)
          Adds a command to this schedule.
 ScheduledCommand getCommand(java.lang.String name)
          Returns a ScheduledCommand associated to this schedule by name.
 java.util.HashMap getCommands()
          Returns all ScheduledCommands associated to this schedule.
 MailService getMailService()
          This method returns the MailService object that will be associated to the Schedule as specified in the deployment document.
 java.lang.String getName()
          Returns the Schedule name according to information found in the config document for the application being configured.
 ScheduleIdStore getScheduleIdStore()
           
 java.util.List getScheduleRuntimes()
          Returns a List that contains ScheduleRuntime objects associated to this Schedule.
 boolean isImmediate()
          Tells the caller if this Schedule is suppose to run immediately.
 void setCommands(java.util.HashMap commands)
          Sets all ScheduledCommands associated to this schedule.
 void setMailService(MailService m)
          This method sets the MailService object that will be associated to the Schedule as specified in the deployment document.
 void setName(java.lang.String name)
          Sets the Schedule name according to information found in the config document for the application being configured.
 void setScheduleIdStore(ScheduleIdStore store)
           
 boolean shouldRun()
          Determines if the ScheduledCommands associated to this Schedule should run.
 void stop()
           
 
Methods inherited from class org.openeai.OpenEaiObject
getAppName, getDebug, getFromAddr, getMailHost, getProperties, getToAddr, initializeLog4j, initializeLog4j, initializeLog4j, setAppName, setDebug, setFromAddr, setMailHost, setProperties, setToAddr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUNDAY

public static final java.lang.String SUNDAY
See Also:
Constant Field Values

MONDAY

public static final java.lang.String MONDAY
See Also:
Constant Field Values

TUESDAY

public static final java.lang.String TUESDAY
See Also:
Constant Field Values

WEDNESDAY

public static final java.lang.String WEDNESDAY
See Also:
Constant Field Values

THURSDAY

public static final java.lang.String THURSDAY
See Also:
Constant Field Values

FRIDAY

public static final java.lang.String FRIDAY
See Also:
Constant Field Values

SATURDAY

public static final java.lang.String SATURDAY
See Also:
Constant Field Values
Constructor Detail

Schedule

public Schedule(ScheduleConfig sConfig)
         throws java.lang.InstantiationException
Constructs the Schedule object with a ScheduleConfig object which wraps the Schedules information found in the ScheduledApp's deployment document.

Throws:
java.lang.InstantiationException
Method Detail

stop

public void stop()

setScheduleIdStore

public void setScheduleIdStore(ScheduleIdStore store)

getScheduleIdStore

public ScheduleIdStore getScheduleIdStore()

addCommand

public final void addCommand(java.lang.String name,
                             CommandConfig cConfig)
                      throws java.lang.InstantiationException,
                             java.lang.NoSuchMethodException
Adds a command to this schedule. This will be performed when AppConfig is instantiating and configuring the ScheduledApp that contains this schedule. This method will instantiate the command by passing the CommandConfig object and link that command to a name. Then when it is determined that the Schedule is suppose to run, it will be able to return the command(s) associated to this Schedule for execution.

Parameters:
cConfig - CommandConfig the CommandConfig object that AppConfig has made available and is used instantiate the command associated to this Schedule.
Throws:
java.lang.InstantiationException
java.lang.NoSuchMethodException

getCommand

public final ScheduledCommand getCommand(java.lang.String name)
Returns a ScheduledCommand associated to this schedule by name. This will be called by the ScheduledApp when it determines that this schedule should execute. It will retrieve command(s) from this Schedule and call their 'execute' methods.

Parameters:
name - String command name.
Returns:
ScheduledCommand an implementation of the ScheduledCommand interface.

setCommands

public final void setCommands(java.util.HashMap commands)
Sets all ScheduledCommands associated to this schedule. This is called when the Schedule is initialized.

Parameters:
commands - HashMap of ScheduledCommands.

getCommands

public final java.util.HashMap getCommands()
Returns all ScheduledCommands associated to this schedule.

Returns:
HashMap of ScheduledCommands.

setName

public final void setName(java.lang.String name)
Sets the Schedule name according to information found in the config document for the application being configured.

Parameters:
name - String the Schedule name

getName

public final java.lang.String getName()
Returns the Schedule name according to information found in the config document for the application being configured.

Returns:
String the Schedule name

getScheduleRuntimes

public final java.util.List getScheduleRuntimes()
Returns a List that contains ScheduleRuntime objects associated to this Schedule. These will be used to determine if it's time to run this schedule.

Returns:
java.util.List

setMailService

public void setMailService(MailService m)
This method sets the MailService object that will be associated to the Schedule as specified in the deployment document. This MailService object will be used by the ScheduleApp foundation to notify someone if a 'daemon' type application (ScheduledCommand) throws an exception during execution.

Overrides:
setMailService in class OpenEaiObject
Parameters:
m - the mail service object to associate to this schedule.

getMailService

public MailService getMailService()
This method returns the MailService object that will be associated to the Schedule as specified in the deployment document. This MailService object will be used by the ScheduleApp foundation to notify someone if a 'daemon' type application (ScheduledCommand) throws an exception during execution.

Overrides:
getMailService in class OpenEaiObject
Returns:
MailService the mail service object.

shouldRun

public final boolean shouldRun()
                        throws ScheduleIdStoreException
Determines if the ScheduledCommands associated to this Schedule should run. This is determined by a number of factors all configured via the ScheduledApp's deployment document.

Factors that determine when a Schedule should be ran include the Schedule's 'runtime'. The Schedule object contains a list of 'runtimes' associated to this Schedule that tell it the Days and Times that this Schedule should be ran. When a Schedule has been executed, it will update its ScheduleIdStore indicating that the Schedule has been run. This store is checked to ensure a Schedule is not executed more than once in a given day. This store is persisted to a configurable location to survive the application stopping and starting. When the day changes (midnight is reached) the Schedule will remove any Schedule id's from the store for the new day so they will again be executed.

Returns:
boolean, true if the ScheduledCommands associated to this Schedule should run, false if not.
Throws:
ScheduleIdStoreException - if errors occur determining if the Schedule should be ran.
See Also:
ScheduleRuntime, ScheduleIdStore

isImmediate

public final boolean isImmediate()
Tells the caller if this Schedule is suppose to run immediately.

Returns:
boolean


Copyright © 2002,2003 OpenEAI Software Foundation