當前位置: 首頁>>代碼示例>>Java>>正文


Java JobBuilder.newJob方法代碼示例

本文整理匯總了Java中org.quartz.JobBuilder.newJob方法的典型用法代碼示例。如果您正苦於以下問題:Java JobBuilder.newJob方法的具體用法?Java JobBuilder.newJob怎麽用?Java JobBuilder.newJob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.quartz.JobBuilder的用法示例。


在下文中一共展示了JobBuilder.newJob方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addSchedule

import org.quartz.JobBuilder; //導入方法依賴的package包/類
/**
 * 增加一個調度任務(cron版)
 * 
 * @param name
 *            任務名稱
 * @param job
 *            執行內容
 * @param cronExpression
 *            cron表達式
 * @throws SchedulerException
 */
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
		throws SchedulerException {
	Scheduler sched = SF.getScheduler();
	JobBuilder builder = JobBuilder.newJob(task);
	builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
	if (param != null) {
		builder.usingJobData(param);
	}
	Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
			.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
	sched.scheduleJob(builder.build(), trigger);
	if (!sched.isShutdown())
		sched.start();
	return trigger;
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:27,代碼來源:SchedulerUtil.java

示例2: addJob

import org.quartz.JobBuilder; //導入方法依賴的package包/類
private void addJob(JobType jobType, JobKey jk)
		throws ClassNotFoundException, SchedulerException {
	JobDetail jd;
	JobBuilder jb = JobBuilder.newJob((Class<? extends Job>) Class.forName(jobType.getClassName()));
	for (ParamType pt : jobType.getParam()) {
		jb.usingJobData(pt.getName(), pt.getValue());
	}
	jb.withIdentity(jk);
	
	jd = jb.build();
	
	StringBuffer cron = new StringBuffer();
	cron.append(jobType.getCronSchedule().getSeconds()).append(' ')
	    .append(jobType.getCronSchedule().getMinutes()).append(' ')
	    .append(jobType.getCronSchedule().getHours()).append(' ')
	    .append(jobType.getCronSchedule().getDayOfMonth()).append(' ')
	    .append(jobType.getCronSchedule().getMonth()).append(' ')
	    .append(jobType.getCronSchedule().getDayOfWeek()).append(' ')
	    .append(jobType.getCronSchedule().getYear());
	
	TriggerBuilder tb = TriggerBuilder.newTrigger()
			                           .withIdentity("trigger_" + jobType.getName(),jobType.getGroup())
			                           .withSchedule(CronScheduleBuilder.cronSchedule(cron.toString()).withMisfireHandlingInstructionFireAndProceed());;
			                        		
	this.scheduler.scheduleJob(jd, tb.build());
}
 
開發者ID:TremoloSecurity,項目名稱:OpenUnison,代碼行數:27,代碼來源:ProvisioningEngineImpl.java

示例3: createMember

import org.quartz.JobBuilder; //導入方法依賴的package包/類
@Override
public void createMember(RequestContext ctx, ResourceState state, Responder responder) throws Exception {

    String id = UUID.randomUUID().toString();

    TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
    triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule((String) state.getProperty("cron")));
    triggerBuilder.withIdentity(id);
    Trigger trigger = triggerBuilder.build();

    TriggerResource resource = new TriggerResource(this, trigger);

    JobDataMap dataMap = new JobDataMap();
    dataMap.put("resource", resource);

    JobBuilder jobBuilder = JobBuilder.newJob();
    jobBuilder.withIdentity(id);
    jobBuilder.ofType(LiveOakJob.class);
    jobBuilder.setJobData(dataMap);

    JobDetail jobDetail = jobBuilder.build();

    this.scheduler.scheduleJob(jobDetail, trigger);
    this.children.put(id, resource);
    responder.resourceCreated(resource);
}
 
開發者ID:liveoak-io,項目名稱:liveoak,代碼行數:27,代碼來源:SchedulerResource.java

示例4: addScript

import org.quartz.JobBuilder; //導入方法依賴的package包/類
private void addScript(ScheduledScript script) throws Exception {
    TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
    triggerBuilder.withIdentity(script.getId());

    if (script.getCron() != null) {
        triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(script.getCron()));
    }

    if (script.getAt() != null) {
        triggerBuilder.startAt(script.getAt());
    }

    if (script.getUntil() != null) {
        triggerBuilder.endAt(script.getUntil());
    }

    Trigger trigger = triggerBuilder.build();

    JobDataMap dataMap = new JobDataMap();
    dataMap.put(SCRIPT_DATAMAP_KEY, script);
    dataMap.put(SCRIPT_MANAGER_DATAMAP_KEY, scriptManager);

    JobBuilder jobBuilder = JobBuilder.newJob();
    jobBuilder.withIdentity(script.getId());
    jobBuilder.ofType(ScriptJob.class);
    jobBuilder.setJobData(dataMap);

    scheduler.scheduleJob(jobBuilder.build(), trigger);
}
 
開發者ID:liveoak-io,項目名稱:liveoak,代碼行數:30,代碼來源:ScheduleManager.java

示例5: schedule

import org.quartz.JobBuilder; //導入方法依賴的package包/類
@Override
public synchronized boolean schedule(String name, Runnable fn, Map<ScheduleOption, Object> opts) throws Exception {
    Options<ScheduleOption> options = new Options<>(opts);
    validateOptions(options);

    start();

    final boolean replacedExisting = unschedule(name);

    final JobDataMap jobDataMap = new JobDataMap();

    final Map contextOptions = new HashMap();
    contextOptions.put(ExecutionContext.CreateOption.SINGLETON, options.getBoolean(SINGLETON));

    final ImmediateContext context = WunderBoss.findOrCreateComponent(ImmediateContext.class, name, contextOptions);
    context.setAction(fn);

    // TODO: Quartz says only serializable things should be in here
    jobDataMap.put(RunnableJob.RUN_FUNCTION_KEY, context);
    
    JobBuilder jobBuilder;
    if (options.getBoolean(ALLOW_CONCURRENT_EXEC)) {
        jobBuilder = JobBuilder.newJob(RunnableJob.class);
    } else {
        jobBuilder = JobBuilder.newJob(RunnableJob.NotConcurrentlyExecuting.class);
    }

    JobDetail job = jobBuilder.usingJobData(jobDataMap).build();

    this.scheduler.scheduleJob(job, initTrigger(name, options));

    this.currentJobs.put(name, job.getKey());

    return replacedExisting;
}
 
開發者ID:projectodd,項目名稱:wunderboss,代碼行數:36,代碼來源:QuartzScheduling.java

示例6: updateTask

import org.quartz.JobBuilder; //導入方法依賴的package包/類
/**
 * 新增job
 * @param taskScheduled
 * @return boolean
 */
public boolean updateTask(TaskScheduled taskScheduled) {
    String jobGroup = taskScheduled.getTaskGroup();
    if (DataUtil.isEmpty(jobGroup)) {
        jobGroup = "ds_job";
    }
    String jobName = taskScheduled.getTaskName();
    if (DataUtil.isEmpty(jobName)) {
        jobName = String.valueOf(System.currentTimeMillis());
    }
    String cronExpression = taskScheduled.getTaskCron();
    String targetObject = taskScheduled.getTargetObject();
    String targetMethod = taskScheduled.getTargetMethod();
    String jobDescription = taskScheduled.getTaskDesc();
    String jobType = taskScheduled.getJobType();
    String taskType = taskScheduled.getTaskType();
    JobDataMap jobDataMap = new JobDataMap();
    if (TaskType.dubbo.equals(taskType)) {
        jobDataMap.put("targetSystem", taskScheduled.getTargetSystem());
    }
    jobDataMap.put("targetObject", targetObject);
    jobDataMap.put("targetMethod", targetMethod);
    jobDataMap.put("taskType", taskType);
    jobDataMap.put("contactName", taskScheduled.getContactName());
    jobDataMap.put("contactEmail", taskScheduled.getContactEmail());

    JobBuilder jobBuilder = null;
    if (JobType.job.equals(jobType)) {
        jobBuilder = JobBuilder.newJob(BaseJob.class);
    } else if (JobType.statefulJob.equals(jobType)) {
        jobBuilder = JobBuilder.newJob(StatefulJob.class);
    }
    if (jobBuilder != null) {
        JobDetail jobDetail = jobBuilder.withIdentity(jobName, jobGroup).withDescription(jobDescription)
            .storeDurably(true).usingJobData(jobDataMap).build();

        Trigger trigger = TriggerBuilder.newTrigger().withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
            .withIdentity(jobName, jobGroup).withDescription(jobDescription).forJob(jobDetail)
            .usingJobData(jobDataMap).build();

        try {
            JobDetail detail = scheduler.getJobDetail(new JobKey(jobName, jobGroup));
            if (detail == null) {
                scheduler.scheduleJob(jobDetail, trigger);
            } else {
                scheduler.addJob(jobDetail, true);
                scheduler.rescheduleJob(new TriggerKey(jobName, jobGroup), trigger);
            }
            return true;
        } catch (SchedulerException e) {
            logger.error("SchedulerException", e);
            throw new BusinessException(e);
        }
    }
    return false;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:61,代碼來源:SchedulerManager.java

示例7: updateTask

import org.quartz.JobBuilder; //導入方法依賴的package包/類
/**
   * 新增job
   * 
   * @param inputObject
   * @param outputObject
   * @throws Exception
   */
  public boolean updateTask(TaskScheduled taskScheduled) {
  	String jobGroup = taskScheduled.getTaskGroup();
      if (DataUtil.isEmpty(jobGroup)) {
	jobGroup = "ds_job";
}
      String jobName = taskScheduled.getTaskName();
      if (DataUtil.isEmpty(jobName)) {
          jobName = String.valueOf(System.currentTimeMillis());
      }
      String cronExpression = taskScheduled.getTaskCron();
      String targetObject = taskScheduled.getTargetObject();
      String targetMethod = taskScheduled.getTargetMethod();
      String jobDescription = taskScheduled.getTaskDesc();
      String jobType = taskScheduled.getJobType();
      String taskType = taskScheduled.getTaskType();
      JobDataMap jobDataMap = new JobDataMap();
      if (TaskType.dubbo.equals(taskType)) {
          jobDataMap.put("targetSystem", taskScheduled.getTargetSystem());
      }
      jobDataMap.put("targetObject", targetObject);
      jobDataMap.put("targetMethod", targetMethod);
      jobDataMap.put("taskType", taskType);
      jobDataMap.put("contactName", taskScheduled.getContactName());
      jobDataMap.put("contactEmail", taskScheduled.getContactEmail());

      JobBuilder jobBuilder = null;
      if (JobType.job.equals(jobType)) {
          jobBuilder = JobBuilder.newJob(BaseJob.class);
      } else if (JobType.statefulJob.equals(jobType)) {
          jobBuilder = JobBuilder.newJob(StatefulJob.class);
      }
      if (jobBuilder != null) {
          JobDetail jobDetail = jobBuilder.withIdentity(jobName, jobGroup).withDescription(jobDescription)
              .storeDurably(true).usingJobData(jobDataMap).build();

          Trigger trigger = TriggerBuilder.newTrigger().withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
              .withIdentity(jobName, jobGroup).withDescription(jobDescription).forJob(jobDetail)
              .usingJobData(jobDataMap).build();

          try {
              JobDetail detail = scheduler.getJobDetail(new JobKey(jobName, jobGroup));
              if (detail == null) {
                  scheduler.scheduleJob(jobDetail, trigger);
              } else {
                  scheduler.addJob(jobDetail, true);
                  scheduler.rescheduleJob(new TriggerKey(jobName, jobGroup), trigger);
              }
              return true;
          } catch (SchedulerException e) {
              logger.error("SchedulerException", "SchedulerException", e);
              throw new BusinessException(e);
          }
      }
      return false;
  }
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:63,代碼來源:SchedulerManager.java


注:本文中的org.quartz.JobBuilder.newJob方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。