@Override
  public void afterPropertiesSet() throws Exception {

    JobClientProperties properties = null;
    if (locations == null || locations.length == 0) {
      properties = new JobClientProperties();
      properties.setUseRetryClient(useRetryClient);
      properties.setClusterName(clusterName);
      properties.setDataPath(dataPath);
      properties.setNodeGroup(nodeGroup);
      properties.setRegistryAddress(registryAddress);
      properties.setBindIp(bindIp);
      properties.setIdentity(identity);
      properties.setConfigs(CollectionUtils.toMap(configs));

    } else {
      properties =
          PropertiesConfigurationFactory.createPropertiesConfiguration(
              JobClientProperties.class, locations);
    }

    jobClient = JobClientBuilder.buildByProperties(properties);

    if (jobCompletedHandler != null) {
      jobClient.setJobCompletedHandler(jobCompletedHandler);
    }

    if (masterChangeListeners != null) {
      for (MasterChangeListener masterChangeListener : masterChangeListeners) {
        jobClient.addMasterChangeListener(masterChangeListener);
      }
    }
  }
Exemplo n.º 2
0
 public void submitWithTrigger(final JobClient jobClient, String triggerTime)
     throws ParseException, JobSubmitException {
   Job job = new Job();
   job.setTaskId(StringUtils.generateUUID());
   job.setParam("shopId", "111");
   //        job.setMaxRetryTimes(5);
   job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
   job.setNeedFeedback(true);
   if (triggerTime != null && !"".equals(triggerTime.trim())) {
     job.setTriggerTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(triggerTime).getTime());
   }
   Response response = jobClient.submitJob(job);
   System.out.println(response);
 }
Exemplo n.º 3
0
  public void submitWithCronExpression(final JobClient jobClient, String cronExpression)
      throws ParseException, JobSubmitException {
    Job job = new Job();
    // 必填,尽量taskId 有一定规律性,能让自己识别
    job.setTaskId(StringUtils.generateUUID());
    // 任务的参数,value必须为字符串
    job.setParam("shopId", "111");
    // 执行节点的group名称
    job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
    // 是否接收执行反馈消息 jobClient.setJobCompletedHandler(new JobFinishedHandlerImpl()); 中接受
    job.setNeedFeedback(true);
    // 这个是 cron expression 和 quartz 一样,可选
    job.setCronExpression(cronExpression);
    // 这个是指定执行时间,可选
    // job.setTriggerTime(new Date());
    // 当 cronExpression 和 triggerTime 都不设置的时候,默认是立即执行任务
    // response 返回提交成功还是失败
    Response response = jobClient.submitJob(job);

    System.out.println(response);
  }
 @Override
 public void destroy() throws Exception {
   jobClient.stop();
 }
 /** 可以自己得到JobTracker对象后调用,也可以直接使用spring配置中的init属性指定该方法 */
 public void start() {
   if (!started) {
     jobClient.start();
     started = true;
   }
 }