Ignore:
Timestamp:
10/29/2017 03:13:25 PM (9 years ago)
Author:
jdalbey
Message:

TrafficModelManager?.java: Now integrated into CAD Server. Passes smoke test, needs system testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java

    r187 r188  
    2626import java.util.logging.Logger; 
    2727import javax.swing.JOptionPane; 
     28import javax.swing.JWindow; 
    2829import javax.swing.Timer; 
     30import javax.swing.UIManager; 
    2931import tmcsim.cadsimulator.Coordinator; 
     32import tmcsim.cadsimulator.viewer.model.CADSimulatorState; 
    3033import tmcsim.client.ATMSBatchDriver; 
    3134import tmcsim.client.ATMSBatchViewer; 
     
    3942 * @version 2.0 
    4043 */ 
    41 public class TrafficModelManager extends Observable  
     44public class TrafficModelManager 
    4245{ 
    4346    private final static int ONE_SECOND = 1000; 
     
    7881    }; 
    7982 
    80     /** 
    81      * Reference to the simulation Coordinator from whom we get simulation 
    82      * elapsed time. 
    83      */ 
    84     private Coordinator theCoordinator; 
    8583 
    8684    /** 
     
    112110     * 
    113111     * @param propertiesFile Target file path of properties file. 
    114      */ 
    115     public TrafficModelManager(String propertiesFile) throws SimulationException  
     112     * @param theCoordinator Reference to the simulation Coordinator from whom we get simulation 
     113     * elapsed time. 
     114     */ 
     115    public TrafficModelManager(String propertiesFile, final Coordinator theCoordinator)  
     116            throws SimulationException  
    116117    { 
    117118        if (!loadProperties(propertiesFile)) 
     
    119120            System.exit(0); 
    120121        } 
    121  
     122//        final Coordinator theCoordinator = theCoordinator; 
    122123        // Initialize the highway model 
    123124        incidents = new HashMap<String, List<TrafficEvent>>(); 
    124125        highways = new Highways( 
    125                 "config/vds_data/highways_fullmap.txt", 
     126                atmsProperties.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name), 
     127                //"config/vds_data/highways_fullmap.txt", 
    126128                //        "192.168.251.46", 8080);  //IP address of FEP Sim Linux VM 
    127                 "localhost", 8080);  
     129                atmsProperties.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name), 
     130                8080);  
    128131 
    129132        // READ THE BATCH FILE OF COMMANDS and put in a queue 
    130         readBatchFile(); 
     133        eventQueue = readBatchFile(); 
    131134        // Launch the display 
    132135        theView = new TrafficModelViewer(this, new ArrayList<String>(incidents.keySet())); 
     
    245248        return true; 
    246249    } 
    247     private void readBatchFile() 
     250    /** 
     251     * Read a file of traffic events.   
     252     * @return the chronologically ordered list of events 
     253     */ 
     254    // Method is package private to facilitate unit testing. 
     255    LinkedList<TrafficEvent> readBatchFile() 
    248256    { 
    249257        FileInputStream fis; 
     258        LinkedList<TrafficEvent> eventList = new LinkedList<TrafficEvent>(); 
    250259        try 
    251260        { 
    252             fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt"); 
    253             eventQueue = new LinkedList<TrafficEvent>(); 
     261            fis = new FileInputStream( 
     262                    //"config/vds_data/atmsBatchEvents.txt"); 
     263            atmsProperties.getProperty(PROPERTIES.EVENTS_FILE.name)); 
    254264            // Read all lines from the file of events 
    255265            Scanner scan = new Scanner(fis); 
     
    264274                    { 
    265275                        evt = new TrafficEvent(line); 
    266                         eventQueue.add(evt); 
     276                        eventList.add(evt); 
    267277                        String incident = evt.incident; 
    268278                        // Add the line to the list for the corresponding incident 
     
    293303            Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 
    294304        } 
    295         System.out.println("Events file read, " + eventQueue.size() + " events queued."); 
     305        System.out.println("Events file read, " + eventList.size() + " events queued."); 
    296306        // Put the events in chronological order 
    297         Collections.sort(eventQueue); 
     307        Collections.sort(eventList); 
     308        return eventList; 
    298309    } 
    299310 
     
    343354    } 
    344355 
     356    /** 
     357     * Construct the CADClient with the properties file path, either from the 
     358     * command line arguments or default. 
     359     * 
     360     * @param args Command line arguments. 
     361     */ 
     362    public static void main(String[] args) throws RemoteException 
     363    { 
     364        final String CONFIG_FILE_NAME = "traffic_model_config.properties";         
     365        if (System.getProperty("CONFIG_DIR") == null) 
     366        { 
     367            System.setProperty("CONFIG_DIR", "config"); 
     368        } 
     369        CADSimulatorState theModel = new CADSimulatorState(); 
     370        Coordinator theCoordinator = new Coordinator(theModel); 
     371        try 
     372        { 
     373            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     374            new TrafficModelManager(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME, 
     375            theCoordinator); 
     376 
     377        } 
     378        catch (Exception e) 
     379        { 
     380            atmsLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
     381                    "Error initializing application."); 
     382 
     383            JOptionPane.showMessageDialog(new JWindow(), e.getMessage(), 
     384                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     385 
     386            System.exit(-1); 
     387        } 
     388 
     389    } 
    345390    class WriteToFEPThread extends Thread 
    346391    { 
Note: See TracChangeset for help on using the changeset viewer.