Class QuartzScheduler
- java.lang.Object
-
- org.pentaho.platform.scheduler2.quartz.QuartzScheduler
-
- All Implemented Interfaces:
IScheduler
public class QuartzScheduler extends Object implements IScheduler
A Quartz implementation ofIScheduler
- Author:
- aphillips
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.pentaho.platform.api.scheduler2.IScheduler
IScheduler.SchedulerStatus
-
-
Field Summary
Fields Modifier and Type Field Description static String
RESERVEDMAPKEY_ACTIONCLASS
static String
RESERVEDMAPKEY_ACTIONID
static String
RESERVEDMAPKEY_ACTIONUSER
static String
RESERVEDMAPKEY_APPEND_DATE_FORMAT
static String
RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME
static String
RESERVEDMAPKEY_LINEAGE_ID
static String
RESERVEDMAPKEY_RESTART_FLAG
static String
RESERVEDMAPKEY_STREAMPROVIDER
static String
RESERVEDMAPKEY_STREAMPROVIDER_INPUTFILE
static String
RESERVEDMAPKEY_UIPASSPARAM
-
Constructor Summary
Constructors Constructor Description QuartzScheduler()
QuartzScheduler(org.quartz.SchedulerFactory schedulerFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ISchedulerListener listener)
static ComplexJobTrigger
createComplexTrigger(String cronExpression)
Job
createJob(String jobName, Class<? extends org.pentaho.platform.api.action.IAction> action, Map<String,Serializable> jobParams, IJobTrigger trigger)
Schedules a job to be run at one or more times in the future.Job
createJob(String jobName, Class<? extends org.pentaho.platform.api.action.IAction> action, Map<String,Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider)
Schedules a job to be run at one or more times in the future.Job
createJob(String jobName, String actionId, Map<String,Serializable> jobParams, IJobTrigger 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, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider)
Schedules a job to be run at one or more times in the future.protected Job
createJob(String jobName, Map<String,Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider)
static org.quartz.Trigger
createQuartzTrigger(IJobTrigger jobTrigger, QuartzJobKey jobId)
void
fireJobCompleted(org.pentaho.platform.api.action.IAction actionBean, String actionUser, Map<String,Serializable> params, IBackgroundExecutionStreamProvider streamProvider)
Not intended for public use.Map<IScheduleSubject,ComplexJobTrigger>
getAvailabilityWindows()
Gets the scheduler availability window for all subjects for whom a window has been setprotected String
getCurrentUser()
Job
getJob(String jobId)
Fetches a Job by jobIdList<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.org.quartz.Scheduler
getQuartzScheduler()
IScheduler.SchedulerStatus
getStatus()
Returns the current scheduler status.ComplexJobTrigger
getSubjectAvailabilityWindow(IScheduleSubject subject)
Gets the scheduler availability window to the specified subjectvoid
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 jobsvoid
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.protected void
setJobNextRun(Job job, org.quartz.Trigger trigger)
void
setListeners(Collection<ISchedulerListener> listeners)
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 QuartzSchedulerFactory
.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
triggerNow(String jobId)
Triggers the given quartz job by jobId to be executed immediatelyvoid
updateJob(String jobId, Map<String,Serializable> jobParams, IJobTrigger trigger)
Updates both the parameters and trigger to be used to execute an existing scheduled action.void
validateJobParams(Map<String,Serializable> jobParams)
Checks if the text configuration for the input/output files is present.
-
-
-
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
-
RESERVEDMAPKEY_STREAMPROVIDER
public static final String RESERVEDMAPKEY_STREAMPROVIDER
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_STREAMPROVIDER_INPUTFILE
public static final String RESERVEDMAPKEY_STREAMPROVIDER_INPUTFILE
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_UIPASSPARAM
public static final String RESERVEDMAPKEY_UIPASSPARAM
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_LINEAGE_ID
public static final String RESERVEDMAPKEY_LINEAGE_ID
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_RESTART_FLAG
public static final String RESERVEDMAPKEY_RESTART_FLAG
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME
public static final String RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME
- See Also:
- Constant Field Values
-
RESERVEDMAPKEY_APPEND_DATE_FORMAT
public static final String RESERVEDMAPKEY_APPEND_DATE_FORMAT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setQuartzSchedulerFactory
public void setQuartzSchedulerFactory(org.quartz.SchedulerFactory quartzSchedulerFactory) throws SchedulerException
Overrides the default QuartzSchedulerFactory
. Note: depending on the type of scheduler you are setting here, there may be initializing required prior to this setter being called. Only theSchedulerFactory.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- Throws:
SchedulerException
-
getQuartzScheduler
public org.quartz.Scheduler getQuartzScheduler() throws org.quartz.SchedulerException
- Throws:
org.quartz.SchedulerException
-
createJob
public Job createJob(String jobName, String actionId, Map<String,Serializable> jobParams, IJobTrigger trigger) throws SchedulerException
Schedules a job to be run at one or more times in the future.- Specified by:
createJob
in interfaceIScheduler
- Parameters:
jobName
- the user defined name for the jobactionId
- the bean Id of the action to be run as defined an a plugin's plugin.xmljobParams
- the parameters to be passed to the action when it runstrigger
- the time(s) at which to run the action- Returns:
- the scheduled job
- Throws:
SchedulerException
- If the job could not be scheduled
-
createJob
public Job createJob(String jobName, Class<? extends org.pentaho.platform.api.action.IAction> action, Map<String,Serializable> jobParams, IJobTrigger trigger) throws SchedulerException
Schedules a job to be run at one or more times in the future.- Specified by:
createJob
in interfaceIScheduler
- Parameters:
jobName
- the user defined name for the jobaction
- the action to be run at the scheduled time(s)jobParams
- the parameters to be passed to the action when it runstrigger
- the time(s) at which to run the action- Returns:
- the scheduled job
- Throws:
SchedulerException
- If the job could not be scheduled
-
createJob
public Job createJob(String jobName, Class<? extends org.pentaho.platform.api.action.IAction> action, Map<String,Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException
Schedules a job to be run at one or more times in the future.- Specified by:
createJob
in interfaceIScheduler
- Parameters:
jobName
- the user defined name for the jobaction
- the action to be run at the scheduled time(s)jobParams
- the parameters to be passed to the action when it runstrigger
- the time(s) at which to run the actionoutputStreamProvider
- if the action being scheduled expects to write to an output stream, at the time of action execution the this provider will be used to create the stream that passed to the action.- Returns:
- the scheduled job
- Throws:
SchedulerException
- If the job could not be scheduled
-
createJob
public Job createJob(String jobName, String actionId, Map<String,Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException
Schedules a job to be run at one or more times in the future.- Specified by:
createJob
in interfaceIScheduler
- Parameters:
jobName
- the user defined name for the jobactionId
- the bean Id of the action to be run as defined an a plugin's plugin.xmljobParams
- the parameters to be passed to the action when it runstrigger
- the time(s) at which to run the actionoutputStreamProvider
- if the action being scheduled expects to write to an output stream, at the time of action execution the this provider will be used to create the stream that passed to the action.- Returns:
- the scheduled job
- Throws:
SchedulerException
- If the job could not be scheduled
-
createQuartzTrigger
public static org.quartz.Trigger createQuartzTrigger(IJobTrigger jobTrigger, QuartzJobKey jobId) throws SchedulerException
- Throws:
SchedulerException
-
createJob
protected Job createJob(String jobName, Map<String,Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException
- Throws:
SchedulerException
-
updateJob
public void updateJob(String jobId, Map<String,Serializable> jobParams, IJobTrigger 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 interfaceIScheduler
- Parameters:
jobId
- the ID of an existing scheduled jobjobParams
- the parameters to be passed to the action when it runstrigger
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- Parameters:
jobId
- the job for which to query it's execution history- Returns:
- the execution history for the given job
-
triggerNow
public void triggerNow(String jobId) throws SchedulerException
Triggers the given quartz job by jobId to be executed immediately- Specified by:
triggerNow
in interfaceIScheduler
- Parameters:
jobId
- the job to be executed- Throws:
SchedulerException
-
getJob
public Job getJob(String jobId) throws SchedulerException
Fetches a Job by jobId- Specified by:
getJob
in interfaceIScheduler
- Parameters:
jobId
- the job to be returned- Throws:
SchedulerException
-
getJobs
public List<Job> getJobs(IJobFilter filter) throws SchedulerException
Lists currently scheduled jobs.- Specified by:
getJobs
in interfaceIScheduler
- 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
-
setJobNextRun
protected void setJobNextRun(Job job, org.quartz.Trigger trigger)
-
getMinScheduleInterval
public Integer getMinScheduleInterval(IScheduleSubject subject)
Get the minimum time that must elapse between job runs.- Specified by:
getMinScheduleInterval
in interfaceIScheduler
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- Throws:
SchedulerException
-
resumeJob
public void resumeJob(String jobId) throws SchedulerException
Allows previously paused jobs to resume running in the future.- Specified by:
resumeJob
in interfaceIScheduler
- 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 interfaceIScheduler
- 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 interfaceIScheduler
- Parameters:
subject
- the subject to which the interval appliesintervalInSeconds
- the interval in seconds
-
setSubjectAvailabilityWindow
public void setSubjectAvailabilityWindow(IScheduleSubject subject, ComplexJobTrigger availability)
Sets when a particular subject is allowed to schedule jobs.- Specified by:
setSubjectAvailabilityWindow
in interfaceIScheduler
- Parameters:
subject
- the subject to which the subject appliesavailability
- the window of time at which the scheduler is available
-
getCurrentUser
protected String getCurrentUser()
- Returns:
-
createComplexTrigger
public static ComplexJobTrigger createComplexTrigger(String cronExpression)
-
getStatus
public IScheduler.SchedulerStatus getStatus() throws SchedulerException
Returns the current scheduler status.- Specified by:
getStatus
in interfaceIScheduler
- 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 interfaceIScheduler
- Throws:
SchedulerException
-
prettyPrintMap
public static String prettyPrintMap(Map<String,Serializable> map)
-
addListener
public void addListener(ISchedulerListener listener)
- Specified by:
addListener
in interfaceIScheduler
-
setListeners
public void setListeners(Collection<ISchedulerListener> listeners)
-
fireJobCompleted
public void fireJobCompleted(org.pentaho.platform.api.action.IAction actionBean, String actionUser, Map<String,Serializable> params, IBackgroundExecutionStreamProvider streamProvider)
Description copied from interface:IScheduler
Not intended for public use.- Specified by:
fireJobCompleted
in interfaceIScheduler
-
validateJobParams
public void validateJobParams(Map<String,Serializable> jobParams) throws SchedulerException
Checks if the text configuration for the input/output files is present. If not - silently returns. If present checks if the input file is allowed to be scheduled.- Specified by:
validateJobParams
in interfaceIScheduler
- Parameters:
jobParams
- scheduling job parameters- Throws:
SchedulerException
- the configuration is recognized but the file can't be scheduled, is a folder or doesn't exist.
-
-