Search in sources :

Example 71 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class DefaultSchedulerService method addCronTrigger.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#addCronTrigger(org
     * .opennms.web.report.database.model.DatabaseReportCriteria,
     * java.lang.String, java.lang.String, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/**
 * {@inheritDoc}
 */
@Override
public String addCronTrigger(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, String cronExpression, RequestContext context) {
    CronTriggerImpl cronTrigger = null;
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            LOG.error(PARAMETER_ERROR);
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            try {
                cronTrigger = new CronTriggerImpl();
                cronTrigger.setGroup(m_triggerGroup);
                cronTrigger.setName(deliveryOptions.getInstanceId());
                cronTrigger.setJobName(m_jobDetail.getKey().getName());
                cronTrigger.setCronExpression(cronExpression);
            // cronTrigger = new CronTrigger(triggerName, m_triggerGroup,
            // cronExpression);
            } catch (ParseException e) {
                LOG.error(TRIGGER_PARSE_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(TRIGGER_PARSE_ERROR).build());
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(e.getMessage()).build());
                return ERROR;
            }
            cronTrigger.setJobName(m_jobDetail.getKey().getName());
            cronTrigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            cronTrigger.getJobDataMap().put("reportId", id);
            cronTrigger.getJobDataMap().put("mode", ReportMode.SCHEDULED);
            cronTrigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(cronTrigger);
            } catch (SchedulerException e) {
                LOG.error(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException)

Example 72 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class DefaultSchedulerService method getTriggerDescriptions.

/**
 * <p>getTriggerDescriptions</p>
 *
 * @return a {@link java.util.List} object.
 */
@Override
public List<TriggerDescription> getTriggerDescriptions() {
    List<TriggerDescription> triggerDescriptions = new ArrayList<>();
    try {
        Set<TriggerKey> triggerKeys = m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(m_triggerGroup));
        for (TriggerKey triggerKey : triggerKeys) {
            TriggerDescription description = new TriggerDescription();
            Trigger trigger = m_scheduler.getTrigger(triggerKey);
            description.setNextFireTime(trigger.getNextFireTime());
            description.setTriggerName(triggerKey.getName());
            description.setReportId((String) trigger.getJobDataMap().get("reportId"));
            description.setDeliveryOptions((DeliveryOptions) trigger.getJobDataMap().get("deliveryOptions"));
            description.setReportParameters(((ReportParameters) trigger.getJobDataMap().get("criteria")).getReportParms());
            triggerDescriptions.add(description);
        }
    } catch (SchedulerException e) {
        LOG.error("exception lretrieving trigger descriptions", e);
    }
    return triggerDescriptions;
}
Also used : TriggerKey(org.quartz.TriggerKey) TriggerDescription(org.opennms.web.svclayer.model.TriggerDescription) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList)

Example 73 with SchedulerException

use of org.quartz.SchedulerException in project Dempsy by Dempsy.

the class RelativeOutputSchedule method start.

/**
 * Container will invoke this method.
 */
@Override
public void start(final Infrastructure infra) {
    try {
        final OutputQuartzHelper outputQuartzHelper = new OutputQuartzHelper();
        final JobDetail jobDetail = outputQuartzHelper.getJobDetail(outputInvoker);
        final Trigger trigger = outputQuartzHelper.getSimpleTrigger(timeUnit, (int) interval);
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    } catch (final SchedulerException se) {
        LOGGER.error("Error occurred while starting the relative scheduler : " + se.getMessage(), se);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 74 with SchedulerException

use of org.quartz.SchedulerException in project Dempsy by Dempsy.

the class CronOutputSchedule method start.

/*
     * (non-Javadoc)
     * 
     * @see com.nokia.dempsy.output.OutputExecuter#start()
     */
@Override
public void start(final Infrastructure infra) {
    try {
        final OutputQuartzHelper outputQuartzHelper = new OutputQuartzHelper();
        final JobDetail jobDetail = outputQuartzHelper.getJobDetail(outputInvoker);
        final Trigger trigger = outputQuartzHelper.getCronTrigger(cronExpression);
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    } catch (final SchedulerException se) {
        LOGGER.error("Error occurred while starting the cron scheduler : " + se.getMessage(), se);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 75 with SchedulerException

use of org.quartz.SchedulerException in project openhab1-addons by openhab.

the class PlugwiseBinding method execute.

@Override
protected void execute() {
    if (isProperlyConfigured()) {
        try {
            Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
            scheduleJobs(sched);
        } catch (SchedulerException e) {
            logger.error("An exception occurred while getting a reference to the Quartz Scheduler ({})", e.getMessage());
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Aggregations

SchedulerException (org.quartz.SchedulerException)133 JobDetail (org.quartz.JobDetail)59 Trigger (org.quartz.Trigger)42 Scheduler (org.quartz.Scheduler)37 JobKey (org.quartz.JobKey)33 SimpleTrigger (org.quartz.SimpleTrigger)19 JobDataMap (org.quartz.JobDataMap)18 CronTrigger (org.quartz.CronTrigger)17 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 ApplicationContext (org.springframework.context.ApplicationContext)15 ArrayList (java.util.ArrayList)12 SchedulerContext (org.quartz.SchedulerContext)12 IOException (java.io.IOException)11 TriggerKey (org.quartz.TriggerKey)10 Date (java.util.Date)9 JobExecutionException (org.quartz.JobExecutionException)9 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)6 ParseException (java.text.ParseException)5 Command (org.openhab.core.types.Command)5 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)4