// Path: examples/src/main/java/fixio/examples/common/Quote.java
// public class Quote {
// 
//     private final double bid;
//     private final double offer;
// 
//     public Quote(double bid, double offer) {
//         this.bid = bid;
//         this.offer = offer;
//     }
// 
//     public double getBid() {
//         return bid;
//     }
// 
//     public double getOffer() {
//         return offer;
//     }
// }
// 
// Path: examples/src/main/java/fixio/examples/common/QuoteGeneratorTask.java
// public class QuoteGeneratorTask implements Runnable {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(QuoteGeneratorTask.class);
//     private final BlockingQueue<Quote> receiver;
// 
//     private static int DATA_SIZE = 1000;
//     private final Quote[] data = new Quote[DATA_SIZE];
// 
//     public QuoteGeneratorTask(BlockingQueue<Quote> receiverQueue) {
//         receiver = receiverQueue;
//         for (int i = 0; i < DATA_SIZE; i++) {
//             data[i] = createQuote(i);
//         }
//     }
// 
//     @Override
//     public void run() {
//         LOGGER.info("Started");
//         final Thread thread = Thread.currentThread();
//         int t = 0;
//         while (!thread.isInterrupted()) {
//             if (receiver.remainingCapacity() > 1000) {
//                 try {
//                     Quote quote = data[t % DATA_SIZE];
//                     t++;
//                     receiver.put(quote);
//                     Thread.yield();
//                 } catch (InterruptedException e) {
//                     LOGGER.info("Interrupted.");
//                     thread.interrupt();
//                     return;
//                 } catch (Throwable e) {
//                     LOGGER.error("Unable to submit quote.", e);
//                 }
//             }
//             Thread.yield();
//         }
//         LOGGER.info("Stopped");
//     }
// 
//     private static Quote createQuote(double t) {
//         double bid = Math.sin(t / 100) * 2 + 0.5;
//         double offer = Math.sin(t - 10 / 100) * 2 + 0.5;
//         return new Quote(bid, offer);
//     }
// 
//     public void stop() {
//         Thread.currentThread().interrupt();
//     }
// }


import fixio.examples.common.Quote;
import fixio.examples.common.QuoteGeneratorTask;
import quickfix.Acceptor;
import quickfix.Application;
import quickfix.ConfigError;
import quickfix.DefaultMessageFactory;
import quickfix.LogFactory;
import quickfix.MemoryStoreFactory;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.SLF4JLogFactory;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;
import java.util.concurrent.ArrayBlockingQueue;
/*
 * Copyright 2014 The FIX.io Project
 *
 * The FIX.io Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package fixio.examples.quickfix;



public class QuickFixServer {

    private final ArrayBlockingQueue<Quote> quoteQueue = new ArrayBlockingQueue<>(8192);
    private Thread generator;
    private QuoteGeneratorTask generatorTask;
    private Acceptor acceptor;

    public QuickFixServer() throws ConfigError {
        SessionSettings settings = new SessionSettings(getClass().getResourceAsStream("/quickfix/quickfix-server.properties"));
        MessageStoreFactory storeFactory = new MemoryStoreFactory();
        LogFactory logFactory = new SLF4JLogFactory(settings);
        MessageFactory messageFactory = new DefaultMessageFactory();

        Application application = new QuickFixStreamingApp(quoteQueue);

        acceptor = new SocketAcceptor(application, storeFactory, settings, logFactory, messageFactory);
    }

    public void start() throws ConfigError {
// Path: examples/src/main/java/fixio/examples/common/Quote.java
// public class Quote {
// 
//     private final double bid;
//     private final double offer;
// 
//     public Quote(double bid, double offer) {
//         this.bid = bid;
//         this.offer = offer;
//     }
// 
//     public double getBid() {
//         return bid;
//     }
// 
//     public double getOffer() {
//         return offer;
//     }
// }
// 
// Path: examples/src/main/java/fixio/examples/common/QuoteGeneratorTask.java
// public class QuoteGeneratorTask implements Runnable {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(QuoteGeneratorTask.class);
//     private final BlockingQueue<Quote> receiver;
// 
//     private static int DATA_SIZE = 1000;
//     private final Quote[] data = new Quote[DATA_SIZE];
// 
//     public QuoteGeneratorTask(BlockingQueue<Quote> receiverQueue) {
//         receiver = receiverQueue;
//         for (int i = 0; i < DATA_SIZE; i++) {
//             data[i] = createQuote(i);
//         }
//     }
// 
//     @Override
//     public void run() {
//         LOGGER.info("Started");
//         final Thread thread = Thread.currentThread();
//         int t = 0;
//         while (!thread.isInterrupted()) {
//             if (receiver.remainingCapacity() > 1000) {
//                 try {
//                     Quote quote = data[t % DATA_SIZE];
//                     t++;
//                     receiver.put(quote);
//                     Thread.yield();
//                 } catch (InterruptedException e) {
//                     LOGGER.info("Interrupted.");
//                     thread.interrupt();
//                     return;
//                 } catch (Throwable e) {
//                     LOGGER.error("Unable to submit quote.", e);
//                 }
//             }
//             Thread.yield();
//         }
//         LOGGER.info("Stopped");
//     }
// 
//     private static Quote createQuote(double t) {
//         double bid = Math.sin(t / 100) * 2 + 0.5;
//         double offer = Math.sin(t - 10 / 100) * 2 + 0.5;
//         return new Quote(bid, offer);
//     }
// 
//     public void stop() {
//         Thread.currentThread().interrupt();
//     }
// }


// Path: examples/src/main/java/fixio/examples/quickfix/QuickFixServer.java
import fixio.examples.common.Quote;
import fixio.examples.common.QuoteGeneratorTask;
import quickfix.Acceptor;
import quickfix.Application;
import quickfix.ConfigError;
import quickfix.DefaultMessageFactory;
import quickfix.LogFactory;
import quickfix.MemoryStoreFactory;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.SLF4JLogFactory;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;
import java.util.concurrent.ArrayBlockingQueue;

/*
 * Copyright 2014 The FIX.io Project
 *
 * The FIX.io Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package fixio.examples.quickfix;



public class QuickFixServer {

    private final ArrayBlockingQueue<Quote> quoteQueue = new ArrayBlockingQueue<>(8192);
    private Thread generator;
    private QuoteGeneratorTask generatorTask;
    private Acceptor acceptor;

    public QuickFixServer() throws ConfigError {
        SessionSettings settings = new SessionSettings(getClass().getResourceAsStream("/quickfix/quickfix-server.properties"));
        MessageStoreFactory storeFactory = new MemoryStoreFactory();
        LogFactory logFactory = new SLF4JLogFactory(settings);
        MessageFactory messageFactory = new DefaultMessageFactory();

        Application application = new QuickFixStreamingApp(quoteQueue);

        acceptor = new SocketAcceptor(application, storeFactory, settings, logFactory, messageFactory);
    }

    public void start() throws ConfigError {
        generatorTask = new QuoteGeneratorTask(quoteQueue);