org.springframework.batch.core.Job.getJobParametersIncrementer()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中org.springframework.batch.core.Job.getJobParametersIncrementer()方法的一些代码示例,展示了Job.getJobParametersIncrementer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Job.getJobParametersIncrementer()方法的具体详情如下:
包路径:org.springframework.batch.core.Job
类名称:Job
方法名:getJobParametersIncrementer

Job.getJobParametersIncrementer介绍

[英]If clients need to generate new parameters for the next execution in a sequence they can use this incrementer. The return value may be null, in the case that this job does not have a natural sequence.
[中]如果客户端需要为序列中的下一次执行生成新参数,则可以使用此递增器。如果此作业没有自然序列,则返回值可能为null。

代码示例

代码示例来源:origin: spring-projects/spring-batch

@Override
@Nullable
public JobParametersIncrementer getJobParametersIncrementer() {
  return delegate.getJobParametersIncrementer();
}

代码示例来源:origin: spring-projects/spring-batch

Assert.state(this.jobExplorer != null, "A JobExplorer is required to get next job parameters");
Assert.notNull(job, "Job must not be null");
Assert.notNull(job.getJobParametersIncrementer(), "No job parameters incrementer found for job=" + job.getName());
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
if (lastInstances.isEmpty()) {

代码示例来源:origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

@Override
public JobParametersIncrementer getJobParametersIncrementer() {
  return delegate.getJobParametersIncrementer();
}

代码示例来源:origin: org.springframework.batch/org.springframework.batch.core

public JobParametersIncrementer getJobParametersIncrementer() {
  return delegate.getJobParametersIncrementer();
}

代码示例来源:origin: org.springframework.batch/spring-batch-core

@Override
@Nullable
public JobParametersIncrementer getJobParametersIncrementer() {
  return delegate.getJobParametersIncrementer();
}

代码示例来源:origin: apache/servicemix-bundles

@Override
@Nullable
public JobParametersIncrementer getJobParametersIncrementer() {
  return delegate.getJobParametersIncrementer();
}

代码示例来源:origin: spring-cloud/spring-cloud-dataflow

@Override
public boolean isIncrementable(String jobName) {
  try {
    return jobLocator.getJobNames().contains(jobName)
        && jobLocator.getJob(jobName).getJobParametersIncrementer() != null;
  }
  catch (NoSuchJobException e) {
    // Should not happen
    throw new IllegalStateException("Unexpected non-existent job: " + jobName);
  }
}

代码示例来源:origin: spring-projects/spring-batch-admin

@Override
public boolean isIncrementable(String jobName) {
  try {
    return jobLocator.getJobNames().contains(jobName)
        && jobLocator.getJob(jobName).getJobParametersIncrementer() != null;
  }
  catch (NoSuchJobException e) {
    // Should not happen
    throw new IllegalStateException("Unexpected non-existent job: " + jobName);
  }
}

代码示例来源:origin: com.github.almex/raildelays-batch

public JobExecution start(String jobName, JobParameters jobParameters, boolean newInstance) throws JobInstanceAlreadyExistsException, NoSuchJobException, JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
    LOGGER.info("Checking status of job with name=" + jobName);

//        if (jobRepository.isJobInstanceExists(jobName, jobParameters)) {
//            throw new JobInstanceAlreadyExistsException(String.format(
//                    "Cannot start a job instance that already exists with name=%s and parameters=%s", jobName,
//                    jobParameters));
//        }   //-- Useless in our case. We would like to restart it

    Job job = jobRegistry.getJob(jobName);
    JobParameters effectiveJobParameters = jobParameters;

    if (newInstance) {
      Assert.notNull(job.getJobParametersIncrementer(), "You must configure a jobParametersIncrementer for this job in order to start a new instance.");

      effectiveJobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    LOGGER.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, effectiveJobParameters.getParameters()));

    return jobLauncher.run(job, effectiveJobParameters);
  }

代码示例来源:origin: spring-projects/spring-batch-admin

@ServiceActivator
public JobLaunchRequest adapt(File file) throws NoSuchJobException {
  String fileName = file.getAbsolutePath();
  if (!fileName.startsWith("/")) {
    fileName = "/" + fileName;
  }
  fileName = "file://" + fileName;
  JobParameters jobParameters = new JobParametersBuilder().addString(
      "input.file", fileName).toJobParameters();
  if (job.getJobParametersIncrementer() != null) {
    jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
  }
  return new JobLaunchRequest(job, jobParameters);
}

代码示例来源:origin: arey/spring-batch-toolkit

@ServiceActivator
  public JobLaunchRequest adapt(File file) throws NoSuchJobException {

    String jobName = fileToJobConverter.getJobNameFromFile(file);
    Job job = jobLocator.getJob(jobName);

    String fileName = file.getAbsolutePath();

    if (!fileName.startsWith("/")) {
      fileName = "/" + fileName;
    }

    fileName = "file://" + fileName;

    JobParameters jobParameters = new JobParametersBuilder().addString(
        "input.file", fileName).toJobParameters();

    if (job.getJobParametersIncrementer() != null) {
      jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    return new JobLaunchRequest(job, jobParameters);

  }
}

代码示例来源:origin: codecentric/spring-boot-starter-batch-web

/**
 * Borrowed from CommandLineJobRunner.
 *
 * @param job
 *            the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException
 *             if there is a problem
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
  String jobIdentifier = job.getName();
  JobParameters jobParameters;
  List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);
  JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
  if (lastInstances.isEmpty()) {
    jobParameters = incrementer.getNext(new JobParameters());
    if (jobParameters == null) {
      throw new JobParametersNotFoundException(
          "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
    }
  } else {
    List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
    jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
  }
  return jobParameters;
}

代码示例来源:origin: de.codecentric/batch-web-spring-boot-autoconfigure

/**
 * Borrowed from CommandLineJobRunner.
 *
 * @param job
 *            the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException
 *             if there is a problem
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
  String jobIdentifier = job.getName();
  JobParameters jobParameters;
  List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);
  JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
  if (lastInstances.isEmpty()) {
    jobParameters = incrementer.getNext(new JobParameters());
    if (jobParameters == null) {
      throw new JobParametersNotFoundException(
          "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
    }
  } else {
    List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
    jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
  }
  return jobParameters;
}

代码示例来源:origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

/**
 * @param job the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException if there is a problem
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
  String jobIdentifier = job.getName();
  JobParameters jobParameters;
  List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);
  JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
  if (incrementer == null) {
    throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobIdentifier);
  }
  if (lastInstances.isEmpty()) {
    jobParameters = incrementer.getNext(new JobParameters());
    if (jobParameters == null) {
      throw new JobParametersNotFoundException("No bootstrap parameters found from incrementer for job="
          + jobIdentifier);
    }
  }
  else {
    List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
    jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
  }
  return jobParameters;
}

代码示例来源:origin: org.springframework.batch/org.springframework.batch.core

/**
 * @param job the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException if there is a problem
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
  String jobIdentifier = job.getName();
  JobParameters jobParameters;
  List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);
  JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
  if (incrementer == null) {
    throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobIdentifier);
  }
  if (lastInstances.isEmpty()) {
    jobParameters = incrementer.getNext(new JobParameters());
    if (jobParameters == null) {
      throw new JobParametersNotFoundException("No bootstrap parameters found from incrementer for job="
          + jobIdentifier);
    }
  }
  else {
    jobParameters = incrementer.getNext(lastInstances.get(0).getJobParameters());
  }
  return jobParameters;
}

代码示例来源:origin: com.github.almex/raildelays-batch

@Override
public JobParameters getJobParameters(Job job, StepExecution stepExecution) {
  JobParameters jobParameters = super.getJobParameters(job, stepExecution);
  JobExecution jobExecution = stepExecution.getJobExecution();
  JobParametersIncrementer jobParametersIncrementer = job.getJobParametersIncrementer();
  if (jobParametersIncrementer != null) {
    jobParameters = jobParametersIncrementer.getNext(jobParameters);
  }
  jobParameters = addJobParametersFromContext(jobParameters, stepExecution.getExecutionContext());
  jobParameters = addJobParametersFromContext(jobParameters, jobExecution.getExecutionContext());
  return jobParameters;
}

代码示例来源:origin: codecentric/spring-boot-starter-batch-web

private JobParameters createJobParametersWithIncrementerIfAvailable(String parameters, Job job)
    throws JobParametersNotFoundException {
  JobParameters jobParameters = jobParametersConverter
      .getJobParameters(PropertiesConverter.stringToProperties(parameters));
  // use JobParametersIncrementer to create JobParameters if incrementer is set and only if the job is no restart
  if (job.getJobParametersIncrementer() != null) {
    JobExecution lastJobExecution = jobRepository.getLastJobExecution(job.getName(), jobParameters);
    boolean restart = false;
    // check if job failed before
    if (lastJobExecution != null) {
      BatchStatus status = lastJobExecution.getStatus();
      if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
        restart = true;
      }
    }
    // if it's not a restart, create new JobParameters with the incrementer
    if (!restart) {
      JobParameters nextParameters = getNextJobParameters(job);
      Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
      map.putAll(jobParameters.getParameters());
      jobParameters = new JobParameters(map);
    }
  }
  return jobParameters;
}

代码示例来源:origin: de.codecentric/batch-web-spring-boot-autoconfigure

private JobParameters createJobParametersWithIncrementerIfAvailable(String parameters, Job job)
    throws JobParametersNotFoundException {
  JobParameters jobParameters = jobParametersConverter
      .getJobParameters(PropertiesConverter.stringToProperties(parameters));
  // use JobParametersIncrementer to create JobParameters if incrementer is set and only if the job is no restart
  if (job.getJobParametersIncrementer() != null) {
    JobExecution lastJobExecution = jobRepository.getLastJobExecution(job.getName(), jobParameters);
    boolean restart = false;
    // check if job failed before
    if (lastJobExecution != null) {
      BatchStatus status = lastJobExecution.getStatus();
      if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
        restart = true;
      }
    }
    // if it's not a restart, create new JobParameters with the incrementer
    if (!restart) {
      JobParameters nextParameters = getNextJobParameters(job);
      Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
      map.putAll(jobParameters.getParameters());
      jobParameters = new JobParameters(map);
    }
  }
  return jobParameters;
}

代码示例来源:origin: io.oasp.java.modules/oasp4j-batch

@Override
public JobExecution run(final Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
  JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
 if (!job.isRestartable()) {
  JobParameters originalParameters = jobParameters;
  while (this.jobRepository.isJobInstanceExists(job.getName(), jobParameters)) {
   // check if batch job is still running or was completed already
   // analogous to SimpleJobRepository#createJobExecution
   JobExecution jobExecution = this.jobRepository.getLastJobExecution(job.getName(), jobParameters);
   if (jobExecution.isRunning()) {
    throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: "
      + jobExecution.getJobInstance());
   }
   BatchStatus status = jobExecution.getStatus();
   if (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED) {
    throw new JobInstanceAlreadyCompleteException("A job instance already exists and is complete for parameters="
      + originalParameters + ".  If you want to run this job again, change the parameters.");
   }
   // if there is a NullPointerException executing the following statement
   // there has not been a JobParametersIncrementer set for the job
   jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
  }
 }
 return super.run(job, jobParameters);
}

代码示例来源:origin: oasp/oasp4j

@Override
public JobExecution run(final Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
  JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
 if (!job.isRestartable()) {
  JobParameters originalParameters = jobParameters;
  while (this.jobRepository.isJobInstanceExists(job.getName(), jobParameters)) {
   // check if batch job is still running or was completed already
   // analogous to SimpleJobRepository#createJobExecution
   JobExecution jobExecution = this.jobRepository.getLastJobExecution(job.getName(), jobParameters);
   if (jobExecution.isRunning()) {
    throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: "
      + jobExecution.getJobInstance());
   }
   BatchStatus status = jobExecution.getStatus();
   if (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED) {
    throw new JobInstanceAlreadyCompleteException("A job instance already exists and is complete for parameters="
      + originalParameters + ".  If you want to run this job again, change the parameters.");
   }
   // if there is a NullPointerException executing the following statement
   // there has not been a JobParametersIncrementer set for the job
   jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
  }
 }
 return super.run(job, jobParameters);
}

相关文章