View Javadoc

1   /*
2    * Copyright 2006-2007 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.job.flow;
17  
18  import org.springframework.batch.core.JobExecution;
19  import org.springframework.batch.core.JobInterruptedException;
20  import org.springframework.batch.core.StartLimitExceededException;
21  import org.springframework.batch.core.Step;
22  import org.springframework.batch.core.StepExecution;
23  import org.springframework.batch.core.repository.JobRestartException;
24  
25  /**
26   * Context and execution strategy for {@link FlowJob} to allow it to delegate
27   * its execution step by step.
28   * 
29   * @author Dave Syer
30   * @since 2.0
31   */
32  public interface FlowExecutor {
33  
34  	/**
35  	 * @param step a {@link Step} to execute
36  	 * @return the exit status that drives the surrounding {@link Flow}
37  	 * @throws StartLimitExceededException
38  	 * @throws JobRestartException
39  	 * @throws JobInterruptedException
40  	 */
41  	String executeStep(Step step) throws JobInterruptedException, JobRestartException, StartLimitExceededException;
42  
43  	/**
44  	 * @return the current {@link JobExecution}
45  	 */
46  	JobExecution getJobExecution();
47  
48  	/**
49  	 * @return the latest {@link StepExecution} or null if there is none
50  	 */
51  	StepExecution getStepExecution();
52  
53  	/**
54  	 * Chance to clean up resources at the end of a flow (whether it completed
55  	 * successfully or not).
56  	 * 
57  	 * @param result the final {@link FlowExecution}
58  	 */
59  	void close(FlowExecution result);
60  
61  	/**
62  	 * Handle any status changes that might be needed at the start of a state.
63  	 */
64  	void abandonStepExecution();
65  
66  	/**
67  	 * Handle any status changes that might be needed in the
68  	 * {@link JobExecution}.
69  	 */
70  	void updateJobExecutionStatus(FlowExecutionStatus status);
71  
72  	/**
73  	 * @return true if the flow is at the beginning of a restart
74  	 */
75  	boolean isRestart();
76  
77  	/**
78  	 * @param code the label for the exit status when a flow or sub-flow ends
79  	 */
80  	void addExitStatus(String code);
81  
82  }