Package com.xpn.xwiki.plugin.scheduler
Class SchedulerPluginApi
- java.lang.Object
-
- com.xpn.xwiki.api.Api
-
- com.xpn.xwiki.plugin.PluginApi<SchedulerPlugin>
-
- com.xpn.xwiki.plugin.scheduler.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 theSchedulerPlugin.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 implementingJob
- Version:
- $Id: e5c7325b85806541bfb2202a280f603a0de6f2b8 $
-
-
Constructor Summary
Constructors Constructor Description SchedulerPluginApi(SchedulerPlugin plugin, XWikiContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JobState
getJobStatus(Object object)
JobState
getJobStatus(BaseObject object)
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 stateDate
getNextFireTime(Object object)
Give, for a XObject job in aJobState.STATE_NORMAL
state, the next date at which the job will be executed, according to its cron expression.Date
getNextFireTime(BaseObject object)
Date
getPreviousFireTime(Object object)
Give, for a XObject job in aJobState.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 .Date
getPreviousFireTime(BaseObject object)
Give, for a BaseObject job in aJobState.STATE_NORMAL
state, the previous date at which the job has been executed.String
getStatus(Object object)
Return the trigger state of the givenSchedulerPlugin.XWIKI_JOB_CLASS
XObject job.boolean
pauseJob(Object object)
Pause the given XObject job by pausing all of its current triggers.boolean
pauseJob(BaseObject object)
boolean
resumeJob(Object object)
Resume a XObject job that is in aJobState.STATE_PAUSED
state.boolean
resumeJob(BaseObject object)
boolean
scheduleJob(Object object)
Schedule the given XObject to be executed according to its parameters.boolean
scheduleJob(BaseObject object)
boolean
scheduleJobs(Document document)
Schedule allSchedulerPlugin.XWIKI_JOB_CLASS
XObjects stored inside the given Wiki document, according to each XObject own parameters.boolean
triggerJob(Object object)
Trigger a XObject job (execute it now).boolean
triggerJob(BaseObject object)
Trigger a BaseObject job (execute it now).boolean
unscheduleJob(Object object)
Unschedule a XObject job by deleting it from the jobs table.boolean
unscheduleJob(BaseObject object)
-
Methods inherited from class com.xpn.xwiki.plugin.PluginApi
getInternalPlugin, getProtectedPlugin, setPlugin
-
Methods inherited from class com.xpn.xwiki.api.Api
convert, convert, convert, convertAttachments, getAuthorizationManager, getContextualAuthorizationManager, getXWikiContext, hasAccess, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
-
-
-
-
Constructor Detail
-
SchedulerPluginApi
public SchedulerPluginApi(SchedulerPlugin plugin, XWikiContext context)
-
-
Method Detail
-
getStatus
public String getStatus(Object object)
Return the trigger state of the givenSchedulerPlugin.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
-
getJobStatus
public JobState getJobStatus(Object object) throws org.quartz.SchedulerException, SchedulerPluginException
- Throws:
org.quartz.SchedulerException
SchedulerPluginException
-
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 theSchedulerPlugin.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 allSchedulerPlugin.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 asscheduleJob(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 aJobState.STATE_PAUSED
state. Can be called the same way asscheduleJob(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 asscheduleJob(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 aJobState.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 aJobState.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 aJobState.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 theSchedulerPlugin.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)
-
-