List of usage examples for org.springframework.batch.core.scope.context ChunkContext isComplete
public boolean isComplete()
From source file:org.springframework.batch.core.scope.context.StepContextRepeatCallback.java
/** * Manage the {@link StepContext} lifecycle. Business processing should be * delegated to {@link #doInChunkContext(RepeatContext, ChunkContext)}. This * is to ensure that the current thread has a reference to the context, even * if the callback is executed in a pooled thread. Handles the registration * and unregistration of the step context, so clients should not duplicate * those calls.// www. ja v a 2 s .c om * * @see RepeatCallback#doInIteration(RepeatContext) */ @Override public RepeatStatus doInIteration(RepeatContext context) throws Exception { // The StepContext has to be the same for all chunks, // otherwise step-scoped beans will be re-initialised for each chunk. StepContext stepContext = StepSynchronizationManager.register(stepExecution); if (logger.isDebugEnabled()) { logger.debug("Preparing chunk execution for StepContext: " + ObjectUtils.identityToString(stepContext)); } ChunkContext chunkContext = attributeQueue.poll(); if (chunkContext == null) { chunkContext = new ChunkContext(stepContext); } try { if (logger.isDebugEnabled()) { logger.debug("Chunk execution starting: queue size=" + attributeQueue.size()); } return doInChunkContext(context, chunkContext); } finally { // Still some stuff to do with the data in this chunk, // pass it back. if (!chunkContext.isComplete()) { attributeQueue.add(chunkContext); } StepSynchronizationManager.close(); } }
From source file:org.springframework.xd.dirt.plugins.job.support.listener.SimpleXdChunkListener.java
private ChunkContextInfo convertChunkContext(ChunkContext context) { final ChunkContextInfo chunkContextInfo = new ChunkContextInfo(); chunkContextInfo.setComplete(context.isComplete()); chunkContextInfo.setStepExecution(context.getStepContext().getStepExecution()); final String[] attributeNames = context.attributeNames(); for (String attributeName : attributeNames) { final Object attribute = context.getAttribute(attributeName); chunkContextInfo.getAttributes().put(attributeName, attribute); }/*from w w w. j a v a 2s. co m*/ return chunkContextInfo; }