List of usage examples for org.springframework.batch.core.scope.context ChunkContext getStepContext
public StepContext getStepContext()
From source file:org.sbq.batch.tasks.CalculateEventMetricsTask.java
@Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { Date startingFrom = (Date) chunkContext.getStepContext().getJobParameters().get("startingFrom"); Date endingAt = (Date) chunkContext.getStepContext().getJobParameters().get("endingAt"); metricsService.calculateEventMetrics(startingFrom, endingAt); return RepeatStatus.FINISHED; }
From source file:org.sbq.batch.tasks.CalculateOnlineMetricsTask.java
@Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { Date scheduledFireTime = (Date) chunkContext.getStepContext().getJobParameters().get("scheduledFireTime"); metricsService.calculateOnlineMetrics(scheduledFireTime); return RepeatStatus.FINISHED; }
From source file:com.javaetmoi.core.batch.test.EndTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { JobExecution jobExecution = chunkContext.getStepContext().getStepExecution().getJobExecution(); StepExecution resume = getUnpartitionedStepResume(jobExecution); LOG.info("{} masterpiece(s) have been processed", resume.getWriteCount()); return RepeatStatus.FINISHED; }
From source file:org.sbq.batch.tasks.LongRunningBatchTask.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Date scheduledFireTime = (Date) chunkContext.getStepContext().getJobParameters().get("scheduledFireTime"); System.out.println(">>>> LongRunningBatchTask.execute( " + scheduledFireTime.toString() + " )"); int i = 0;//from ww w .jav a2 s . c o m while (i < 600) // we don't pay attention if we are interrupted { i++; try { Thread.sleep(1000L); } catch (InterruptedException e) { Thread.interrupted(); } } return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.complex.crosscutting.interstepcommunication.promotion.ChangingStepExecutionContextTasklet.java
/** {@inheritDoc} */ @Override/* w ww. j a v a 2 s . c o m*/ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // set variable in JobExecutionContext chunkContext.getStepContext().getStepExecution().getExecutionContext().put("value", "foo"); // exit the step return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.complex.crosscutting.interstepcommunication.jobcontext.ChangingJobExecutionContextTasklet.java
/** {@inheritDoc} */ @Override//from w w w . j av a2 s. c o m public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // set variable in JobExecutionContext chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("value", "foo"); // exit the step return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.playground.tasklet.interstepcommunication.ReadingJobExecutionContextTasklet.java
/** {@inheritDoc} */ @Override/*from ww w. jav a2 s .com*/ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // pull variable from JobExecutionContext String value = (String) chunkContext.getStepContext().getStepExecution().getJobExecution() .getExecutionContext().get("value"); LOG.debug("Found value in JobExecutionContext:" + value); // exit the step return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.complex.file.renamefile.simple.SimpleRenameFileTaskletStep.java
/** */ @Override/* w w w . j a v a 2s . co m*/ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // get used output file String outputFilePath = (String) chunkContext.getStepContext().getJobParameters().get("output.file"); UrlResource oldFile = new UrlResource(outputFilePath); // get desired output file name String desiredOutputFilePath = (String) chunkContext.getStepContext().getJobExecutionContext() .get("desired.output.file"); UrlResource newFile = new UrlResource(desiredOutputFilePath); // rename oldFile.getFile().renameTo(newFile.getFile()); return RepeatStatus.FINISHED; }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.tasklets.ProjectsExtractorTasklet.java
/** * {@inheritDoc}// w w w .jav a2s .c om * @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext) */ @Override public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext) throws Exception { final Set<BigInteger> projectsId = (Set<BigInteger>) chunkContext.getStepContext().getJobExecutionContext() .get("mantis.loop.projects_to_process"); if (projectsId != null && !projectsId.isEmpty()) { final BigInteger id = projectsId.iterator().next(); projectsId.remove(id); chunkContext.getStepContext().getStepExecution().getExecutionContext().put("mantis.loop.project_id", id); } else { chunkContext.getStepContext().getStepExecution().getExecutionContext().remove("mantis.loop.project_id"); } return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.complex.crosscutting.interstepcommunication.jobcontext.ReadingJobExecutionContextTasklet.java
/** {@inheritDoc} */ @Override//from ww w . j av a2 s. c o m public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // pull variable from JobExecutionContext, accesses a unmodifiable map String value = (String) chunkContext.getStepContext().getJobExecutionContext().get("value"); // check for the value if (StringUtils.trimToNull(value) != null) { LOG.debug("Found value in JobExecutionContext:" + value); } else { throw new Exception("Did not found value in JobExecutionContext"); } // exit the step return RepeatStatus.FINISHED; }