Warning: Can't use blame annotator:
svn blame failed on branches/trunk/src/atmsdriver/ATMSDriver.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/branches/trunk/src/atmsdriver/ATMSDriver.java @ 82

Revision 82, 3.8 KB checked in by jtorres, 9 years ago (diff)

Added socket client to ATMSDriver. Added socket server to FEPSim

RevLine 
1package atmsdriver;
2
3import atmsdriver.model.Network;
4import java.io.File;
5import java.io.FileInputStream;
6import java.util.Properties;
7import java.util.logging.Level;
8import java.util.logging.Logger;
9
10/**
11 *
12 * @author John A. Torres
13 * @version 09/10/2017
14 */
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        FEP_WRITER_HOST("FEPWriterHost"),
39        FEP_WRITER_PORT("FEPWriterPort");
40
41        public String name;
42
43        private PROPERTIES(String n) {
44            name = n;
45        }
46    }
47
48    /** Network model. */
49    final private Network network;
50   
51    /** Sleep Time (10 seconds). **/
52    private static final int SLEEP_TIME = 10000;
53   
54    /** Exchange Reader */
55    private ExchangeReader exchangeReader;
56   
57    @Override
58    public void run() {
59        // Check for packets and update the simulator
60        for (;;) {
61            // Flush the input file
62            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties
63                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name));
64           
65            network.writeToFEP();
66           
67            // Update if exchangeInfo is recieved
68            if (exInfo != null) {
69               
70            }
71
72            // Sleep
73            try {
74                Thread.sleep(SLEEP_TIME);
75            } catch (InterruptedException ie) {
76               
77            }
78        }
79    }
80
81    public ATMSDriver(String propertiesFile) {
82
83        if (!verifyProperties(propertiesFile)) {
84            System.exit(0);
85        }
86
87        network = new Network(
88                new File(ATMSDriverProperties.getProperty(
89                                PROPERTIES.LDS_FILE_NAME.name)),
90                new File(ATMSDriverProperties.getProperty(
91                                PROPERTIES.LOOP_FILE_NAME.name)),
92                ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name),
93                Integer.parseInt(ATMSDriverProperties.getProperty(
94                        PROPERTIES.FEP_WRITER_PORT.name)));
95       
96        exchangeReader = new ExchangeReader();
97    }
98
99    private boolean verifyProperties(String propertiesFile) {
100        // Load the properties file.
101        try {
102            ATMSDriverProperties = new Properties();
103            ATMSDriverProperties.load(new FileInputStream(propertiesFile));
104        } catch (Exception e) {
105            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver",
106                    "Constructor", "Exception in reading properties file.", e);
107        }
108
109        return true;
110    }
111
112    /**
113     * Runs the Paramics simulator.
114     */
115    public static void main(String[] args) {
116        try {
117            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) {
118                new Thread(new ATMSDriver(System.getProperty(
119                        "ATMSDRIVER_PROPERTIES"))).start();
120            } else {
121                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined.");
122            }
123        } catch (Exception e) {
124            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main",
125                    "Error occured initializing application", e);
126            System.exit(-1);
127        }
128    }
129}
Note: See TracBrowser for help on using the repository browser.