Java Code Examples for org.quartz.impl.JobDetailImpl#setJobClass()

The following examples show how to use org.quartz.impl.JobDetailImpl#setJobClass() . 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: MethodInvokingJobDetailFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name);
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example 2
Source File: MethodInvokingJobDetailFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name != null ? name : toString());
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example 3
Source File: JobDetailSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param cData
 * @return JobDetail
 */
public static JobDetail newJobDetail(CompositeData cData)
  throws ClassNotFoundException
{
    JobDetailImpl jobDetail = new JobDetailImpl();

    int i = 0;
    jobDetail.setName((String) cData.get(ITEM_NAMES[i++]));
    jobDetail.setGroup((String) cData.get(ITEM_NAMES[i++]));
    jobDetail.setDescription((String) cData.get(ITEM_NAMES[i++]));
    Class<?> jobClass = Class.forName((String) cData.get(ITEM_NAMES[i++]));
    @SuppressWarnings("unchecked")
    Class<? extends Job> jobClassTyped = (Class<? extends Job>)jobClass;
    jobDetail.setJobClass(jobClassTyped);
    jobDetail.setJobDataMap(JobDataMapSupport.newJobDataMap((TabularData) cData.get(ITEM_NAMES[i++])));
    jobDetail.setDurability((Boolean) cData.get(ITEM_NAMES[i++]));
    jobDetail.setRequestsRecovery((Boolean) cData.get(ITEM_NAMES[i++]));

    return jobDetail;
}
 
Example 4
Source File: UtilsToolTest.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInterruptable() throws Exception {
    JobDetailImpl job = new JobDetailImpl();
    job.setJobClass(DummyJob.class);

    Assert.assertEquals(true, utilsTool.isInterruptible(job));
}
 
Example 5
Source File: CFCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
public void task(List<Long> users,String cronExpression) throws SchedulerException
{
    // Initiate a Schedule Factory
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    // Retrieve a scheduler from schedule factory
    Scheduler scheduler = schedulerFactory.getScheduler();
    
    // Initiate JobDetail with job name, job group, and executable job class
    JobDetailImpl jobDetailImpl = 
    	new JobDetailImpl();
    jobDetailImpl.setJobClass(CFJob.class);
    jobDetailImpl.setKey(new JobKey("CFJob1"));
    jobDetailImpl.getJobDataMap().put("users", users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("CFCronTrigger1");
    try {
        // setup CronExpression
        CronExpression cexp = new CronExpression(cronExpression);
        // Assign the CronExpression to CronTrigger
        cronTriggerImpl.setCronExpression(cexp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // schedule a job with JobDetail and Trigger
    scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl);
    
    // start the scheduler
    scheduler.start();
}
 
Example 6
Source File: JobDetailFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
	if (this.name == null) {
		this.name = this.beanName;
	}
	if (this.group == null) {
		this.group = Scheduler.DEFAULT_GROUP;
	}
	if (this.applicationContextJobDataKey != null) {
		if (this.applicationContext == null) {
			throw new IllegalStateException(
				"JobDetailBean needs to be set up in an ApplicationContext " +
				"to be able to handle an 'applicationContextJobDataKey'");
		}
		getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext);
	}

	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(this.name);
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) this.jobClass);
	jdi.setJobDataMap(this.jobDataMap);
	jdi.setDurability(this.durability);
	jdi.setRequestsRecovery(this.requestsRecovery);
	jdi.setDescription(this.description);
	this.jobDetail = jdi;
}
 
Example 7
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithTaskExecutor() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setTaskExecutor(taskExecutor);
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
	assertEquals(DummyJob.count, taskExecutor.count);

	bean.destroy();
}
 
Example 8
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJobBean.param = 0;
	DummyJobBean.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example 9
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJobBean.param = 0;
	DummyJobBean.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example 10
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}
 
Example 11
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void schedulerWithQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example 12
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJobBean.param = 0;
	DummyJobBean.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example 13
Source File: JobDetailSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param attrMap the attributes that define the job
 * @return JobDetail
 */
public static JobDetail newJobDetail(Map<String, Object> attrMap)
    throws ClassNotFoundException
{
    JobDetailImpl jobDetail = new JobDetailImpl();

    int i = 0;
    jobDetail.setName((String) attrMap.get(ITEM_NAMES[i++]));
    jobDetail.setGroup((String) attrMap.get(ITEM_NAMES[i++]));
    jobDetail.setDescription((String) attrMap.get(ITEM_NAMES[i++]));
    Class<?> jobClass = Class.forName((String) attrMap.get(ITEM_NAMES[i++]));
    @SuppressWarnings("unchecked")
    Class<? extends Job> jobClassTyped = (Class<? extends Job>)jobClass;
    jobDetail.setJobClass(jobClassTyped);
    if(attrMap.containsKey(ITEM_NAMES[i])) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>)attrMap.get(ITEM_NAMES[i]); 
        jobDetail.setJobDataMap(JobDataMapSupport.newJobDataMap(map));
    }
    i++;
    if(attrMap.containsKey(ITEM_NAMES[i])) {
        jobDetail.setDurability((Boolean) attrMap.get(ITEM_NAMES[i]));
    }
    i++;
    if(attrMap.containsKey(ITEM_NAMES[i])) {
        jobDetail.setRequestsRecovery((Boolean) attrMap.get(ITEM_NAMES[i]));
    }
    i++;
    
    return jobDetail;
}
 
Example 14
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}
 
Example 15
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}
 
Example 16
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithTaskExecutor() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setTaskExecutor(taskExecutor);
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
	assertEquals(DummyJob.count, taskExecutor.count);

	bean.destroy();
}
 
Example 17
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void jobDetailWithRunnableInsteadOfJob() {
	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setJobClass((Class) DummyRunnable.class);
}
 
Example 18
Source File: OrientDelegate.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public JobDetail selectJobForTrigger(final Connection conn,
                                     final ClassLoadHelper loadHelper,
                                     final TriggerKey triggerKey,
                                     boolean loadJobClass)
    throws ClassNotFoundException, SQLException
{
  PreparedStatement ps = null;
  ResultSet rs = null;
  String jobName;
  String jobGroup;

  try {
    ps = conn.prepareStatement(rtp(SELECT_TRIGGER));
    ps.setString(1, triggerKey.getName());
    ps.setString(2, triggerKey.getGroup());
    rs = ps.executeQuery();

    if (rs.next()) {
      jobName = rs.getString(COL_JOB_NAME);
      jobGroup = rs.getString(COL_JOB_GROUP);
    }
    else {
      if (logger.isDebugEnabled()) {
        logger.debug("No job for trigger '{}'.", triggerKey);
      }
      return null;
    }
  }
  finally {
    closeResultSet(rs);
    closeStatement(ps);
  }

  try {
    ps = conn.prepareStatement(rtp(SELECT_JOB_DETAIL));
    ps.setString(1, jobName);
    ps.setString(2, jobGroup);
    rs = ps.executeQuery();

    if (rs.next()) {
      JobDetailImpl job = new JobDetailImpl();
      job.setName(jobName);
      job.setGroup(jobGroup);
      job.setDurability(getBoolean(rs, COL_IS_DURABLE));
      if (loadJobClass) {
        job.setJobClass(loadHelper.loadClass(rs.getString(COL_JOB_CLASS), Job.class));
      }
      job.setRequestsRecovery(getBoolean(rs, COL_REQUESTS_RECOVERY));

      return job;
    }
    else {
      return null;
    }
  } finally {
    closeResultSet(rs);
    closeStatement(ps);
  }
}
 
Example 19
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void jobDetailWithRunnableInsteadOfJob() {
	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setJobClass((Class) DummyRunnable.class);
}
 
Example 20
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void jobDetailWithRunnableInsteadOfJob() {
	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setJobClass((Class) DummyRunnable.class);
}