List of usage examples for org.springframework.batch.core.job.flow State getName
String getName();
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
/** * @see Flow#start(FlowExecutor)//from w ww . j a v a 2s . c om */ @Override public FlowExecution start(FlowExecutor executor) throws FlowExecutionException { if (startState == null) { initializeTransitions(); } State state = startState; String stateName = state.getName(); return resume(stateName, executor); }
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
/** * @see Flow#resume(String, FlowExecutor) *//* w w w . ja v a2s .co m*/ @Override public FlowExecution resume(String stateName, FlowExecutor executor) throws FlowExecutionException { FlowExecutionStatus status = FlowExecutionStatus.UNKNOWN; State state = stateMap.get(stateName); if (logger.isDebugEnabled()) { logger.debug("Resuming state=" + stateName + " with status=" + status); } StepExecution stepExecution = null; // Terminate if there are no more states while (isFlowContinued(state, status, stepExecution)) { stateName = state.getName(); try { if (logger.isDebugEnabled()) { logger.debug("Handling state=" + stateName); } status = state.handle(executor); stepExecution = executor.getStepExecution(); } catch (FlowExecutionException e) { executor.close(new FlowExecution(stateName, status)); throw e; } catch (Exception e) { executor.close(new FlowExecution(stateName, status)); throw new FlowExecutionException( String.format("Ended flow=%s at state=%s with exception", name, stateName), e); } if (logger.isDebugEnabled()) { logger.debug("Completed state=" + stateName + " with status=" + status); } state = nextState(stateName, status, stepExecution); } FlowExecution result = new FlowExecution(stateName, status); executor.close(result); return result; }
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
protected boolean isFlowContinued(State state, FlowExecutionStatus status, StepExecution stepExecution) { boolean continued = true; continued = state != null && status != FlowExecutionStatus.STOPPED; if (stepExecution != null) { Boolean reRun = (Boolean) stepExecution.getExecutionContext().get("batch.restart"); Boolean executed = (Boolean) stepExecution.getExecutionContext().get("batch.executed"); if ((executed == null || !executed) && reRun != null && reRun && status == FlowExecutionStatus.STOPPED && !state.getName().endsWith(stepExecution.getStepName())) { continued = true;/*from w w w . j av a 2 s . c o m*/ } } return continued; }
From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java
private boolean stateNameEndsWithStepName(State state, StepExecution stepExecution) { return !(stepExecution == null || state == null) && !state.getName().endsWith(stepExecution.getStepName()); }
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./*from w w w . j a v a 2s . 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(); }