@Test public void stepExecutionRequestShouldBeDeserializableWithJackson() throws IOException { // when StepExecutionRequest deserializedRequest = this.objectMapper.readValue(SERIALIZED_REQUEST, StepExecutionRequest.class); // then Assert.assertNotNull(deserializedRequest); Assert.assertEquals("step", deserializedRequest.getStepName()); Assert.assertEquals(1L, deserializedRequest.getJobExecutionId().longValue()); Assert.assertEquals(1L, deserializedRequest.getStepExecutionId().longValue()); } }
private Message<StepExecutionRequest> createMessage(int sequenceNumber, int sequenceSize, StepExecutionRequest stepExecutionRequest, PollableChannel replyChannel) { return MessageBuilder.withPayload(stepExecutionRequest).setSequenceNumber(sequenceNumber) .setSequenceSize(sequenceSize) .setCorrelationId(stepExecutionRequest.getJobExecutionId() + ":" + stepExecutionRequest.getStepName()) .setReplyChannel(replyChannel) .build(); } }
@Test public void stepExecutionRequestShouldBeSerializableWithJackson() throws IOException { // given StepExecutionRequest request = new StepExecutionRequest("step", 1L, 1L); // when String serializedRequest = this.objectMapper.writeValueAsString(request); // then Assert.assertEquals(SERIALIZED_REQUEST, serializedRequest); }
/** * Sends {@link StepExecutionRequest} objects to the request channel of the {@link MessagingTemplate}, and then * receives the result back as a list of {@link StepExecution} on a reply channel. Use the {@link #aggregate(List)} * method as an aggregator of the individual remote replies. The receive timeout needs to be set realistically in * the {@link MessagingTemplate} <b>and</b> the aggregator, so that there is a good chance of all work being done. * * @see PartitionHandler#handle(StepExecutionSplitter, StepExecution) */ public Collection<StepExecution> handle(StepExecutionSplitter stepExecutionSplitter, final StepExecution masterStepExecution) throws Exception { final Set<StepExecution> split = stepExecutionSplitter.split(masterStepExecution, gridSize); if(CollectionUtils.isEmpty(split)) { return split; } int count = 0; for (StepExecution stepExecution : split) { Message<StepExecutionRequest> request = createMessage(count++, split.size(), new StepExecutionRequest( stepName, stepExecution.getJobExecutionId(), stepExecution.getId()), replyChannel); if (logger.isDebugEnabled()) { logger.debug("Sending request: " + request); } messagingGateway.send(request); } if(!pollRepositoryForResults) { return receiveReplies(replyChannel); } else { return pollReplies(masterStepExecution, split); } }
@ServiceActivator public StepExecution handle(StepExecutionRequest request) { Long jobExecutionId = request.getJobExecutionId(); Long stepExecutionId = request.getStepExecutionId(); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException("No StepExecution could be located for this request: " + request); } String stepName = request.getStepName(); Step step = stepLocator.getStep(stepName); if (step == null) { throw new NoSuchStepException(String.format("No Step with name [%s] could be located.", stepName)); } try { step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); // The receiver should update the stepExecution in repository } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); // The receiver should update the stepExecution in repository } return stepExecution; }