// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/NoodleBar.java
// public interface NoodleBar {
// 
//     /**
//      * Places a noodle order.
//      * 
//      * @param order
//      *            the new noodle order being placed.
//      */
//     public void placeOrder(NoodleOrder order);
// 
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/NoodleOrder.java
// public class NoodleOrder {
//     private OrderStatus status = NEW;
// 
//     public synchronized void setStatus(OrderStatus status) {
//         this.status = status;
//     }
// 
//     public OrderStatus getStatus() {
//         return this.status;
//     }
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/OrderStatus.java
// public enum OrderStatus {
//     NEW, RECEIVED, REJECTED, BEING_COOKED, COMPLETE
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/throughput/NoodleOrderThroughputMonitor.java
// public class NoodleOrderThroughputMonitor implements ThroughputMonitor {
//     private long averageThroughput = 0l;
// 
//     public synchronized void receiveCurrentThroughput(long ordersProcessedPerDuration) {
//         this.averageThroughput = ordersProcessedPerDuration;
//     }
// 
//     public synchronized long getAverageThroughput() {
//         return averageThroughput;
//     }
// }


import org.opencredo.esper.samples.noodlebar.domain.NoodleBar;
import org.opencredo.esper.samples.noodlebar.domain.NoodleOrder;
import org.opencredo.esper.samples.noodlebar.domain.OrderStatus;
import org.opencredo.esper.samples.noodlebar.domain.throughput.NoodleOrderThroughputMonitor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
            // Sleep a little bit between orders
            try {
                Thread.sleep(5l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        boolean processing = true;
        while (processing) {
            processing = false;
            for (NoodleOrder order : orders) {
                if (order.getStatus() == OrderStatus.COMPLETE) {
                    System.out.println("Order Completed!");
                } else {
                    processing = true;
                }
            }
            try {
                Thread.sleep(20l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private static void initializeDependencies() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "classpath:async-noodlebar-context.xml");

// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/NoodleBar.java
// public interface NoodleBar {
// 
//     /**
//      * Places a noodle order.
//      * 
//      * @param order
//      *            the new noodle order being placed.
//      */
//     public void placeOrder(NoodleOrder order);
// 
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/NoodleOrder.java
// public class NoodleOrder {
//     private OrderStatus status = NEW;
// 
//     public synchronized void setStatus(OrderStatus status) {
//         this.status = status;
//     }
// 
//     public OrderStatus getStatus() {
//         return this.status;
//     }
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/OrderStatus.java
// public enum OrderStatus {
//     NEW, RECEIVED, REJECTED, BEING_COOKED, COMPLETE
// }
// 
// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/domain/throughput/NoodleOrderThroughputMonitor.java
// public class NoodleOrderThroughputMonitor implements ThroughputMonitor {
//     private long averageThroughput = 0l;
// 
//     public synchronized void receiveCurrentThroughput(long ordersProcessedPerDuration) {
//         this.averageThroughput = ordersProcessedPerDuration;
//     }
// 
//     public synchronized long getAverageThroughput() {
//         return averageThroughput;
//     }
// }


// Path: esper-samples/simple-esper-si-sample/src/main/java/org/opencredo/esper/samples/noodlebar/main/AsyncNoodleOrderGenerator.java
import org.opencredo.esper.samples.noodlebar.domain.NoodleBar;
import org.opencredo.esper.samples.noodlebar.domain.NoodleOrder;
import org.opencredo.esper.samples.noodlebar.domain.OrderStatus;
import org.opencredo.esper.samples.noodlebar.domain.throughput.NoodleOrderThroughputMonitor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

            // Sleep a little bit between orders
            try {
                Thread.sleep(5l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        boolean processing = true;
        while (processing) {
            processing = false;
            for (NoodleOrder order : orders) {
                if (order.getStatus() == OrderStatus.COMPLETE) {
                    System.out.println("Order Completed!");
                } else {
                    processing = true;
                }
            }
            try {
                Thread.sleep(20l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private static void initializeDependencies() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "classpath:async-noodlebar-context.xml");

        noodleBar = (NoodleBar) applicationContext.getBean(NOODLE_BAR_BEAN_NAME);