Changeset 121 in tmcsimulator for trunk/src/tmcsim


Ignore:
Timestamp:
10/14/2017 01:33:24 PM (9 years ago)
Author:
jdalbey
Message:

ATMSBatchDriver.java Add thread to run writeToFEP() every 30 seconds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/ATMSBatchDriver.java

    r120 r121  
    11package tmcsim.client; 
    22 
     3import atmsdriver.ATMSDriver; 
    34import atmsdriver.ConsoleDriver; 
     5import atmsdriver.ExchangeInfo; 
    46import atmsdriver.model.Highways; 
    57import atmsdriver.model.Station; 
     
    4850    private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 
    4951    private final static int ONE_SECOND = 1000; 
     52    private static final int FEPSIM_INTERVAL = 30000; 
    5053    private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 
    5154    /** 
     
    98101     */ 
    99102    private CADClientInterface client = this; 
     103 
     104    /** 
     105     * Highways in traffic network 
     106     */ 
     107    final private Highways highways; 
    100108     
    101109    /**  
     
    121129            System.exit(0); 
    122130        } 
    123         Highways highways = new Highways( 
     131        highways = new Highways( 
    124132        "config/vds_data/lds.txt", 
    125133        "config/vds_data/loop.txt", 
    126134        "config/vds_data/highwaysMeta.txt", 
    127135        "localhost", 8080); 
     136        // Create console driver but don't start run() method 
    128137        console = new ConsoleDriver(highways); 
    129138         
     
    133142        // READ THE BATCH FILE OF COMMANDS and put in a queue 
    134143        readBatchFile(); 
    135          
    136144        // Create a timer that fetches the simulation time every second. 
    137145        Timer timer = new Timer(ONE_SECOND, new ActionListener() 
    138146        { 
     147            // Every second, see if an event should be launched 
    139148            public void actionPerformed(ActionEvent e) 
    140149            { 
     
    205214        timer.start(); 
    206215 
     216        // Start the FEP thread (to update ATMS every 30 sec) 
     217        new WriteToFEPThread().run(); 
     218 
    207219        ensureProperShutdown(); 
    208220    } 
     
    222234            Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 
    223235        } 
     236        System.out.println("Events file read, " + eventQueue.size() + " events queued."); 
    224237    } 
    225238     
     
    358371 
    359372    } 
     373 
     374    class WriteToFEPThread extends Thread 
     375    { 
     376 
     377        public void run() 
     378        { 
     379            System.out.println("WriteToFEP Thread starting."); 
     380            // Run indefinitely 
     381            while (true) 
     382            { 
     383                // Write the highway network status to the FEP Simulator 
     384                highways.writeToFEP(); 
     385 
     386                // Wait for FEP Sim to process the data we just sent 
     387                try 
     388                { 
     389                    Thread.sleep(FEPSIM_INTERVAL); 
     390                } 
     391                catch (InterruptedException ie) 
     392                { 
     393                    ie.printStackTrace(); 
     394                } 
     395            } 
     396 
     397        } 
     398    } 
    360399} 
Note: See TracChangeset for help on using the changeset viewer.