Tabnine Logo
RepeatTemplate
Code IndexAdd Tabnine to your IDE (free)

How to use
RepeatTemplate
in
org.springframework.batch.repeat.support

Best Java code snippets using org.springframework.batch.repeat.support.RepeatTemplate (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

protected RepeatOperations createChunkOperations() {
  RepeatOperations repeatOperations = chunkOperations;
  if (repeatOperations == null) {
    RepeatTemplate repeatTemplate = new RepeatTemplate();
    repeatTemplate.setCompletionPolicy(getChunkCompletionPolicy());
    repeatOperations = repeatTemplate;
  }
  return repeatOperations;
}
origin: spring-projects/spring-batch

stepOperations = new RepeatTemplate();
((RepeatTemplate) stepOperations).setExceptionHandler(exceptionHandler);
origin: spring-projects/spring-batch

@Test
public void testNestedSession() throws Exception {
  RepeatTemplate outer = getRepeatTemplate();
  RepeatTemplate inner = new RepeatTemplate();
  outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++;
      assertNotNull(context);
      assertNotSame("Nested batch should have new session", context, context.getParent());
      assertSame(context, RepeatSynchronizationManager.getContext());
      return RepeatStatus.FINISHED;
    }
  }) {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++;
      assertNotNull(context);
      assertSame(context, RepeatSynchronizationManager.getContext());
      return super.doInIteration(context);
    }
  });
  assertTrue("Too few attempts: " + count, count >= 1);
  assertTrue("Too many attempts: " + count, count <= 10);
}
origin: spring-projects/spring-batch

  private RepeatOperations createRepeatOperations() {
    RepeatTemplate repeatOperations = new RepeatTemplate();
    repeatOperations.setCompletionPolicy(getChunkCompletionPolicy());
    repeatOperations.setExceptionHandler(getExceptionHandler());
    return repeatOperations;
  }
}
origin: spring-projects/spring-batch

RepeatContext context = start();
boolean running = !isMarkedComplete(context);
  running = running && !isMarkedComplete(context);
  if (!running)
    break;
RepeatInternalState state = createInternalState(context);
      running = running && !isMarkedComplete(context);
        result = getNextResult(context, callback, state);
        executeAfterInterceptors(context, result);
        doHandle(throwable, context, deferred);
      if (isComplete(context, result) || isMarkedComplete(context) || !deferred.isEmpty()) {
        running = false;
  result = result.and(waitForResults(state));
  for (Throwable throwable : throwables) {
    doHandle(throwable, context, deferred);
            + throwable.getClass().getName() + ": " + throwable.getMessage());
      rethrow(throwable);
origin: spring-projects/spring-batch

public void testOpenInterceptors() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  final List<Object> calls = new ArrayList<>();
  template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
    @Override
    public void open(RepeatContext context) {
      calls.add("1");
    }
  }, new RepeatListenerSupport() {
    @Override
    public void open(RepeatContext context) {
      calls.add("2");
      context.setCompleteOnly();
    }
  } });
  template.iterate(new RepeatCallback() {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++;
      return RepeatStatus.CONTINUABLE;
    }
  });
  assertEquals(0, count);
  assertEquals("[1, 2]", calls.toString());
}
origin: spring-projects/spring-batch

  public void testExecute() throws Exception {
    NestedRepeatCallback callback = new NestedRepeatCallback(new RepeatTemplate(), new RepeatCallback() {
      @Override
      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
  }
}
origin: spring-projects/spring-batch

/**
 * Chunking using a dedicated TerminationPolicy. Transactions would be laid
 * on at the level of chunkTemplate.execute() or the surrounding callback.
 */
@Test
public void testChunkedBatchWithTerminationPolicy() throws Exception {
  RepeatTemplate repeatTemplate = new RepeatTemplate();
  final RepeatCallback callback = new ItemReaderRepeatCallback<>(provider, processor);
  final RepeatTemplate chunkTemplate = new RepeatTemplate();
  // The policy is resettable so we only have to resolve this dependency
  // once
  chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
  RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++; // for test assertion
      return super.doInIteration(context);
    }
  });
  assertEquals(NUMBER_OF_ITEMS, processor.count);
  // The chunk executes 3 times because the last one
  // returns false. We terminate the main batch when
  // we encounter a partially empty chunk.
  assertEquals(3, count);
  assertFalse(result.isContinuable());
}
origin: spring-projects/spring-batch

/**
 * Check that a dedicated TerminationPolicy can terminate the batch.
 * 
 * @throws Exception
 */
@Test
public void testEarlyCompletionWithPolicy() throws Exception {
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  template.iterate(new ItemReaderRepeatCallback<>(provider, processor));
  assertEquals(2, processor.count);
}
origin: spring-projects/spring-batch

public void testBeforeInterceptorCanVeto() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  final List<Object> calls = new ArrayList<>();
  template.registerListener(new RepeatListenerSupport() {
    @Override
    public void before(RepeatContext context) {
      calls.add("1");
      context.setCompleteOnly();
    }
  });
  template.iterate(new RepeatCallback() {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++;
      return RepeatStatus.FINISHED;
    }
  });
  assertEquals(0, count);
  // ... but the interceptor before() was called:
  assertEquals("[1]", calls.toString());
}
origin: spring-projects/spring-batch

  @Override
  public RepeatStatus doInIteration(RepeatContext context) throws Exception {
    stepTemplate.iterate(stepCallback);
    return RepeatStatus.FINISHED;
  }
};
origin: spring-projects/spring-batch

template.setExceptionHandler(exHandler);
template.setListeners(new RepeatListener[] { listener });
  template.iterate(new RepeatCallback() {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
origin: spring-projects/spring-batch

/**
 * Check that the exception handler is called.
 * 
 * @throws Exception
 */
@Test
public void testExceptionHandlerCalledOnAbnormalCompletion() throws Exception {
  final List<Throwable> list = new ArrayList<>();
  template.setExceptionHandler(new ExceptionHandler() {
    @Override
    public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException {
      list.add(throwable);
      throw (RuntimeException) throwable;
    }
  });
  try {
    template.iterate(new RepeatCallback() {
      @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        throw new RuntimeException("foo");
      }
    });
  }
  catch (RuntimeException e) {
    assertEquals("foo", e.getMessage());
  }
  assertEquals(1, count);
  assertEquals(1, list.size());
}
origin: spring-projects/spring-batch

SimpleRetryExceptionHandler exceptionHandler = new SimpleRetryExceptionHandler(retryPolicyWrapper,
    getExceptionHandler(), nonRetryableExceptionClasses);
((RepeatTemplate) stepOperations).setExceptionHandler(exceptionHandler);
origin: spring-projects/spring-batch

    .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
repeatTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
origin: org.springframework.batch/spring-batch-core

  private RepeatOperations createRepeatOperations() {
    RepeatTemplate repeatOperations = new RepeatTemplate();
    repeatOperations.setCompletionPolicy(getChunkCompletionPolicy());
    repeatOperations.setExceptionHandler(getExceptionHandler());
    return repeatOperations;
  }
}
origin: spring-projects/spring-batch

public void testAfterInterceptors() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  final List<Object> calls = new ArrayList<>();
  template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
    @Override
    public void after(RepeatContext context, RepeatStatus result) {
      calls.add("1");
    }
  }, new RepeatListenerSupport() {
    @Override
    public void after(RepeatContext context, RepeatStatus result) {
      calls.add("2");
    }
  } });
  template.iterate(new RepeatCallback() {
    @Override
    public RepeatStatus doInIteration(RepeatContext context) throws Exception {
      count++;
      return RepeatStatus.continueIf(count <= 1);
    }
  });
  // 2 calls to the callback, and the second one had no processing...
  assertEquals(2, count);
  // ... so the interceptor after() is not called:
  assertEquals("[2, 1]", calls.toString());
}
origin: spring-projects/spring-batch

@Test
public void testProvide() throws Exception {
  provider = new SimpleChunkProvider<>(new ListItemReader<>(Arrays.asList("foo", "bar")),
      new RepeatTemplate());
  Chunk<String> chunk = provider.provide(contribution);
  assertNotNull(chunk);
  assertEquals(2, chunk.getItems().size());
}
origin: spring-projects/spring-batch

template.setCompletionPolicy(new CompletionPolicySupport() {
  @Override
  public RepeatContext start(RepeatContext c) {
template.iterate(new RepeatCallback() {
  @Override
  public RepeatStatus doInIteration(RepeatContext context) throws Exception {
origin: apache/servicemix-bundles

RepeatContext context = start();
boolean running = !isMarkedComplete(context);
  running = running && !isMarkedComplete(context);
  if (!running)
    break;
RepeatInternalState state = createInternalState(context);
      running = running && !isMarkedComplete(context);
        result = getNextResult(context, callback, state);
        executeAfterInterceptors(context, result);
        doHandle(throwable, context, deferred);
      if (isComplete(context, result) || isMarkedComplete(context) || !deferred.isEmpty()) {
        running = false;
  result = result.and(waitForResults(state));
  for (Throwable throwable : throwables) {
    doHandle(throwable, context, deferred);
            + throwable.getClass().getName() + ": " + throwable.getMessage());
      rethrow(throwable);
org.springframework.batch.repeat.supportRepeatTemplate

Javadoc

Simple implementation and base class for batch templates implementing RepeatOperations. Provides a framework including interceptors and policies. Subclasses just need to provide a method that gets the next result and one that waits for all the results to be returned from concurrent processes or threads.
N.B. the template accumulates thrown exceptions during the iteration, and they are all processed together when the main loop ends (i.e. finished processing the items). Clients that do not want to stop execution when an exception is thrown can use a specific CompletionPolicy that does not finish when exceptions are received. This is not the default behaviour.
Clients that want to take some business action when an exception is thrown by the RepeatCallback can consider using a custom RepeatListenerinstead of trying to customise the CompletionPolicy. This is generally a friendlier interface to implement, and the RepeatListener#after(RepeatContext,RepeatStatus) method is passed in the result of the callback, which would be an instance of Throwableif the business processing had thrown an exception. If the exception is not to be propagated to the caller, then a non-default CompletionPolicyneeds to be provided as well, but that could be off the shelf, with the business action implemented only in the interceptor.

Most used methods

  • <init>
  • setCompletionPolicy
  • setExceptionHandler
  • iterate
  • createInternalState
    Create an internal state object that is used to store data needed internally in the scope of an iter
  • doHandle
  • executeAfterInterceptors
    Convenience method to execute after interceptors on a callback result.
  • executeInternal
    Internal convenience method to loop over interceptors and batch callbacks.
  • getNextResult
    Get the next completed result, possibly executing several callbacks until one finally finishes. Norm
  • isComplete
    Delegate to the CompletionPolicy.
  • isMarkedComplete
  • rethrow
    Re-throws the original throwable if it is unchecked, wraps checked exceptions into RepeatException.
  • isMarkedComplete,
  • rethrow,
  • start,
  • unwrapIfRethrown,
  • update,
  • waitForResults,
  • registerListener,
  • setListeners

Popular in Java

  • Reading from database using SQL prepared statement
  • getApplicationContext (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JComboBox (javax.swing)
  • JPanel (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now