Class JobsScheduler
- All Implemented Interfaces:
ISubsystem
,Runnable
The interval jobsScheduler.interval in the configuration is specified as number of minutes. If not set, the default is 1 minute. Note that the cron specification for each job CAN NOT be finer than the granularity of the Scheduler daemon interval. For example, if the daemon interval is set to 5 minute, a job cron for every minute at 7am on each Tuesday (e.g. * 7 * * 2) will result in the execution of the job thread only once every 5 minutes during that hour. The inteval value is recommended at 1 minute, setting it otherwise has the potential of forever missing the beat. Use with caution.
- Version:
- $Revision$, $Date$
- Author:
- cfu
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
static final String
The ID of this componentstatic org.slf4j.Logger
protected String
Scheduler thread doing job schedulingprotected static final long
protected Thread
static final String
constant that represents the configuration parameter "class" for this component in CMS.cfg.static final String
constant that represents the configuration parameter "enabled" for this component in CMS.cfg.static final String
constant that represents the configuration parameter "impl" for this component in CMS.cfg.static final String
constant that represents the configuration parameter "interval" for this component in CMS.cfg.static final String
constant that represents the configuration parameter "job" for this component in CMS.cfg.static final String
constant that represents the configuration parameter "pluginName" for this component in CMS.cfg. -
Method Summary
Modifier and TypeMethodDescriptioncreateJobCron
(String cs) Creates a job cron.String[]
getConfigParams
(String implName) Retrieves the configuration parameters of the given implementation.Returns the root configuration storage of this system.getId()
Retrieves id (name) of this subsystem.static JobsScheduler
Retrieves all the job instances.Retrieves all the job implementations.void
init
(ConfigStore config) read from the config file all implementations of Jobs, register and initialize themprotected boolean
isShowTime
(IJob job, Calendar now) Is it time for the job?void
Writes a message to the system log.void
run()
when wake up: .void
Sets id string to this subsystem.void
setInterval
(int minutes) Sets daemon's wakeup interval.void
shutdown()
shuts down Jobs one by one.void
Starts up the JobsScheduler daemon.void
startup()
registers the administration servlet with the administration subsystem.
-
Field Details
-
logger
public static org.slf4j.Logger logger -
ID
The ID of this component- See Also:
-
PROP_ENABLED
constant that represents the configuration parameter "enabled" for this component in CMS.cfg. The value of which tells CMS whether the JobsScheduler is enabled or not- See Also:
-
PROP_INTERVAL
constant that represents the configuration parameter "interval" for this component in CMS.cfg. The value of which tells CMS the interval that the JobsScheduler thread should wake up and look for jobs to execute- See Also:
-
PROP_CLASS
constant that represents the configuration parameter "class" for this component in CMS.cfg. The values of which are the actual implementation classes- See Also:
-
PROP_JOB
constant that represents the configuration parameter "job" for this component in CMS.cfg. The values of which gives configuration information specific to one single job instance. There may be multiple jobs served by the jobsScheduler- See Also:
-
PROP_IMPL
constant that represents the configuration parameter "impl" for this component in CMS.cfg. The values of which are actual plugin implementation(s)- See Also:
-
PROP_PLUGIN
constant that represents the configuration parameter "pluginName" for this component in CMS.cfg. The value of which gives the pluginName for the job it associates with- See Also:
-
MINUTE_MILLI
protected static final long MINUTE_MILLI- See Also:
-
DELIM
- See Also:
-
mId
Scheduler thread doing job scheduling -
mScheduleThread
-
mJobPlugins
-
mJobs
-
-
Method Details
-
getInstance
-
init
read from the config file all implementations of Jobs, register and initialize themthe config params have the following formats: jobScheduler.impl.[implementation name].class=[package name] jobScheduler.job.[job name].pluginName=[implementation name] jobScheduler.job.[job name].cron=[crontab format] jobScheduler.job.[job name].[any job specific params]=[values]
- Specified by:
init
in interfaceISubsystem
- Parameters:
config
- jobsScheduler configStore- Throws:
EBaseException
EJobsException
-
getPlugins
Retrieves all the job implementations.- Returns:
- a Hashtable of available job plugin implementations
-
getInstances
Retrieves all the job instances.- Returns:
- a Hashtable of job instances
-
run
public void run()when wake up: . execute the scheduled job(s) * if job still running from previous interval, skip it . figure out when is the next wakeup time (every interval). If current wakup time runs over the interval, skip the missed interval(s) . sleep till the next wakeup time -
createJobCron
Creates a job cron. Each job is associated with a "cron" which specifies the rule of frequency that this job should be executed (e.g. every Sunday at midnight). This method is called by each job at initialization time.- Parameters:
cs
- the string that represents the cron. See IJobCron for detail of the format.- Returns:
- IJobCron an IJobCron
- Throws:
EBaseException
- when the cron string, cs, can not be parsed correctly
-
isShowTime
Is it time for the job? -
getId
Retrieves id (name) of this subsystem.- Specified by:
getId
in interfaceISubsystem
- Returns:
- name of the Jobs Scheduler subsystem
-
setId
Sets id string to this subsystem.Use with caution. Should not do it when sharing with others
- Specified by:
setId
in interfaceISubsystem
- Parameters:
id
- name to be applied to an Jobs Scheduler subsystem- Throws:
EBaseException
- failed to set id
-
startDaemon
public void startDaemon()Starts up the JobsScheduler daemon. Usually called from the initialization method when it's successfully initialized. -
startup
registers the administration servlet with the administration subsystem.- Specified by:
startup
in interfaceISubsystem
- Throws:
EBaseException
- failed to start up
-
shutdown
public void shutdown()shuts down Jobs one by one.- Specified by:
shutdown
in interfaceISubsystem
-
getConfigStore
Returns the root configuration storage of this system.- Specified by:
getConfigStore
in interfaceISubsystem
- Returns:
- configuration store of this subsystem
-
getConfigParams
Retrieves the configuration parameters of the given implementation. It is used to return to the Console for configuration- Parameters:
implName
- the pulubin implementation name- Returns:
- a String array of required configuration parameters of the given implementation.
- Throws:
EJobsException
- when job plugin implementation can not be found, instantiation is impossible, permission problem with the class.
-
setInterval
public void setInterval(int minutes) Sets daemon's wakeup interval.- Parameters:
minutes
- time in minutes that is to be the frequency of JobsScheduler wakeup call.
-
log
Writes a message to the system log.- Parameters:
level
- an integer representing the log message level. Depending on the configuration set by the administrator, this value is a determining factor for whether this message will be actually logged or not. The lower the level, the higher the priority, and the higher chance it will be logged.msg
- the message to be written. Ideally should call CMS.getLogMessage() to get the localizable message from the log properties file.
-
getJobPlugins
-