package com.henrypump.poc; import java.time.ZonedDateTime; /** * Created by patrickjmcd on 2/1/17. * POC Class * */ public class POC implements Runnable{ protected Well thisWell; private Thread t; private boolean ioEnabled; POC(String dbHostname){ ioEnabled = true; thisWell = new Well(dbHostname, 99, 99, 7); thisWell.getWellSetup(); } POC(String simFileName, boolean ioEnabled, String dbHostname){ this.ioEnabled = ioEnabled; if (this.ioEnabled) { thisWell = new Well(dbHostname, simFileName,99, 99, 7); } else { thisWell = new Well(dbHostname, simFileName,99, 99, 99); } thisWell.getWellSetup(); } public void run(){ new Thread(new CLScanner(this)).start(); if(ioEnabled){ new Thread(new IOControl(this)).start(); } long sleepMilliseconds = (long) (thisWell.getDt() * 1000); thisWell.checkSafeties(); while (true) { for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) { thisWell.eval(i); try { Thread.sleep(sleepMilliseconds); } catch (InterruptedException e) { e.printStackTrace(); } } } } public void start () { System.out.println("Starting POC Thread"); if (t == null) { t = new Thread (this, "POC-Thread"); t.start (); } } public static void main(String[] args) { if (args[0].equals("help")){ System.out.println("Pass command line parameters..."); System.out.println("============="); System.out.println(""); System.out.println("Simulation Mode:"); System.out.println("-------------"); System.out.println(" "); System.out.println(""); System.out.println("IO Mode:"); System.out.println("-------------"); System.out.println(""); System.out.println(""); System.out.println("If updating config via json file, place a config file named 'wellSetup.json' in the project directory."); System.exit(2); } String dbHostname = "localhost"; if (args.length > 2){ dbHostname = args[2]; } if (args.length == 1){ dbHostname = args[1]; } if (args.length < 2){ final POC realPOC = new POC(dbHostname); try { WebServer httpServer = new WebServer(8000, realPOC); } catch (Exception e){ System.out.println("problem starting web server"); System.out.println(e); } realPOC.start(); } else { final POC simPOC = new POC(args[0], args[1].equals("true"), dbHostname); try { WebServer httpServer = new WebServer(8000, simPOC); } catch (Exception e){ System.out.println("problem starting web server"); System.out.println(e); } simPOC.start(); } } }