Search in sources :

Example 91 with SchedulerException

use of org.quartz.SchedulerException in project elastic-job by dangdangdotcom.

the class JobScheduler method createScheduler.

private Scheduler createScheduler(final boolean isMisfire) {
    Scheduler result;
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(getBaseQuartzProperties(isMisfire));
        result = factory.getScheduler();
        result.getListenerManager().addTriggerListener(jobExecutor.getSchedulerFacade().newJobTriggerListener());
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
    return result;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 92 with SchedulerException

use of org.quartz.SchedulerException in project elastic-job by dangdangdotcom.

the class TransientProducerScheduler method register.

// TODO 并发优化
synchronized void register(final CloudJobConfiguration jobConfig) {
    String cron = jobConfig.getTypeConfig().getCoreConfig().getCron();
    JobKey jobKey = buildJobKey(cron);
    repository.put(jobKey, jobConfig.getJobName());
    try {
        if (!scheduler.checkExists(jobKey)) {
            scheduler.scheduleJob(buildJobDetail(jobKey), buildTrigger(jobKey.getName()));
        }
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
}
Also used : JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 93 with SchedulerException

use of org.quartz.SchedulerException in project elastic-job by dangdangdotcom.

the class JobScheduleController method getNextFireTime.

/**
     * 获取下次作业触发时间.
     * 
     * @return 下次作业触发时间
     */
public Date getNextFireTime() {
    List<? extends Trigger> triggers;
    try {
        triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
    } catch (final SchedulerException ex) {
        return null;
    }
    Date result = null;
    for (Trigger each : triggers) {
        Date nextFireTime = each.getNextFireTime();
        if (null == nextFireTime) {
            continue;
        }
        if (null == result) {
            result = nextFireTime;
        } else if (nextFireTime.getTime() < result.getTime()) {
            result = nextFireTime;
        }
    }
    return result;
}
Also used : SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) Date(java.util.Date)

Example 94 with SchedulerException

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

the class GCalEventDownloader method createJobInfo.

/**
     * Creates a detailed description of a <code>job</code> for logging purpose.
     *
     * @param job the job to create a detailed description for
     * @return a detailed description of the new <code>job</code>
     */
private String createJobInfo(Event event, JobDetail job) {
    if (job == null) {
        return "SchedulerJob [null]";
    }
    StringBuffer sb = new StringBuffer();
    sb.append("SchedulerJob [jobKey=").append(job.getKey().getName());
    sb.append(", jobGroup=").append(job.getKey().getGroup());
    try {
        List<? extends Trigger> triggers = scheduler.getTriggersOfJob(job.getKey());
        sb.append(", ").append(triggers.size()).append(" triggers=[");
        int maxTriggerLogs = 24;
        for (int triggerIndex = 0; triggerIndex < triggers.size() && triggerIndex < maxTriggerLogs; triggerIndex++) {
            Trigger trigger = triggers.get(triggerIndex);
            sb.append(trigger.getStartTime());
            if (triggerIndex < triggers.size() - 1 && triggerIndex < maxTriggerLogs - 1) {
                sb.append(", ");
            }
        }
        if (triggers.size() >= maxTriggerLogs) {
            sb.append(" and ").append(triggers.size() - maxTriggerLogs).append(" more ...");
        }
        if (triggers.size() == 0) {
            sb.append("there are no triggers - probably the event lies in the past");
        }
    } catch (SchedulerException e) {
    }
    sb.append("], content=").append(event.getDescription());
    return sb.toString();
}
Also used : Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException)

Example 95 with SchedulerException

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

the class GCalEventDownloader method execute.

/**
     * @{inheritDoc}
     */
@Override
protected void execute() {
    Events myFeed = downloadEventFeed();
    if (myFeed != null) {
        List<Event> entries = myFeed.getItems();
        if (entries.size() > 0) {
            logger.debug("found {} calendar events to process", entries.size());
            try {
                if (scheduler.isShutdown()) {
                    logger.warn("Scheduler has been shut down - probably due to exceptions?");
                }
                cleanJobs();
                processEntries(entries);
            } catch (SchedulerException se) {
                logger.error("scheduling jobs throws exception", se);
            }
        } else {
            logger.debug("gcal feed contains no events ...");
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) Events(com.google.api.services.calendar.model.Events) Event(com.google.api.services.calendar.model.Event)

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