Search in sources :

Example 71 with Trigger

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

the class JobScheduler method schedule.

/**
     * Schedules a job at the specified date/time, deletes a previously
     * scheduled job.
     */
private void schedule(Calendar calendar, String jobName, JobDataMap jobDataMap, Class<? extends Job> jobClass) {
    if (System.currentTimeMillis() < calendar.getTimeInMillis()) {
        try {
            JobKey jobKey = new JobKey(jobName, JOB_GROUP);
            if (scheduler.getJobDetail(jobKey) != null) {
                scheduler.deleteJob(jobKey);
            }
            Trigger trigger = newTrigger().withIdentity(jobName + "-Trigger", JOB_GROUP).startAt(calendar.getTime()).build();
            JobDetail jobDetail = newJob(jobClass).withIdentity(jobKey).usingJobData(jobDataMap).build();
            scheduler.scheduleJob(jobDetail, trigger);
            logger.debug("Scheduled job with name {} at {}", jobName, sdf.format(calendar.getTime()));
        } catch (SchedulerException ex) {
            logger.error(ex.getMessage(), ex);
        }
    } else {
        logger.debug("Skipping job with name {} for today, starttime is in the past", jobName);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException)

Example 72 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class RedisCenterImpl method unDeployRedisCollection.

@Override
public boolean unDeployRedisCollection(long appId, String host, int port) {
    Assert.isTrue(appId > 0);
    Assert.hasText(host);
    Assert.isTrue(port > 0);
    TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_TRIGGER_GROUP + appId);
    Trigger trigger = schedulerCenter.getTrigger(triggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(triggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Example 73 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class RedisJob method action.

/**
     * 实现收集任务,通过RedisCenter
     *
     * @param context
     */
@Override
public void action(JobExecutionContext context) {
    JobDataMap dataMap = new JobDataMap();
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        RedisCenter redisCenter = (RedisCenter) applicationContext.getBean("redisCenter");
        dataMap = context.getMergedJobDataMap();
        String host = dataMap.getString(ConstUtils.HOST_KEY);
        int port = dataMap.getInt(ConstUtils.PORT_KEY);
        long appId = dataMap.getLong(ConstUtils.APP_KEY);
        Trigger trigger = context.getTrigger();
        long collectTime = ScheduleUtil.getCollectTime(trigger.getPreviousFireTime());
        redisCenter.collectRedisInfo(appId, collectTime, host, port);
    } catch (SchedulerException e) {
        logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
        logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
        logger.error(e.getMessage(), e);
    } catch (Exception e) {
        logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
        logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
        logger.error(e.getMessage(), e);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ApplicationContext(org.springframework.context.ApplicationContext) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) RedisCenter(com.sohu.cache.redis.RedisCenter) SchedulerContext(org.quartz.SchedulerContext) SchedulerException(org.quartz.SchedulerException)

Example 74 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class MachineCenterImpl method unDeployServerCollection.

@Override
public boolean unDeployServerCollection(long hostId, String ip) {
    Assert.hasText(ip);
    TriggerKey collectionTriggerKey = TriggerKey.triggerKey(ip, ConstUtils.SERVER_TRIGGER_GROUP + ip);
    Trigger trigger = schedulerCenter.getTrigger(collectionTriggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(collectionTriggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Example 75 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class MachineCenterImpl method unDeployMachineCollection.

@Override
public boolean unDeployMachineCollection(long hostId, String ip) {
    Assert.isTrue(hostId > 0);
    Assert.hasText(ip);
    TriggerKey collectionTriggerKey = TriggerKey.triggerKey(ip, ConstUtils.MACHINE_TRIGGER_GROUP + hostId);
    Trigger trigger = schedulerCenter.getTrigger(collectionTriggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(collectionTriggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Aggregations

Trigger (org.quartz.Trigger)104 JobDetail (org.quartz.JobDetail)51 SchedulerException (org.quartz.SchedulerException)40 CronTrigger (org.quartz.CronTrigger)29 Test (org.junit.Test)23 Scheduler (org.quartz.Scheduler)22 JobDataMap (org.quartz.JobDataMap)21 SimpleTrigger (org.quartz.SimpleTrigger)20 TriggerKey (org.quartz.TriggerKey)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)19 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)3