Changeset 435 in tmcsimulator for trunk/src/tmcsim/cadsimulator/Coordinator.java
- Timestamp:
- 07/10/2019 01:47:15 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/tmcsim/cadsimulator/Coordinator.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/Coordinator.java
r432 r435 100 100 private String kSimClockFilename; 101 101 /** 102 * Name of output file for CAD comments 103 */ 104 private static final String LOG_FILE_NAME = "CADcomments.log"; 105 /** 102 106 * Error logger. 103 107 */ … … 714 718 715 719 CADServer.theIncidentMgr.tick(currentSimTime); 716 /* Write the currentSimTime to a file. 717 This will be read asynchronously by web clients, e.g., 718 the electronic instructor notebook, that want to display 719 the current simulation time. 720 */ 721 PrintWriter writer = null; 722 try { 723 writer = new PrintWriter(new FileWriter(kSimClockFilename)); 724 // Format output as json 725 String lineout = "{\"elapsedtime\":\"" 726 + currentSimTime + "\"}"; 727 writer.println(lineout); 728 writer.close(); 729 } catch (Exception ex) 730 { 731 coorLogger.logp(Level.SEVERE, "Coordinator", "tick:run", 732 "Failed to write current sim time to file.", ex); 733 } 734 } 720 writeCADlog(); 721 writeSimTime(currentSimTime); 722 } 735 723 }; 736 724 … … 739 727 } 740 728 } 741 729 /** Helper method to write the current CAD comment log to a file. 730 * Invoked from tick() method. Note: This writes all comments each time it's 731 * invoked. It doesn't have any intelligence to selectively write only the 732 * most recently updated comments. 733 * @author jdalbey July 2019 734 */ 735 private void writeCADlog() 736 { 737 // Obtain the current incident list 738 Vector<Incident> incList = null; 739 try { 740 incList = getIncidentList(); 741 } catch (RemoteException ex) { 742 Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex); 743 } 744 // Initialize an output buffer 745 StringBuffer output = new StringBuffer(); 746 // Process all the incidents 747 for (Incident incident: incList) 748 { 749 // Retrieve the table of comments/notes the users created 750 DefaultTableModel notesTable = incident.getCommentsNotesTable(); 751 // Retrieve the notes chronologically (Most recent is in first row) 752 for (int row=notesTable.getRowCount()-1; row >=0; row--) 753 { 754 // Combine the fields into one output entry 755 String initials = (String) notesTable.getValueAt(row,2); // user initials 756 // If there are user intials, include this item. 757 // Zero length initials mean it's a scripted item, ignore it. 758 if (initials.length() > 0) 759 {//CAD Log Entry, Incident #187, Sharon: REQUEST EXTRA ANCHOVIES 760 output.append("CAD log entry, "); 761 output.append("Incident #" + incident.logNum + ", "); 762 output.append(initials + ": "); 763 output.append(notesTable.getValueAt(row,4) + "\n"); // notes 764 } 765 } 766 } 767 // Write output buffer to a file 768 try 769 { 770 PrintWriter writer = new PrintWriter(new FileWriter(LOG_FILE_NAME)); 771 writer.print(output); 772 writer.close(); 773 } catch (Exception exc) 774 { 775 exc.printStackTrace(); 776 } 777 } 778 779 /** Write the currentSimTime to a file. 780 This will be read asynchronously by web clients, e.g., 781 the electronic instructor notebook, that want to display 782 the current simulation time. 783 */ 784 private void writeSimTime(long currentSimTime) 785 { 786 PrintWriter writer = null; 787 try { 788 writer = new PrintWriter(new FileWriter(kSimClockFilename)); 789 // Format output as json 790 String lineout = "{\"elapsedtime\":\"" 791 + currentSimTime + "\"}"; 792 writer.println(lineout); 793 writer.close(); 794 } catch (Exception ex) 795 { 796 coorLogger.logp(Level.SEVERE, "Coordinator", "tick:run", 797 "Failed to write current sim time to file.", ex); 798 } 799 } 742 800 /** 743 801 * Method notifies observers with an IncidentSummaryModel_obj to signify
Note: See TracChangeset
for help on using the changeset viewer.
