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);
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations