View Javadoc

1   /*
2    * Copyright 2006-2011 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.core.step.builder;
17  
18  import org.springframework.batch.core.Job;
19  import org.springframework.batch.core.Step;
20  import org.springframework.batch.core.job.flow.Flow;
21  import org.springframework.batch.core.partition.support.Partitioner;
22  import org.springframework.batch.core.step.tasklet.Tasklet;
23  import org.springframework.batch.repeat.CompletionPolicy;
24  
25  /**
26   * Convenient entry point for building all kinds of steps. Use this as a factory for fluent builders of any step.
27   * 
28   * @author Dave Syer
29   * 
30   * @since 2.2
31   */
32  public class StepBuilder extends StepBuilderHelper<StepBuilder> {
33  
34  	/**
35  	 * Initialize a step builder for a step with the given name.
36  	 * 
37  	 * @param name the name of the step
38  	 */
39  	public StepBuilder(String name) {
40  		super(name);
41  	}
42  
43  	/**
44  	 * Build a step with a custom tasklet, not necessarily item processing.
45  	 * 
46  	 * @param tasklet a tasklet
47  	 * @return a {@link TaskletStepBuilder}
48  	 */
49  	public TaskletStepBuilder tasklet(Tasklet tasklet) {
50  		return new TaskletStepBuilder(this).tasklet(tasklet);
51  	}
52  
53  	/**
54  	 * Build a step that processes items in chunks with the size provided. To extend the step to being fault tolerant,
55  	 * call the {@link SimpleStepBuilder#faultTolerant()} method on the builder.
56  	 * 
57  	 * @param chunkSize the chunk size (commit interval)
58  	 * @return a {@link SimpleStepBuilder}
59  	 */
60  	public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize) {
61  		return new SimpleStepBuilder<I, O>(this).chunk(chunkSize);
62  	}
63  
64  	/**
65  	 * Build a step that processes items in chunks with the completion policy provided. To extend the step to being
66  	 * fault tolerant, call the {@link SimpleStepBuilder#faultTolerant()} method on the builder.
67  	 * 
68  	 * @param completionPolicy the completion policy to use to control chunk processing
69  	 * @return a {@link SimpleStepBuilder}
70  	 */
71  	public <I, O> SimpleStepBuilder<I, O> chunk(CompletionPolicy completionPolicy) {
72  		return new SimpleStepBuilder<I, O>(this).chunk(completionPolicy);
73  	}
74  
75  	/**
76  	 * Create a partition step builder for a remote (or local) step.
77  	 * 
78  	 * @param stepName the name of the remote or delegate step
79  	 * @param partitioner a partitioner to be used to construct new step executions
80  	 * @return a {@link PartitionStepBuilder}
81  	 */
82  	public PartitionStepBuilder partitioner(String stepName, Partitioner partitioner) {
83  		return new PartitionStepBuilder(this).partitioner(stepName, partitioner);
84  	}
85  
86  	/**
87  	 * Create a partition step builder for a remote (or local) step.
88  	 * 
89  	 * @param step the step to execute in parallel
90  	 * @param partitioner a partitioner to be used to construct new step executions
91  	 * @return a PartitionStepBuilder
92  	 */
93  	public PartitionStepBuilder partitioner(Step step) {
94  		return new PartitionStepBuilder(this).step(step);
95  	}
96  
97  	/**
98  	 * Create a new step builder that will execute a job.
99  	 * 
100 	 * @param job a job to execute
101 	 * @return a {@link JobStepBuilder}
102 	 */
103 	public JobStepBuilder job(Job job) {
104 		return new JobStepBuilder(this).job(job);
105 	}
106 
107 	/**
108 	 * Create a new step builder that will execute a flow.
109 	 * 
110 	 * @param flow a flow to execute
111 	 * @return a {@link FlowStepBuilder}
112 	 */
113 	public FlowStepBuilder flow(Flow flow) {
114 		return new FlowStepBuilder(this).flow(flow);
115 	}
116 
117 }