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

The following examples show how to use org.quartz.impl.JobDetailImpl#setJobDataMap() . 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: EntityMocksHelper.java    From griffin with Apache License 2.0 6 votes vote down vote up
public static JobDetailImpl createJobDetail(
    String measureJson,
    String predicatesJson) {
    JobDetailImpl jobDetail = new JobDetailImpl();
    JobKey jobKey = new JobKey("name", "group");
    jobDetail.setKey(jobKey);
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(MEASURE_KEY, measureJson);
    jobDataMap.put(PREDICATES_KEY, predicatesJson);
    jobDataMap.put(JOB_NAME, "jobName");
    jobDataMap.put("jobName", "jobName");
    jobDataMap.put(PREDICATE_JOB_NAME, "predicateJobName");
    jobDataMap.put(GRIFFIN_JOB_ID, 1L);
    jobDetail.setJobDataMap(jobDataMap);
    return jobDetail;
}
 
Example 2
Source File: JobBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Produce the <code>JobDetail</code> instance defined by this 
 * <code>JobBuilder</code>.
 * 
 * @return the defined JobDetail.
 */
public JobDetail build() {

    JobDetailImpl job = new JobDetailImpl();
    
    job.setJobClass(jobClass);
    job.setDescription(description);
    if(key == null)
        key = new JobKey(Key.createUniqueName(null), null);
    job.setKey(key); 
    job.setDurability(durability);
    job.setRequestsRecovery(shouldRecover);
    
    
    if(!jobDataMap.isEmpty())
        job.setJobDataMap(jobDataMap);
    
    return job;
}
 
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: AbstractRedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve a job from redis
 * @param jobKey the job key detailing the identity of the job to be retrieved
 * @param jedis a thread-safe Redis connection
 * @return the {@link org.quartz.JobDetail} of the desired job
 * @throws JobPersistenceException if the desired job does not exist
 * @throws ClassNotFoundException
 */
public JobDetail retrieveJob(JobKey jobKey, T jedis) throws JobPersistenceException, ClassNotFoundException{
    final String jobHashKey = redisSchema.jobHashKey(jobKey);
    final String jobDataMapHashKey = redisSchema.jobDataMapHashKey(jobKey);

    final Map<String, String> jobDetailMap = jedis.hgetAll(jobHashKey);
    if(jobDetailMap == null || jobDetailMap.size() == 0){
        // desired job does not exist
        return null;
    }
    JobDetailImpl jobDetail = mapper.convertValue(jobDetailMap, JobDetailImpl.class);
    jobDetail.setKey(jobKey);

    final Map<String, String> jobData = jedis.hgetAll(jobDataMapHashKey);
    if(jobData != null && !jobData.isEmpty()){
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.putAll(jobData);
        jobDetail.setJobDataMap(jobDataMap);
    }

    return jobDetail;
}
 
Example 5
Source File: DelayedAsynchronousServiceCallProxy.java    From rice with Educational Community License v2.0 6 votes vote down vote up
protected void scheduleMessage(PersistedMessageBO message) throws SchedulerException {
 LOG.debug("Scheduling execution of a delayed asynchronous message.");
 Scheduler scheduler = KSBServiceLocator.getScheduler();
 JobDataMap jobData = new JobDataMap();
 jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, message);

    JobDetailImpl jobDetail = new JobDetailImpl("Delayed_Asynchronous_Call-" + Math.random(), "Delayed_Asynchronous_Call",
  MessageServiceExecutorJob.class);
 jobDetail.setJobDataMap(jobData);

    scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());

    SimpleTriggerImpl trigger = new SimpleTriggerImpl("Delayed_Asynchronous_Call_Trigger-" + Math.random(),
  "Delayed_Asynchronous_Call", message.getQueueDate());

    trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke
 scheduler.scheduleJob(jobDetail, trigger);
}
 
Example 6
Source File: DefaultExceptionServiceImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
public void scheduleExecution(Throwable throwable, PersistedMessageBO message, String description) throws Exception {
	KSBServiceLocator.getMessageQueueService().delete(message);
       PersistedMessageBO messageCopy = message.copy();
	Scheduler scheduler = KSBServiceLocator.getScheduler();
	JobDataMap jobData = new JobDataMap();
	jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, messageCopy);
	JobDetailImpl jobDetail = new JobDetailImpl("Exception_Message_Job " + Math.random(), "Exception Messaging",
		MessageServiceExecutorJob.class);
	jobDetail.setJobDataMap(jobData);

       if (!StringUtils.isBlank(description)) {
	    jobDetail.setDescription(description);
	}

       scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());

       SimpleTriggerImpl trigger = new SimpleTriggerImpl("Exception_Message_Trigger " + Math.random(), "Exception Messaging", messageCopy
		.getQueueDate());
	trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke

       scheduler.scheduleJob(jobDetail, trigger);
}
 
Example 7
Source File: QuartzTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Test
   public void testSchedulingJob() throws Exception {
Scheduler scheduler = KSBServiceLocator.getScheduler();
JobDataMap datMap = new JobDataMap();
datMap.put("yo", "yo");
JobDetailImpl jobDetail = new JobDetailImpl("myJob", null, TestJob.class);
jobDetail.setJobDataMap(datMap);

   TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
   triggerBuilder.startAt(new Date());
   triggerBuilder.withIdentity("i'm a trigger puller");
   triggerBuilder.usingJobData(datMap);
   triggerBuilder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(1).withIntervalInMilliseconds(1L));

   Trigger trigger = triggerBuilder.build();

scheduler.scheduleJob(jobDetail, trigger);


synchronized (TestJob.LOCK) {
    TestJob.LOCK.wait(30 * 1000);    
}

assertTrue("job never fired", TestJob.EXECUTED);
   }
 
Example 8
Source File: AuroraCronJobTest.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  storage = MemStorageModule.newEmptyStorage();
  stateManager = createMock(StateManager.class);
  backoffHelper = createMock(BackoffHelper.class);
  context = createMock(JobExecutionContext.class);

  jobDetails = new JobDetailImpl();
  jobDetails.setKey(Quartz.jobKey(AURORA_JOB_KEY));
  jobDetails.setJobDataMap(new JobDataMap(new HashMap()));
  expect(context.getJobDetail()).andReturn(jobDetails).anyTimes();

  batchWorker = createMock(CronBatchWorker.class);
  expectBatchExecute(batchWorker, storage, control).anyTimes();

  auroraCronJob = new AuroraCronJob(
      new AuroraCronJob.Config(backoffHelper),
      stateManager,
      batchWorker);
}
 
Example 9
Source File: JobDetailFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	Assert.notNull(this.jobClass, "Property 'jobClass' is required");

	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 != null ? this.name : toString());
	jdi.setGroup(this.group);
	jdi.setJobClass(this.jobClass);
	jdi.setJobDataMap(this.jobDataMap);
	jdi.setDurability(this.durability);
	jdi.setRequestsRecovery(this.requestsRecovery);
	jdi.setDescription(this.description);
	this.jobDetail = jdi;
}
 
Example 10
Source File: JobDetailFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	Assert.notNull(this.jobClass, "Property 'jobClass' is required");

	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 != null ? this.name : toString());
	jdi.setGroup(this.group);
	jdi.setJobClass(this.jobClass);
	jdi.setJobDataMap(this.jobDataMap);
	jdi.setDurability(this.durability);
	jdi.setRequestsRecovery(this.requestsRecovery);
	jdi.setDescription(this.description);
	this.jobDetail = jdi;
}
 
Example 11
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 12
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 13
Source File: JobDetailFactoryBean.java    From spring4-understanding with Apache License 2.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;
}