Search in sources :

Example 36 with JobDetail

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

the class CronOutputSchedule method start.

/* (non-Javadoc)
   * @see com.nokia.dempsy.output.OutputExecuter#start()
   */
public void start() {
    try {
        JobDetail jobDetail = super.getJobDetail();
        Trigger trigger = getCronTrigger(cronExpression);
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    } catch (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 37 with JobDetail

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

the class RelativeOutputSchedule method start.

/**
 * Container will invoke this method.
 */
@Override
public void start() {
    try {
        JobDetail jobDetail = super.getJobDetail();
        Trigger trigger = getSimpleTrigger(timeUnit, (int) interval);
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    } catch (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 38 with JobDetail

use of org.quartz.JobDetail in project series-rest-api by 52North.

the class JobScheduler method scheduleJob.

private void scheduleJob(ScheduledJob taskToSchedule) {
    try {
        JobDetail details = taskToSchedule.createJobDetails();
        Trigger trigger = taskToSchedule.createTrigger(details.getKey());
        scheduler.scheduleJob(details, trigger);
        if (taskToSchedule.isTriggerAtStartup()) {
            LOGGER.debug("Schedule job '{}' to run once at startup.", details.getKey());
            Trigger onceAtStartup = TriggerBuilder.newTrigger().withIdentity("onceAtStartup").forJob(details.getKey()).build();
            scheduler.scheduleJob(onceAtStartup);
        }
    } catch (SchedulerException e) {
        LOGGER.warn("Could not schdule Job '{}'.", taskToSchedule.getJobName(), e);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 39 with JobDetail

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

the class ReportScheduler method buildReportSchedule.

private void buildReportSchedule() {
    synchronized (m_lock) {
        for (Report report : m_configDao.getReports()) {
            JobDetail detail = null;
            CronTriggerImpl trigger = null;
            try {
                detail = new JobDetailImpl(report.getReportName(), JOB_GROUP, ReportJob.class, false, false);
                detail.getJobDataMap().put(ReportJob.KEY, report);
                trigger = new CronTriggerImpl(report.getReportName(), JOB_GROUP, report.getCronSchedule());
                trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
                getScheduler().scheduleJob(detail, trigger);
            } catch (ParseException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            } catch (SchedulerException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            }
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Report(org.opennms.netmgt.config.reportd.Report) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException)

Example 40 with JobDetail

use of org.quartz.JobDetail in project karaf by apache.

the class QuartzScheduler method schedule.

/**
     * Schedule a job
     * @see org.apache.karaf.scheduler.Scheduler#schedule(java.lang.Object, org.apache.karaf.scheduler.ScheduleOptions)
     * @throws SchedulerException if the job can't be scheduled
     * @throws IllegalArgumentException If the preconditions are not met
     */
public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException, SchedulerException {
    this.checkJob(job);
    if (!(options instanceof InternalScheduleOptions)) {
        throw new IllegalArgumentException("Options has not been created via schedule or is null.");
    }
    final InternalScheduleOptions opts = (InternalScheduleOptions) options;
    if (opts.argumentException != null) {
        throw opts.argumentException;
    }
    // as this method might be called from unbind and during
    // unbind a deactivate could happen, we check the scheduler first
    final org.quartz.Scheduler s = this.scheduler;
    if (s == null) {
        throw new IllegalStateException("Scheduler is not available anymore.");
    }
    final String name;
    if (opts.name != null) {
        // if there is already a job with the name, remove it first
        try {
            final JobKey key = JobKey.jobKey(opts.name);
            final JobDetail jobdetail = s.getJobDetail(key);
            if (jobdetail != null) {
                s.deleteJob(key);
                this.logger.debug("Unscheduling job with name {}", opts.name);
            }
        } catch (final SchedulerException ignored) {
        // ignore
        }
        name = opts.name;
    } else {
        name = job.getClass().getName() + ':' + UUID.randomUUID();
        opts.name = name;
    }
    final Trigger trigger = opts.trigger.withIdentity(name).build();
    // create the data map
    final JobDataMap jobDataMap = this.initDataMap(name, job, opts);
    final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
    this.logger.debug("Scheduling job {} with name {} and trigger {}", job, name, trigger);
    s.scheduleJob(detail, trigger);
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4