Changeset 105 in tmcsimulator for trunk/src


Ignore:
Timestamp:
10/12/2017 09:57:54 AM (9 years ago)
Author:
jdalbey
Message:

ATMSDriverClient.java Enhanced so it now syncs with Sim Mgr clock and reads a file of events and pretends to launch each event at the schedule time. Added batch event data file.

File:
1 edited

Legend:

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

    r102 r105  
    44import java.awt.event.ActionListener; 
    55import java.io.FileInputStream; 
     6import java.io.FileNotFoundException; 
    67import java.rmi.Naming; 
    78import java.rmi.RemoteException; 
    89import java.rmi.server.UnicastRemoteObject; 
     10import java.util.LinkedList; 
    911import java.util.Properties; 
     12import java.util.Queue; 
     13import java.util.Scanner; 
    1014import java.util.concurrent.TimeUnit; 
    1115import java.util.logging.Level; 
     
    3337        CADClientInterface 
    3438{ 
     39    private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 
     40    private final static int ONE_SECOND = 1000; 
    3541    /** 
    3642     * Error logger. 
     
    8288     */ 
    8389    private CADClientInterface client = this; 
    84     private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 
    85     private final static int ONE_SECOND = 1000; 
     90     
     91    /**  
     92     * Queue of batch events 
     93     */ 
     94    private Queue<String> eventQueue; 
     95     
    8696 
    8797    /** 
     
    104114 
    105115        // READ THE BATCH FILE OF COMMANDS and put in a queue 
     116        readBatchFile(); 
    106117        // Consider special cases:  1) time to fire first command 
    107118        // has already past when application starts. 
     
    114125            public void actionPerformed(ActionEvent e) 
    115126            { 
     127                String currentClock = ""; 
    116128                try 
    117129                { 
    118130                    long simtime = theCoorInt.getCurrentSimulationTime(); 
     131                    currentClock = formatInterval(simtime); 
     132                    System.out.println("Current clock: " + currentClock); 
     133                } catch (RemoteException ex) 
     134                { 
     135                    Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex); 
     136                } 
     137                if (!eventQueue.isEmpty()) 
     138                { 
    119139                    // Check the queue of commands to see if the first 
    120140                    // item matches the current time.  IF so,  
    121141                    // issue that command and remove it from queue. 
    122                      
     142                    String nextEvent = eventQueue.peek(); 
     143                    String eventTime = nextEvent.substring(0,8); 
     144                    System.out.println("Next event will be launched at: " + eventTime); 
     145                    if (eventTime.equals(currentClock)) 
     146                    { 
     147                        System.out.println("LAUNCHING EVENT at " + nextEvent ); 
     148                        eventQueue.remove(); 
     149                    } 
    123150                    //theView.updateTime("" + formatInterval(simtime)); 
    124                 } catch (RemoteException ex) 
    125                 { 
    126                     Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex); 
    127151                } 
    128152            } 
     
    133157    } 
    134158 
     159    private void readBatchFile() 
     160    { 
     161        FileInputStream fis; 
     162        try { 
     163            fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt"); 
     164            Scanner scan = new Scanner(fis); 
     165            eventQueue = new LinkedList<String>(); 
     166            while (scan.hasNext()) 
     167            { 
     168                eventQueue.add(scan.nextLine()); 
     169            } 
     170        } catch (FileNotFoundException ex) { 
     171            Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex); 
     172        } 
     173    } 
     174     
    135175    /** 
    136176     * Connect to the Coordinator's RMI object, and register this object for 
Note: See TracChangeset for help on using the changeset viewer.