@Override public TaskletStepBuilder tasklet(Tasklet tasklet) { configureWorkerIntegrationFlow(); return super.tasklet(tasklet); }
/** * @return a new {@link TaskletStep} */ protected TaskletStep createTaskletStep() { TaskletStepBuilder builder = new StepBuilder(name).tasklet(tasklet); enhanceTaskletStepBuilder(builder); return builder.build(); }
@Bean protected Step step1() throws Exception { return steps.get("step1").tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return null; } }).build(); }
@Bean public Step step() { return stepBuilderFactory.get("step1").tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return null; } }).build(); }
@Bean protected Step step3() throws Exception { return steps.get("step3").tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext context) throws Exception { return RepeatStatus.FINISHED; } }).build(); } }
@Bean public Step firstStep() { return stepBuilderFactory.get("firstStep") .tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println(">> Beginning concurrent job test"); return RepeatStatus.FINISHED; } }).build(); }
@Bean public Step lastStep() { return stepBuilderFactory.get("lastStep") .tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println(">> Ending concurrent job test"); return RepeatStatus.FINISHED; } }).build(); }
@Bean Step step1 () { return stepFactory.get("step1").tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return RepeatStatus.FINISHED; } }).build(); }
@Bean protected Step step3() throws Exception { return steps.get("step3").tasklet(tasklet).build(); }
@Bean protected Step step1() throws Exception { return steps.get("step1").tasklet(tasklet()).build(); }
@Bean protected Step step2() throws Exception { return steps.get("step2").tasklet(tasklet()).build(); }
@Bean protected Step step1() throws Exception { return steps.get("step1").tasklet(tasklet()).build(); }
@Bean protected Step step2() throws Exception { return steps.get("step2").tasklet(tasklet()).build(); }
@Bean public Job job() { return this.jobBuilderFactory.get("job") .start(this.stepBuilderFactory.get("step") .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .build()) .build(); } }
@Bean public Flow flow() { return new FlowBuilder<Flow>("flow") .start(stepBuilderFactory.get("flow.step1") .tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return RepeatStatus.FINISHED; } }).build() ).next(stepBuilderFactory.get("flow.step2") .tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return RepeatStatus.FINISHED; } }).build() ).build(); }
@Test public void test() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution( "step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository) .transactionManager(transactionManager).tasklet((contribution, chunkContext) -> null); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); }
@Test public void testAnnotationBasedChunkListenerForTaskletStep() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .tasklet((contribution, chunkContext) -> null) .listener(new AnnotationBasedChunkListener()); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount); assertEquals(1, AnnotationBasedChunkListener.afterChunkCount); }
@Test public void testListeners() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .listener(new InterfaceBasedStepExecutionListener()) .listener(new AnnotationBasedStepExecutionListener()) .tasklet((contribution, chunkContext) -> null); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, InterfaceBasedStepExecutionListener.beforeStepCount); assertEquals(1, InterfaceBasedStepExecutionListener.afterStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.beforeStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.afterStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.beforeChunkCount); assertEquals(1, AnnotationBasedStepExecutionListener.afterChunkCount); }
@Bean public Step step1() { return this.stepBuilderFactory.get("step1") .tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println("Tasklet has run"); return RepeatStatus.FINISHED; } }).build(); }
/** * @return a new {@link TaskletStep} */ protected TaskletStep createTaskletStep() { TaskletStepBuilder builder = new StepBuilder(name).tasklet(tasklet); enhanceTaskletStepBuilder(builder); return builder.build(); }