List of usage examples for org.springframework.batch.integration.chunk ChunkResponse getJobId
public Long getJobId()
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. * /* w w w . j a v a 2 s .c om*/ * @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
/** * Get the next result if it is available (within the timeout specified in the gateway), otherwise do nothing. * * @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)//from ww w .ja va2s .co m */ private void getNextResult() throws AsynchronousFailureException { Message<ChunkResponse> message = (Message<ChunkResponse>) messagingGateway.receive(replyChannel); if (message != null) { ChunkResponse payload = message.getPayload(); 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.pushResponse(payload); localState.incrementActual(); if (!payload.isSuccessful()) { throw new AsynchronousFailureException( "Failure or interrupt detected in handler: " + payload.getMessage()); } } }
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()); }