From 442e5f74adc2c2a24464ed1b73f44cd0c19251df Mon Sep 17 00:00:00 2001 From: David Syer Date: Sun, 11 Apr 2010 08:08:08 +0000 Subject: [PATCH] BATCHADM-49: fix build by checking for fault tolerant processor --- .../chunk/ChunkProcessorChunkHandler.java | 81 +++++++++++-------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java index f9fb868ff..3a4290ed7 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java @@ -22,6 +22,7 @@ import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.item.Chunk; import org.springframework.batch.core.step.item.ChunkProcessor; +import org.springframework.batch.core.step.item.FaultTolerantChunkProcessor; import org.springframework.batch.core.step.skip.NonSkippableReadException; import org.springframework.batch.core.step.skip.SkipLimitExceededException; import org.springframework.batch.core.step.skip.SkipListenerFailedException; @@ -32,9 +33,11 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.util.Assert; @MessageEndpoint -public class ChunkProcessorChunkHandler implements ChunkHandler, InitializingBean { +public class ChunkProcessorChunkHandler implements ChunkHandler, + InitializingBean { - private static final Log logger = LogFactory.getLog(ChunkProcessorChunkHandler.class); + private static final Log logger = LogFactory + .getLog(ChunkProcessorChunkHandler.class); private ChunkProcessor chunkProcessor; @@ -51,7 +54,8 @@ public class ChunkProcessorChunkHandler implements ChunkHandler, Initializ /** * Public setter for the {@link ChunkProcessor}. * - * @param chunkProcessor the chunkProcessor to set + * @param chunkProcessor + * the chunkProcessor to set */ public void setChunkProcessor(ChunkProcessor chunkProcessor) { this.chunkProcessor = chunkProcessor; @@ -62,55 +66,62 @@ public class ChunkProcessorChunkHandler implements ChunkHandler, Initializ * @see ChunkHandler#handleChunk(ChunkRequest) */ @ServiceActivator - public ChunkResponse handleChunk(ChunkRequest chunkRequest) throws Exception { + public ChunkResponse handleChunk(ChunkRequest chunkRequest) + throws Exception { logger.debug("Handling chunk: " + chunkRequest); StepContribution stepContribution = chunkRequest.getStepContribution(); - Throwable failure = null; - try { - process(chunkRequest, stepContribution); - } - catch (SkipLimitExceededException e) { - failure = e; - } - catch (NonSkippableReadException e) { - failure = e; - } - catch (SkipListenerFailedException e) { - failure = e; - } - catch (RetryException e) { - failure = e; - } - catch (JobInterruptedException e) { - failure = e; - } - catch (Exception e) { - // try again... - throw e; - } + Throwable failure = process(chunkRequest, stepContribution); if (failure != null) { logger.debug("Failed chunk", failure); - return new ChunkResponse(false, chunkRequest.getJobId(), stepContribution, failure.getClass().getName() - + ": " + failure.getMessage()); + return new ChunkResponse(false, chunkRequest.getJobId(), + stepContribution, failure.getClass().getName() + ": " + + failure.getMessage()); } logger.debug("Completed chunk handling with " + stepContribution); - return new ChunkResponse(true, chunkRequest.getJobId(), stepContribution); + return new ChunkResponse(true, chunkRequest.getJobId(), + stepContribution); } /** - * @param chunkRequest the current request - * @param stepContribution the step contribution to update - * @throws Exception if there is a fatal exception + * @param chunkRequest + * the current request + * @param stepContribution + * the step contribution to update + * @throws Exception + * if there is a fatal exception */ - private void process(ChunkRequest chunkRequest, StepContribution stepContribution) throws Exception { + private Throwable process(ChunkRequest chunkRequest, + StepContribution stepContribution) throws Exception { Chunk chunk = new Chunk(chunkRequest.getItems()); - chunkProcessor.process(stepContribution, chunk); + Throwable failure = null; + try { + chunkProcessor.process(stepContribution, chunk); + } catch (SkipLimitExceededException e) { + failure = e; + } catch (NonSkippableReadException e) { + failure = e; + } catch (SkipListenerFailedException e) { + failure = e; + } catch (RetryException e) { + failure = e; + } catch (JobInterruptedException e) { + failure = e; + } catch (Exception e) { + if (chunkProcessor instanceof FaultTolerantChunkProcessor) { + // try again... + throw e; + } else { + failure = e; + } + } + + return failure; } }