public class SingularSchedulerBean
extends org.opensingular.schedule.quartz.SingularSchedulerAccessor
implements org.springframework.beans.factory.FactoryBean<org.quartz.Scheduler>, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.SmartLifecycle, org.opensingular.lib.commons.util.Loggable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_THREAD_COUNT |
static String |
PROP_THREAD_COUNT |
Constructor and Description |
---|
SingularSchedulerBean(DataSource dataSource) |
Modifier and Type | Method and Description |
---|---|
void |
addJob(org.quartz.JobDetail jobDetail) |
void |
addTrigger(org.quartz.Trigger trigger)
Add trigger and the trigger's job detail.
|
void |
addTrigger(org.quartz.Trigger trigger,
org.quartz.JobDetail jobDetail) |
void |
afterPropertiesSet() |
protected org.quartz.Scheduler |
createScheduler(org.quartz.SchedulerFactory schedulerFactory,
String schedulerName)
Create the Scheduler instance for the given factory and scheduler name.
|
void |
destroy()
Shut down the Quartz scheduler on bean factory shutdown,
stopping all scheduled jobs.
|
Set<org.quartz.JobKey> |
getAllJobKeys() |
static DataSource |
getConfigTimeDataSource()
Return the DataSource for the currently configured Quartz Scheduler,
to be used by SingularLocalDataSourceJobStore.
|
static DataSource |
getConfigTimeNonTransactionalDataSource()
Return the non-transactional DataSource for the currently configured
Quartz Scheduler, to be used by SingularLocalDataSourceJobStore.
|
static Executor |
getConfigTimeTaskExecutor()
Return the TaskExecutor for the currently configured Quartz Scheduler,
to be used by LocalTaskExecutorThreadPool.
|
org.quartz.Scheduler |
getObject() |
Class<?> |
getObjectType() |
int |
getPhase() |
org.quartz.Scheduler |
getScheduler() |
void |
initialize() |
boolean |
isAutoStartup() |
boolean |
isRunning() |
boolean |
isSingleton() |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey)
Set the key of an ApplicationContext reference to expose in the
SchedulerContext, for example "applicationContext".
|
void |
setAutoStartup(boolean autoStartup)
Set whether to automatically start the scheduler after initialization.
|
void |
setBeanName(String name) |
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the Quartz properties config file, for example
as classpath resource "classpath:quartz.properties".
|
void |
setConfigLocation(ResourceBundle configLocation) |
void |
setDataSource(DataSource dataSource)
Set the default DataSource to be used by the Scheduler.
|
void |
setExposeSchedulerInRepository(boolean exposeSchedulerInRepository)
Set whether to expose the Spring-managed
Scheduler instance in the
Quartz SchedulerRepository . |
void |
setJobFactory(org.quartz.spi.JobFactory jobFactory)
Set the Quartz JobFactory to use for this Scheduler.
|
void |
setNonTransactionalDataSource(DataSource nonTransactionalDataSource)
Set the DataSource to be used by the Scheduler for non-transactional access.
|
void |
setPhase(int phase)
Specify the phase in which this scheduler should be started and
stopped.
|
void |
setQuartzProperties(Properties quartzProperties)
Set Quartz properties, like "org.quartz.threadPool.class".
|
void |
setSchedulerContextAsMap(Map<String,?> schedulerContextAsMap)
Register objects in the Scheduler context via a given Map.
|
void |
setSchedulerFactoryClass(Class<? extends org.quartz.SchedulerFactory> schedulerFactoryClass)
Set the Quartz SchedulerFactory implementation to use.
|
void |
setSchedulerName(String schedulerName)
Set the name of the Scheduler to create via the SchedulerFactory.
|
void |
setStartupDelay(int startupDelay)
Set the number of seconds to wait after initialization before
starting the scheduler asynchronously.
|
void |
setTaskExecutor(Executor taskExecutor)
Set the Spring TaskExecutor to use as Quartz backend.
|
void |
setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for running jobs to complete on shutdown.
|
void |
start() |
void |
start(int startupDelay) |
protected void |
startScheduler(org.quartz.Scheduler scheduler,
int startupDelay)
Start the Quartz Scheduler, respecting the "startupDelay" setting.
|
void |
stop() |
void |
stop(Runnable callback) |
void |
triggerJob(org.quartz.JobKey jobKey)
Trigger the identified
JobDetail (execute it now). |
addJobToScheduler, addTriggerToScheduler, registerJobsAndTriggers, registerListeners, setCalendars, setGlobalJobListeners, setGlobalTriggerListeners, setJobDetails, setJobSchedulingDataLocation, setJobSchedulingDataLocations, setOverwriteExistingJobs, setSchedulerListeners, setTriggers
public static final String PROP_THREAD_COUNT
public static final int DEFAULT_THREAD_COUNT
public SingularSchedulerBean(DataSource dataSource)
public static Executor getConfigTimeTaskExecutor()
This instance will be set before initialization of the corresponding Scheduler, and reset immediately afterwards. It is thus only available during configuration.
setTaskExecutor(java.util.concurrent.Executor)
,
LocalTaskExecutorThreadPool
public static DataSource getConfigTimeDataSource()
This instance will be set before initialization of the corresponding Scheduler, and reset immediately afterwards. It is thus only available during configuration.
public static DataSource getConfigTimeNonTransactionalDataSource()
This instance will be set before initialization of the corresponding Scheduler, and reset immediately afterwards. It is thus only available during configuration.
public void setSchedulerFactoryClass(Class<? extends org.quartz.SchedulerFactory> schedulerFactoryClass)
Default is StdSchedulerFactory
, reading in the standard
quartz.properties
from quartz.jar
.
To use custom Quartz properties, specify the "configLocation"
or "quartzProperties" bean property on this FactoryBean.
StdSchedulerFactory
,
setConfigLocation(java.util.ResourceBundle)
,
setQuartzProperties(java.util.Properties)
public void setSchedulerName(String schedulerName)
If not specified, the bean name will be used as default scheduler name.
setSchedulerName
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
SchedulerFactory.getScheduler()
,
SchedulerFactory.getScheduler(String)
public void setConfigLocation(ResourceBundle configLocation)
setConfigLocation
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Note: Can be omitted when all necessary properties are specified locally via this bean, or when relying on Quartz' default configuration.
public void setQuartzProperties(Properties quartzProperties)
Can be used to override values in a Quartz properties config file, or to specify all necessary properties locally.
setQuartzProperties
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
setConfigLocation(java.util.ResourceBundle)
public void setTaskExecutor(Executor taskExecutor)
Can be used to assign a JDK 1.5 ThreadPoolExecutor or a CommonJ WorkManager as Quartz backend, to avoid Quartz's manual thread creation.
By default, a Quartz SimpleThreadPool will be used, configured through the corresponding Quartz properties.
setQuartzProperties(java.util.Properties)
,
LocalTaskExecutorThreadPool
,
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
,
org.springframework.scheduling.commonj.WorkManagerTaskExecutor
public void setDataSource(DataSource dataSource)
Note: If this is set, the Quartz settings should not define a job store "dataSource" to avoid meaningless double configuration.
A Spring-specific subclass of Quartz' JobStoreCMT will be used. It is therefore strongly recommended to perform all operations on the Scheduler within Spring-managed (or plain JTA) transactions. Else, database locking will not properly work and might even break (e.g. if trying to obtain a lock on Oracle without a transaction).
Supports both transactional and non-transactional DataSource access. With a non-XA DataSource and local Spring transactions, a single DataSource argument is sufficient. In case of an XA DataSource and global JTA transactions, SchedulerFactoryBean's "nonTransactionalDataSource" property should be set, passing in a non-XA DataSource that will not participate in global transactions.
public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource)
This is only necessary if the default DataSource is an XA DataSource that will always participate in transactions: A non-XA version of that DataSource should be specified as "nonTransactionalDataSource" in such a scenario.
This is not relevant with a local DataSource instance and Spring transactions. Specifying a single default DataSource as "dataSource" is sufficient there.
public void setSchedulerContextAsMap(Map<String,?> schedulerContextAsMap)
Note: When using persistent Jobs whose JobDetail will be kept in the database, do not put Spring-managed beans or an ApplicationContext reference into the JobDataMap but rather into the SchedulerContext.
schedulerContextAsMap
- Map with String keys and any objects as
values (for example Spring-managed beans)JobDetailFactoryBean.setJobDataAsMap(java.util.Map<java.lang.String, ?>)
public void setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey)
Note: When using persistent Jobs whose JobDetail will be kept in the database, do not put an ApplicationContext reference into the JobDataMap but rather into the SchedulerContext.
In case of a QuartzJobBean, the reference will be applied to the Job instance as bean property. An "applicationContext" attribute will correspond to a "setApplicationContext" method in that scenario.
Note that BeanFactory callback interfaces like ApplicationContextAware are not automatically applied to Quartz Job instances, because Quartz itself is responsible for the lifecycle of its Jobs.
JobDetailFactoryBean.setApplicationContextJobDataKey(java.lang.String)
,
ApplicationContext
public void setJobFactory(org.quartz.spi.JobFactory jobFactory)
Default is Spring's AdaptableJobFactory
, which supports
Runnable
objects as well as standard Quartz
Job
instances. Note that this default only applies
to a local Scheduler, not to a RemoteScheduler (where setting
a custom JobFactory is not supported by Quartz).
Specify an instance of Spring's SpringBeanJobFactory
here
(typically as an inner bean definition) to automatically populate a job's
bean properties from the specified job data map and scheduler context.
setJobFactory
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
AdaptableJobFactory
,
SpringBeanJobFactory
public void setAutoStartup(boolean autoStartup)
Default is "true"; set this to "false" to allow for manual startup.
public void setPhase(int phase)
public void setStartupDelay(int startupDelay)
Setting this to 10 or 20 seconds makes sense if no jobs should be run before the entire application has started up.
public void setExposeSchedulerInRepository(boolean exposeSchedulerInRepository)
Scheduler
instance in the
Quartz SchedulerRepository
. Default is "false", since the Spring-managed
Scheduler is usually exclusively intended for access within the Spring context.
Switch this flag to "true" in order to expose the Scheduler globally. This is not recommended unless you have an existing Spring application that relies on this behavior. Note that such global exposure was the accidental default in earlier Spring versions; this has been fixed as of Spring 2.5.6.
setExposeSchedulerInRepository
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Default is "false". Switch this to "true" if you prefer fully completed jobs at the expense of a longer shutdown phase.
setWaitForJobsToCompleteOnShutdown
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
Scheduler.shutdown(boolean)
public void initialize() throws org.opensingular.lib.commons.base.SingularException
initialize
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
org.opensingular.lib.commons.base.SingularException
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
protected org.quartz.Scheduler createScheduler(org.quartz.SchedulerFactory schedulerFactory, String schedulerName) throws org.quartz.SchedulerException
afterPropertiesSet()
.
The default implementation invokes SchedulerFactory's getScheduler
method. Can be overridden for custom Scheduler creation.
schedulerFactory
- the factory to create the Scheduler withschedulerName
- the name of the scheduler to createorg.quartz.SchedulerException
- if thrown by Quartz methodsafterPropertiesSet()
,
SchedulerFactory.getScheduler()
protected void startScheduler(org.quartz.Scheduler scheduler, int startupDelay) throws org.quartz.SchedulerException
scheduler
- the Scheduler to startstartupDelay
- the number of seconds to wait before starting
the Scheduler asynchronouslyorg.quartz.SchedulerException
public org.quartz.Scheduler getScheduler()
getScheduler
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
getScheduler
in class org.opensingular.schedule.quartz.SingularSchedulerAccessor
public void start() throws org.springframework.scheduling.SchedulingException
start
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
start
in interface org.springframework.context.Lifecycle
org.springframework.scheduling.SchedulingException
public void start(int startupDelay) throws org.quartz.SchedulerException
start
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
org.quartz.SchedulerException
public void stop() throws org.springframework.scheduling.SchedulingException
stop
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
stop
in interface org.springframework.context.Lifecycle
org.springframework.scheduling.SchedulingException
public boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void stop(Runnable callback) throws org.springframework.scheduling.SchedulingException
stop
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
stop
in interface org.springframework.context.SmartLifecycle
org.springframework.scheduling.SchedulingException
public boolean isRunning() throws org.springframework.scheduling.SchedulingException
isRunning
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
isRunning
in interface org.springframework.context.Lifecycle
org.springframework.scheduling.SchedulingException
public void destroy() throws org.quartz.SchedulerException
destroy
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
destroy
in interface org.springframework.beans.factory.DisposableBean
org.quartz.SchedulerException
public void setBeanName(String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public org.quartz.Scheduler getObject() throws Exception
getObject
in interface org.springframework.beans.factory.FactoryBean<org.quartz.Scheduler>
Exception
public Class<?> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<org.quartz.Scheduler>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<org.quartz.Scheduler>
public int getPhase()
getPhase
in interface org.springframework.context.Phased
public void addJob(org.quartz.JobDetail jobDetail) throws org.quartz.SchedulerException
addJob
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
org.quartz.SchedulerException
public void addTrigger(org.quartz.Trigger trigger, org.quartz.JobDetail jobDetail) throws org.quartz.SchedulerException
addTrigger
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
org.quartz.SchedulerException
public void addTrigger(org.quartz.Trigger trigger) throws org.quartz.SchedulerException
addTrigger
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
trigger
- the trigger.org.quartz.SchedulerException
- if could not start Quartz Scheduler.public void triggerJob(org.quartz.JobKey jobKey) throws org.quartz.SchedulerException
JobDetail
(execute it now).triggerJob
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
jobKey
- org.quartz.SchedulerException
public Set<org.quartz.JobKey> getAllJobKeys() throws org.quartz.SchedulerException
getAllJobKeys
in interface org.opensingular.schedule.quartz.SingularQuartzSchedulerAcessor
getAllJobKeys
in class org.opensingular.schedule.quartz.SingularSchedulerAccessor
org.quartz.SchedulerException
Copyright © 2019. All rights reserved.