Example usage for org.springframework.batch.core.job.flow State handle

List of usage examples for org.springframework.batch.core.job.flow State handle

Introduction

In this page you can find the example usage for org.springframework.batch.core.job.flow State handle.

Prototype

FlowExecutionStatus handle(FlowExecutor executor) throws Exception;

Source Link

Document

Handle some business or processing logic and return a status that can be used to drive a flow to the next State .

Usage

From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java

/**
 * @see Flow#resume(String, FlowExecutor)
 *///from w  w  w .ja  v  a2  s .  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;

}