Example usage for org.springframework.batch.repeat RepeatStatus isContinuable

List of usage examples for org.springframework.batch.repeat RepeatStatus isContinuable

Introduction

In this page you can find the example usage for org.springframework.batch.repeat RepeatStatus isContinuable.

Prototype

public boolean isContinuable() 

Source Link

Usage

From source file:org.springframework.batch.repeat.support.RepeatTemplate.java

/**
 * Check return value from batch operation.
 * /*  w  w  w. j  a v a  2s. c o  m*/
 * @param value the last callback result.
 * @return true if the value is {@link RepeatStatus#CONTINUABLE}.
 */
protected final boolean canContinue(RepeatStatus value) {
    return value.isContinuable();
}

From source file:org.springframework.batch.repeat.support.RepeatTemplate.java

/**
 * Convenience method to execute after interceptors on a callback result.
 * /*www  .j a  v a2 s .c  om*/
 * @param context the current batch context.
 * @param value the result of the callback to process.
 */
protected void executeAfterInterceptors(final RepeatContext context, RepeatStatus value) {

    // Don't re-throw exceptions here: let the exception handler deal with
    // that...

    if (value != null && value.isContinuable()) {
        for (int i = listeners.length; i-- > 0;) {
            RepeatListener interceptor = listeners[i];
            interceptor.after(context, value);
        }

    }

}

From source file:org.springframework.batch.repeat.support.TaskExecutorRepeatTemplateBulkAsynchronousTests.java

@Before
public void setUp() {

    template = new TaskExecutorRepeatTemplate();
    TaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    threadPool.setMaxPoolSize(300);/*from w  ww  . j a va  2s.co  m*/
    threadPool.setCorePoolSize(10);
    threadPool.setQueueCapacity(0);
    threadPool.afterPropertiesSet();
    taskExecutor = threadPool;
    template.setTaskExecutor(taskExecutor);
    template.setThrottleLimit(throttleLimit);

    items = Collections.synchronizedList(new ArrayList<String>());

    callback = new RepeatCallback() {

        private volatile AtomicInteger count = new AtomicInteger(0);

        @Override
        public RepeatStatus doInIteration(RepeatContext context) throws Exception {
            int position = count.incrementAndGet();
            String item = position <= total ? "" + position : null;
            items.add("" + item);
            if (item != null) {
                beBusy();
            }
            /*
             * In a multi-threaded task, one of the callbacks can call
             * 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;
        }
    };

}