/** * Used by the configuration to create a new Scheduler during system startup.<p> * * @param configuredJobs the jobs from the configuration */ public CmsScheduleManager(List<CmsScheduledJobInfo> configuredJobs) { m_configuredJobs = configuredJobs; int size = 0; if (m_configuredJobs != null) { size = m_configuredJobs.size(); } if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_CREATED_1, new Integer(size))); } }
/** * Used by the configuration to create a new Scheduler during system startup.<p> * * @param configuredJobs the jobs from the configuration */ public CmsScheduleManager(List configuredJobs) { m_configuredJobs = configuredJobs; int size = 0; if (m_configuredJobs != null) { size = m_configuredJobs.size(); } if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_CREATED_1, new Integer(size))); } }
/** * Shuts down this instance of the OpenCms scheduler manager.<p> */ public synchronized void shutDown() { m_adminCms = null; if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_1, this.getClass().getName())); } if (m_scheduler != null) { try { m_scheduler.shutdown(); } catch (SchedulerException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_SHUTDOWN_ERROR_0)); } } m_scheduler = null; }
/** * Shuts down this instance of the OpenCms scheduler manager.<p> */ public synchronized void shutDown() { m_adminCms = null; if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_1, this.getClass().getName())); } if (m_scheduler != null) { try { m_scheduler.shutdown(); } catch (SchedulerException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_SHUTDOWN_ERROR_0)); } } m_scheduler = null; }
/** * Sets the job name.<p> * * @param jobName the job name to set */ public void setJobName(String jobName) { checkFrozen(); if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName)); } m_jobName = jobName; }
/** * Sets the job name.<p> * * @param jobName the job name to set */ public void setJobName(String jobName) { checkFrozen(); if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName)); } m_jobName = jobName; }
/** * Implementation of the Quartz job interface.<p> * * The architecture is that this scheduler manager generates * a new (empty) instance of itself for every OpenCms job scheduled with Quartz. * When the Quartz job is executed, the configured * implementation of {@link I_CmsScheduledJob} will be called from this method.<p> * * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) */ public void execute(JobExecutionContext context) { JobDataMap jobData = context.getJobDetail().getJobDataMap(); CmsScheduledJobInfo jobInfo = (CmsScheduledJobInfo)jobData.get(SCHEDULER_JOB_INFO); if (jobInfo == null) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_JOB_1, context.getJobDetail().getFullName())); // can not continue return; } executeJob(jobInfo); }
/** * Sets the job parameters.<p> * * @param parameters the parameters to set */ public void setParameters(SortedMap<String, String> parameters) { checkFrozen(); if (parameters == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_PARAMS_0)); } // make sure the parameters are a sorted map m_parameters = new TreeMap<String, String>(parameters); }
/** * Sets the job parameters.<p> * * @param parameters the parameters to set */ public void setParameters(SortedMap parameters) { checkFrozen(); if (parameters == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_PARAMS_0)); } // make sure the parameters are a sorted map m_parameters = new TreeMap(parameters); }
/** * Checks if this job info configuration is frozen.<p> * * @throws CmsRuntimeException in case the configuration is already frozen */ protected void checkFrozen() throws CmsRuntimeException { if (m_frozen) { throw new CmsRuntimeException(Messages.get().container(Messages.ERR_JOB_INFO_FROZEN_1, getJobName())); } }
/** * Checks if this job info configuration is frozen.<p> * * @throws CmsRuntimeException in case the configuration is already frozen */ protected void checkFrozen() throws CmsRuntimeException { if (m_frozen) { throw new CmsRuntimeException(Messages.get().container(Messages.ERR_JOB_INFO_FROZEN_1, getJobName())); } }
throw new SchedulerConfigException(Messages.get().getBundle().key(Messages.ERR_MAX_THREAD_COUNT_BOUNDS_0)); throw new SchedulerConfigException(Messages.get().getBundle().key(Messages.ERR_INIT_THREAD_COUNT_BOUNDS_0)); throw new SchedulerConfigException(Messages.get().getBundle().key(Messages.ERR_SCHEDULER_PRIORITY_BOUNDS_0)); LOG.debug(Messages.get().getBundle().key( Messages.LOG_USING_THREAD_CLASSLOADER_1, Thread.currentThread().getName()));
/** * Sets the context information for the user executing the job.<p> * * This will also "freeze" the context information that is set.<p> * * @param contextInfo the context information for the user executing the job * * @see CmsContextInfo#freeze() */ public void setContextInfo(CmsContextInfo contextInfo) { checkFrozen(); if (contextInfo == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_CONTEXT_INFO_0)); } m_context = contextInfo; }
/** * Sets the context information for the user executing the job.<p> * * This will also "freeze" the context information that is set.<p> * * @param contextInfo the context information for the user executing the job * * @see CmsContextInfo#freeze() */ public void setContextInfo(CmsContextInfo contextInfo) { checkFrozen(); if (contextInfo == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_CONTEXT_INFO_0)); } m_context = contextInfo; }
/** * Given a job ID, this directly executes the corresponding job.<p> * * @param jobId the job id */ public void executeDirectly(String jobId) { final CmsScheduledJobInfo jobInfo = (CmsScheduledJobInfo)getJob(jobId).clone(); if (jobInfo == null) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_JOB_1, "null")); return; } Thread thread = new Thread() { /** * @see java.lang.Thread#run() */ @Override public void run() { executeJob(jobInfo); } }; thread.start(); }
/** * Loop, executing targets as they are received.<p> */ @Override public void run() { boolean runOnce = (m_runnable != null); while (m_run) { setPriority(m_pool.getThreadPriority()); try { if (m_runnable == null) { m_runnable = m_pool.getNextRunnable(); } if (m_runnable != null) { m_runnable.run(); } } catch (InterruptedException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_INTERRUPTED_1, getName()), e); } catch (Throwable t) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_ERROR_1, getName()), t); } finally { if (runOnce) { m_run = false; } m_runnable = null; } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_THREAD_SHUTDOWN_1, getName())); } }
/** * Loop, executing targets as they are received.<p> */ @Override public void run() { boolean runOnce = (m_runnable != null); while (m_run) { setPriority(m_pool.getThreadPriority()); try { if (m_runnable == null) { m_runnable = m_pool.getNextRunnable(); } if (m_runnable != null) { m_runnable.run(); } } catch (InterruptedException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_INTERRUPTED_1, getName()), e); } catch (Throwable t) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_ERROR_1, getName()), t); } finally { if (runOnce) { m_run = false; } m_runnable = null; } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_THREAD_SHUTDOWN_1, getName())); } }
LOG.debug(Messages.get().getBundle().key(Messages.LOG_JOB_STARTING_1, jobInfo.getJobName())); if (CmsStringUtil.isNotEmpty(result) && LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key(Messages.LOG_JOB_EXECUTION_OK_2, jobInfo.getJobName(), result)); LOG.error(Messages.get().getBundle().key(Messages.LOG_JOB_EXECUTION_ERROR_1, jobInfo.getJobName()), t); LOG.debug(Messages.get().getBundle().key(Messages.LOG_JOB_EXECUTED_1, jobInfo.getJobName())); Date nextExecution = jobInfo.getExecutionTimeNext(); if (nextExecution != null) { LOG.info( Messages.get().getBundle().key( Messages.LOG_JOB_NEXT_EXECUTION_2, jobInfo.getJobName(),
/** * Sets the cron expression for this job entry.<p> * * @param cronExpression the cron expression to set */ public void setCronExpression(String cronExpression) { checkFrozen(); try { // check if the cron expression is valid new CronTrigger().setCronExpression(cronExpression); } catch (Exception e) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_BAD_CRON_EXPRESSION_2, getJobName(), cronExpression)); } m_cronExpression = cronExpression; }
/** * Sets the cron expression for this job entry.<p> * * @param cronExpression the cron expression to set */ public void setCronExpression(String cronExpression) { checkFrozen(); try { // check if the cron expression is valid new CronTrigger().setCronExpression(cronExpression); } catch (Exception e) { throw new CmsIllegalArgumentException(Messages.get().container( Messages.ERR_BAD_CRON_EXPRESSION_2, getJobName(), cronExpression)); } m_cronExpression = cronExpression; }