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


Ignore:
Timestamp:
10/05/2017 12:51:23 PM (9 years ago)
Author:
jtorres
Message:

new atmsdriver package in trunk. fep_rpc_client dynamic data packing added in branches. fep_rpc_client refactored data packing code into static DataPacker? class. Added vds_data folder into config/. Added new project configuration for ATMSDriver.

Location:
trunk/src/atmsdriver
Files:
1 added
1 copied

Legend:

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

    r77 r79  
    11package atmsdriver; 
    22 
    3 import atmsdriver.network.model.Network; 
     3import atmsdriver.model.Network; 
    44import java.io.File; 
     5import java.io.FileInputStream; 
     6import java.util.Properties; 
    57import java.util.logging.Level; 
    68import java.util.logging.Logger; 
    79 
    8 /**  
     10/** 
    911 * 
    1012 * @author John A. Torres 
    1113 * @version 09/10/2017 
    1214 */ 
    13 public class ATMSDriver { 
    14     final private String ldsFileName = "./lds_data/lookup_lds"; 
    15     final private String loopFileName = "./lds_data/lookup_loop"; 
    16     final private String networkFileName = "./networkFile.txt"; 
     15public class ATMSDriver implements Runnable { 
     16 
     17    /** ATMSDriver Error logger. */ 
     18    private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver"); 
     19 
     20    private static final String CONFIG_FILE_NAME = "atms_driver_config.properties"; 
     21 
     22    /** Properties object for the CADClient class. */ 
     23    private Properties ATMSDriverProperties; 
     24 
     25    /** 
     26     * Enumeration containing properties name values. See ATMSDriver class 
     27     * description for more information. 
     28     * 
     29     * @author John Torres 
     30     * @see ATMSDriver 
     31     */ 
     32    private static enum PROPERTIES { 
     33 
     34        LDS_FILE_NAME("LDSFileName"), 
     35        LOOP_FILE_NAME("LoopFileName"), 
     36        NETWORK_FILE_NAME("NetworkFileName"), 
     37        EXCHANGE_FILE_NAME("ExchangeFileName"); 
     38 
     39        public String name; 
     40 
     41        private PROPERTIES(String n) { 
     42            name = n; 
     43        } 
     44    } 
     45 
     46    /** Network model. */ 
    1747    final private Network network; 
    1848     
    19     public ATMSDriver() 
    20     { 
    21         File ldsFile = new File(ldsFileName); 
    22         File loopFile = new File(loopFileName); 
    23         File networkFile = new File(networkFileName); 
    24         network = new Network(ldsFile, loopFile, networkFile); 
    25         try { 
     49    /** Sleep Time (10 seconds). **/ 
     50    private static final int SLEEP_TIME = 10000; 
     51     
     52    /** Exchange Reader */ 
     53    private ExchangeReader exchangeReader; 
     54     
     55    @Override 
     56    public void run() { 
     57        // Check for packets and update the simulator 
     58        for (;;) { 
     59            // Flush the input file 
     60            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 
     61                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 
    2662            network.toXML(); 
    27         } catch (Exception ex) { 
    28             Logger.getLogger(ATMSDriver.class.getName()).log(Level.SEVERE, null, ex); 
     63            // Update if packet is recieved 
     64            if (exInfo != null) { 
     65                System.out.println("Grabbed"); 
     66            } 
     67 
     68            // Sleep 
     69            try { 
     70                Thread.sleep(SLEEP_TIME); 
     71            } catch (InterruptedException ie) { 
     72                 
     73            } 
    2974        } 
    3075    } 
    31      
     76 
     77    public ATMSDriver(String propertiesFile) { 
     78 
     79        if (!verifyProperties(propertiesFile)) { 
     80            System.exit(0); 
     81        } 
     82 
     83        network = new Network( 
     84                new File(ATMSDriverProperties.getProperty( 
     85                                PROPERTIES.LDS_FILE_NAME.name)), 
     86                new File(ATMSDriverProperties.getProperty( 
     87                                PROPERTIES.LOOP_FILE_NAME.name)), 
     88                new File(ATMSDriverProperties.getProperty( 
     89                                PROPERTIES.NETWORK_FILE_NAME.name))); 
     90        network.toXML(); 
     91        exchangeReader = new ExchangeReader(); 
     92    } 
     93 
     94    private boolean verifyProperties(String propertiesFile) { 
     95        // Load the properties file. 
     96        try { 
     97            ATMSDriverProperties = new Properties(); 
     98            ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 
     99        } catch (Exception e) { 
     100            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 
     101                    "Constructor", "Exception in reading properties file.", e); 
     102        } 
     103 
     104        return true; 
     105    } 
     106 
    32107    /** 
    33      * @param args the command line arguments 
     108     * Runs the Paramics simulator. 
    34109     */ 
    35110    public static void main(String[] args) { 
    36         ATMSDriver driver = new ATMSDriver(); 
     111        try { 
     112            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 
     113                new Thread(new ATMSDriver(System.getProperty( 
     114                        "ATMSDRIVER_PROPERTIES"))).start(); 
     115            } else { 
     116                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 
     117            } 
     118        } catch (Exception e) { 
     119            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 
     120                    "Error occured initializing application", e); 
     121            System.exit(-1); 
     122        } 
    37123    } 
    38      
    39124} 
Note: See TracChangeset for help on using the changeset viewer.