Class JobsScheduler
- java.lang.Object
-
- com.netscape.cmscore.jobs.JobsScheduler
-
- All Implemented Interfaces:
ISubsystem
,IJobsScheduler
,java.lang.Runnable
public class JobsScheduler extends java.lang.Object implements java.lang.Runnable, IJobsScheduler
This is a daemon thread that handles scheduled jobs like cron would do with different jobs. This daemon wakes up at a pre-configured interval to see if there is any job to be done, if so, a thread is created to execute the job(s).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:
JobCron
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
DELIM
static org.slf4j.Logger
logger
protected java.lang.String
mId
Scheduler thread doing job schedulingprotected static long
MINUTE_MILLI
java.util.Hashtable<java.lang.String,JobPlugin>
mJobPlugins
java.util.Hashtable<java.lang.String,IJob>
mJobs
protected java.lang.Thread
mScheduleThread
-
Fields inherited from interface com.netscape.certsrv.jobs.IJobsScheduler
ID, PROP_CLASS, PROP_ENABLED, PROP_IMPL, PROP_INTERVAL, PROP_JOB, PROP_PLUGIN
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IJobCron
createJobCron(java.lang.String cs)
Creates a job cron.java.lang.String[]
getConfigParams(java.lang.String implName)
Gets configuration parameters for the given job plugin.IConfigStore
getConfigStore()
Returns the root configuration storage of this system.java.lang.String
getId()
Retrieves id (name) of this subsystem.static JobsScheduler
getInstance()
java.util.Hashtable<java.lang.String,IJob>
getInstances()
Retrieves all the job instances.java.util.Hashtable<java.lang.String,JobPlugin>
getJobPlugins()
java.util.Hashtable<java.lang.String,JobPlugin>
getPlugins()
Retrieves all the job implementations.void
init(IConfigStore config)
read from the config file all implementations of Jobs, register and initialize themprotected boolean
isShowTime(IJob job, java.util.Calendar now)
Is it time for the job?void
log(int level, java.lang.String msg)
Writes a message to the system log.void
run()
when wake up: .void
setId(java.lang.String id)
Sets id string to this subsystem.void
setInterval(int minutes)
Sets daemon's wakeup interval.void
shutdown()
shuts down Jobs one by one.void
startDaemon()
creates and starts the daemon threadvoid
startup()
registers the administration servlet with the administration subsystem.
-
-
-
Field Detail
-
logger
public static org.slf4j.Logger logger
-
MINUTE_MILLI
protected static final long MINUTE_MILLI
- See Also:
- Constant Field Values
-
DELIM
protected static final java.lang.String DELIM
- See Also:
- Constant Field Values
-
mId
protected java.lang.String mId
Scheduler thread doing job scheduling
-
mScheduleThread
protected java.lang.Thread mScheduleThread
-
mJobPlugins
public java.util.Hashtable<java.lang.String,JobPlugin> mJobPlugins
-
mJobs
public java.util.Hashtable<java.lang.String,IJob> mJobs
-
-
Method Detail
-
getInstance
public static JobsScheduler getInstance()
-
init
public void init(IConfigStore config) throws EBaseException, EJobsException
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
- failed to initializeEJobsException
-
getPlugins
public java.util.Hashtable<java.lang.String,JobPlugin> getPlugins()
Description copied from interface:IJobsScheduler
Retrieves all the job implementations.- Specified by:
getPlugins
in interfaceIJobsScheduler
- Returns:
- a Hashtable of available job plugin implementations
-
getInstances
public java.util.Hashtable<java.lang.String,IJob> getInstances()
Description copied from interface:IJobsScheduler
Retrieves all the job instances.- Specified by:
getInstances
in interfaceIJobsScheduler
- 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- Specified by:
run
in interfacejava.lang.Runnable
-
createJobCron
public IJobCron createJobCron(java.lang.String cs) throws EBaseException
Description copied from interface:IJobsScheduler
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.- Specified by:
createJobCron
in interfaceIJobsScheduler
- 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
protected boolean isShowTime(IJob job, java.util.Calendar now)
Is it time for the job?
-
getId
public java.lang.String getId()
Retrieves id (name) of this subsystem.- Specified by:
getId
in interfaceISubsystem
- Returns:
- name of the Jobs Scheduler subsystem
-
setId
public void setId(java.lang.String id) throws EBaseException
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()
creates and starts the daemon thread- Specified by:
startDaemon
in interfaceIJobsScheduler
-
startup
public void startup() throws EBaseException
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
public IConfigStore getConfigStore()
Returns the root configuration storage of this system.- Specified by:
getConfigStore
in interfaceISubsystem
- Returns:
- configuration store of this subsystem
-
getConfigParams
public java.lang.String[] getConfigParams(java.lang.String implName) throws EJobsException
Gets configuration parameters for the given job plugin.- Specified by:
getConfigParams
in interfaceIJobsScheduler
- Parameters:
implName
- Name of the job plugin.- Returns:
- Hashtable of required parameters.
- Throws:
EJobsException
- when job plugin implementation can not be found, instantiation is impossible, permission problem with the class.
-
setInterval
public void setInterval(int minutes)
Description copied from interface:IJobsScheduler
Sets daemon's wakeup interval.- Specified by:
setInterval
in interfaceIJobsScheduler
- Parameters:
minutes
- time in minutes that is to be the frequency of JobsScheduler wakeup call.
-
log
public void log(int level, java.lang.String msg)
Description copied from interface:IJobsScheduler
Writes a message to the system log.- Specified by:
log
in interfaceIJobsScheduler
- 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
public java.util.Hashtable<java.lang.String,JobPlugin> getJobPlugins()
-
-