Example usage for org.springframework.batch.core.job.flow FlowExecutor close

List of usage examples for org.springframework.batch.core.job.flow FlowExecutor close

Introduction

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

Prototype

void close(FlowExecution result);

Source Link

Document

Chance to clean up resources at the end of a flow (whether it completed successfully or not).

Usage

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

/**
 * @see Flow#resume(String, FlowExecutor)
 */// w  w w .j  av a  2  s.  com
@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;

}