Class SchedulerPluginApi


  • public class SchedulerPluginApi
    extends PluginApi<SchedulerPlugin>
    A Scheduler plugin to plan execution of Jobs from XWiki with cron expressions. The plugin uses Quartz's scheduling library.

    Jobs are represented by Object XObjects, instances of the SchedulerPlugin.XWIKI_JOB_CLASS XClass. These XObjects do store a job name, the implementation class name of the job to be executed, the cron expression to precise when the job should be fired, and possibly a groovy script with the job's program.

    The plugin offers a GroovyJob Groovy Job wrapper to execute groovy scripts (typically for use inside the Wiki), but can also be used with any Java class implementing Job

    Version:
    $Id: e5c7325b85806541bfb2202a280f603a0de6f2b8 $
    • Method Detail

      • getStatus

        public String getStatus​(Object object)
        Return the trigger state of the given SchedulerPlugin.XWIKI_JOB_CLASS XObject job. Possible values are : None (the trigger does not exists yet, or has been deleted), Normal, Blocked, Complete, Error and Paused
        Parameters:
        object - the XObject job to give the state of
        Returns:
        a String representing this state
      • getJobStatus

        public JobState getJobStatus​(BaseObject object)
                              throws org.quartz.SchedulerException
        Return the trigger state as a $JobState, that holds both the integer trigger's inner value of the state and a String as a human readable representation of that state
        Throws:
        org.quartz.SchedulerException
      • scheduleJob

        public boolean scheduleJob​(Object object)
        Schedule the given XObject to be executed according to its parameters. Errors are returned in the context map. Scheduling can be called for example: #if($xwiki.scheduler.scheduleJob($job)!=true) #error($xcontext.get("error") #else #info("Job scheduled") #end Where $job is an XObject, instance of the SchedulerPlugin.XWIKI_JOB_CLASS XClass
        Parameters:
        object - the XObject to be scheduled, an instance of the XClass XWiki.SchedulerJobClass
        Returns:
        true on success, false on failure
      • scheduleJob

        public boolean scheduleJob​(BaseObject object)
      • scheduleJobs

        public boolean scheduleJobs​(Document document)
        Schedule all SchedulerPlugin.XWIKI_JOB_CLASS XObjects stored inside the given Wiki document, according to each XObject own parameters.
        Parameters:
        document - the document holding the XObjects Jobs to be scheduled
        Returns:
        true on success, false on failure.
      • pauseJob

        public boolean pauseJob​(Object object)
        Pause the given XObject job by pausing all of its current triggers. Can be called the same way as scheduleJob(Object)
        Parameters:
        object - the wrapped XObject Job to be paused
        Returns:
        true on success, false on failure.
      • pauseJob

        public boolean pauseJob​(BaseObject object)
      • resumeJob

        public boolean resumeJob​(Object object)
        Resume a XObject job that is in a JobState.STATE_PAUSED state. Can be called the same way as scheduleJob(Object)
        Parameters:
        object - the wrapped XObject Job to be paused
        Returns:
        true on success, false on failure.
      • resumeJob

        public boolean resumeJob​(BaseObject object)
      • unscheduleJob

        public boolean unscheduleJob​(Object object)
        Unschedule a XObject job by deleting it from the jobs table. Can be called the same way as scheduleJob(Object)
        Parameters:
        object - the wrapped XObject Job to be paused
        Returns:
        true on success, false on failure.
      • unscheduleJob

        public boolean unscheduleJob​(BaseObject object)
      • triggerJob

        public boolean triggerJob​(Object object)
        Trigger a XObject job (execute it now).
        Parameters:
        object - the wrapped XObject Job to be triggered
        Returns:
        true on success, false on failure.
      • triggerJob

        public boolean triggerJob​(BaseObject object)
        Trigger a BaseObject job (execute it now).
        Parameters:
        object - the BaseObject Job to be triggered
        Returns:
        true on success, false on failure.
      • getPreviousFireTime

        public Date getPreviousFireTime​(Object object)
        Give, for a XObject job in a JobState.STATE_NORMAL state, the previous date at which the job has been executed, the fire time is not computed from the CRON expression, this method will return null if the .
        Parameters:
        object - the wrapped XObject for which to give the fire time
        Returns:
        the date the job has been executed
      • getPreviousFireTime

        public Date getPreviousFireTime​(BaseObject object)
        Give, for a BaseObject job in a JobState.STATE_NORMAL state, the previous date at which the job has been executed. Note that this method does not compute a date from the CRON expression, it only returns a date value which is set each time the job is executed. If the job has never been fired this method will return null.
        Parameters:
        object - the BaseObject for which to give the fire time
        Returns:
        the date the job has been executed
      • getNextFireTime

        public Date getNextFireTime​(Object object)
        Give, for a XObject job in a JobState.STATE_NORMAL state, the next date at which the job will be executed, according to its cron expression. Errors are returned in the context map. Can be called for example: #set($firetime = $xwiki.scheduler.getNextFireTime($job)) #if (!$firetime || $firetime=="") #error($xcontext.get("error") #else #info("Fire time : $firetime") #end Where $job is an XObject, instance of the SchedulerPlugin.XWIKI_JOB_CLASS XClass
        Parameters:
        object - the wrapped XObject for which to give the fire date
        Returns:
        the date the job will be executed
      • getNextFireTime

        public Date getNextFireTime​(BaseObject object)