org.pentaho.platform.scheduler2.quartz
Class QuartzScheduler

java.lang.Object
  extended by org.pentaho.platform.scheduler2.quartz.QuartzScheduler
All Implemented Interfaces:
IScheduler

public class QuartzScheduler
extends Object
implements IScheduler

A Quartz implementation of IScheduler

Author:
aphillips

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.pentaho.platform.api.scheduler2.IScheduler
IScheduler.SchedulerStatus
 
Field Summary
static String RESERVEDMAPKEY_ACTIONCLASS
           
static String RESERVEDMAPKEY_ACTIONID
           
static String RESERVEDMAPKEY_ACTIONUSER
           
 
Constructor Summary
QuartzScheduler()
           
QuartzScheduler(org.quartz.SchedulerFactory schedulerFactory)
           
 
Method Summary
static ComplexJobTrigger createComplexTrigger(String cronExpression)
           
 Job createJob(String jobName, Class<? extends IAction> action, Map<String,Serializable> jobParams, JobTrigger trigger)
          Schedules a job to be run at one or more times in the future.
 Job createJob(String jobName, String actionId, Map<String,Serializable> jobParams, JobTrigger trigger)
          
 Map<IScheduleSubject,ComplexJobTrigger> getAvailabilityWindows()
          Gets the scheduler availability window for all subjects for whom a window has been set
 List<IJobResult> getJobHistory(String jobId)
          Returns a history of the runs for a particular job.
 List<Job> getJobs(IJobFilter filter)
          Lists currently scheduled jobs.
 Integer getMinScheduleInterval(IScheduleSubject subject)
          Get the minimum time that must elapse between job runs.
 IScheduler.SchedulerStatus getStatus()
          Returns the current scheduler status.
 ComplexJobTrigger getSubjectAvailabilityWindow(IScheduleSubject subject)
          Gets the scheduler availability window to the specified subject
 void pause()
          Pauses the entire scheduler, which prevents all scheduled jobs from running.
 void pauseJob(String jobId)
          Prevents the specified job from running in the future.
static String prettyPrintMap(Map<String,Serializable> map)
           
 void removeJob(String jobId)
          Removes the specified job from the list of scheduled jobs
 void resumeJob(String jobId)
          Allows previously paused jobs to resume running in the future.
 void setAvailabilityWindows(Map<IScheduleSubject,ComplexJobTrigger> availability)
          Replaces the scheduler availability map with the provided availability map.
 void setMinScheduleInterval(IScheduleSubject subject, int intervalInSeconds)
          Sets the minimum time that must elapse between runs of any jobs.
 void setQuartzSchedulerFactory(org.quartz.SchedulerFactory quartzSchedulerFactory)
          Overrides the default Quartz SchedulerFactory.
 void setSubjectAvailabilityWindow(IScheduleSubject subject, ComplexJobTrigger availability)
          Sets when a particular subject is allowed to schedule jobs.
 void shutdown()
          Shuts the scheduler down so it will process no more jobs.
 void start()
          Allows the scheduler to process scheduled jobs.
 void updateJob(String jobId, Map<String,Serializable> jobParams, JobTrigger trigger)
          Updates both the parameters and trigger to be used to execute an existing scheduled action.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESERVEDMAPKEY_ACTIONCLASS

public static final String RESERVEDMAPKEY_ACTIONCLASS
See Also:
Constant Field Values

RESERVEDMAPKEY_ACTIONUSER

public static final String RESERVEDMAPKEY_ACTIONUSER
See Also:
Constant Field Values

RESERVEDMAPKEY_ACTIONID

public static final String RESERVEDMAPKEY_ACTIONID
See Also:
Constant Field Values
Constructor Detail

QuartzScheduler

public QuartzScheduler(org.quartz.SchedulerFactory schedulerFactory)

QuartzScheduler

public QuartzScheduler()
Method Detail

setQuartzSchedulerFactory

public void setQuartzSchedulerFactory(org.quartz.SchedulerFactory quartzSchedulerFactory)
Overrides the default Quartz SchedulerFactory. Note: depending on the type of scheduler you are setting here, there may be initializing required prior to this setter being called. Only the SchedulerFactory.getScheduler() will be called later, so the factory set here must already be in a state where that invocation will be successful.

Parameters:
quartzSchedulerFactory - the quartz factory to use for generating scheduler instances

createJob

public Job createJob(String jobName,
                     String actionId,
                     Map<String,Serializable> jobParams,
                     JobTrigger trigger)
              throws SchedulerException

Specified by:
createJob in interface IScheduler
Throws:
SchedulerException

createJob

public Job createJob(String jobName,
                     Class<? extends IAction> action,
                     Map<String,Serializable> jobParams,
                     JobTrigger trigger)
              throws SchedulerException
Schedules a job to be run at one or more times in the future.

Specified by:
createJob in interface IScheduler
Parameters:
jobName - the user defined name for the job
action - the action to be run at the scheduled time(s)
jobParams - the parameters to be passed to the action when it runs
trigger - the time(s) at which to run the action
Returns:
the scheduled job
Throws:
SchedulerException - If the job could not be scheduled

updateJob

public void updateJob(String jobId,
                      Map<String,Serializable> jobParams,
                      JobTrigger trigger)
               throws SchedulerException
Description copied from interface: IScheduler
Updates both the parameters and trigger to be used to execute an existing scheduled action.

Specified by:
updateJob in interface IScheduler
Parameters:
jobId - the ID of an existing scheduled job
jobParams - the parameters to be passed to the action when it runs
trigger - the time(s) at which to run the action
Throws:
SchedulerException - If the job could not be updated

getAvailabilityWindows

public Map<IScheduleSubject,ComplexJobTrigger> getAvailabilityWindows()
Gets the scheduler availability window for all subjects for whom a window has been set

Specified by:
getAvailabilityWindows in interface IScheduler
Returns:
the scheduler availability map

getJobHistory

public List<IJobResult> getJobHistory(String jobId)
Returns a history of the runs for a particular job.

Specified by:
getJobHistory in interface IScheduler
Parameters:
jobId - the job for which to query it's execution history
Returns:
the execution history for the given job

getJobs

public List<Job> getJobs(IJobFilter filter)
                  throws SchedulerException
Lists currently scheduled jobs.

Specified by:
getJobs in interface IScheduler
Parameters:
filter - the filter to use to determine which jobs to return. If null all scheduled jobs are return.
Returns:
the scheduled jobs
Throws:
SchedulerException

getMinScheduleInterval

public Integer getMinScheduleInterval(IScheduleSubject subject)
Get the minimum time that must elapse between job runs.

Specified by:
getMinScheduleInterval in interface IScheduler
Parameters:
subject - the subject whose min interval is being requested return the minimum interval or null if no interval has been set

getSubjectAvailabilityWindow

public ComplexJobTrigger getSubjectAvailabilityWindow(IScheduleSubject subject)
Gets the scheduler availability window to the specified subject

Specified by:
getSubjectAvailabilityWindow in interface IScheduler
Parameters:
subject - the subject whose window is being requested
Returns:
the subject's availability window

pause

public void pause()
           throws SchedulerException
Pauses the entire scheduler, which prevents all scheduled jobs from running. Any currently running jobs are allowed to complete. Note that the "paused" state of individual jobs is not changed by this call.

Specified by:
pause in interface IScheduler
Throws:
SchedulerException

pauseJob

public void pauseJob(String jobId)
              throws SchedulerException
Prevents the specified job from running in the future. The job remains in the list of scheduled jobs in a "paused" state. If the job is currently running, the currently running job is allowed to complete.

Specified by:
pauseJob in interface IScheduler
Parameters:
jobId - the job to be paused
Throws:
SchedulerException

removeJob

public void removeJob(String jobId)
               throws SchedulerException
Removes the specified job from the list of scheduled jobs

Specified by:
removeJob in interface IScheduler
Parameters:
jobId - the job to be removed
Throws:
SchedulerException

start

public void start()
           throws SchedulerException
Allows the scheduler to process scheduled jobs. Note that the "paused" state of individual jobs is not changed by this call.

Specified by:
start in interface IScheduler
Throws:
SchedulerException

resumeJob

public void resumeJob(String jobId)
               throws SchedulerException
Allows previously paused jobs to resume running in the future.

Specified by:
resumeJob in interface IScheduler
Parameters:
jobId - the job to be resumed
Throws:
SchedulerException

setAvailabilityWindows

public void setAvailabilityWindows(Map<IScheduleSubject,ComplexJobTrigger> availability)
Replaces the scheduler availability map with the provided availability map.

Specified by:
setAvailabilityWindows in interface IScheduler
Parameters:
availability - the new scheduler availability map

setMinScheduleInterval

public void setMinScheduleInterval(IScheduleSubject subject,
                                   int intervalInSeconds)
Sets the minimum time that must elapse between runs of any jobs. For example if set to "5" then a job may not be scheduled to run less than 5 seconds apart.

Specified by:
setMinScheduleInterval in interface IScheduler
Parameters:
subject - the subject to which the interval applies

setSubjectAvailabilityWindow

public void setSubjectAvailabilityWindow(IScheduleSubject subject,
                                         ComplexJobTrigger availability)
Sets when a particular subject is allowed to schedule jobs.

Specified by:
setSubjectAvailabilityWindow in interface IScheduler
Parameters:
subject - the subject to which the subject applies
availability - the window of time at which the scheduler is available

createComplexTrigger

public static ComplexJobTrigger createComplexTrigger(String cronExpression)

getStatus

public IScheduler.SchedulerStatus getStatus()
                                     throws SchedulerException
Returns the current scheduler status.

Specified by:
getStatus in interface IScheduler
Returns:
the scheduler status
Throws:
SchedulerException

shutdown

public void shutdown()
              throws SchedulerException
Shuts the scheduler down so it will process no more jobs. The implementation will decide if this means kill jobs in progress or let them finish.

Specified by:
shutdown in interface IScheduler
Throws:
SchedulerException

prettyPrintMap

public static String prettyPrintMap(Map<String,Serializable> map)