Search in sources :

Example 51 with SchedulerException

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);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobExecutionContext(org.quartz.JobExecutionContext)

Example 52 with SchedulerException

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);
    }
}
Also used : Scheduled(org.apache.deltaspike.scheduler.api.Scheduled) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) List(java.util.List)

Example 53 with SchedulerException

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;
}
Also used : Job(org.quartz.Job) SchedulerException(org.quartz.SchedulerException)

Example 54 with SchedulerException

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);
}
Also used : TriggerKey(org.quartz.TriggerKey) SchedulerException(org.quartz.SchedulerException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with SchedulerException

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);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext) EmailComponent(com.sohu.cache.web.component.EmailComponent) ErrorLoggerWatcherMBean(com.sohu.cache.jmx.ErrorLoggerWatcherMBean) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) Date(java.util.Date)

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