Package org.springframework.batch.core

Examples of org.springframework.batch.core.JobInterruptedException


    if (stepExecution == null) {
      return  ExitStatus.COMPLETED.getExitCode();
    }
    if (stepExecution.isTerminateOnly()) {
      throw new JobInterruptedException("Step requested termination: "+stepExecution, stepExecution.getStatus());
    }

    if(isRerun) {
      stepExecution.getExecutionContext().put("batch.restart", true);
    }
View Full Code Here


    SimpleFlow flow = new JsrFlow("job");
    List<StateTransition> transitions = new ArrayList<StateTransition>();
    transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1") {
      @Override
      public void execute(StepExecution stepExecution) throws JobInterruptedException {
        throw new JobInterruptedException("Stopped");
      }
    }), "end0"));
    transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
    flow.setStateTransitions(transitions);
    flow.afterPropertiesSet();
View Full Code Here

    List<StateTransition> transitions = new ArrayList<StateTransition>();
    transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1") {
      @Override
      public void execute(StepExecution stepExecution) throws JobInterruptedException {
        throw new JobInterruptedException("Stopped");
      }
    }), "end0"));
    transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
    flow1.setStateTransitions(new ArrayList<StateTransition>(transitions));
    flow1.afterPropertiesSet();
View Full Code Here

  public void testInterruptedWithCustomStatus() throws Exception {
    taskletStep.setTasklet(new Tasklet() {
      @Override
      public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        contribution.setExitStatus(new ExitStatus("FUNNY"));
        throw new JobInterruptedException("Planned");
      }
    });
    taskletStep.execute(stepExecution);
    assertEquals(STOPPED, stepExecution.getStatus());
    assertEquals("FUNNY", stepExecution.getExitStatus().getExitCode());
View Full Code Here

  @Override
  public StepExecution handleStep(Step step, JobExecution execution) throws JobInterruptedException,
  JobRestartException, StartLimitExceededException {
    if (execution.isStopping()) {
      throw new JobInterruptedException("JobExecution interrupted.");
    }

    JobInstance jobInstance = execution.getJobInstance();

    StepExecution lastStepExecution = jobRepository.getLastStepExecution(jobInstance, step.getName());
    if (stepExecutionPartOfExistingJobExecution(execution, lastStepExecution)) {
      // If the last execution of this step was in the same job, it's
      // probably intentional so we want to run it again...
      logger.info(String.format("Duplicate step [%s] detected in execution of job=[%s]. "
          + "If either step fails, both will be executed again on restart.", step.getName(), jobInstance
          .getJobName()));
      lastStepExecution = null;
    }
    StepExecution currentStepExecution = lastStepExecution;

    if (shouldStart(lastStepExecution, execution, step)) {

      currentStepExecution = execution.createStepExecution(step.getName());

      boolean isRestart = (lastStepExecution != null && !lastStepExecution.getStatus().equals(
          BatchStatus.COMPLETED));

      if (isRestart) {
        currentStepExecution.setExecutionContext(lastStepExecution.getExecutionContext());

        if(lastStepExecution.getExecutionContext().containsKey("batch.executed")) {
          currentStepExecution.getExecutionContext().remove("batch.executed");
        }
      }
      else {
        currentStepExecution.setExecutionContext(new ExecutionContext(executionContext));
      }

      jobRepository.add(currentStepExecution);

      logger.info("Executing step: [" + step.getName() + "]");
      try {
        step.execute(currentStepExecution);
        currentStepExecution.getExecutionContext().put("batch.executed", true);
      }
      catch (JobInterruptedException e) {
        // Ensure that the job gets the message that it is stopping
        // and can pass it on to other steps that are executing
        // concurrently.
        execution.setStatus(BatchStatus.STOPPING);
        throw e;
      }

      jobRepository.updateExecutionContext(execution);

      if (currentStepExecution.getStatus() == BatchStatus.STOPPING
          || currentStepExecution.getStatus() == BatchStatus.STOPPED) {
        // Ensure that the job gets the message that it is stopping
        execution.setStatus(BatchStatus.STOPPING);
        throw new JobInterruptedException("Job interrupted by step execution");
      }

    }

    return currentStepExecution;
View Full Code Here

        systemCommandTask.cancel(interruptOnCancel);
        throw new SystemCommandException("Execution of system command did not finish within the timeout");
      }
      else if (execution.isTerminateOnly()) {
        systemCommandTask.cancel(interruptOnCancel);
        throw new JobInterruptedException("Job interrupted while executing system command '" + command + "'");
      }
      else if (stopped) {
        systemCommandTask.cancel(interruptOnCancel);
        contribution.setExitStatus(ExitStatus.STOPPED);
        return RepeatStatus.FINISHED;
View Full Code Here

    StepInterruptionPolicy interruptionPolicy = new StepInterruptionPolicy() {

      @Override
      public void checkInterrupted(StepExecution stepExecution) throws JobInterruptedException {
        throw new JobInterruptedException("interrupted");
      }
    };

    step.setInterruptionPolicy(interruptionPolicy);
View Full Code Here

  @Test
  public void testInterrupted() throws Exception {
    step1.setStartLimit(5);
    step2.setStartLimit(5);
    final JobInterruptedException exception = new JobInterruptedException("Interrupt!");
    step1.setProcessException(exception);
    job.execute(jobExecution);
    assertEquals(1, jobExecution.getAllFailureExceptions().size());
    assertEquals(exception, jobExecution.getStepExecutions().iterator().next().getFailureExceptions().get(0));
    assertEquals(0, list.size());
View Full Code Here

  @Test
  public void testInterruptedAfterUnknownStatus() throws Exception {
    step1.setStartLimit(5);
    step2.setStartLimit(5);
    final JobInterruptedException exception = new JobInterruptedException("Interrupt!", BatchStatus.UNKNOWN);
    step1.setProcessException(exception);
    job.execute(jobExecution);
    assertEquals(1, jobExecution.getAllFailureExceptions().size());
    assertEquals(exception, jobExecution.getStepExecutions().iterator().next().getFailureExceptions().get(0));
    assertEquals(0, list.size());
View Full Code Here

    assertFalse(step2.passedInStepContext.isEmpty());
  }

  @Test
  public void testInterruptWithListener() throws Exception {
    step1.setProcessException(new JobInterruptedException("job interrupted!"));

    JobExecutionListener listener = mock(JobExecutionListener.class);
    listener.beforeJob(jobExecution);
    listener.afterJob(jobExecution);
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.JobInterruptedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.