| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.batch.repeat.support.RepeatTemplate
public class RepeatTemplate
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 RepeatListener
 instead 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 Throwable
 if the business processing had thrown an exception. If the exception is not
 to be propagated to the caller, then a non-default CompletionPolicy
 needs to be provided as well, but that could be off the shelf, with the
 business action implemented only in the interceptor.
| Field Summary | |
|---|---|
| protected  Log | logger | 
| Constructor Summary | |
|---|---|
| RepeatTemplate() | |
| Method Summary | |
|---|---|
| protected  boolean | canContinue(RepeatStatus value)Check return value from batch operation. | 
| protected  RepeatInternalState | createInternalState(RepeatContext context)Create an internal state object that is used to store data needed internally in the scope of an iteration. | 
| protected  void | executeAfterInterceptors(RepeatContext context,
                         RepeatStatus value)Convenience method to execute after interceptors on a callback result. | 
| protected  RepeatStatus | getNextResult(RepeatContext context,
              RepeatCallback callback,
              RepeatInternalState state)Get the next completed result, possibly executing several callbacks until one finally finishes. | 
| protected  boolean | isComplete(RepeatContext context)Delegate to CompletionPolicy. | 
| protected  boolean | isComplete(RepeatContext context,
           RepeatStatus result)Delegate to the CompletionPolicy. | 
|  RepeatStatus | iterate(RepeatCallback callback)Execute the batch callback until the completion policy decides that we are finished. | 
|  void | registerListener(RepeatListener listener)Register an additional listener. | 
|  void | setCompletionPolicy(CompletionPolicy terminationPolicy)Setter for policy to decide when the batch is complete. | 
|  void | setExceptionHandler(ExceptionHandler exceptionHandler)Setter for exception handler strategy. | 
|  void | setListeners(RepeatListener[] listeners)Set the listeners for this template, registering them for callbacks at appropriate times in the iteration. | 
| protected  RepeatContext | start()Delegate to the CompletionPolicy. | 
| protected  void | update(RepeatContext context)Delegate to the CompletionPolicy. | 
| protected  boolean | waitForResults(RepeatInternalState state)If necessary, wait for results to come back from remote or concurrent processes. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
protected Log logger
| Constructor Detail | 
|---|
public RepeatTemplate()
| Method Detail | 
|---|
public void setListeners(RepeatListener[] listeners)
listeners - public void registerListener(RepeatListener listener)
listener - public void setExceptionHandler(ExceptionHandler exceptionHandler)
CompletionPolicy has determined
 that the batch is complete. By default all exceptions are re-thrown.
exceptionHandler - the ExceptionHandler to use.ExceptionHandler, 
DefaultExceptionHandler, 
setCompletionPolicy(CompletionPolicy)public void setCompletionPolicy(CompletionPolicy terminationPolicy)
RepeatStatus which
 is not marked as continuable, and abnormally when the callback throws an
 exception (but the decision to re-throw the exception is deferred to the
 ExceptionHandler).
terminationPolicy - a TerminationPolicy.
IllegalArgumentException - if the argument is nullsetExceptionHandler(ExceptionHandler)public RepeatStatus iterate(RepeatCallback callback)
iterate in interface RepeatOperationscallback - the batch callback.
RepeatOperations can continue
 processing if this method is called again.RepeatOperations.iterate(org.springframework.batch.repeat.RepeatCallback)protected RepeatInternalState createInternalState(RepeatContext context)
context - the current RepeatContext
RepeatInternalState instance.waitForResults(RepeatInternalState)
protected RepeatStatus getNextResult(RepeatContext context,
                                     RepeatCallback callback,
                                     RepeatInternalState state)
                              throws Throwable
createInternalState(RepeatContext) because the
 implementation of this method would rely on the details of the internal
 state.
context - current BatchContext.callback - the callback to execute.state - maintained by the implementation.
ThrowableisComplete(RepeatContext), 
createInternalState(RepeatContext)protected boolean waitForResults(RepeatInternalState state)
state - the internal state.
canContinue(RepeatStatus) is true for all
 results retrieved.protected final boolean canContinue(RepeatStatus value)
value - the last callback result.
RepeatStatus.CONTINUABLE.
protected void executeAfterInterceptors(RepeatContext context,
                                        RepeatStatus value)
context - the current batch context.value - the result of the callback to process.
protected boolean isComplete(RepeatContext context,
                             RepeatStatus result)
CompletionPolicy.
CompletionPolicy.isComplete(RepeatContext,
 RepeatStatus)protected boolean isComplete(RepeatContext context)
CompletionPolicy.
CompletionPolicy.isComplete(RepeatContext)protected RepeatContext start()
CompletionPolicy.
CompletionPolicy.start(RepeatContext)protected void update(RepeatContext context)
CompletionPolicy.
CompletionPolicy.update(RepeatContext)| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||