001/* 002 * Copyright 2006-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.core.job.flow; 017 018import org.springframework.batch.core.JobExecution; 019import org.springframework.batch.core.JobInterruptedException; 020import org.springframework.batch.core.StartLimitExceededException; 021import org.springframework.batch.core.Step; 022import org.springframework.batch.core.StepExecution; 023import org.springframework.batch.core.repository.JobRestartException; 024import org.springframework.lang.Nullable; 025 026/** 027 * Context and execution strategy for {@link FlowJob} to allow it to delegate 028 * its execution step by step. 029 * 030 * @author Dave Syer 031 * @author Mahmoud Ben Hassine 032 * @since 2.0 033 */ 034public interface FlowExecutor { 035 036 /** 037 * @param step a {@link Step} to execute 038 * @return the exit status that drives the surrounding {@link Flow} 039 * @throws StartLimitExceededException thrown if start limit is exceeded. 040 * @throws JobRestartException thrown if job restart is not allowed. 041 * @throws JobInterruptedException thrown if job was interrupted. 042 */ 043 String executeStep(Step step) throws JobInterruptedException, JobRestartException, StartLimitExceededException; 044 045 /** 046 * @return the current {@link JobExecution} 047 */ 048 JobExecution getJobExecution(); 049 050 /** 051 * @return the latest {@link StepExecution} or null if there is none 052 */ 053 @Nullable 054 StepExecution getStepExecution(); 055 056 /** 057 * Chance to clean up resources at the end of a flow (whether it completed 058 * successfully or not). 059 * 060 * @param result the final {@link FlowExecution} 061 */ 062 void close(FlowExecution result); 063 064 /** 065 * Handle any status changes that might be needed at the start of a state. 066 */ 067 void abandonStepExecution(); 068 069 /** 070 * Handle any status changes that might be needed in the 071 * {@link JobExecution}. 072 * 073 * @param status status to update the {@link JobExecution} to. 074 */ 075 void updateJobExecutionStatus(FlowExecutionStatus status); 076 077 /** 078 * @return true if the flow is at the beginning of a restart 079 */ 080 boolean isRestart(); 081 082 /** 083 * @param code the label for the exit status when a flow or sub-flow ends 084 */ 085 void addExitStatus(String code); 086 087}