Example usage for org.springframework.batch.core.job.flow.support StateTransition matches

List of usage examples for org.springframework.batch.core.job.flow.support StateTransition matches

Introduction

In this page you can find the example usage for org.springframework.batch.core.job.flow.support StateTransition matches.

Prototype

public boolean matches(String status) 

Source Link

Document

Check if the provided status matches the pattern, signalling that the next State should be executed.

Usage

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 a  va  2 s. com*/
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);

}