List of usage examples for org.springframework.batch.core StepContribution setExitStatus
public void setExitStatus(ExitStatus status)
From source file:org.obiba.onyx.core.etl.participant.impl.DeleteUnreceivedParticipantsTasklet.java
public RepeatStatus execute(StepContribution stepContribution, ChunkContext context) throws Exception { if (log.isDebugEnabled()) { log.debug("e:DeleteUnreceivedParticipantsTasklet.execute() "); }//from w ww .j av a 2s. c o m try { if (isUpdateAvailable()) { log.debug("About to invoke cleanUpAppointment()"); participantService.cleanUpAppointment(); log.debug("About to set exit status: UPDATE"); stepContribution.setExitStatus(new ExitStatus("UPDATE")); } else { log.debug("About to set exit status: NO UPDATE"); stepContribution.setExitStatus(new ExitStatus("NO UPDATE")); } log.debug("About to return repeat status: FINISHED"); return RepeatStatus.FINISHED; } finally { if (log.isDebugEnabled()) { log.debug("x:DeleteUnreceivedParticipantsTasklet.execute() "); } } }
From source file:es.fcs.batch.integration.chunk.MyRemoteChunkHandlerFactoryBean.java
/** * Update a StepContribution with all the data from a StepContributionSource. The filter and write conuts plus the * exit status will be updated to reflect the data in the source. * //w ww . jav a 2s . co m * @param contribution the current contribution * @param stepContributionSource a source of StepContributions */ protected void updateStepContribution(StepContribution contribution, StepContributionSource stepContributionSource) { for (StepContribution result : stepContributionSource.getStepContributions()) { contribution.incrementFilterCount(result.getFilterCount()); contribution.incrementWriteCount(result.getWriteCount()); for (int i = 0; i < result.getProcessSkipCount(); i++) { contribution.incrementProcessSkipCount(); } for (int i = 0; i < result.getWriteSkipCount(); i++) { contribution.incrementWriteSkipCount(); } contribution.setExitStatus(contribution.getExitStatus().and(result.getExitStatus())); } }
From source file:org.springframework.batch.core.step.tasklet.SystemCommandTasklet.java
/** * Execute system command and map its exit code to {@link ExitStatus} using * {@link SystemProcessExitCodeMapper}./*w w w. j ava 2 s.c o m*/ */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { FutureTask<Integer> systemCommandTask = new FutureTask<Integer>(new Callable<Integer>() { @Override public Integer call() throws Exception { Process process = Runtime.getRuntime().exec(command, environmentParams, workingDirectory); return process.waitFor(); } }); long t0 = System.currentTimeMillis(); taskExecutor.execute(systemCommandTask); while (true) { Thread.sleep(checkInterval);//moved to the end of the logic if (stoppable) { JobExecution jobExecution = jobExplorer .getJobExecution(chunkContext.getStepContext().getStepExecution().getJobExecutionId()); if (jobExecution.isStopping()) { stopped = true; } } if (systemCommandTask.isDone()) { contribution.setExitStatus(systemProcessExitCodeMapper.getExitStatus(systemCommandTask.get())); return RepeatStatus.FINISHED; } else if (System.currentTimeMillis() - t0 > timeout) { systemCommandTask.cancel(interruptOnCancel); throw new SystemCommandException("Execution of system command did not finish within the timeout"); } else if (execution.isTerminateOnly()) { systemCommandTask.cancel(interruptOnCancel); throw new JobInterruptedException( "Job interrupted while executing system command '" + command + "'"); } else if (stopped) { systemCommandTask.cancel(interruptOnCancel); contribution.setExitStatus(ExitStatus.STOPPED); return RepeatStatus.FINISHED; } } }