org.quartz.spi.JobFactory Java Examples

The following examples show how to use org.quartz.spi.JobFactory. 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: ScheduleAutoConfiguration.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: QuartzSchedulerProvider.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public QuartzSchedulerProvider(final NodeAccess nodeAccess,
                               final Provider<JobStore> jobStore,
                               final JobFactory jobFactory,
                               @Named("${nexus.quartz.poolSize:-20}") final int threadPoolSize,
                               @Named("${nexus.quartz.taskThreadPriority:-5}") final int threadPriority)
{
  this.nodeAccess = checkNotNull(nodeAccess);
  this.jobStore = checkNotNull(jobStore);
  this.jobFactory = checkNotNull(jobFactory);
  checkArgument(threadPoolSize > 0, "Invalid thread-pool size: %s", threadPoolSize);
  this.threadPoolSize = threadPoolSize;
  this.threadPriority = threadPriority;
  log.info("Thread-pool size: {}, Thread-pool priority: {}", threadPoolSize, threadPriority);
}
 
Example #3
Source File: PacmanQuartzConfiguration.java    From pacbot with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory) throws IOException {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setOverwriteExistingJobs(true);
	factory.setDataSource(dataSource);
	factory.setJobFactory(jobFactory);
	factory.setQuartzProperties(quartzProperties());

	// Here we will set all the trigger beans we have defined.
	if (!NotificationUtil.isObjectEmpty(listOfTrigger)) {
		factory.setTriggers(listOfTrigger.toArray(new Trigger[listOfTrigger.size()]));
	}

	return factory;
}
 
Example #4
Source File: SchedulerConfig.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource,
                                                 JobFactory jobFactory) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    factory.setQuartzProperties(quartzConf);
    return factory;
}
 
Example #5
Source File: SchedulerConfig.java    From quartz-manager with Apache License 2.0 5 votes vote down vote up
@Bean(name = "scheduler")
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory,
		@Qualifier("jobTrigger") Trigger sampleJobTrigger) throws IOException {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setJobFactory(jobFactory);
	factory.setQuartzProperties(quartzProperties());
	factory.setTriggers(sampleJobTrigger);
	factory.setAutoStartup(false);
	return factory;
}
 
Example #6
Source File: Module.java    From mangooio with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    Names.bindProperties(binder(), config.toProperties());
    
    bind(JobFactory.class).to(SchedulerFactory.class);
    bind(Cache.class).toProvider(CacheProvider.class);
    bind(MangooAuthorizationService.class).to(AuthorizationService.class);
}
 
Example #7
Source File: QuartzSchedulerAutoConfiguration.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
@Bean(name = QUARTZ_JOB_FACTORY_BEAN_NAME)
@ConditionalOnMissingBean(name = QUARTZ_JOB_FACTORY_BEAN_NAME)
   public JobFactory autoJobFactory(ApplicationContext applicationContext,
   		@Autowired(required=false) QuartzSchedulerProperties properties) {
	if (null == properties) {
		LOGGER.warn("no QuartzSchedulerProperties found, consider to set quartz.enabled=true in properties");
		return null;
	}
       AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
       jobFactory.setApplicationContext(applicationContext);
       return jobFactory;
   }
 
Example #8
Source File: SchedulerConfig.java    From ehousechina with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory, @Qualifier("sampleJobTrigger") Trigger sampleJobTrigger) throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    return factory;
}
 
Example #9
Source File: ModuleTest.java    From mangooio with Apache License 2.0 5 votes vote down vote up
@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<TemplateEngine> templateEngine = guice.getBinding(TemplateEngine.class);		
	Binding<OncePerRequestFilter> mangooRequestFilter = guice.getBinding(OncePerRequestFilter.class);
	Binding<MangooBootstrap> mangooBootstrap = guice.getBinding(MangooBootstrap.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.core.Config"));
	assertThat(jobFactory.getKey().getTypeLiteral().getType().getTypeName(), equalTo("org.quartz.spi.JobFactory"));
	assertThat(cache.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.cache.Cache"));
	assertThat(templateEngine.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.templating.TemplateEngine"));
	assertThat(mangooRequestFilter.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.filters.OncePerRequestFilter"));
	assertThat(mangooBootstrap.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.MangooBootstrap"));
}
 
Example #10
Source File: StdScheduler.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    sched.setJobFactory(factory);
}
 
Example #11
Source File: TaskSchedulerHelper.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
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);
  lastShutdownTimeService = mock(LastShutdownTimeService.class);
  statusDelayedExecutor = mock(DatabaseStatusDelayedExecutor.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);

    doAnswer(i  -> {
      ((Runnable) i.getArguments()[0]).run();
      return null;
    }).when(statusDelayedExecutor).execute(notNull(Runnable.class));
    binder.bind(DatabaseStatusDelayedExecutor.class)
        .toInstance(statusDelayedExecutor);

    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);
    }

    binder.bind(LastShutdownTimeService.class).toInstance(lastShutdownTimeService);
    when(lastShutdownTimeService.estimateLastShutdownTime()).thenReturn(Optional.empty());

    // filtering by feature flag is not supported here yet
    binder.bind(JobStore.class).to(JobStoreImpl.class);
  };

  this.injector = Guice.createInjector(new WireModule(
      module, new StateGuardModule(),
      new SpaceModule(new URLClassSpace(TaskSchedulerHelper.class.getClassLoader()), BeanScanning.INDEX)
  ));
  injector.injectMembers(this);
}
 
Example #12
Source File: DynamicJobFactory.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
public DynamicJobFactory(JobFactory defaultFactory) {
    this.defaultFactory = defaultFactory;
}
 
Example #13
Source File: ScheduleAutoConfiguration.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@Bean
public JobFactory jobFactory() {
    return new DynamicJobFactory(new AdaptableJobFactory());
}
 
Example #14
Source File: QuartzSchedulerAutoConfiguration.java    From spring-boot-starter-quartz with Apache License 2.0 4 votes vote down vote up
@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 #15
Source File: QuartzScheduler.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
public JobFactory getJobFactory()  {
    return jobFactory;
}
 
Example #16
Source File: RemoteScheduler.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * @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);
}
 
Example #17
Source File: RemoteMBeanScheduler.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * @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);
}
 
Example #18
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public JobFactory getJobFactory()  {
    return jobFactory;
}
 
Example #19
Source File: FoxbpmScheduler.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public void setJobFactory(JobFactory factory) throws SchedulerException {
	scheduler.setJobFactory(factory);
}
 
Example #20
Source File: RemoteScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @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.");
}
 
Example #21
Source File: StdScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    sched.setJobFactory(factory);
}
 
Example #22
Source File: RemoteMBeanScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @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.");
}
 
Example #23
Source File: AbstractScheduler.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: QuartzConfig.java    From TrackRay with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public Scheduler scheduler(JobFactory jobFactory) {
    return schedulerFactoryBean(jobFactory).getScheduler();
}
 
Example #25
Source File: CdiAwareJobFactory.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public CdiAwareJobFactory()
{
    String defaultJobFactoryName = SchedulerBaseConfig.JobCustomization.DEFAULT_JOB_FACTORY_CLASS_NAME;

    defaultFactory = ClassUtils.tryToInstantiateClassForName(defaultJobFactoryName, JobFactory.class);
}
 
Example #26
Source File: QuartzScheduler.java    From AsuraFramework with Apache License 2.0 3 votes vote down vote up
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;
    }
 
Example #27
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
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;
    }
 
Example #28
Source File: Scheduler.java    From AsuraFramework with Apache License 2.0 2 votes vote down vote up
/**
 * <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;
 
Example #29
Source File: SchedulerFactoryBean.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: SchedulerFactoryBean.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set the Quartz {@link 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.
 * @since 2.0
 * @see AdaptableJobFactory
 * @see SpringBeanJobFactory
 */
public void setJobFactory(JobFactory jobFactory) {
	this.jobFactory = jobFactory;
	this.jobFactorySet = true;
}