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

source: tmcsimulator/trunk/src/archive/ATMSDriver.java @ 340

Revision 340, 4.9 KB checked in by jdalbey, 7 years ago (diff)

move old ATMS driver to archive package

RevLine 
1package archive;
2
3import atmsdriver.ConsoleTrafficDriver;
4import atmsdriver.model.Highways;
5import java.io.FileInputStream;
6import java.util.Properties;
7import java.util.logging.Level;
8import java.util.logging.Logger;
9import tmcsim.common.SimulationException;
10
11/** "Super Old"
12 * ATMS Driver reads the current simulation traffic conditions from the
13 * EXCHANGE.XML file and constructs the Highway Network status info in the
14 * format required by the FEP. It then sends this XML data over a socket to the
15 * FEP Simulator.
16 *
17 * @author John A. Torres
18 * @version 09/10/2017
19 */
20public class ATMSDriver implements Runnable
21{
22
23    /**
24     * ATMSDriver Error logger.
25     */
26    private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver");
27
28    /**
29     * Properties object for the CADClient class.
30     */
31    private Properties ATMSDriverProperties;
32
33    /**
34     * Enumeration containing properties name values. See ATMSDriver class
35     * description for more information.
36     *
37     * @author John Torres
38     * @see ATMSDriver
39     */
40    private static enum PROPERTIES
41    {
42        HIGHWAYS_MAP_FILE_NAME("HighwaysMapFileName"),
43        EXCHANGE_FILE_NAME("ExchangeFileName"),
44        FEP_WRITER_HOST("FEPWriterHost"),
45        FEP_WRITER_PORT("FEPWriterPort");
46
47        public String name;
48
49        private PROPERTIES(String n)
50        {
51            name = n;
52        }
53    }
54
55    /**
56     * Highways in traffic network
57     */
58    final private Highways highways;
59
60    /**
61     * Sleep Time (30 seconds). *
62     */
63    private static final int SLEEP_TIME = 30000;
64
65    /**
66     * Exchange Reader
67     */
68    private ExchangeReader exchangeReader;
69
70    @Override
71    public void run()
72    {
73        // Check for packets and update the simulator
74        while (true)
75        {
76            // Flush the input file
77            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties
78                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name));
79
80            try
81            {
82                highways.writeToFEP();
83            } catch (SimulationException ex)
84            {
85                System.out.println("Skipping writeToFEP...");
86            }
87            // Update if exchangeInfo is recieved
88            if (exInfo != null)
89            {
90                // TODO: handle this condition
91                Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null");
92            }
93
94            // Wait for FEP Sim to process the data we just sent
95            try
96            {
97                Thread.sleep(SLEEP_TIME);
98            } catch (InterruptedException ie)
99            {
100                ie.printStackTrace();
101            }
102        }
103    }
104
105    public ATMSDriver(String propertiesFile)
106    {
107        // verify properties file
108        if (!verifyProperties(propertiesFile))
109        {
110            System.exit(0);
111        }
112        // create the highways model
113        highways = new Highways(
114                ATMSDriverProperties.getProperty(
115                        PROPERTIES.HIGHWAYS_MAP_FILE_NAME.name),
116                ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name),
117                Integer.parseInt(ATMSDriverProperties.getProperty(
118                                PROPERTIES.FEP_WRITER_PORT.name)));
119        // create the exchange reader
120        exchangeReader = new ExchangeReader();
121    }
122
123    /**
124     * Verifies that the properties file has all necessary properties.
125     *
126     * @param propertiesFile
127     * @return
128     */
129    private boolean verifyProperties(String propertiesFile)
130    {
131        // Load the properties file.
132        try
133        {
134            ATMSDriverProperties = new Properties();
135            ATMSDriverProperties.load(new FileInputStream(propertiesFile));
136        } catch (Exception e)
137        {
138            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver",
139                    "Constructor", "Exception in reading properties file.", e);
140        }
141
142        return true;
143    }
144
145    /**
146     * Runs the ATMS Driver.
147     */
148    public static void main(String[] args)
149    {
150        try
151        {
152            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null)
153            {
154                // Create and run the ATMSDriver thread
155                ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES"));
156                Thread ATMSDriverThread = new Thread(atmsDriver);
157                ATMSDriverThread.start();
158
159                // run the console driver, pass it the atmsDriver highways model
160                ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways);
161
162            } else
163            {
164                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined.");
165            }
166        } catch (Exception e)
167        {
168            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main",
169                    "Error occured initializing application", e);
170            System.exit(-1);
171        }
172    }
173}
Note: See TracBrowser for help on using the repository browser.