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

The following examples show how to use org.quartz.impl.JobDetailImpl#setKey() . 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: 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 4
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 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: HRCronTriggerRunner.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(HRJob.class);
    jobDetailImpl.setKey(new JobKey("HRJob1"));
    jobDetailImpl.getJobDataMap().put("users",users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("HRCronTrigger1");
    
    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 7
Source File: CBCronTriggerRunner.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(CBJob.class);
    jobDetailImpl.setKey(new JobKey("CBJob1"));
    jobDetailImpl.getJobDataMap().put("users", users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("CBCronTrigger1");
    
    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 8
Source File: InstanceDetection.java    From uflo with Apache License 2.0 5 votes vote down vote up
private JobDetailImpl initJobDetail(String currentInstanceName){
	String clusterJobInstanceNames[]=instanceNames.split(",");
	SessionFactory sessionFactory=EnvironmentUtils.getEnvironment().getSessionFactory();
	JobDetailImpl jobDetail=new DetectionJobDetail(sessionFactory,currentInstanceName,clusterJobInstanceNames,schedulerService);
	jobDetail.setKey(new JobKey("UfloDaemonJobDetail"));
	jobDetail.setName("UfloDaemonDetectionJobDetail");
	return jobDetail;
}