List of usage examples for org.springframework.batch.integration.chunk ChunkResponse getStepContribution
public StepContribution getStepContribution()
From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java
/** * Get the next result if it is available (within the timeout specified in the gateway), otherwise do nothing. * //from w ww .j a v a 2 s. com * @throws AsynchronousFailureException If there is a response and it contains a failed chunk response. * * @throws IllegalStateException if the result contains the wrong job instance id (maybe we are sharing a channel * and we shouldn't be) */ private void getNextResult() throws AsynchronousFailureException { ChunkResponse payload = (ChunkResponse) messagingGateway.receive(); if (payload != null) { if (logger.isDebugEnabled()) { logger.debug("Found result: " + payload); } Long jobInstanceId = payload.getJobId(); Assert.state(jobInstanceId != null, "Message did not contain job instance id."); Assert.state(jobInstanceId.equals(localState.getJobId()), "Message contained wrong job instance id [" + jobInstanceId + "] should have been [" + localState.getJobId() + "]."); if (payload.isRedelivered()) { logger.warn( "Redelivered result detected, which may indicate stale state. In the best case, we just picked up a timed out message " + "from a previous failed execution. In the worst case (and if this is not a restart), " + "the step may now timeout. In that case if you believe that all messages " + "from workers have been sent, the business state " + "is probably inconsistent, and the step will fail."); localState.incrementRedelivered(); } localState.pushStepContribution(payload.getStepContribution()); localState.incrementActual(); if (!payload.isSuccessful()) { throw new AsynchronousFailureException( "Failure or interrupt detected in handler: " + payload.getMessage()); } } }
From source file:org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.java
public Collection<StepContribution> getStepContributions() { List<StepContribution> contributions = new ArrayList<StepContribution>(); for (ChunkResponse response : localState.pollChunkResponses()) { StepContribution contribution = response.getStepContribution(); if (logger.isDebugEnabled()) { logger.debug("Applying: " + response); }//from w w w . j a v a 2 s . com contributions.add(contribution); } return contributions; }
From source file:org.springframework.batch.integration.chunk.ChunkResponseTests.java
@Test public void testSerializable() throws Exception { ChunkResponse result = (ChunkResponse) SerializationUtils .deserialize(SerializationUtils.serialize(response)); assertNotNull(result.getStepContribution()); assertEquals(new Long(111L), result.getJobId()); }