Changeset 184 in tmcsimulator for trunk/src/atmsdriver/ATMSDriver.java
- Timestamp:
- 10/28/2017 05:24:02 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/atmsdriver/ATMSDriver.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/ATMSDriver.java
r180 r184 17 17 * @version 09/10/2017 18 18 */ 19 public class ATMSDriver implements Runnable { 19 public class ATMSDriver implements Runnable 20 { 20 21 21 22 /** … … 36 37 * @see ATMSDriver 37 38 */ 38 private static enum PROPERTIES { 39 LDS_FILE_NAME("LDSFileName"), 40 LOOPS_FILE_NAME("LoopsFileName"), 41 HIGHWAY_META_FILE("HighwayMetaFileName"), 39 private static enum PROPERTIES 40 { 41 HIGHWAYS_MAP_FILE_NAME("HighwaysMapFileName"), 42 42 EXCHANGE_FILE_NAME("ExchangeFileName"), 43 43 FEP_WRITER_HOST("FEPWriterHost"), … … 46 46 public String name; 47 47 48 private PROPERTIES(String n) { 48 private PROPERTIES(String n) 49 { 49 50 name = n; 50 51 } … … 67 68 68 69 @Override 69 public void run() { 70 public void run() 71 { 70 72 // Check for packets and update the simulator 71 while (true) { 73 while (true) 74 { 72 75 // Flush the input file 73 76 ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 74 77 .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 75 78 76 try { 79 try 80 { 77 81 highways.writeToFEP(); 78 } catch (SimulationException ex) { 79 System.out.println("Skipping writeToFEP..."); 82 } catch (SimulationException ex) 83 { 84 System.out.println("Skipping writeToFEP..."); 80 85 } 81 86 // Update if exchangeInfo is recieved 82 if (exInfo != null) { 87 if (exInfo != null) 88 { 83 89 // TODO: handle this condition 84 90 Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null"); … … 86 92 87 93 // Wait for FEP Sim to process the data we just sent 88 try { 94 try 95 { 89 96 Thread.sleep(SLEEP_TIME); 90 } catch (InterruptedException ie) { 97 } catch (InterruptedException ie) 98 { 91 99 ie.printStackTrace(); 92 100 } … … 94 102 } 95 103 96 public ATMSDriver(String propertiesFile) { 104 public ATMSDriver(String propertiesFile) 105 { 97 106 // verify properties file 98 if (!verifyProperties(propertiesFile)) { 107 if (!verifyProperties(propertiesFile)) 108 { 99 109 System.exit(0); 100 110 } … … 102 112 highways = new Highways( 103 113 ATMSDriverProperties.getProperty( 104 PROPERTIES.LDS_FILE_NAME.name), 105 ATMSDriverProperties.getProperty( 106 PROPERTIES.LOOPS_FILE_NAME.name), 107 ATMSDriverProperties.getProperty( 108 PROPERTIES.HIGHWAY_META_FILE.name), 114 PROPERTIES.HIGHWAYS_MAP_FILE_NAME.name), 109 115 ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name), 110 116 Integer.parseInt(ATMSDriverProperties.getProperty( … … 113 119 exchangeReader = new ExchangeReader(); 114 120 } 115 121 116 122 /** 117 123 * Verifies that the properties file has all necessary properties. 118 * 124 * 119 125 * @param propertiesFile 120 * @return 126 * @return 121 127 */ 122 private boolean verifyProperties(String propertiesFile) { 128 private boolean verifyProperties(String propertiesFile) 129 { 123 130 // Load the properties file. 124 try { 131 try 132 { 125 133 ATMSDriverProperties = new Properties(); 126 134 ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 127 } catch (Exception e) { 135 } catch (Exception e) 136 { 128 137 ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 129 138 "Constructor", "Exception in reading properties file.", e); … … 136 145 * Runs the ATMS Driver. 137 146 */ 138 public static void main(String[] args) { 139 try { 140 if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 147 public static void main(String[] args) 148 { 149 try 150 { 151 if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) 152 { 141 153 // Create and run the ATMSDriver thread 142 154 ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 143 155 Thread ATMSDriverThread = new Thread(atmsDriver); 144 156 ATMSDriverThread.start(); 145 157 146 158 // run the console driver, pass it the atmsDriver highways model 147 159 ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways); 148 149 } else { 160 161 } else 162 { 150 163 throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 151 164 } 152 } catch (Exception e) { 165 } catch (Exception e) 166 { 153 167 ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 154 168 "Error occured initializing application", e);
Note: See TracChangeset
for help on using the changeset viewer.
