Search in sources :

Example 1 with JobDetail

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

the class Notebook method refreshCron.

public void refreshCron(String id) {
    removeCron(id);
    synchronized (notes) {
        Note note = notes.get(id);
        if (note == null) {
            return;
        }
        Map<String, Object> config = note.getConfig();
        if (config == null) {
            return;
        }
        String cronExpr = (String) note.getConfig().get("cron");
        if (cronExpr == null || cronExpr.trim().length() == 0) {
            return;
        }
        JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(id, "note").usingJobData("noteId", id).build();
        Map<String, Object> info = note.getInfo();
        info.put("cron", null);
        CronTrigger trigger = null;
        try {
            trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note").withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note").build();
        } catch (Exception e) {
            logger.error("Error", e);
            info.put("cron", e.getMessage());
        }
        try {
            if (trigger != null) {
                quartzSched.scheduleJob(newJob, trigger);
            }
        } catch (SchedulerException e) {
            logger.error("Error", e);
            info.put("cron", "Scheduler Exception");
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) AngularObject(org.apache.zeppelin.display.AngularObject) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException)

Example 2 with JobDetail

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

the class JobScheduler method createJobDetail.

private JobDetail createJobDetail(final String jobClass) {
    JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(jobName).build();
    result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
    Optional<ElasticJob> elasticJobInstance = createElasticJobInstance();
    if (elasticJobInstance.isPresent()) {
        result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJobInstance.get());
    } else if (!jobClass.equals(ScriptJob.class.getCanonicalName())) {
        try {
            result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, Class.forName(jobClass).newInstance());
        } catch (final ReflectiveOperationException ex) {
            throw new JobConfigurationException("Elastic-Job: Job class '%s' can not initialize.", jobClass);
        }
    }
    return result;
}
Also used : JobDetail(org.quartz.JobDetail) ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) JobConfigurationException(com.dangdang.ddframe.job.exception.JobConfigurationException)

Example 3 with JobDetail

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

the class StatisticsScheduler method register.

/**
     * 注册统计作业.
     * 
     * @param statisticJob 统计作业
     */
void register(final StatisticJob statisticJob) {
    try {
        JobDetail jobDetail = statisticJob.buildJobDetail();
        Map<String, Object> dataMap = statisticJob.getDataMap();
        for (String each : dataMap.keySet()) {
            jobDetail.getJobDataMap().put(each, dataMap.get(each));
        }
        scheduler.scheduleJob(jobDetail, statisticJob.buildTrigger());
    } catch (final SchedulerException ex) {
        throw new JobStatisticException(ex);
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobStatisticException(com.dangdang.ddframe.job.exception.JobStatisticException)

Example 4 with JobDetail

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

the class TaskResultStatisticJob method buildJobDetail.

@Override
public JobDetail buildJobDetail() {
    JobDetail result = JobBuilder.newJob(this.getClass()).withIdentity(getJobName() + "_" + statisticInterval).build();
    result.getJobDataMap().put("statisticUnit", statisticInterval);
    return result;
}
Also used : JobDetail(org.quartz.JobDetail)

Example 5 with JobDetail

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

the class JmxTransformer method scheduleJob.

private void scheduleJob(Server server) throws ParseException, SchedulerException {
    String name = server.getHost() + ":" + server.getPort() + "-" + System.currentTimeMillis() + "-" + RandomStringUtils.randomNumeric(10);
    JobDetail jd = new JobDetail(name, "ServerJob", ServerJob.class);
    JobDataMap map = new JobDataMap();
    map.put(Server.class.getName(), server);
    jd.setJobDataMap(map);
    Trigger trigger;
    if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
        trigger = new CronTrigger();
        ((CronTrigger) trigger).setCronExpression(server.getCronExpression());
        trigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        trigger.setStartTime(computeSpreadStartDate(configuration.getRunPeriod()));
    } else {
        int runPeriod = configuration.getRunPeriod();
        if (server.getRunPeriodSeconds() != null)
            runPeriod = server.getRunPeriodSeconds();
        Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(runPeriod);
        minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        minuteTrigger.setStartTime(computeSpreadStartDate(runPeriod));
        trigger = minuteTrigger;
    // TODO replace Quartz with a ScheduledExecutorService
    }
    serverScheduler.scheduleJob(jd, trigger);
    if (log.isDebugEnabled()) {
        log.debug("Scheduled job: " + jd.getName() + " for server: " + server);
    }
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server)

Aggregations

JobDetail (org.quartz.JobDetail)122 SchedulerException (org.quartz.SchedulerException)56 Trigger (org.quartz.Trigger)47 Scheduler (org.quartz.Scheduler)33 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)25 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)21 JobDataMap (org.quartz.JobDataMap)18 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 IOException (java.io.IOException)5 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4