Changeset 184 in tmcsimulator for trunk/src/atmsdriver/ATMSDriver.java


Ignore:
Timestamp:
10/28/2017 05:24:02 PM (9 years ago)
Author:
jtorres
Message:

highways.java: converted to immutable, removed use of FEPLineLoader and added loadLines(), loadLine(), loadStation(), and loadLoop() methods. Renamed loadHighways() to configureHighways(), renamed writeHighwaysMeta() to getHighwaysMeta() which now returns a String containing metadata instead of opening a file and writing to it, which is more flexible. FEPLineLoader.java: deleted, no longer need it. FEPLine.java: converted to immutable, removed unnecessary member variables and adjusted all methods accordingly. Station.java: MLTotVol() and OppTotVol?() are now being updated at end of updateByDirection(). ATMSDriver.java: Now using one config file: highways_fullmap.txt, as opposed to the older lds.txt and loop.txt files. config/vds_data: added highways_fullmap.txt. config/atms_driver_config.properties, atms_driver_config_local.properties: updated config to reflect use of highways_fullmap.txt instead of old loop.txt and lds.txt configuration. ATMSBatchDriver.java: conformed highways initialization in constructor to reflect use of highways_fullmap.txt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/ATMSDriver.java

    r180 r184  
    1717 * @version 09/10/2017 
    1818 */ 
    19 public class ATMSDriver implements Runnable { 
     19public class ATMSDriver implements Runnable 
     20{ 
    2021 
    2122    /** 
     
    3637     * @see ATMSDriver 
    3738     */ 
    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"), 
    4242        EXCHANGE_FILE_NAME("ExchangeFileName"), 
    4343        FEP_WRITER_HOST("FEPWriterHost"), 
     
    4646        public String name; 
    4747 
    48         private PROPERTIES(String n) { 
     48        private PROPERTIES(String n) 
     49        { 
    4950            name = n; 
    5051        } 
     
    6768 
    6869    @Override 
    69     public void run() { 
     70    public void run() 
     71    { 
    7072        // Check for packets and update the simulator 
    71         while (true) { 
     73        while (true) 
     74        { 
    7275            // Flush the input file 
    7376            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 
    7477                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 
    7578 
    76             try { 
     79            try 
     80            { 
    7781                highways.writeToFEP(); 
    78             } catch (SimulationException ex) { 
    79                             System.out.println("Skipping writeToFEP..."); 
     82            } catch (SimulationException ex) 
     83            { 
     84                System.out.println("Skipping writeToFEP..."); 
    8085            } 
    8186            // Update if exchangeInfo is recieved 
    82             if (exInfo != null) { 
     87            if (exInfo != null) 
     88            { 
    8389                // TODO: handle this condition 
    8490                Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null"); 
     
    8692 
    8793            // Wait for FEP Sim to process the data we just sent 
    88             try { 
     94            try 
     95            { 
    8996                Thread.sleep(SLEEP_TIME); 
    90             } catch (InterruptedException ie) { 
     97            } catch (InterruptedException ie) 
     98            { 
    9199                ie.printStackTrace(); 
    92100            } 
     
    94102    } 
    95103 
    96     public ATMSDriver(String propertiesFile) { 
     104    public ATMSDriver(String propertiesFile) 
     105    { 
    97106        // verify properties file 
    98         if (!verifyProperties(propertiesFile)) { 
     107        if (!verifyProperties(propertiesFile)) 
     108        { 
    99109            System.exit(0); 
    100110        } 
     
    102112        highways = new Highways( 
    103113                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), 
    109115                ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name), 
    110116                Integer.parseInt(ATMSDriverProperties.getProperty( 
     
    113119        exchangeReader = new ExchangeReader(); 
    114120    } 
    115      
     121 
    116122    /** 
    117123     * Verifies that the properties file has all necessary properties. 
    118      *  
     124     * 
    119125     * @param propertiesFile 
    120      * @return  
     126     * @return 
    121127     */ 
    122     private boolean verifyProperties(String propertiesFile) { 
     128    private boolean verifyProperties(String propertiesFile) 
     129    { 
    123130        // Load the properties file. 
    124         try { 
     131        try 
     132        { 
    125133            ATMSDriverProperties = new Properties(); 
    126134            ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 
    127         } catch (Exception e) { 
     135        } catch (Exception e) 
     136        { 
    128137            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 
    129138                    "Constructor", "Exception in reading properties file.", e); 
     
    136145     * Runs the ATMS Driver. 
    137146     */ 
    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            { 
    141153                // Create and run the ATMSDriver thread 
    142154                ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 
    143155                Thread ATMSDriverThread = new Thread(atmsDriver); 
    144156                ATMSDriverThread.start(); 
    145                  
     157 
    146158                // run the console driver, pass it the atmsDriver highways model 
    147159                ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways); 
    148                  
    149             } else { 
     160 
     161            } else 
     162            { 
    150163                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 
    151164            } 
    152         } catch (Exception e) { 
     165        } catch (Exception e) 
     166        { 
    153167            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 
    154168                    "Error occured initializing application", e); 
Note: See TracChangeset for help on using the changeset viewer.