Search in sources :

Example 1 with XMLSchedulingDataProcessor

use of org.quartz.xml.XMLSchedulingDataProcessor in project spring-framework by spring-projects.

the class SchedulerAccessor method registerJobsAndTriggers.

/**
	 * Register jobs and triggers (within a transaction, if possible).
	 */
protected void registerJobsAndTriggers() throws SchedulerException {
    TransactionStatus transactionStatus = null;
    if (this.transactionManager != null) {
        transactionStatus = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    }
    try {
        if (this.jobSchedulingDataLocations != null) {
            ClassLoadHelper clh = new ResourceLoaderClassLoadHelper(this.resourceLoader);
            clh.initialize();
            XMLSchedulingDataProcessor dataProcessor = new XMLSchedulingDataProcessor(clh);
            for (String location : this.jobSchedulingDataLocations) {
                dataProcessor.processFileAndScheduleJobs(location, getScheduler());
            }
        }
        // Register JobDetails.
        if (this.jobDetails != null) {
            for (JobDetail jobDetail : this.jobDetails) {
                addJobToScheduler(jobDetail);
            }
        } else {
            // Create empty list for easier checks when registering triggers.
            this.jobDetails = new LinkedList<>();
        }
        // Register Calendars.
        if (this.calendars != null) {
            for (String calendarName : this.calendars.keySet()) {
                Calendar calendar = this.calendars.get(calendarName);
                getScheduler().addCalendar(calendarName, calendar, true, true);
            }
        }
        // Register Triggers.
        if (this.triggers != null) {
            for (Trigger trigger : this.triggers) {
                addTriggerToScheduler(trigger);
            }
        }
    } catch (Throwable ex) {
        if (transactionStatus != null) {
            try {
                this.transactionManager.rollback(transactionStatus);
            } catch (TransactionException tex) {
                logger.error("Job registration exception overridden by rollback exception", ex);
                throw tex;
            }
        }
        if (ex instanceof SchedulerException) {
            throw (SchedulerException) ex;
        }
        if (ex instanceof Exception) {
            throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage(), ex);
        }
        throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage());
    }
    if (transactionStatus != null) {
        this.transactionManager.commit(transactionStatus);
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) SchedulerException(org.quartz.SchedulerException) XMLSchedulingDataProcessor(org.quartz.xml.XMLSchedulingDataProcessor) Calendar(org.quartz.Calendar) TransactionStatus(org.springframework.transaction.TransactionStatus) ClassLoadHelper(org.quartz.spi.ClassLoadHelper) SchedulerException(org.quartz.SchedulerException) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) TransactionException(org.springframework.transaction.TransactionException) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) TransactionException(org.springframework.transaction.TransactionException)

Aggregations

Calendar (org.quartz.Calendar)1 JobDetail (org.quartz.JobDetail)1 ObjectAlreadyExistsException (org.quartz.ObjectAlreadyExistsException)1 SchedulerException (org.quartz.SchedulerException)1 Trigger (org.quartz.Trigger)1 ClassLoadHelper (org.quartz.spi.ClassLoadHelper)1 XMLSchedulingDataProcessor (org.quartz.xml.XMLSchedulingDataProcessor)1 TransactionException (org.springframework.transaction.TransactionException)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1