@Bean(name = "batch") public SchedulerFactoryBean schedulerFactoryBean( DataSource dataSource, JobFactory jobFactory) { SchedulerFactoryBean factory = new SchedulerFactoryBean(); factory.setOverwriteExistingJobs(true); factory.setDataSource(dataSource); factory.setJobFactory(jobFactory); Properties props = new Properties(); props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "batch"); props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, "auto"); props.setProperty("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.HSQLDBDelegate"); props.setProperty("org.quartz.scheduler.skipUpdateCheck", "true"); // factory.setQuartzProperties(props); // factory.setTriggers(sampleJobTrigger); return factory; }
@Bean public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) { SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); schedulerFactoryBean.setApplicationContext(applicationContext); schedulerFactoryBean.setAutoStartup(schedulerProperties.isAutoStartup()); schedulerFactoryBean.setDataSource(dataSource); schedulerFactoryBean.setTransactionManager(platformTransactionManager); schedulerFactoryBean.setOverwriteExistingJobs(schedulerProperties.isOverwriteExistingJobs()); schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class); schedulerFactoryBean.setBeanName(schedulerProperties.getBeanName()); schedulerFactoryBean.setJobFactory(jobFactory); schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(schedulerProperties.isWaitOnShutdown()); schedulerFactoryBean.setQuartzProperties(schedulerProperties.getProperties()); schedulerFactoryBean.setStartupDelay(schedulerProperties.getStartupDelay()); schedulerFactoryBean.setCalendars(calendarMap); schedulerFactoryBean.setSchedulerListeners(schedulerListeners); return schedulerFactoryBean; }
@Bean public SchedulerFactoryBean schedulerFactoryBean( DataSource dataSource, PlatformTransactionManager transactionManager, JobFactory jobFactory) { final SchedulerFactoryBean factory = new SchedulerFactoryBean(); factory.setOverwriteExistingJobs(true); factory.setTaskExecutor(commonTaskScheduler.getScheduledExecutor()); factory.setDataSource(dataSource); factory.setTransactionManager(transactionManager); factory.setJobFactory(jobFactory); factory.setQuartzProperties(quartzProperties); factory.setSchedulerName(SCHEDULER_NAME); factory.setAutoStartup(true); factory.setWaitForJobsToCompleteOnShutdown(true); // Delay added to avoid errors caused by updating registered tasks and reduce load on startup factory.setStartupDelay(30); return factory; }
@Inject public QuartzSchedulerSPI(final EventManager eventManager, final NodeAccess nodeAccess, final Provider<JobStore> jobStoreProvider, final JobFactory jobFactory, @Named("${nexus.quartz.poolSize:-20}") final int threadPoolSize) throws Exception { this.eventManager = checkNotNull(eventManager); this.nodeAccess = checkNotNull(nodeAccess); this.jobStoreProvider = checkNotNull(jobStoreProvider); this.jobFactory = checkNotNull(jobFactory); checkArgument(threadPoolSize > 0, "Invalid thread-pool size: %s", threadPoolSize); this.threadPoolSize = threadPoolSize; log.info("Thread-pool size: {}", threadPoolSize); this.scheduleFactory = new QuartzScheduleFactory(); this.triggerConverter = new QuartzTriggerConverter(this.scheduleFactory); // FIXME: sort out with refinement to lifecycle below this.active = true; }
@Bean public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) throws IOException { SchedulerFactoryBean factory = new SchedulerFactoryBean(); factory.setSchedulerName("Sentry"); factory.setJobFactory(jobFactory); factory.setQuartzProperties(quartzProperties()); // this allows to update triggers in DB when updating settings in config file: factory.setOverwriteExistingJobs(true); return factory; }
@Bean(name = QUARTZ_JOB_FACTORY_BEAN_NAME) @ConditionalOnMissingBean(name = QUARTZ_JOB_FACTORY_BEAN_NAME) public JobFactory autoJobFactory(ApplicationContext applicationContext) { AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory(); jobFactory.setApplicationContext(applicationContext); return jobFactory; }
@Override protected void configure() { bind(MentorEventBus.class); bind(JobFactory.class).to(GuiceJobFactory.class); bind(Garbageman.class); bind(MentorStatus.class); }
@Provides @Singleton Scheduler provideScheduler(JobFactory jobFactory) throws SchedulerException { Scheduler scheduler = new StdSchedulerFactory("quartz.properties").getScheduler(); scheduler.setJobFactory(jobFactory); return scheduler; }
@Override public JobFactory getInitialJobFactory() { if (ipojoJobFactory == null) { ipojoJobFactory = new IPOJOJobFactory(); } return ipojoJobFactory; }
@Override protected void configure() { bind(Config.class).toInstance(new Config()); bind(JobFactory.class).to(SchedulerFactory.class); bind(Cache.class).toProvider(CacheProvider.class); bind(MangooTemplateEngine.class).toProvider(TemplateEngineProvider.class); }
@Test public void testBindings() { //given Injector guice = Application.getInjector(); //when Binding<Stage> stage = guice.getBinding(Stage.class); Binding<Injector> injector = guice.getBinding(Injector.class); Binding<Logger> logger = guice.getBinding(Logger.class); Binding<Config> config = guice.getBinding(Config.class); Binding<JobFactory> jobFactory = guice.getBinding(JobFactory.class); Binding<Cache> cache = guice.getBinding(Cache.class); Binding<MangooTemplateEngine> mangooTemplateEngine = guice.getBinding(MangooTemplateEngine.class); Binding<MangooRequestFilter> mangooRequestFilter = guice.getBinding(MangooRequestFilter.class); Binding<MangooLifecycle> mangooLifecycle = guice.getBinding(MangooLifecycle.class); //then assertThat(stage.getKey().getTypeLiteral().getType().getTypeName(), equalTo("com.google.inject.Stage")); assertThat(injector.getKey().getTypeLiteral().getType().getTypeName(), equalTo("com.google.inject.Injector")); assertThat(logger.getKey().getTypeLiteral().getType().getTypeName(), equalTo("java.util.logging.Logger")); assertThat(config.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.configuration.Config")); assertThat(jobFactory.getKey().getTypeLiteral().getType().getTypeName(), equalTo("org.quartz.spi.JobFactory")); assertThat(cache.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.cache.Cache")); assertThat(mangooTemplateEngine.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.MangooTemplateEngine")); assertThat(mangooRequestFilter.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.MangooRequestFilter")); assertThat(mangooLifecycle.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.MangooLifecycle")); }
@Bean public SchedulerFactoryBean schedulerFactoryBean(ApplicationContext applicationContext, DataSource dataSource, JobFactory jobFactory) { SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean(); schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties")); schedulerFactory.setAutoStartup(true); schedulerFactory.setDataSource(dataSource); schedulerFactory.setJobFactory(jobFactory); return schedulerFactory; }
/** * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory) */ public void setJobFactory(JobFactory factory) throws SchedulerException { throw new SchedulerException("Operation not supported for remote schedulers."); }
/** * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory) */ public void setJobFactory(JobFactory factory) throws SchedulerException { sched.setJobFactory(factory); }
/** * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory) */ public void setJobFactory(JobFactory factory) throws SchedulerException { throw new SchedulerException( "Operation not supported for remote schedulers."); }
public JobFactory getJobFactory() { return jobFactory; }
/** * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory) */ public void setJobFactory(JobFactory factory) throws SchedulerException { throw new SchedulerException( "Operation not supported for remote schedulers.", SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); }
@Bean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME) @ConditionalOnMissingBean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME) public SchedulerFactoryBean autoSchedulerFactory(ApplicationContext applicationContext, JobFactory jobFactory, QuartzSchedulerProperties properties, @Qualifier(QUARTZ_PROPERTIES_BEAN_NAME) Properties quartzProperties) { LOGGER.debug("creating SchedulerFactory"); 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); if (null != txManager) { factory.setTransactionManager(txManager); } } } SchedulerFactory factorySettings = properties.getSchedulerFactory(); factory.setSchedulerName(factorySettings.getSchedulerName()); 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); 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; }
@Bean public JobFactory jobFactory() { return new SpringBeanJobFactory(); }
@Bean public JobFactory jobFactory() { return new DynamicJobFactory(new AdaptableJobFactory()); }
public DynamicJobFactory(JobFactory defaultFactory) { this.defaultFactory = defaultFactory; }
/** * @see Scheduler#setJobFactory(JobFactory) */ @Override public void setJobFactory(JobFactory factory) throws SchedulerException { getScheduler().setJobFactory(factory); }
public void init(@Nullable final Integer poolSize, @Nullable final JobFactory factory) throws Exception { eventManager = new SimpleEventManager(); applicationDirectories = mock(ApplicationDirectories.class); baseUrlManager = mock(BaseUrlManager.class); nodeAccess = mock(NodeAccess.class); Module module = binder -> { Properties properties = new Properties(); properties.put("basedir", util.getBaseDir()); if (poolSize != null) { properties.put("nexus.quartz.poolSize", poolSize); } binder.bind(ParameterKeys.PROPERTIES) .toInstance(properties); binder.bind(EventManager.class).toInstance(eventManager); File workDir = util.createTempDir(util.getTargetDir(), "workdir"); when(applicationDirectories.getWorkDirectory(anyString())).thenReturn(workDir); binder.bind(ApplicationDirectories.class) .toInstance(applicationDirectories); binder.bind(BaseUrlManager.class) .toInstance(baseUrlManager); binder.bind(DatabaseInstance.class) .annotatedWith(Names.named("config")) .toInstance(databaseInstance); when(nodeAccess.getId()).thenReturn("test-12345"); when(nodeAccess.getMemberIds()).thenReturn(ImmutableSet.of("test-12345")); binder.bind(NodeAccess.class) .toInstance(nodeAccess); if (factory != null) { binder.bind(JobFactory.class).toInstance(factory); } }; this.injector = Guice.createInjector(new WireModule( module, new StateGuardModule(), new SpaceModule(new URLClassSpace(TaskSchedulerHelper.class.getClassLoader()), BeanScanning.INDEX) )); injector.injectMembers(this); }
/** * {@inheritDoc} */ @Override protected final void setup() { checkState(jobListeners == null, "Re-entry is not allowed."); checkState(triggerListeners == null, "Re-entry is not allowed."); checkState(schedulerListeners == null, "Re-entry is not allowed."); checkState(schedulerConfiguration == null, "Re-entry is not allowed."); jobListeners = Multibinder.newSetBinder(binder(), JobListener.class); triggerListeners = Multibinder.newSetBinder(binder(), TriggerListener.class); schedulerListeners = Multibinder.newSetBinder(binder(), SchedulerListener.class); schedulerConfiguration = new SchedulerConfiguration(); // load the quartz config if (getSettings() != null) { URL configFileUrl = getSettings().getFileUrl("quartz.configurationFile", "classpath:conf/quartz.properties"); if (configFileUrl == null) { log.debug("Failed to find Quartz Scheduler config file '{}'", getSettings().getString("quartz.configurationFile", "classpath:conf/quartz.properties")); } else { try (InputStream is = configFileUrl.openStream()) { Properties properties = new Properties(); properties.load(is); schedulerConfiguration.withProperties(properties); log.info("Configured Quartz Scheduler from '{}'", configFileUrl); } catch (IOException e) { } } } addJobListener(JobsMonitor.class); try { schedule(); bind(JobFactory.class).to(InjectorJobFactory.class).in(Scopes.SINGLETON); bind(Scheduler.class).toProvider(SchedulerProvider.class).asEagerSingleton(); bind(SchedulerConfiguration.class).toInstance(schedulerConfiguration); } finally { jobListeners = null; triggerListeners = null; schedulerListeners = null; schedulerConfiguration = null; } }
public void setJobFactory(JobFactory jobFactory) { this.jobFactory = jobFactory; }
public void setJobFactory(JobFactory factory) throws SchedulerException { scheduler.setJobFactory(factory); }
@Test public void testSchedulerFactoryBeanWithListeners() throws Exception { JobFactory jobFactory = new AdaptableJobFactory(); final Scheduler scheduler = mock(Scheduler.class); SchedulerListener schedulerListener = new TestSchedulerListener(); JobListener globalJobListener = new TestJobListener(); JobListener jobListener = new TestJobListener(); TriggerListener globalTriggerListener = new TestTriggerListener(); TriggerListener triggerListener = new TestTriggerListener(); SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean() { @Override protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) { return scheduler; } }; schedulerFactoryBean.setJobFactory(jobFactory); schedulerFactoryBean.setSchedulerListeners(new SchedulerListener[] {schedulerListener}); schedulerFactoryBean.setGlobalJobListeners(new JobListener[] {globalJobListener}); schedulerFactoryBean.setJobListeners(new JobListener[] {jobListener}); schedulerFactoryBean.setGlobalTriggerListeners(new TriggerListener[] {globalTriggerListener}); schedulerFactoryBean.setTriggerListeners(new TriggerListener[] {triggerListener}); try { schedulerFactoryBean.afterPropertiesSet(); schedulerFactoryBean.start(); } finally { schedulerFactoryBean.destroy(); } verify(scheduler).setJobFactory(jobFactory); verify(scheduler).addSchedulerListener(schedulerListener); verify(scheduler).addGlobalJobListener(globalJobListener); verify(scheduler).addJobListener(jobListener); verify(scheduler).addGlobalTriggerListener(globalTriggerListener); verify(scheduler).addTriggerListener(triggerListener); verify(scheduler).start(); verify(scheduler).shutdown(false); }
@Test public void testSchedulerFactoryBeanWithPlainQuartzObjects() throws Exception { JobFactory jobFactory = new AdaptableJobFactory(); TestBean tb = new TestBean("tb", 99); JobDetail jobDetail0 = new JobDetail(); jobDetail0.setJobClass(Job.class); jobDetail0.setName("myJob0"); jobDetail0.setGroup(Scheduler.DEFAULT_GROUP); jobDetail0.getJobDataMap().put("testBean", tb); assertEquals(tb, jobDetail0.getJobDataMap().get("testBean")); CronTrigger trigger0 = new CronTrigger(); trigger0.setName("myTrigger0"); trigger0.setGroup(Scheduler.DEFAULT_GROUP); trigger0.setJobName("myJob0"); trigger0.setJobGroup(Scheduler.DEFAULT_GROUP); trigger0.setStartTime(new Date()); trigger0.setCronExpression("0/1 * * * * ?"); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryBean mijdfb = new MethodInvokingJobDetailFactoryBean(); mijdfb.setName("myJob1"); mijdfb.setGroup(Scheduler.DEFAULT_GROUP); mijdfb.setTargetObject(task1); mijdfb.setTargetMethod("doSomething"); mijdfb.afterPropertiesSet(); JobDetail jobDetail1 = mijdfb.getObject(); SimpleTrigger trigger1 = new SimpleTrigger(); trigger1.setName("myTrigger1"); trigger1.setGroup(Scheduler.DEFAULT_GROUP); trigger1.setJobName("myJob1"); trigger1.setJobGroup(Scheduler.DEFAULT_GROUP); trigger1.setStartTime(new Date()); trigger1.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY); trigger1.setRepeatInterval(20); final Scheduler scheduler = mock(Scheduler.class); given(scheduler.scheduleJob(trigger0)).willReturn(new Date()); given(scheduler.scheduleJob(trigger1)).willReturn(new Date()); SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean() { @Override protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) { return scheduler; } }; schedulerFactoryBean.setJobFactory(jobFactory); schedulerFactoryBean.setJobDetails(new JobDetail[] {jobDetail0, jobDetail1}); schedulerFactoryBean.setTriggers(new Trigger[] {trigger0, trigger1}); try { schedulerFactoryBean.afterPropertiesSet(); schedulerFactoryBean.start(); } finally { schedulerFactoryBean.destroy(); } verify(scheduler).setJobFactory(jobFactory); verify(scheduler).getJobDetail("myJob0", Scheduler.DEFAULT_GROUP); verify(scheduler).getJobDetail("myJob1", Scheduler.DEFAULT_GROUP); verify(scheduler).getTrigger("myTrigger0", Scheduler.DEFAULT_GROUP); verify(scheduler).getTrigger("myTrigger1", Scheduler.DEFAULT_GROUP); verify(scheduler).addJob(jobDetail0, true); verify(scheduler).addJob(jobDetail1, true); verify(scheduler).scheduleJob(trigger0); verify(scheduler).scheduleJob(trigger1); verify(scheduler).start(); verify(scheduler).shutdown(false); }
public CdiAwareJobFactory() { String defaultJobFactoryName = SchedulerBaseConfig.JobCustomization.DEFAULT_JOB_FACTORY_CLASS_NAME; defaultFactory = ClassUtils.tryToInstantiateClassForName(defaultJobFactoryName, JobFactory.class); }
public void setJobFactory(JobFactory factory) throws SchedulerException { if(factory == null) { throw new IllegalArgumentException("JobFactory cannot be set to null!"); } getLog().info("JobFactory set to: " + factory); this.jobFactory = factory; }
/** * Set the Quartz JobFactory to use for this Scheduler. * <p>Default is Spring's {@link AdaptableJobFactory}, which supports * {@link java.lang.Runnable} objects as well as standard Quartz * {@link org.quartz.Job} instances. Note that this default only applies * to a <i>local</i> Scheduler, not to a RemoteScheduler (where setting * a custom JobFactory is not supported by Quartz). * <p>Specify an instance of Spring's {@link 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. * @see AdaptableJobFactory * @see SpringBeanJobFactory */ public void setJobFactory(JobFactory jobFactory) { this.jobFactory = jobFactory; this.jobFactorySet = true; }
/** * Set the <code>JobFactory</code> that will be responsible for producing * instances of <code>Job</code> classes. * * <p> * JobFactories may be of use to those wishing to have their application * produce <code>Job</code> instances via some special mechanism, such as to * give the opportunity for dependency injection. * </p> * * @see org.quartz.spi.JobFactory */ void setJobFactory(JobFactory factory) throws SchedulerException;
/** * <p> * Set the <code>JobFactory</code> that will be responsible for producing * instances of <code>Job</code> classes. * </p> * * <p> * JobFactories may be of use to those wishing to have their application * produce <code>Job</code> instances via some special mechanism, such as to * give the opportunity for dependency injection. * </p> * * @see org.quartz.spi.JobFactory */ void setJobFactory(JobFactory factory) throws SchedulerException;