Search in sources :

Example 46 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class ReportScheduler method buildReportSchedule.

private void buildReportSchedule() {
    synchronized (m_lock) {
        for (Report report : m_configDao.getReports()) {
            JobDetail detail = null;
            CronTriggerImpl trigger = null;
            try {
                detail = new JobDetailImpl(report.getReportName(), JOB_GROUP, ReportJob.class, false, false);
                detail.getJobDataMap().put(ReportJob.KEY, report);
                trigger = new CronTriggerImpl(report.getReportName(), JOB_GROUP, report.getCronSchedule());
                trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
                getScheduler().scheduleJob(detail, trigger);
            } catch (ParseException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            } catch (SchedulerException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            }
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Report(org.opennms.netmgt.config.reportd.Report) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException)

Example 47 with SchedulerException

use of org.quartz.SchedulerException in project OpenClinica by OpenClinica.

the class ImportSpringJob method executeInternal.

@Override
protected void executeInternal(final JobExecutionContext context) throws JobExecutionException {
    ApplicationContext appContext;
    try {
        appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
        TransactionTemplate transactionTemplate = (TransactionTemplate) appContext.getBean("sharedTransactionTemplate");
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                executeInternalInTransaction(context);
            }
        });
    } catch (SchedulerException e) {
        throw new JobExecutionException(e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SchedulerException(org.quartz.SchedulerException) JobExecutionException(org.quartz.JobExecutionException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 48 with SchedulerException

use of org.quartz.SchedulerException in project karaf by apache.

the class QuartzScheduler method schedule.

/**
     * Schedule a job
     * @see org.apache.karaf.scheduler.Scheduler#schedule(java.lang.Object, org.apache.karaf.scheduler.ScheduleOptions)
     * @throws SchedulerException if the job can't be scheduled
     * @throws IllegalArgumentException If the preconditions are not met
     */
public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException, SchedulerException {
    this.checkJob(job);
    if (!(options instanceof InternalScheduleOptions)) {
        throw new IllegalArgumentException("Options has not been created via schedule or is null.");
    }
    final InternalScheduleOptions opts = (InternalScheduleOptions) options;
    if (opts.argumentException != null) {
        throw opts.argumentException;
    }
    // as this method might be called from unbind and during
    // unbind a deactivate could happen, we check the scheduler first
    final org.quartz.Scheduler s = this.scheduler;
    if (s == null) {
        throw new IllegalStateException("Scheduler is not available anymore.");
    }
    final String name;
    if (opts.name != null) {
        // if there is already a job with the name, remove it first
        try {
            final JobKey key = JobKey.jobKey(opts.name);
            final JobDetail jobdetail = s.getJobDetail(key);
            if (jobdetail != null) {
                s.deleteJob(key);
                this.logger.debug("Unscheduling job with name {}", opts.name);
            }
        } catch (final SchedulerException ignored) {
        // ignore
        }
        name = opts.name;
    } else {
        name = job.getClass().getName() + ':' + UUID.randomUUID();
        opts.name = name;
    }
    final Trigger trigger = opts.trigger.withIdentity(name).build();
    // create the data map
    final JobDataMap jobDataMap = this.initDataMap(name, job, opts);
    final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
    this.logger.debug("Scheduling job {} with name {} and trigger {}", job, name, trigger);
    s.scheduleJob(detail, trigger);
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger)

Example 49 with SchedulerException

use of org.quartz.SchedulerException in project sling by apache.

the class QuartzScheduler method removeJob.

/**
     * @see org.apache.sling.commons.scheduler.Scheduler#removeJob(java.lang.String)
     */
public void removeJob(final Long bundleId, final String jobName) throws NoSuchElementException {
    // as this method might be called from unbind and during
    // unbind a deactivate could happen, we check the scheduler first
    final Map<String, SchedulerProxy> proxies;
    synchronized (this.schedulers) {
        if (this.active) {
            proxies = new HashMap<>(this.schedulers);
        } else {
            proxies = Collections.emptyMap();
        }
    }
    for (final SchedulerProxy proxy : proxies.values()) {
        synchronized (proxy) {
            try {
                final JobKey key = JobKey.jobKey(jobName);
                final JobDetail jobdetail = proxy.getScheduler().getJobDetail(key);
                if (jobdetail != null) {
                    proxy.getScheduler().deleteJob(key);
                    this.logger.debug("Unscheduling job with name {}", jobName);
                    return;
                }
            } catch (final SchedulerException ignored) {
            // ignore
            }
        }
    }
    if (this.active) {
        throw new NoSuchElementException("No job found with name " + jobName);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) NoSuchElementException(java.util.NoSuchElementException)

Example 50 with SchedulerException

use of org.quartz.SchedulerException in project deltaspike by apache.

the class AbstractQuartzScheduler method start.

@Override
public void start() {
    if (this.scheduler != null) {
        throw new UnsupportedOperationException("the scheduler is started already");
    }
    SchedulerFactory schedulerFactory = null;
    try {
        Properties properties = new Properties();
        properties.put(StdSchedulerFactory.PROP_SCHED_JOB_FACTORY_CLASS, CdiAwareJobFactory.class.getName());
        try {
            ResourceBundle config = loadCustomQuartzConfig();
            Enumeration<String> keys = config.getKeys();
            String key;
            while (keys.hasMoreElements()) {
                key = keys.nextElement();
                properties.put(key, config.getString(key));
            }
        } catch (Exception e1) {
            LOG.info("no custom quartz-config file found. falling back to the default config provided by quartz.");
            InputStream inputStream = null;
            try {
                inputStream = ClassUtils.getClassLoader(null).getResourceAsStream("org/quartz/quartz.properties");
                properties.load(inputStream);
            } catch (Exception e2) {
                LOG.warning("failed to load quartz default-config");
                schedulerFactory = new StdSchedulerFactory();
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
            }
        }
        if (schedulerFactory == null) {
            schedulerFactory = new StdSchedulerFactory(properties);
        }
    } catch (Exception e) {
        LOG.log(Level.WARNING, "fallback to default scheduler-factory", e);
        schedulerFactory = new StdSchedulerFactory();
    }
    try {
        this.scheduler = schedulerFactory.getScheduler();
        if (SchedulerBaseConfig.LifecycleIntegration.START_SCOPES_PER_JOB) {
            this.scheduler.getListenerManager().addJobListener(new InjectionAwareJobListener());
        }
        if (!this.scheduler.isStarted()) {
            this.scheduler.startDelayed(SchedulerBaseConfig.LifecycleIntegration.DELAYED_START_IN_SECONDS);
        }
    } catch (SchedulerException e) {
        throw ExceptionUtils.throwAsRuntimeException(e);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) InputStream(java.io.InputStream) ResourceBundle(java.util.ResourceBundle) Properties(java.util.Properties) SchedulerException(org.quartz.SchedulerException) JobExecutionException(org.quartz.JobExecutionException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

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