/**
  * 注册作业启动信息.
  *
  * @param jobExecutionShardingContext 作业运行时分片上下文
  */
 public void registerJobBegin(
     final JobExecutionMultipleShardingContext jobExecutionShardingContext) {
   if (!jobExecutionShardingContext.getShardingItems().isEmpty()
       && configService.isMonitorExecution()) {
     serverService.updateServerStatus(ServerStatus.RUNNING);
     for (int each : jobExecutionShardingContext.getShardingItems()) {
       jobNodeStorage.fillEphemeralJobNode(ExecutionNode.getRunningNode(each), "");
       jobNodeStorage.replaceJobNode(
           ExecutionNode.getLastBeginTimeNode(each), System.currentTimeMillis());
       Date nextFireTime =
           JobRegistry.getInstance().getJob(jobConfiguration.getJobName()).getNextFireTime();
       if (null != nextFireTime) {
         jobNodeStorage.replaceJobNode(
             ExecutionNode.getNextFireTimeNode(each), nextFireTime.getTime());
       }
     }
   }
 }
 /**
  * 注册作业完成信息.
  *
  * @param jobExecutionShardingContext 作业运行时分片上下文
  */
 public void registerJobCompleted(
     final JobExecutionMultipleShardingContext jobExecutionShardingContext) {
   if (!configService.isMonitorExecution()) {
     return;
   }
   serverService.updateServerStatus(ServerStatus.READY);
   for (int each : jobExecutionShardingContext.getShardingItems()) {
     jobNodeStorage.createJobNodeIfNeeded(ExecutionNode.getCompletedNode(each));
     jobNodeStorage.removeJobNodeIfExisted(ExecutionNode.getRunningNode(each));
     jobNodeStorage.replaceJobNode(
         ExecutionNode.getLastCompleteTimeNode(each), System.currentTimeMillis());
   }
 }
Example #3
0
 @Override
 public void process(final JobExecutionMultipleShardingContext context) {
   printContext.printProcessJobMessage(context.getShardingItems());
   fooRepository.findActive(context.getShardingItems());
   // do something
 }
 /**
  * 获取当前作业服务器运行时分片上下文.
  *
  * @return 当前作业服务器运行时分片上下文
  */
 public JobExecutionMultipleShardingContext getJobExecutionShardingContext() {
   JobExecutionMultipleShardingContext result = new JobExecutionMultipleShardingContext();
   result.setJobName(jobConfiguration.getJobName());
   result.setShardingTotalCount(configService.getShardingTotalCount());
   List<Integer> shardingItems = shardingService.getLocalHostShardingItems();
   if (configService.isFailover()) {
     List<Integer> failoverItems = failoverService.getLocalHostFailoverItems();
     if (!failoverItems.isEmpty()) {
       result.setShardingItems(failoverItems);
     } else {
       shardingItems.removeAll(failoverService.getLocalHostTakeOffItems());
       result.setShardingItems(shardingItems);
     }
   } else {
     result.setShardingItems(shardingItems);
   }
   boolean isMonitorExecution = configService.isMonitorExecution();
   if (isMonitorExecution) {
     removeRunningItems(shardingItems);
   }
   result.setJobParameter(configService.getJobParameter());
   result.setMonitorExecution(isMonitorExecution);
   result.setFetchDataCount(configService.getFetchDataCount());
   if (result.getShardingItems().isEmpty()) {
     return result;
   }
   Map<Integer, String> shardingItemParameters = configService.getShardingItemParameters();
   for (int each : result.getShardingItems()) {
     if (shardingItemParameters.containsKey(each)) {
       result.getShardingItemParameters().put(each, shardingItemParameters.get(each));
     }
   }
   result.setOffsets(offsetService.getOffsets(result.getShardingItems()));
   return result;
 }
 @Override
 public List<Foo> fetchData(final JobExecutionMultipleShardingContext context) {
   printContext.printFetchDataMessage(context.getShardingItems());
   return fooRepository.findActive(context.getShardingItems());
 }