Search in sources :

Example 1 with SchedulingException

use of org.springframework.scheduling.SchedulingException in project spring-framework by spring-projects.

the class WorkManagerTaskExecutor method execute.

//-------------------------------------------------------------------------
// Implementation of the Spring SchedulingTaskExecutor interface
//-------------------------------------------------------------------------
@Override
public void execute(Runnable task) {
    Assert.state(this.workManager != null, "No WorkManager specified");
    Work work = new DelegatingWork(this.taskDecorator != null ? this.taskDecorator.decorate(task) : task);
    try {
        if (this.workListener != null) {
            this.workManager.schedule(work, this.workListener);
        } else {
            this.workManager.schedule(work);
        }
    } catch (WorkRejectedException ex) {
        throw new TaskRejectedException("CommonJ WorkManager did not accept task: " + task, ex);
    } catch (WorkException ex) {
        throw new SchedulingException("Could not schedule task on CommonJ WorkManager", ex);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) WorkRejectedException(commonj.work.WorkRejectedException) WorkException(commonj.work.WorkException) Work(commonj.work.Work) SchedulingException(org.springframework.scheduling.SchedulingException)

Example 2 with SchedulingException

use of org.springframework.scheduling.SchedulingException in project spring-framework by spring-projects.

the class SchedulerFactoryBean method startScheduler.

/**
 * Start the Quartz Scheduler, respecting the "startupDelay" setting.
 * @param scheduler the Scheduler to start
 * @param startupDelay the number of seconds to wait before starting
 * the Scheduler asynchronously
 */
protected void startScheduler(final Scheduler scheduler, final int startupDelay) throws SchedulerException {
    if (startupDelay <= 0) {
        logger.info("Starting Quartz Scheduler now");
        scheduler.start();
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Will start Quartz Scheduler [" + scheduler.getSchedulerName() + "] in " + startupDelay + " seconds");
        }
        // Not using the Quartz startDelayed method since we explicitly want a daemon
        // thread here, not keeping the JVM alive in case of all other threads ending.
        Thread schedulerThread = new Thread() {

            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(startupDelay);
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                // simply proceed
                }
                if (logger.isInfoEnabled()) {
                    logger.info("Starting Quartz Scheduler now, after delay of " + startupDelay + " seconds");
                }
                try {
                    scheduler.start();
                } catch (SchedulerException ex) {
                    throw new SchedulingException("Could not start Quartz Scheduler after delay", ex);
                }
            }
        };
        schedulerThread.setName("Quartz Scheduler [" + scheduler.getSchedulerName() + "]");
        schedulerThread.setDaemon(true);
        schedulerThread.start();
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) SchedulingException(org.springframework.scheduling.SchedulingException)

Example 3 with SchedulingException

use of org.springframework.scheduling.SchedulingException in project spring-framework by spring-projects.

the class WorkManagerTaskExecutor method execute.

@Override
public void execute(Runnable task, long startTimeout) {
    Assert.state(this.workManager != null, "No WorkManager specified");
    Work work = new DelegatingWork(this.taskDecorator != null ? this.taskDecorator.decorate(task) : task);
    try {
        if (this.blockUntilCompleted) {
            if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
                this.workManager.doWork(work, startTimeout, null, this.workListener);
            } else {
                this.workManager.doWork(work);
            }
        } else if (this.blockUntilStarted) {
            if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
                this.workManager.startWork(work, startTimeout, null, this.workListener);
            } else {
                this.workManager.startWork(work);
            }
        } else {
            if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
                this.workManager.scheduleWork(work, startTimeout, null, this.workListener);
            } else {
                this.workManager.scheduleWork(work);
            }
        }
    } catch (WorkRejectedException ex) {
        if (WorkException.START_TIMED_OUT.equals(ex.getErrorCode())) {
            throw new TaskTimeoutException("JCA WorkManager rejected task because of timeout: " + task, ex);
        } else {
            throw new TaskRejectedException("JCA WorkManager rejected task: " + task, ex);
        }
    } catch (WorkException ex) {
        throw new SchedulingException("Could not schedule task on JCA WorkManager", ex);
    }
}
Also used : TaskTimeoutException(org.springframework.core.task.TaskTimeoutException) TaskRejectedException(org.springframework.core.task.TaskRejectedException) WorkRejectedException(javax.resource.spi.work.WorkRejectedException) WorkException(javax.resource.spi.work.WorkException) Work(javax.resource.spi.work.Work) SchedulingException(org.springframework.scheduling.SchedulingException)

Aggregations

SchedulingException (org.springframework.scheduling.SchedulingException)3 TaskRejectedException (org.springframework.core.task.TaskRejectedException)2 Work (commonj.work.Work)1 WorkException (commonj.work.WorkException)1 WorkRejectedException (commonj.work.WorkRejectedException)1 Work (javax.resource.spi.work.Work)1 WorkException (javax.resource.spi.work.WorkException)1 WorkRejectedException (javax.resource.spi.work.WorkRejectedException)1 SchedulerException (org.quartz.SchedulerException)1 TaskTimeoutException (org.springframework.core.task.TaskTimeoutException)1