// Path: spring-mvc-asynch/src/main/java/se/callista/springmvc/asynch/common/statemachine/State.java
// public class State {
// 
//     private static final AtomicLong lastProcessId = new AtomicLong(0);
// 
//     private StateProcessingStepIterator processingSteps;
//     private long processId;
//     private LogHelper log;
//     private StateMachineCallback completionCallback;
//     private String result = "";
// 
//     public State(Iterator<Processor> processingSteps, LogHelper log, StateMachineCallback completionCallback) {
//         this.processingSteps = new StateProcessingStepIterator(processingSteps);
//         this.log = log;
//         this.completionCallback = completionCallback;
//         this.processId = lastProcessId.incrementAndGet();
//     }
// 
//     public LogHelper getLog() {
//         return log;
//     }
//     public long getProcessId() {
//         return processId;
//     }
// 
//     public Iterator<Processor> getProcessingSteps() {
//         return processingSteps;
//     }
//     public int getProcessingStepNo() { return processingSteps.getProcessingStepNo(); }
// 
//     public StateMachineCallback getCompletionCallback() {
//         return completionCallback;
//     }
// 
//     public String appendResult(String newResult) {
//         return result += newResult;
//     }
//     public String getResult() {
//         return result;
//     }
// }
// 
// Path: spring-mvc-asynch/src/main/java/se/callista/springmvc/asynch/common/statemachine/StateMachine.java
// @Component
// public class StateMachine {
// 
//     public void initProcessing(Iterator<Processor> processingSteps, LogHelper log, StateMachineCallback completionCallback) {
//         executeNextStep(new State(processingSteps, log, completionCallback));
//     }
// 
//     public void executeNextStep(State state) {
// 
//         if (state.getProcessingSteps().hasNext()) {
//             // Initiate next processing step...
//             state.getProcessingSteps().next().process(state);
// 
//         } else {
//             // We are done...
//             state.getCompletionCallback().onCompleted(state);
//         }
//     }
// 
// }


import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.callista.springmvc.asynch.common.statemachine.State;
import se.callista.springmvc.asynch.common.statemachine.StateMachine;
package se.callista.springmvc.asynch.pattern.routingslip.nonblocking.statemachine;


public class AsynchProcessorCallback extends AsyncCompletionHandler<Response> {

    private static final Logger LOG = LoggerFactory.getLogger(AsynchProcessorCallback.class);

    private final StateMachine stateMachine;
    private final State state;

//    private long reqId;
//    private AtomicLong concurrentRequests;
//    private DeferredResult<String> deferredResult;

// Path: spring-mvc-asynch/src/main/java/se/callista/springmvc/asynch/common/statemachine/State.java
// public class State {
// 
//     private static final AtomicLong lastProcessId = new AtomicLong(0);
// 
//     private StateProcessingStepIterator processingSteps;
//     private long processId;
//     private LogHelper log;
//     private StateMachineCallback completionCallback;
//     private String result = "";
// 
//     public State(Iterator<Processor> processingSteps, LogHelper log, StateMachineCallback completionCallback) {
//         this.processingSteps = new StateProcessingStepIterator(processingSteps);
//         this.log = log;
//         this.completionCallback = completionCallback;
//         this.processId = lastProcessId.incrementAndGet();
//     }
// 
//     public LogHelper getLog() {
//         return log;
//     }
//     public long getProcessId() {
//         return processId;
//     }
// 
//     public Iterator<Processor> getProcessingSteps() {
//         return processingSteps;
//     }
//     public int getProcessingStepNo() { return processingSteps.getProcessingStepNo(); }
// 
//     public StateMachineCallback getCompletionCallback() {
//         return completionCallback;
//     }
// 
//     public String appendResult(String newResult) {
//         return result += newResult;
//     }
//     public String getResult() {
//         return result;
//     }
// }
// 
// Path: spring-mvc-asynch/src/main/java/se/callista/springmvc/asynch/common/statemachine/StateMachine.java
// @Component
// public class StateMachine {
// 
//     public void initProcessing(Iterator<Processor> processingSteps, LogHelper log, StateMachineCallback completionCallback) {
//         executeNextStep(new State(processingSteps, log, completionCallback));
//     }
// 
//     public void executeNextStep(State state) {
// 
//         if (state.getProcessingSteps().hasNext()) {
//             // Initiate next processing step...
//             state.getProcessingSteps().next().process(state);
// 
//         } else {
//             // We are done...
//             state.getCompletionCallback().onCompleted(state);
//         }
//     }
// 
// }


// Path: spring-mvc-asynch/src/main/java/se/callista/springmvc/asynch/pattern/routingslip/nonblocking/statemachine/AsynchProcessorCallback.java
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.callista.springmvc.asynch.common.statemachine.State;
import se.callista.springmvc.asynch.common.statemachine.StateMachine;

package se.callista.springmvc.asynch.pattern.routingslip.nonblocking.statemachine;


public class AsynchProcessorCallback extends AsyncCompletionHandler<Response> {

    private static final Logger LOG = LoggerFactory.getLogger(AsynchProcessorCallback.class);

    private final StateMachine stateMachine;
    private final State state;

//    private long reqId;
//    private AtomicLong concurrentRequests;
//    private DeferredResult<String> deferredResult;

    public AsynchProcessorCallback(StateMachine stateMachine, State state) {