use of org.quartz.SchedulerException in project deltaspike by apache.
the class AbstractQuartzScheduler method isExecutingJob.
@Override
public boolean isExecutingJob(Class<? extends T> jobClass) {
try {
JobKey jobKey = createJobKey(jobClass);
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
return false;
}
for (JobExecutionContext jobExecutionContext : this.scheduler.getCurrentlyExecutingJobs()) {
if (jobKey.equals(jobExecutionContext.getJobDetail().getKey())) {
return true;
}
}
return false;
} catch (SchedulerException e) {
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
use of org.quartz.SchedulerException in project deltaspike by apache.
the class AbstractQuartzScheduler method registerNewJob.
@Override
public void registerNewJob(Class<? extends T> jobClass) {
JobKey jobKey = createJobKey(jobClass);
try {
Scheduled scheduled = jobClass.getAnnotation(Scheduled.class);
String description = scheduled.description();
if ("".equals(scheduled.description())) {
description = jobClass.getName();
}
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
Trigger trigger;
if (jobDetail == null) {
Class<? extends Job> jobClassToAdd = createFinalJobClass(jobClass);
jobDetail = JobBuilder.newJob(jobClassToAdd).withDescription(description).withIdentity(jobKey).build();
scheduleNewJob(scheduled, jobKey, jobDetail);
} else if (scheduled.overrideOnStartup()) {
List<? extends Trigger> existingTriggers = this.scheduler.getTriggersOfJob(jobKey);
if (existingTriggers == null || existingTriggers.isEmpty()) {
scheduleNewJob(scheduled, jobKey, jobDetail);
return;
}
if (existingTriggers.size() > 1) {
throw new IllegalStateException("multiple triggers found for " + jobKey + " ('" + jobDetail + "')" + ", but aren't supported by @" + Scheduled.class.getName() + "#overrideOnStartup");
}
trigger = existingTriggers.iterator().next();
if (scheduled.cronExpression().startsWith("{") && scheduled.cronExpression().endsWith("}")) {
this.scheduler.unscheduleJobs(Arrays.asList(trigger.getKey()));
scheduleNewJob(scheduled, jobKey, jobDetail);
} else {
trigger = TriggerBuilder.newTrigger().withIdentity(trigger.getKey()).withSchedule(CronScheduleBuilder.cronSchedule(scheduled.cronExpression())).build();
this.scheduler.rescheduleJob(trigger.getKey(), trigger);
}
} else {
Logger.getLogger(AbstractQuartzScheduler.class.getName()).info(jobKey + " exists already and will be ignored.");
}
} catch (SchedulerException e) {
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
use of org.quartz.SchedulerException in project deltaspike by apache.
the class CdiAwareJobFactory method newJob.
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
Job result = null;
try {
Class<? extends Job> jobClass = bundle.getJobDetail().getJobClass();
result = BeanProvider.getContextualReference(jobClass);
scheduler.getContext().put(jobClass.getName(), Boolean.TRUE);
} catch (Exception e) {
if (result == null) {
result = defaultFactory.newJob(bundle, scheduler);
}
}
return result;
}
use of org.quartz.SchedulerException in project cachecloud by sohutv.
the class TriggerController method pauseTrigger.
@RequestMapping(value = "/pause/{appId}/{type}/{host}/{port}")
public void pauseTrigger(@PathVariable long appId, @PathVariable int type, @PathVariable String host, @PathVariable int port) {
Assert.isTrue(appId > 0);
Assert.isTrue(type > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
String triggerName = ObjectConvert.linkIpAndPort(host, port);
String triggerGroup = "";
if (type == ConstUtils.CACHE_TYPE_REDIS_CLUSTER) {
triggerGroup = ConstUtils.REDIS_TRIGGER_GROUP + appId;
}
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroup);
try {
scheduler.pauseTrigger(triggerKey);
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
logger.info("trigger with name: {}, group: {} is paused", port, host);
}
use of org.quartz.SchedulerException in project cachecloud by sohutv.
the class ErrorStatisticsJob method action.
@Override
public void action(JobExecutionContext context) {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SchedulerContext schedulerContext;
try {
schedulerContext = context.getScheduler().getContext();
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
EmailComponent emailComponent = applicationContext.getBean("emailComponent", EmailComponent.class);
ErrorLoggerWatcherMBean errorLoggerWatcher = applicationContext.getBean("errorLoggerWatcher", ErrorLoggerWatcherMBean.class);
// if (errorLoggerWatcher.getTotalErrorCount() == 0L) {
// logger.warn("errorLoggerWatcher.totalErrorCount == 0 -o-");
// return;
// }
String title = "CacheCloud异常统计, 日期:" + dateFormat.format(date) + ";服务器:" + System.getProperty("local.ip") + ";总数:" + errorLoggerWatcher.getTotalErrorCount();
StringBuilder buffer = new StringBuilder();
buffer.append(title + ":<br/>");
for (Map.Entry<String, Long> entry : errorLoggerWatcher.getErrorInfos().entrySet()) {
Long num = entry.getValue();
if (num == 0L) {
continue;
}
String key = entry.getKey();
buffer.append(key + "=" + num + "<br/>");
}
emailComponent.sendMailToAdmin(title, buffer.toString());
//清理异常
errorLoggerWatcher.clear();
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
}
Aggregations