Package org.springframework.batch.repeat

Examples of org.springframework.batch.repeat.RepeatStatus


    @Override
  public RepeatStatus iterate(RepeatCallback callback) {

    RepeatContext outer = RepeatSynchronizationManager.getContext();

    RepeatStatus result = RepeatStatus.CONTINUABLE;
    try {
      // This works with an asynchronous TaskExecutor: the
      // interceptors have to wait for the child processes.
      result = executeInternal(callback);
    }
View Full Code Here


      if (!running)
        break;
    }

    // Return value, default is to allow continued processing.
    RepeatStatus result = RepeatStatus.CONTINUABLE;

    RepeatInternalState state = createInternalState(context);
    // This is the list of exceptions thrown by all active callbacks
    Collection<Throwable> throwables = state.getThrowables();
    // Keep a separate list of exceptions we handled that need to be
    // rethrown
    Collection<Throwable> deferred = new ArrayList<Throwable>();

    try {

      while (running) {

        /*
         * Run the before interceptors here, not in the task executor so
         * that they all happen in the same thread - it's easier for
         * tracking batch status, amongst other things.
         */
        for (int i = 0; i < listeners.length; i++) {
          RepeatListener interceptor = listeners[i];
          interceptor.before(context);
          // Allow before interceptors to veto the batch by setting
          // flag.
          running = running && !isMarkedComplete(context);
        }

        // Check that we are still running (should always be true) ...
        if (running) {

          try {

            result = getNextResult(context, callback, state);
            executeAfterInterceptors(context, result);

          }
          catch (Throwable throwable) {
            doHandle(throwable, context, deferred);
          }

          // N.B. the order may be important here:
          if (isComplete(context, result) || isMarkedComplete(context) || !deferred.isEmpty()) {
            running = false;
          }

        }

      }

      result = result.and(waitForResults(state));
      for (Throwable throwable : throwables) {
        doHandle(throwable, context, deferred);
      }

      // Explicitly drop any references to internal state...
View Full Code Here

      if (future.getError() != null) {
        state.getThrowables().add(future.getError());
        result = false;
      }
      else {
        RepeatStatus status = future.getResult();
        result = result && canContinue(status);
        executeAfterInterceptors(future.getContext(), status);
      }

    }
View Full Code Here

    String command = "java -version";
    tasklet.setCommand(command);
    tasklet.afterPropertiesSet();

    log.info("Executing command: " + command);
    RepeatStatus exitStatus = tasklet.execute(stepExecution.createStepContribution(), null);

    assertEquals(RepeatStatus.FINISHED, exitStatus);
  }
View Full Code Here

    tasklet.afterPropertiesSet();

    log.info("Executing command: " + command);
    try {
      StepContribution contribution = stepExecution.createStepContribution();
      RepeatStatus exitStatus = tasklet.execute(contribution, null);
      assertEquals(RepeatStatus.FINISHED, exitStatus);
      assertEquals(ExitStatus.FAILED, contribution.getExitStatus());
    }
    catch (RuntimeException e) {
      // on some platforms the system call does not return
View Full Code Here

  }
 
  @Test
  public void testNonContinuableResult() throws Exception {
    TimeoutTerminationPolicy policy = new TimeoutTerminationPolicy();
    RepeatStatus result = RepeatStatus.FINISHED;
    assertTrue(policy.isComplete(policy.start(null), result));
  }
View Full Code Here

      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        return RepeatStatus.continueIf(count <= 1);
      }
    });
    RepeatStatus result = callback.doInIteration(null);
    assertEquals(2, count);
    assertFalse(result.isContinuable()); // False because processing has finished
  }
View Full Code Here

         * FINISHED early, while other threads are still working, and
         * would do more work if the callback was called again. (This
         * happens for instance if there is a failure and you want to
         * retry the work.)
         */
        RepeatStatus result = RepeatStatus.continueIf(position != early
            && item != null);
        if (position == error) {
          throw new RuntimeException("Planned");
        }
        if (!result.isContinuable()) {
          logger.debug("Returning " + result + " for count="
              + position);
        }
        return result;
      }
View Full Code Here

TOP

Related Classes of org.springframework.batch.repeat.RepeatStatus

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.