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

source: tmcsimulator/trunk/test/atmsdriver/TrafficModelEventDriver.java @ 204

Revision 204, 4.0 KB checked in by jdalbey, 9 years ago (diff)

TrafficModelManager?.java Refactor for code sharing with TrafficModelEventDriver?. Write unit test.

RevLine 
1package atmsdriver;
2
3import atmsdriver.model.Highways;
4import atmsdriver.model.TrafficEvent;
5import java.io.FileInputStream;
6import java.io.FileNotFoundException;
7import java.rmi.RemoteException;
8import java.util.HashMap;
9import java.util.LinkedList;
10import java.util.List;
11import java.util.Map;
12import java.util.Properties;
13import java.util.Scanner;
14import java.util.logging.Level;
15import java.util.logging.Logger;
16import javax.swing.JOptionPane;
17import javax.swing.JWindow;
18import tmcsim.cadsimulator.managers.TrafficModelManager;
19import tmcsim.common.SimulationException;
20
21/**
22 * Read and process all Traffic Events in a file and show
23 * resulting highway network.
24 * A console display of the highway network is output
25 * for each event.
26 * This application is used by Traffic Event authors to assist
27 * in verifying the correctness of their data file.
28 * Because the output is sent immediately to the console the
29 * author doesn't have to sit through simulation time to
30 * observe dots changing on ATMS client.
31 * @author jdalbey
32 */
33public class TrafficModelEventDriver 
34{
35    /**
36     * Error logger.
37     */
38    private static Logger logger = Logger.getLogger("trafficmodeleventdriver");
39
40    /**
41     * Highways in traffic network
42     */
43    final private Highways highways;
44
45    /**
46     * LinkedList of batch events
47     */
48    private LinkedList<TrafficEvent> eventQueue;
49    /**
50     * Map of incidents to events
51     */
52    private Map<String, List<TrafficEvent>> incidents;
53
54    /**
55     * Constructor. Load highways and events.
56     *
57     */
58    public TrafficModelEventDriver() throws RemoteException, SimulationException
59    {
60        // Initialize the highway model
61        incidents = new HashMap<String, List<TrafficEvent>>();
62        highways = new Highways(
63                "config/vds_data/highways_fullmap.txt",
64                // following aren't used by this application
65                "localhost", 8080);
66        final String CONFIG_FILE_NAME = "traffic_model_config.properties";
67        String propertiesFile = "config" + System.getProperty("file.separator") 
68                 + CONFIG_FILE_NAME;
69        Properties props = TrafficModelManager.loadProperties(propertiesFile);
70
71        FileInputStream fis = null;
72        try
73        {
74            fis = new FileInputStream(props.getProperty("Events_File"));
75        } catch (FileNotFoundException ex)
76        {
77            Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 
78                    "Missing Traffic Events file " + props.getProperty("Events_File"));
79            System.exit(-1);
80        }
81        Scanner fileScanner = new Scanner(fis);       
82        // Read all lines from the file of events and put in a queue
83        eventQueue = TrafficModelManager.readBatchFile(fileScanner);
84    }
85    public void run()
86    {
87        // If we have any events left to process
88        while (!eventQueue.isEmpty())
89        {
90            // Get next event
91            TrafficEvent nextEvent = eventQueue.peek();
92            System.out.println("LAUNCHING EVENT: " + nextEvent.toString());
93            // apply colorization to highways
94            highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir,
95                    nextEvent.postmile, nextEvent.range, nextEvent.color);
96            System.out.println(highways.toString());
97            // Remove this event from the queue, we're done with it.
98            eventQueue.remove();
99        }
100    }
101
102    /**
103     * local main to launch the app.
104     *
105     * @param args Command line arguments.
106     */
107    public static void main(String[] args)
108    {
109        try
110        {
111            TrafficModelEventDriver driver = new TrafficModelEventDriver();
112            driver.run();
113        }
114        catch (Exception e)
115        {
116            logger.logp(Level.SEVERE, "Traffic Model Event Driver", "Main",
117                    "Error initializing application.");
118
119            JOptionPane.showMessageDialog(new JWindow(), e.getMessage(),
120                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);
121
122            System.exit(-1);
123        }
124
125    }
126
127}
Note: See TracBrowser for help on using the repository browser.