List of usage examples for org.springframework.batch.core.job.flow.support StateTransition isEnd
public boolean isEnd()
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
/** * @return the next {@link Step} (or null if this is the end) * @throws org.springframework.batch.core.job.flow.FlowExecutionException *//*from w ww . j av a 2 s . co m*/ protected State nextState(String stateName, FlowExecutionStatus status, StepExecution stepExecution) throws FlowExecutionException { Set<StateTransition> set = transitionMap.get(stateName); if (set == null) { throw new FlowExecutionException( String.format("No transitions found in flow=%s for state=%s", getName(), stateName)); } String next = null; String exitCode = status.getName(); for (StateTransition stateTransition : set) { if (stateTransition.matches(exitCode) || (exitCode.equals("PENDING") && stateTransition.matches("STOPPED"))) { if (stateTransition.isEnd()) { // End of job return null; } next = stateTransition.getNext(); break; } } if (next == null) { throw new FlowExecutionException( String.format("Next state not found in flow=%s for state=%s with exit status=%s", getName(), stateName, status.getName())); } if (!stateMap.containsKey(next)) { throw new FlowExecutionException( String.format("Next state not specified in flow=%s for next=%s", getName(), next)); } return stateMap.get(next); }
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
/** * Analyse the transitions provided and generate all the information needed * to execute the flow.// w ww. j a v a2 s. c o m */ private void initializeTransitions() { startState = null; transitionMap.clear(); stateMap.clear(); boolean hasEndStep = false; if (stateTransitions.isEmpty()) { throw new IllegalArgumentException( "No start state was found. You must specify at least one step in a job."); } for (StateTransition stateTransition : stateTransitions) { State state = stateTransition.getState(); String stateName = state.getName(); stateMap.put(stateName, state); } for (StateTransition stateTransition : stateTransitions) { State state = stateTransition.getState(); if (!stateTransition.isEnd()) { String next = stateTransition.getNext(); if (!stateMap.containsKey(next)) { throw new IllegalArgumentException("Missing state for [" + stateTransition + "]"); } } else { hasEndStep = true; } String name = state.getName(); Set<StateTransition> set = transitionMap.get(name); if (set == null) { // If no comparator is provided, we will maintain the order of insertion if (stateTransitionComparator == null) { set = new LinkedHashSet<StateTransition>(); } else { set = new TreeSet<StateTransition>(stateTransitionComparator); } transitionMap.put(name, set); } set.add(stateTransition); } if (!hasEndStep) { throw new IllegalArgumentException( "No end state was found. You must specify at least one transition with no next state."); } startState = stateTransitions.get(0).getState(); }