/** * @return the default Scheduler instance * @throws SchedulerPluginException if the default Scheduler instance failed to be retrieved for any reason. Note * that on the first call the default scheduler is also initialized. */ private synchronized Scheduler getDefaultSchedulerInstance() throws SchedulerPluginException { Scheduler scheduler; try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_GET_SCHEDULER, "Error getting default Scheduler instance", e); } return scheduler; }
/** * @return the default Scheduler instance * @throws SchedulerPluginException if the default Scheduler instance failed to be retrieved for any reason. Note * that on the first call the default scheduler is also initialized. */ private synchronized Scheduler getDefaultSchedulerInstance() throws SchedulerPluginException { Scheduler scheduler; try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_GET_SCHEDULER, "Error getting default Scheduler instance", e); } return scheduler; }
/** * Get Trigger object of the given job * * @param object the unwrapped XObject to be retrieve the trigger for * @param context the XWiki context * @return the trigger object of the given job */ private Trigger getTrigger(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); Trigger trigger; try { trigger = getScheduler().getTrigger(job, Scheduler.DEFAULT_GROUP); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while getting trigger for job " + job, e); } if (trigger == null) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_DOES_NOT_EXITS, "Job does not exists"); } return trigger; }
/** * Get Trigger object of the given job * * @param object the unwrapped XObject to be retrieve the trigger for * @param context the XWiki context * @return the trigger object of the given job */ private Trigger getTrigger(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); Trigger trigger; try { trigger = getScheduler().getTrigger(new TriggerKey(job)); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while getting trigger for job " + job, e); } if (trigger == null) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_DOES_NOT_EXITS, "Job does not exists"); } return trigger; }
/** * Resume the job with the given name (un-pause) * * @param object the non-wrapped XObject Job to be resumed */ public void resumeJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().resumeJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); saveStatus("Normal", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to resume job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to save status of job " + object.getStringValue("jobName"), e); } }
/** * Unschedule the given job * * @param object the unwrapped XObject job to be unscheduled */ public void unscheduleJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().deleteJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); saveStatus("None", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while unscheduling job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while saving status of job " + object.getStringValue("jobName"), e); } }
/** * Pause the job with the given name by pausing all of its current triggers. * * @param object the non-wrapped XObject Job to be paused */ public void pauseJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().pauseJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); saveStatus("Paused", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_PAUSE_JOB, "Error occured while trying to pause job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_PAUSE_JOB, "Error occured while trying to save status of job " + object.getStringValue("jobName"), e); } }
/** * Unschedule the given job * * @param object the unwrapped XObject job to be unscheduled */ public void unscheduleJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); try { getScheduler().deleteJob(new JobKey(job)); saveStatus("None", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while unscheduling job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while saving status of job " + object.getStringValue("jobName"), e); } }
/** * Pause the job with the given name by pausing all of its current triggers. * * @param object the non-wrapped XObject Job to be paused */ public void pauseJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); try { getScheduler().pauseJob(new JobKey(job)); saveStatus("Paused", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_PAUSE_JOB, "Error occured while trying to pause job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_PAUSE_JOB, "Error occured while trying to save status of job " + object.getStringValue("jobName"), e); } }
/** * Resume the job with the given name (un-pause) * * @param object the non-wrapped XObject Job to be resumed */ public void resumeJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); try { getScheduler().resumeJob(new JobKey(job)); saveStatus("Normal", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to resume job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to save status of job " + object.getStringValue("jobName"), e); } }
/** * Trigger a job (execute it now) * * @param object the non-wrapped XObject Job to be triggered * @param context the XWiki context */ public void triggerJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().triggerJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_TRIGGER_JOB, "Error occured while trying to trigger job " + object.getStringValue("jobName"), e); } }
/** * This function allow to retrieve a com.xpn.xwiki.objects.BaseObject from a com.xpn.xwiki.api.Object without that * the current user needs programming rights (as in com.xpn.xwiki.api.Object#getXWikiObject(). The function is used * internally by this api class and allows wiki users to call methods from the scheduler without having programming * right. The programming right is only needed at script execution time. * * @return object the unwrapped version of the passed api object */ private BaseObject retrieveBaseObject(Object object) throws SchedulerPluginException { String docName = object.getName(); int objNb = object.getNumber(); try { XWikiDocument jobHolder = this.context.getWiki().getDocument(docName, this.context); BaseObject jobObject = jobHolder.getObject(SchedulerPlugin.XWIKI_JOB_CLASS, objNb); return jobObject; } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_UNABLE_TO_RETRIEVE_JOB, "Job in document [" + docName + "] with object number [" + objNb + "] could not be retrieved.", e); } }
/** * Trigger a job (execute it now) * * @param object the non-wrapped XObject Job to be triggered * @param context the XWiki context */ public void triggerJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { String job = getObjectUniqueId(object, context); try { getScheduler().triggerJob(new JobKey(job)); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_TRIGGER_JOB, "Error occured while trying to trigger job " + object.getStringValue("jobName"), e); } }
/** * Associates the scheduler with a StatusListener * * @throws SchedulerPluginException if the status listener failed to be set properly */ private void setStatusListener() throws SchedulerPluginException { StatusListener listener = new StatusListener(); try { getScheduler().addSchedulerListener(listener); getScheduler().addGlobalJobListener(listener); } catch (SchedulerException e) { throw new SchedulerPluginException( SchedulerPluginException.ERROR_SCHEDULERPLUGIN_INITIALIZE_STATUS_LISTENER, "Error while initializing the status listener", e); } }
/** * This function allow to retrieve a com.xpn.xwiki.objects.BaseObject from a com.xpn.xwiki.api.Object without that * the current user needs programming rights (as in com.xpn.xwiki.api.Object#getXWikiObject(). The function is used * internally by this api class and allows wiki users to call methods from the scheduler without having programming * right. The programming right is only needed at script execution time. * * @return object the unwrapped version of the passed api object */ private BaseObject retrieveBaseObject(Object object) throws SchedulerPluginException { String docName = object.getName(); int objNb = object.getNumber(); try { XWikiDocument jobHolder = this.context.getWiki().getDocument(docName, this.context); BaseObject jobObject = jobHolder.getXObject(SchedulerPlugin.XWIKI_JOB_CLASSREFERENCE, objNb); return jobObject; } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_UNABLE_TO_RETRIEVE_JOB, "Job in document [" + docName + "] with object number [" + objNb + "] could not be retrieved.", e); } }
throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_SCHEDULE_JOB, "Error while scheduling job " + object.getStringValue("jobName"), e); } catch (ClassNotFoundException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while loading job class for job : " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while saving job status for job : " + object.getStringValue("jobName"), e);
throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_SCHEDULE_JOB, "Error while scheduling job " + object.getStringValue("jobName"), e); } catch (ParseException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_BAD_CRON_EXPRESSION, "Error while parsing cron expression for job " + object.getStringValue("jobName"), e); } catch (ClassNotFoundException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while loading job class for job : " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while saving job status for job : " + object.getStringValue("jobName"), e);
/** * Associates the scheduler with a StatusListener * * @throws SchedulerPluginException if the status listener failed to be set properly */ private void setStatusListener() throws SchedulerPluginException { StatusListener listener = new StatusListener(); try { getScheduler().getListenerManager().addSchedulerListener(listener); getScheduler().getListenerManager().addJobListener(listener); } catch (SchedulerException e) { throw new SchedulerPluginException( SchedulerPluginException.ERROR_SCHEDULERPLUGIN_INITIALIZE_STATUS_LISTENER, "Error while initializing the status listener", e); } }
xwiki.saveDocument(doc, context); } catch (XWikiException ex) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_SAVE_JOB_CLASS, "Error while saving " + SchedulerPlugin.XWIKI_JOB_CLASS + " class document in XWiki", ex);
context.getWiki().saveDocument(jobHolder, context); } catch (XWikiException e) { throw new SchedulerPluginException( SchedulerPluginException.ERROR_SCHEDULERPLUGIN_UNABLE_TO_PREPARE_JOB_CONTEXT, "Failed to prepare context for job with job name " + job.getStringValue("jobName"), e); scontext.setDoc(cDoc); } catch (Exception e) { throw new SchedulerPluginException( SchedulerPluginException.ERROR_SCHEDULERPLUGIN_UNABLE_TO_PREPARE_JOB_CONTEXT, "Failed to prepare context for job with job name " + job.getStringValue("jobName"), e);