org.quartz.impl.SchedulerRepository Java Examples
The following examples show how to use
org.quartz.impl.SchedulerRepository.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchedulerAccessorBean.java From spring-analysis-note with MIT License | 6 votes |
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; } } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
Example #2
Source File: SchedulerAccessorBean.java From java-technology-stack with MIT License | 6 votes |
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; } } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
Example #3
Source File: SchedulerAccessorBean.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; } } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
Example #4
Source File: SchedulerAccessorBean.java From lams with GNU General Public License v2.0 | 6 votes |
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; } } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
Example #5
Source File: ScriptExecutionTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Set up Quartz to use our mock scheduler class * * @throws SchedulerException */ @BeforeClass public static void setUp() throws SchedulerException { scheduler = new MockScheduler(); System.setProperty(StdSchedulerFactory.PROPERTIES_FILE, "quartz-test.properties"); SchedulerRepository.getInstance().bind(scheduler); assertThat(StdSchedulerFactory.getDefaultScheduler(), sameInstance(scheduler)); }
Example #6
Source File: QuartzSchedulerProvider.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doStop() throws Exception { if (scheduler != null) { scheduler.shutdown(); scheduler = null; } SchedulerRepository.getInstance().remove(SCHEDULER_NAME); }
Example #7
Source File: SchedulerFactoryBean.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create the Scheduler instance for the given factory and scheduler name. * Called by {@link #afterPropertiesSet}. * <p>The default implementation invokes SchedulerFactory's {@code getScheduler} * method. Can be overridden for custom Scheduler creation. * @param schedulerFactory the factory to create the Scheduler with * @param schedulerName the name of the scheduler to create * @return the Scheduler instance * @throws SchedulerException if thrown by Quartz methods * @see #afterPropertiesSet * @see org.quartz.SchedulerFactory#getScheduler */ protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException { // Override thread context ClassLoader to work around naive Quartz ClassLoadHelper loading. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.resourceLoader != null && !this.resourceLoader.getClassLoader().equals(threadContextClassLoader)); if (overrideClassLoader) { currentThread.setContextClassLoader(this.resourceLoader.getClassLoader()); } try { SchedulerRepository repository = SchedulerRepository.getInstance(); synchronized (repository) { Scheduler existingScheduler = (schedulerName != null ? repository.lookup(schedulerName) : null); Scheduler newScheduler = schedulerFactory.getScheduler(); if (newScheduler == existingScheduler) { throw new IllegalStateException("Active Scheduler of name '" + schedulerName + "' already registered " + "in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!"); } if (!this.exposeSchedulerInRepository) { // Need to remove it in this case, since Quartz shares the Scheduler instance by default! SchedulerRepository.getInstance().remove(newScheduler.getSchedulerName()); } return newScheduler; } } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } } }
Example #8
Source File: SchedulerFactoryBean.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Create the Scheduler instance for the given factory and scheduler name. * Called by {@link #afterPropertiesSet}. * <p>The default implementation invokes SchedulerFactory's {@code getScheduler} * method. Can be overridden for custom Scheduler creation. * @param schedulerFactory the factory to create the Scheduler with * @param schedulerName the name of the scheduler to create * @return the Scheduler instance * @throws SchedulerException if thrown by Quartz methods * @see #afterPropertiesSet * @see org.quartz.SchedulerFactory#getScheduler */ protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException { // Override thread context ClassLoader to work around naive Quartz ClassLoadHelper loading. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.resourceLoader != null && !this.resourceLoader.getClassLoader().equals(threadContextClassLoader)); if (overrideClassLoader) { currentThread.setContextClassLoader(this.resourceLoader.getClassLoader()); } try { SchedulerRepository repository = SchedulerRepository.getInstance(); synchronized (repository) { Scheduler existingScheduler = (schedulerName != null ? repository.lookup(schedulerName) : null); Scheduler newScheduler = schedulerFactory.getScheduler(); if (newScheduler == existingScheduler) { throw new IllegalStateException("Active Scheduler of name '" + schedulerName + "' already registered " + "in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!"); } if (!this.exposeSchedulerInRepository) { // Need to remove it in this case, since Quartz shares the Scheduler instance by default! SchedulerRepository.getInstance().remove(newScheduler.getSchedulerName()); } return newScheduler; } } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } } }
Example #9
Source File: SchedulerFactoryBean.java From java-technology-stack with MIT License | 5 votes |
/** * Create the Scheduler instance for the given factory and scheduler name. * Called by {@link #afterPropertiesSet}. * <p>The default implementation invokes SchedulerFactory's {@code getScheduler} * method. Can be overridden for custom Scheduler creation. * @param schedulerFactory the factory to create the Scheduler with * @param schedulerName the name of the scheduler to create * @return the Scheduler instance * @throws SchedulerException if thrown by Quartz methods * @see #afterPropertiesSet * @see org.quartz.SchedulerFactory#getScheduler */ protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName) throws SchedulerException { // Override thread context ClassLoader to work around naive Quartz ClassLoadHelper loading. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.resourceLoader != null && this.resourceLoader.getClassLoader() != threadContextClassLoader); if (overrideClassLoader) { currentThread.setContextClassLoader(this.resourceLoader.getClassLoader()); } try { SchedulerRepository repository = SchedulerRepository.getInstance(); synchronized (repository) { Scheduler existingScheduler = (schedulerName != null ? repository.lookup(schedulerName) : null); Scheduler newScheduler = schedulerFactory.getScheduler(); if (newScheduler == existingScheduler) { throw new IllegalStateException("Active Scheduler of name '" + schedulerName + "' already registered " + "in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!"); } if (!this.exposeSchedulerInRepository) { // Need to remove it in this case, since Quartz shares the Scheduler instance by default! SchedulerRepository.getInstance().remove(newScheduler.getSchedulerName()); } return newScheduler; } } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } } }
Example #10
Source File: SchedulerFactoryBean.java From spring-analysis-note with MIT License | 5 votes |
/** * Create the Scheduler instance for the given factory and scheduler name. * Called by {@link #afterPropertiesSet}. * <p>The default implementation invokes SchedulerFactory's {@code getScheduler} * method. Can be overridden for custom Scheduler creation. * @param schedulerFactory the factory to create the Scheduler with * @param schedulerName the name of the scheduler to create * @return the Scheduler instance * @throws SchedulerException if thrown by Quartz methods * @see #afterPropertiesSet * @see org.quartz.SchedulerFactory#getScheduler */ protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName) throws SchedulerException { // Override thread context ClassLoader to work around naive Quartz ClassLoadHelper loading. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.resourceLoader != null && this.resourceLoader.getClassLoader() != threadContextClassLoader); if (overrideClassLoader) { currentThread.setContextClassLoader(this.resourceLoader.getClassLoader()); } try { SchedulerRepository repository = SchedulerRepository.getInstance(); synchronized (repository) { Scheduler existingScheduler = (schedulerName != null ? repository.lookup(schedulerName) : null); Scheduler newScheduler = schedulerFactory.getScheduler(); if (newScheduler == existingScheduler) { throw new IllegalStateException("Active Scheduler of name '" + schedulerName + "' already registered " + "in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!"); } if (!this.exposeSchedulerInRepository) { // Need to remove it in this case, since Quartz shares the Scheduler instance by default! SchedulerRepository.getInstance().remove(newScheduler.getSchedulerName()); } return newScheduler; } } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } } }
Example #11
Source File: QuartzSchedulerAutoConfiguration.java From spring-boot-starter-quartz with Apache License 2.0 | 4 votes |
@Bean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME) @ConditionalOnMissingBean public SchedulerFactoryBean autoSchedulerFactory(ApplicationContext applicationContext, JobFactory jobFactory, @Autowired(required=false) QuartzSchedulerProperties properties, @Qualifier(QUARTZ_PROPERTIES_BEAN_NAME) Properties quartzProperties, @Autowired(required=false) List<TriggerListener> triggerListeners, @Autowired(required=false) List<JobListener> jobListeners, @Autowired(required=false) List<SchedulerListener> schedulerListeners) { if (null == properties) { LOGGER.warn("no QuartzSchedulerProperties found, consider to set quartz.enabled=true in properties"); return null; } LOGGER.debug("creating SchedulerFactory"); SchedulerFactory factorySettings = properties.getSchedulerFactory(); SchedulerRepository schedulerRepo = SchedulerRepository.getInstance(); if (schedulerRepo.remove(QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)) { LOGGER.debug("removed scheduler from SchedulerRepository with name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME); } if (null != factorySettings.getSchedulerName() && schedulerRepo.remove(factorySettings.getSchedulerName())) { LOGGER.debug("removed scheduler from SchedulerRepository with name: " + factorySettings.getSchedulerName()); } SchedulerFactoryBean factory = BeanUtils.instantiateClass(SchedulerFactoryBean.class); factory.setApplicationContext(applicationContext); factory.setJobFactory(jobFactory); Persistence persistenceSettings = properties.getPersistence(); if (persistenceSettings.isPersisted()) { factory.setDataSource(getDataSource(applicationContext, persistenceSettings)); if (persistenceSettings.isUsePlatformTxManager()) { PlatformTransactionManager txManager = getTransactionManager(applicationContext, persistenceSettings.getPlatformTxManagerBeanName()); if (null != txManager) { factory.setTransactionManager(txManager); } } } if (!StringUtils.isEmpty(factorySettings.getSchedulerName())) { factory.setSchedulerName(factorySettings.getSchedulerName()); } else { LOGGER.debug("no SchedulerName configured, using bean name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME); } factory.setPhase(factorySettings.getPhase()); factory.setStartupDelay(factorySettings.getStartupDelay()); factory.setAutoStartup(factorySettings.isAutoStartup()); factory.setWaitForJobsToCompleteOnShutdown(factorySettings.isWaitForJobsToCompleteOnShutdown()); factory.setOverwriteExistingJobs(factorySettings.isOverwriteExistingJobs()); factory.setExposeSchedulerInRepository(factorySettings.isExposeSchedulerInRepository()); factory.setQuartzProperties(quartzProperties); if (!CollectionUtils.isEmpty(jobListeners)) { LOGGER.info("configuring " + jobListeners.size() + " job listeners"); factory.setGlobalJobListeners(jobListeners.toArray(new JobListener[]{})); } if (!CollectionUtils.isEmpty(triggerListeners)) { LOGGER.info("configuring " + triggerListeners.size() + " trigger listeners"); factory.setGlobalTriggerListeners(triggerListeners.toArray(new TriggerListener[]{})); } if (!CollectionUtils.isEmpty(schedulerListeners)) { LOGGER.info("configuring " + schedulerListeners.size() + " scheduler listeners"); factory.setSchedulerListeners(schedulerListeners.toArray(new SchedulerListener[]{})); } Collection<Trigger> triggers = getTriggers(applicationContext); if (null != triggers && !triggers.isEmpty()) { factory.setTriggers(triggers.toArray(new Trigger[triggers.size()])); LOGGER.info("staring scheduler factory with " + triggers.size() + " job triggers"); } else { LOGGER.info("staring scheduler factory with 0 job triggers"); } QuartzSchedulerFactoryOverrideHook hook = getQuartzSchedulerFactoryOverrideHook(applicationContext); if (null != hook) { factory = hook.override(factory, properties, quartzProperties); } return factory; }
Example #12
Source File: QuartzSupportTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void schedulerRepositoryExposure() throws Exception { ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml"); assertSame(SchedulerRepository.getInstance().lookup("myScheduler"), ctx.getBean("scheduler")); ctx.close(); }
Example #13
Source File: QuartzSupportTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void schedulerRepositoryExposure() throws Exception { ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml"); assertSame(SchedulerRepository.getInstance().lookup("myScheduler"), ctx.getBean("scheduler")); ctx.close(); }
Example #14
Source File: QuartzSupportTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void schedulerRepositoryExposure() throws Exception { ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml"); assertSame(SchedulerRepository.getInstance().lookup("myScheduler"), ctx.getBean("scheduler")); ctx.close(); }
Example #15
Source File: JobInformations.java From javamelody with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static List<Scheduler> getAllSchedulers() { return new ArrayList<Scheduler>(SchedulerRepository.getInstance().lookupAll()); }
Example #16
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 2 votes |
/** * 获取仓库中所有的Scheduler集合 * @return */ public static Collection<Scheduler> getAllScheduler(){ return SchedulerRepository.getInstance().lookupAll(); }
Example #17
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 2 votes |
/** * 删除不够通用 * @param schedName * @return */ public static Scheduler getScheduler(String schedName) { return SchedulerRepository.getInstance().lookup(schedName); }