SPR-5507 SchedulerFactoryBean now implements SmartLifecycle instead of ApplicationListener.

This commit is contained in:
Mark Fisher 2009-11-10 23:25:29 +00:00
parent 7d2b3f2e7e
commit 81efd48352
1 changed files with 13 additions and 26 deletions

View File

@ -32,17 +32,13 @@ import org.quartz.simpl.SimpleThreadPool;
import org.quartz.spi.JobFactory; import org.quartz.spi.JobFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent; import org.springframework.context.SmartLifecycle;
import org.springframework.context.ApplicationListener;
import org.springframework.context.Lifecycle;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.io.support.PropertiesLoaderUtils;
@ -90,9 +86,8 @@ import org.springframework.util.CollectionUtils;
* @see org.quartz.impl.StdSchedulerFactory * @see org.quartz.impl.StdSchedulerFactory
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/ */
public class SchedulerFactoryBean extends SchedulerAccessor public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBean<Scheduler>, BeanNameAware,
implements FactoryBean<Scheduler>, BeanNameAware, ApplicationContextAware, ApplicationContextAware, InitializingBean, DisposableBean, SmartLifecycle {
ApplicationListener<ApplicationEvent>, InitializingBean, DisposableBean, Lifecycle {
public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount"; public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount";
@ -369,6 +364,15 @@ public class SchedulerFactoryBean extends SchedulerAccessor
this.autoStartup = autoStartup; this.autoStartup = autoStartup;
} }
/**
* Return whether this scheduler is configured for auto-startup. If "true",
* the scheduler will start after the context is refreshed and after the
* start delay, if any.
*/
public boolean isAutoStartup() {
return this.autoStartup;
}
/** /**
* Set the number of seconds to wait after initialization before * Set the number of seconds to wait after initialization before
* starting the scheduler asynchronously. Default is 0, meaning * starting the scheduler asynchronously. Default is 0, meaning
@ -678,23 +682,6 @@ public class SchedulerFactoryBean extends SchedulerAccessor
} }
//---------------------------------------------------------------------
// Implementation of ApplicationListener interface
//---------------------------------------------------------------------
public void onApplicationEvent(ApplicationEvent event) {
// auto-start Scheduler if demanded
if (event instanceof ContextRefreshedEvent && this.autoStartup) {
try {
startScheduler(this.scheduler, this.startupDelay);
}
catch (SchedulerException e) {
throw new BeanInitializationException("failed to auto-start scheduler", e);
}
}
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Implementation of Lifecycle interface // Implementation of Lifecycle interface
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@ -702,7 +689,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor
public void start() throws SchedulingException { public void start() throws SchedulingException {
if (this.scheduler != null) { if (this.scheduler != null) {
try { try {
this.scheduler.start(); startScheduler(this.scheduler, this.startupDelay);
} }
catch (SchedulerException ex) { catch (SchedulerException ex) {
throw new SchedulingException("Could not start Quartz Scheduler", ex); throw new SchedulingException("Could not start Quartz Scheduler", ex);