Changeset 347 in tmcsimulator for trunk/src/tmcsim/cadsimulator/Coordinator.java


Ignore:
Timestamp:
03/25/2019 07:35:45 PM (7 years ago)
Author:
jdalbey
Message:

Coordinator.java: Enhance tick() method to write current time to a json file, for use by web clients. Also update build.xml so Sim Mgr jar includes needed time selector library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r310 r347  
    22 
    33import java.io.File; 
     4import java.io.FileWriter; 
     5import java.io.PrintWriter; 
    46import java.rmi.RemoteException; 
    57import java.rmi.server.UnicastRemoteObject; 
     
    6870import tmcsim.interfaces.CoordinatorInterface; 
    6971import tmcsim.interfaces.SimulationManagerInterface; 
     72import tmcsim.simulationmanager.SimulationManagerView; 
    7073 
    7174/** 
     
    9093{ 
    9194    /** 
     95     * The name of the file where the simulation clock time is written 
     96     */ 
     97    public static final String kSimClockFilename = "webapps/sim_clock.json"; 
     98    /** 
    9299     * Error logger. 
    93100     */ 
     
    700707 
    701708                    CADServer.theIncidentMgr.tick(currentSimTime); 
    702                 } 
     709                    /* Write the currentSimTime to a file.  
     710                       This will be read asynchronously by web clients, e.g., 
     711                       the electronic instructor notebook, that want to display 
     712                       the current simulation time. 
     713                    */ 
     714                    PrintWriter writer = null; 
     715                    try { 
     716                        writer = new PrintWriter(new FileWriter(kSimClockFilename)); 
     717                        // Format output as json 
     718                        String lineout =  "{\"clock\":\""  
     719                                + SimulationManagerView.longToTime(currentSimTime) + "\"}"; 
     720                        writer.println(lineout); 
     721                        writer.close(); 
     722                        } catch (Exception ex)  
     723                        { 
     724                        coorLogger.logp(Level.SEVERE, "Coordinator", "tick:run", 
     725                                "Failed to write current sim time to file.", ex); 
     726                        }  
     727                        } 
    703728            }; 
    704729 
Note: See TracChangeset for help on using the changeset viewer.