Ignore:
Timestamp:
04/20/2016 02:29:52 PM (10 years ago)
Author:
jdalbey
Message:

Multifile commit. Add version # to Paramics Communicator. Move Load button in Sim Mgr. Add several tests. Add package jars target.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/paramicscommunicator/ParamicsCommunicator.java

    r2 r6  
    1717import java.util.Properties; 
    1818import java.util.TreeMap; 
    19 import java.util.logging.FileHandler; 
    2019import java.util.logging.Level; 
    2120import java.util.logging.Logger; 
    22  
    2321import javax.swing.JOptionPane; 
    2422import javax.swing.UIManager; 
    25  
    2623import org.w3c.dom.Document; 
    2724import org.w3c.dom.Element; 
    28  
    2925import tmcsim.common.CADProtocol.PARAMICS_ACTIONS; 
    3026import tmcsim.common.CADProtocol.PARAMICS_COMM_TAGS; 
     
    3228import tmcsim.paramicscommunicator.FileRegUpdate.REG_TYPE; 
    3329import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI; 
    34 import tmcsim.simulationmanager.SimulationManager; 
    35  
    3630 
    3731/** 
    38  * ParamicsCommunicator is the main class for this module.  The Paramics  
    39  * Communicator is used to provide communication between the CAD Simulator 
    40  * and the Paramics traffic modeler.  While the application is running, data  
    41  * is received on a socket from the CAD Simulator.  Transmitted data are 
    42  * XML documents containing information and action commands. The CAD Simulator  
    43  * registers readers and writers with the ParamicsCommunicator.  Any data read  
    44  * by a ParamicsReader is sent back to the CAD Simulator.  All data to be  
    45  * written by a ParamicsWriter is received through the socket.<br><br>   
    46  * The properties file for the ParamicsCommunicator class contains the following data.<br> 
     32 * ParamicsCommunicator is the main class for this module. The Paramics 
     33 * Communicator is used to provide communication between the CAD Simulator and 
     34 * the Paramics traffic modeler. While the application is running, data is 
     35 * received on a socket from the CAD Simulator. Transmitted data are XML 
     36 * documents containing information and action commands. The CAD Simulator 
     37 * registers readers and writers with the ParamicsCommunicator. Any data read by 
     38 * a ParamicsReader is sent back to the CAD Simulator. All data to be written by 
     39 * a ParamicsWriter is received through the socket.<br><br> 
     40 * The properties file for the ParamicsCommunicator class contains the following 
     41 * data.<br> 
    4742 * <code> 
    4843 * -----------------------------------------------------------------------------<br> 
    49  * Socket Port          The port number to use for socket communication.<br> 
    50  * Working Directory    The working directory use for Paramics file communication.<br> 
    51  * Error File           The target file to use for error logging.<br> 
     44 * Socket Port The port number to use for socket communication.<br> 
     45 * Working Directory The working directory use for Paramics file 
     46 * communication.<br> 
     47 * Error File The target file to use for error logging.<br> 
    5248 * -----------------------------------------------------------------------------<br> 
    5349 * Example File: <br> 
    54  * SocketPort          = 4450 <br> 
    55  * WorkingDirectory    = c:\\tmc_simulator\\ <br> 
    56  * ErrorFile           = sim_mgr_error.xml <br> 
     50 * SocketPort = 4450 <br> 
     51 * WorkingDirectory = c:\\tmc_simulator\\ <br> 
     52 * ErrorFile = sim_mgr_error.xml <br> 
    5753 * -----------------------------------------------------------------------------<br> 
    5854 * </code> 
    5955 * 
    6056 * @author Matthew Cechini (mcechini@calpoly.edu) 
    61  * @version $Date: 2009/04/17 16:27:46 $ $Revision: 1.7  
     57 * @version $Date: 2009/04/17 16:27:46 $ $Revision: 1.7 
    6258 */ 
    63 public class ParamicsCommunicator extends Observable implements Observer, Runnable { 
    64  
    65     /** Error logger. */ 
     59public class ParamicsCommunicator extends Observable implements Observer, Runnable 
     60{ 
     61 
     62    /** 
     63     * Error logger. 
     64     */ 
    6665    private static Logger paramLogger = Logger.getLogger("tmcsim.paramicscommunicator"); 
    67      
     66 
    6867    /** 
    6968     * Enumeration containing property names. 
     69     * 
    7070     * @author Matthew Cechini 
    7171     */ 
    72     private static enum PROPERTIES { 
    73          
    74         SOCKET_PORT ("SocketPort"), 
    75         WORKING_DIR ("WorkingDirectory");        
    76          
     72    private static enum PROPERTIES 
     73    { 
     74 
     75        SOCKET_PORT("SocketPort"), 
     76        WORKING_DIR("WorkingDirectory"); 
    7777        public String name; 
    78          
    79         private PROPERTIES(String n) { 
     78 
     79        private PROPERTIES(String n) 
     80        { 
    8081            name = n; 
    8182        } 
    8283    } 
    83      
    84          
    85     /** Properties object. */ 
    86     private Properties paramicsCommProp = null;  
    87      
    88     /** Current working directory where files will be read and written */ 
     84    /** 
     85     * Properties object. 
     86     */ 
     87    private Properties paramicsCommProp = null; 
     88    /** 
     89     * Current working directory where files will be read and written 
     90     */ 
    8991    private String workingDirectory = null; 
    90      
    91     /** Socket used to create socket communication with the CAD Simulator.  */ 
     92    /** 
     93     * Socket used to create socket communication with the CAD Simulator. 
     94     */ 
    9295    private ServerSocket serverSocket = null; 
    93      
    94     /** Soccket used to communicate with CAD Simulator.*/ 
    95     private Socket paramicsSocket = null;    
    96      
    97     /** Input Stream for reading data from the CAD Simulator. */ 
     96    /** 
     97     * Soccket used to communicate with CAD Simulator. 
     98     */ 
     99    private Socket paramicsSocket = null; 
     100    /** 
     101     * Input Stream for reading data from the CAD Simulator. 
     102     */ 
    98103    private ObjectInputStream in = null; 
    99      
    100     /** Output Stream for writing data to the CAD Simulator.  */ 
     104    /** 
     105     * Output Stream for writing data to the CAD Simulator. 
     106     */ 
    101107    private ObjectOutputStream out = null; 
    102      
    103     /** Map of all current ParamicsFileWriters referenced by I/O ID. */ 
     108    /** 
     109     * Map of all current ParamicsFileWriters referenced by I/O ID. 
     110     */ 
    104111    private TreeMap<String, ParamicsFileWriter> writers = null; 
    105      
    106     /** Map of all current ParamicsFileReaders referenced by I/O ID.  */ 
     112    /** 
     113     * Map of all current ParamicsFileReaders referenced by I/O ID. 
     114     */ 
    107115    private TreeMap<String, ParamicsFileReader> readers = null; 
    108      
    109     /** The view class for the ParamicsCommunicator. */ 
     116    /** 
     117     * The view class for the ParamicsCommunicator. 
     118     */ 
    110119    private ParamicsCommunicatorGUI theGUI; 
    111      
    112     /** 
    113      * Constructor.  Read in the property values.  If the properties file  
    114      * does not contain a value for the working directory, open a dialog 
    115      * to prompt the user for the path of the Paramics working directory. 
    116      * An empty string is not accepted.  A null signifies that the user 
    117      * pressed cancel.  Prompt the user to accept the cancel and exit the 
    118      * application if confirmed.  Continue until a valid directory has been 
    119      * entered, that exists, and append a '\' to the end of the directory 
    120      * if necessary. 
    121      *  
    122      * Initialize the Sockets 
    123      * and begin communication. 
    124      * 
    125      * @param propertiesFilePath File Path of ParamicsCommunicator properties file. 
    126      */ 
    127     public ParamicsCommunicator (String propertiesFile)  
    128     { 
    129          
     120 
     121    /** 
     122     * Constructor. Read in the property values. If the properties file does not 
     123     * contain a value for the working directory, open a dialog to prompt the 
     124     * user for the path of the Paramics working directory. An empty string is 
     125     * not accepted. A null signifies that the user pressed cancel. Prompt the 
     126     * user to accept the cancel and exit the application if confirmed. Continue 
     127     * until a valid directory has been entered, that exists, and append a '\' 
     128     * to the end of the directory if necessary. 
     129     * 
     130     * Initialize the Sockets and begin communication. 
     131     * 
     132     * @param propertiesFilePath File Path of ParamicsCommunicator properties 
     133     * file. 
     134     */ 
     135    public ParamicsCommunicator(String propertiesFile) 
     136    { 
     137 
    130138        writers = new TreeMap<String, ParamicsFileWriter>(); 
    131139        readers = new TreeMap<String, ParamicsFileReader>(); 
     
    133141        theGUI = new ParamicsCommunicatorGUI(); 
    134142        addObserver(theGUI); 
    135         theGUI.addWindowListener(new WindowListener() {          
    136             public void windowActivated(WindowEvent arg0) {}; 
    137             public void windowClosed(WindowEvent arg0) {}; 
    138             public void windowClosing(WindowEvent arg0) { 
     143        theGUI.addWindowListener(new WindowListener() 
     144        { 
     145            public void windowActivated(WindowEvent arg0) 
     146            { 
     147            } 
     148 
     149            ; 
     150            public void windowClosed(WindowEvent arg0) 
     151            { 
     152            } 
     153 
     154            ; 
     155            public void windowClosing(WindowEvent arg0) 
     156            { 
    139157                System.exit(0); 
    140158            } 
    141             public void windowDeactivated(WindowEvent arg0) {}; 
    142             public void windowDeiconified(WindowEvent arg0) {}; 
    143             public void windowIconified(WindowEvent arg0) {}; 
    144             public void windowOpened(WindowEvent arg0) {}; 
     159 
     160            public void windowDeactivated(WindowEvent arg0) 
     161            { 
     162            } 
     163 
     164            ; 
     165            public void windowDeiconified(WindowEvent arg0) 
     166            { 
     167            } 
     168 
     169            ; 
     170            public void windowIconified(WindowEvent arg0) 
     171            { 
     172            } 
     173 
     174            ; 
     175            public void windowOpened(WindowEvent arg0) 
     176            { 
     177            } 
     178        ; 
    145179        }); 
    146          
    147         try { 
     180 
     181        try 
     182        { 
    148183            paramicsCommProp = new Properties(); 
    149184            paramicsCommProp.load(new FileInputStream(propertiesFile)); 
    150              
    151             if(paramicsCommProp.getProperty(PROPERTIES.SOCKET_PORT.name) == null)  
    152             { 
    153                 JOptionPane.showMessageDialog(theGUI,  
    154                         "Properties file missing CAD Simulator Port information.",  
     185 
     186            if (paramicsCommProp.getProperty(PROPERTIES.SOCKET_PORT.name) == null) 
     187            { 
     188                JOptionPane.showMessageDialog(theGUI, 
     189                        "Properties file missing CAD Simulator Port information.", 
    155190                        "Invalid Configuration", JOptionPane.ERROR_MESSAGE); 
    156191                System.exit(0); 
    157             } 
    158             else if(paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name) == null ||  
    159                     paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name).length() == 0) { 
    160                  
    161                 try { 
     192            } else if (paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name) == null 
     193                    || paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name).length() == 0) 
     194            { 
     195 
     196                try 
     197                { 
    162198                    String workingDir = null; 
    163                      
    164                     while (workingDir == null || workingDir.length() == 0) {                         
     199 
     200                    while (workingDir == null || workingDir.length() == 0) 
     201                    { 
    165202                        workingDir = JOptionPane.showInputDialog(null, 
    166203                                "Please set the output directory for Paramics communication.", 
    167204                                "Paramics Working Directory", JOptionPane.QUESTION_MESSAGE); 
    168                          
    169                         if(workingDir == null) { 
    170                              
    171                         } 
    172                         else if(!new File(workingDir).exists()) { 
     205 
     206                        if (workingDir == null) 
     207                        { 
     208                        } else if (!new File(workingDir).exists()) 
     209                        { 
    173210                            JOptionPane.showMessageDialog(null, 
    174211                                    "Directory does not exist.", 
    175212                                    "Invalid Working Directory", JOptionPane.WARNING_MESSAGE); 
    176                              
     213 
    177214                            workingDir = null; 
    178                         } 
    179                         else if(!new File(workingDir).isDirectory()) { 
     215                        } else if (!new File(workingDir).isDirectory()) 
     216                        { 
    180217                            JOptionPane.showMessageDialog(null, 
    181218                                    workingDir + " is not a directory.", 
    182219                                    "Invalid Working Directory", JOptionPane.WARNING_MESSAGE); 
    183                              
     220 
    184221                            workingDir = null; 
    185                         }                        
     222                        } 
    186223                    } 
    187224 
    188                     if(workingDir.lastIndexOf("\\") != workingDir.length()-1) { 
     225                    if (workingDir.lastIndexOf("\\") != workingDir.length() - 1) 
     226                    { 
    189227                        workingDir = workingDir + "\\"; 
    190228                    } 
    191                      
    192                     paramicsCommProp.setProperty(PROPERTIES.WORKING_DIR.name, workingDir);       
     229 
     230                    paramicsCommProp.setProperty(PROPERTIES.WORKING_DIR.name, workingDir); 
    193231                    paramicsCommProp.store(new FileOutputStream(propertiesFile), ""); 
    194                 } catch (IOException ioe) { 
    195                     paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     232                } catch (IOException ioe) 
     233                { 
     234                    paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    196235                            "Exception in writing properties file.", ioe); 
    197236                } 
    198                  
     237 
    199238            } 
    200239 
    201240            workingDirectory = paramicsCommProp.getProperty( 
    202                     PROPERTIES.WORKING_DIR.name).trim();                     
    203  
    204         } catch (Exception e) { 
    205             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     241                    PROPERTIES.WORKING_DIR.name).trim(); 
     242 
     243        } catch (Exception e) 
     244        { 
     245            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    206246                    "Exception in reading properties file.", e); 
    207247        } 
    208          
    209          
    210         try { 
     248 
     249 
     250        try 
     251        { 
    211252            initializeSockets(Integer.parseInt(paramicsCommProp.getProperty( 
    212253                    PROPERTIES.SOCKET_PORT.name).trim())); 
    213         } 
    214         catch (Exception e) { 
    215             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     254        } catch (Exception e) 
     255        { 
     256            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    216257                    "Exception in initializing sockets.", e); 
    217258        } 
    218259 
    219260    } 
    220      
     261 
    221262    /** 
    222263     * Transmits a message XML document object to the CAD Simulator. 
     
    224265     * @param mess The ParamicsCommMessage to be transmitted. 
    225266     */ 
    226     private void write(Document mess) { 
    227          
    228         synchronized(paramicsSocket) { 
    229             try { 
     267    private void write(Document mess) 
     268    { 
     269 
     270        synchronized (paramicsSocket) 
     271        { 
     272            try 
     273            { 
    230274                out.writeObject(mess); 
    231275                out.flush(); 
    232             } 
    233             catch (Exception e) { 
    234                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "write",  
     276            } catch (Exception e) 
     277            { 
     278                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "write", 
    235279                        "Exception in writing to the socket.", e); 
    236280            } 
    237281        } 
    238282    } 
    239      
    240     /** 
    241      * Observer/Observable update method.  The Paramics Communicator observers 
    242      * registered ParamicsReaders.  When messages are to be sent, they are sent 
    243      * through this method.  All messages are ParamicsCommMessage objects.  Send  
     283 
     284    /** 
     285     * Observer/Observable update method. The Paramics Communicator observers 
     286     * registered ParamicsReaders. When messages are to be sent, they are sent 
     287     * through this method. All messages are ParamicsCommMessage objects. Send 
    244288     * these messages to the write() method for transmission on the socket. 
    245289     */ 
    246     public void update(Observable o, Object arg) {       
    247  
    248         if(arg instanceof Document) { 
    249             write((Document)arg);                
    250         }            
    251     } 
    252      
    253     /** 
    254      * Runnable method.  While this thread is not interrupted, read in an  
    255      * object from the socket input stream.  If an object exists, call 
    256      * doMessage() to parse and perform the received action in the message.   
    257      */ 
    258     public void run() { 
    259          
    260         while(true) {                        
    261             try { 
    262                 doMessage((Document)in.readObject()); 
    263             }  
    264             catch(SocketTimeoutException ste) { 
     290    public void update(Observable o, Object arg) 
     291    { 
     292 
     293        if (arg instanceof Document) 
     294        { 
     295            write((Document) arg); 
     296        } 
     297    } 
     298 
     299    /** 
     300     * Runnable method. While this thread is not interrupted, read in an object 
     301     * from the socket input stream. If an object exists, call doMessage() to 
     302     * parse and perform the received action in the message. 
     303     */ 
     304    public void run() 
     305    { 
     306 
     307        while (true) 
     308        { 
     309            try 
     310            { 
     311                doMessage((Document) in.readObject()); 
     312            } catch (SocketTimeoutException ste) 
     313            { 
    265314                //just try again 
    266             }    
    267             catch(EOFException eofe) { 
    268                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator",  
     315            } catch (EOFException eofe) 
     316            { 
     317                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", 
    269318                        "run", "EOF Exception in reading data from the socket.", eofe); 
    270             } 
    271             catch(Exception e) { 
    272                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator",  
     319            } catch (Exception e) 
     320            { 
     321                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", 
    273322                        "run", "Exception in reading data from the socket.", e); 
    274323 
    275                 JOptionPane.showMessageDialog(theGUI,  
    276                         "Connection has been lost to the CAD Simulator.  " + 
    277                         "Paramics Communicator will now shutdown.",  
     324                JOptionPane.showMessageDialog(theGUI, 
     325                        "Connection has been lost to the CAD Simulator.  " 
     326                        + "Paramics Communicator will now shutdown.", 
    278327                        "Dropped Connection", JOptionPane.ERROR_MESSAGE); 
    279328                break; 
    280             }                    
    281         } 
    282          
    283          
    284         try { in.close(); } catch (Exception e) {} 
    285         try { out.close(); } catch (Exception e) {} 
    286         try { serverSocket.close(); } catch (Exception e) {} 
    287         try { paramicsSocket.close(); } catch (Exception e) {} 
    288          
    289     } 
    290      
     329            } 
     330        } 
     331 
     332 
     333        try 
     334        { 
     335            in.close(); 
     336        } catch (Exception e) 
     337        { 
     338        } 
     339        try 
     340        { 
     341            out.close(); 
     342        } catch (Exception e) 
     343        { 
     344        } 
     345        try 
     346        { 
     347            serverSocket.close(); 
     348        } catch (Exception e) 
     349        { 
     350        } 
     351        try 
     352        { 
     353            paramicsSocket.close(); 
     354        } catch (Exception e) 
     355        { 
     356        } 
     357 
     358    } 
     359 
    291360    /** 
    292361     * Perform the action represented in the received XML document message. 
    293      * First determine if the action is from a READER, WRITER, and RESET.   
    294      * If the paramics action is REGISTER, add a new ParamicsFileReader/Writer  
    295      * to the local list of readers/writers and update the GUI with a  
    296      * FileRegUpdate object. If the paramics action is UNREGISTER, remove the  
    297      * ParamicsFileReader/Writer from the local list of readers/writers and update 
    298      * the GUI with a FileRegUpdate object.  If RESET is received, clear all  
    299      * readers and writers.  
    300      *  
     362     * First determine if the action is from a READER, WRITER, and RESET. If the 
     363     * paramics action is REGISTER, add a new ParamicsFileReader/Writer to the 
     364     * local list of readers/writers and update the GUI with a FileRegUpdate 
     365     * object. If the paramics action is UNREGISTER, remove the 
     366     * ParamicsFileReader/Writer from the local list of readers/writers and 
     367     * update the GUI with a FileRegUpdate object. If RESET is received, clear 
     368     * all readers and writers. 
     369     * 
    301370     * @param mess Received XML document message. 
    302371     */ 
    303     private void doMessage (Document mess) { 
    304          
     372    private void doMessage(Document mess) 
     373    { 
     374 
    305375        Element rootElement = mess.getDocumentElement(); 
    306376 
    307         String id     = null; 
     377        String id = null; 
    308378        String action = null; 
    309          
    310         switch(PARAMICS_COMM_TAGS.fromString(rootElement.getNodeName())) { 
     379 
     380        switch (PARAMICS_COMM_TAGS.fromString(rootElement.getNodeName())) 
     381        { 
    311382            case READER: 
    312                 id     = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
     383                id = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
    313384                action = rootElement.getAttribute(PARAMICS_COMM_TAGS.ACTION.tag); 
    314                  
    315                 switch(PARAMICS_ACTIONS.fromString(action)) { 
     385 
     386                switch (PARAMICS_ACTIONS.fromString(action)) 
     387                { 
    316388                    case REGISTER: 
    317                         Integer interval   = Integer.parseInt(rootElement.getChildNodes().item(0).getTextContent()); 
    318                         String  targetFile = rootElement.getChildNodes().item(1).getTextContent(); 
    319                          
    320                         readers.put(id, new ParamicsFileReader(workingDirectory, id,  
     389                        Integer interval = Integer.parseInt(rootElement.getChildNodes().item(0).getTextContent()); 
     390                        String targetFile = rootElement.getChildNodes().item(1).getTextContent(); 
     391 
     392                        readers.put(id, new ParamicsFileReader(workingDirectory, id, 
    321393                                interval, targetFile)); 
    322394                        readers.get(id).addObserver(this); 
    323395                        readers.get(id).addObserver(theGUI); 
    324                          
     396 
    325397                        setChanged(); 
    326                         notifyObservers(new FileRegUpdate(IO_TYPE.READ,  
     398                        notifyObservers(new FileRegUpdate(IO_TYPE.READ, 
    327399                                REG_TYPE.REGISTER, id, targetFile, interval)); 
    328400                        break; 
    329                     case UNREGISTER:  
     401                    case UNREGISTER: 
    330402                        readers.get(id).deleteObserver(this); 
    331403                        readers.get(id).deleteObserver(theGUI); 
     
    333405 
    334406                        setChanged(); 
    335                         notifyObservers(new FileRegUpdate(IO_TYPE.READ,  
    336                                 REG_TYPE.UNREGISTER, id, null, null));                       
     407                        notifyObservers(new FileRegUpdate(IO_TYPE.READ, 
     408                                REG_TYPE.UNREGISTER, id, null, null)); 
    337409                        break; 
    338410                } 
    339411                break; 
    340412            case WRITER: 
    341                 id     = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
     413                id = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
    342414                action = rootElement.getAttribute(PARAMICS_COMM_TAGS.ACTION.tag); 
    343                  
    344                 switch(PARAMICS_ACTIONS.fromString(action)) { 
     415 
     416                switch (PARAMICS_ACTIONS.fromString(action)) 
     417                { 
    345418                    case REGISTER: 
    346                         String targetFile = rootElement.getChildNodes().item(0).getTextContent();  
    347                          
    348                         writers.put(id, new ParamicsFileWriter(id,  
     419                        String targetFile = rootElement.getChildNodes().item(0).getTextContent(); 
     420 
     421                        writers.put(id, new ParamicsFileWriter(id, 
    349422                                workingDirectory, targetFile)); 
    350423                        writers.get(id).addObserver(theGUI); 
    351                          
     424 
    352425                        setChanged(); 
    353                         notifyObservers(new FileRegUpdate(IO_TYPE.WRITE,  
    354                                 REG_TYPE.REGISTER, id, targetFile, null));       
     426                        notifyObservers(new FileRegUpdate(IO_TYPE.WRITE, 
     427                                REG_TYPE.REGISTER, id, targetFile, null)); 
    355428                        break; 
    356                     case UNREGISTER:  
     429                    case UNREGISTER: 
    357430                        writers.remove(id); 
    358                          
     431 
    359432                        writers.get(id).deleteObserver(theGUI); 
    360433 
    361434                        setChanged(); 
    362                         notifyObservers(new FileRegUpdate(IO_TYPE.WRITE,  
     435                        notifyObservers(new FileRegUpdate(IO_TYPE.WRITE, 
    363436                                REG_TYPE.UNREGISTER, id, null, null)); 
    364437                        break; 
    365438                    case WRITE_FILE: 
    366                         writers.get(id).writeMessage((Element)rootElement.getChildNodes().item(0)); 
     439                        writers.get(id).writeMessage((Element) rootElement.getChildNodes().item(0)); 
    367440                        break; 
    368441                } 
     
    372445                writers.clear(); 
    373446                break; 
    374         }    
    375     } 
    376      
    377     /** 
    378      * Method waits to accept a socket connection from the CAD Simulator.   
    379      * When a connection has been established the method exits.  The input and 
    380      * output streams are created on the new socket. 
    381      *  
    382      * @param socketPort Socket port to use for establishing Socket communication. 
    383      * @throws IOException if there is an exception in establishing Socket communication. 
    384      */ 
    385     private void initializeSockets(Integer socketPort) throws IOException { 
    386      
     447        } 
     448    } 
     449 
     450    /** 
     451     * Method waits to accept a socket connection from the CAD Simulator. When a 
     452     * connection has been established the method exits. The input and output 
     453     * streams are created on the new socket. 
     454     * 
     455     * @param socketPort Socket port to use for establishing Socket 
     456     * communication. 
     457     * @throws IOException if there is an exception in establishing Socket 
     458     * communication. 
     459     */ 
     460    private void initializeSockets(Integer socketPort) throws IOException 
     461    { 
     462 
    387463        boolean waiting = true; 
    388          
    389         try { 
    390             serverSocket = new ServerSocket(socketPort);             
    391             //delay for accept timeout(milliseconds)         
    392             serverSocket.setSoTimeout(10 * 1000);   
    393         } 
    394         catch (IOException ioe) { 
    395             throw new IOException("Exception in creating " + 
    396                     "the server socket on port " + socketPort); 
    397         } 
    398          
    399         while(waiting) {             
    400             try{ 
     464 
     465        try 
     466        { 
     467            serverSocket = new ServerSocket(socketPort); 
     468            //delay for accept timeout(milliseconds) 
     469            serverSocket.setSoTimeout(10 * 1000); 
     470        } catch (IOException ioe) 
     471        { 
     472            throw new IOException("Exception in creating " 
     473                    + "the server socket on port " + socketPort); 
     474        } 
     475 
     476        while (waiting) 
     477        { 
     478            try 
     479            { 
    401480                paramicsSocket = serverSocket.accept(); 
    402481                waiting = false; 
    403             }  
    404             catch(SocketTimeoutException ste) { 
     482            } catch (SocketTimeoutException ste) 
     483            { 
    405484                System.out.println("...waiting..."); 
    406             }    
    407             catch(IOException ioe) { 
    408                 throw new IOException("Exception in creating " + 
    409                         "the receiving socket on port " + socketPort); 
    410             } 
    411         } 
    412  
    413          
     485            } catch (IOException ioe) 
     486            { 
     487                throw new IOException("Exception in creating " 
     488                        + "the receiving socket on port " + socketPort); 
     489            } 
     490        } 
     491 
     492 
    414493        //** out must be performed before in to unlock for connecting socket **// 
    415         try {        
    416             out     = new ObjectOutputStream(paramicsSocket.getOutputStream()); 
    417             in      = new ObjectInputStream(paramicsSocket.getInputStream()); 
    418         } 
    419         catch (IOException ioe) { 
    420             throw new IOException("Exception in creating input " + 
    421                     "and output streams on socket."); 
    422         } 
    423              
    424     } 
    425  
    426     /** 
    427      * Construct the ParamicsCommunicator with the properties file path,  
    428      * either from the command line arguments or default. 
    429      *  
     494        try 
     495        { 
     496            out = new ObjectOutputStream(paramicsSocket.getOutputStream()); 
     497            in = new ObjectInputStream(paramicsSocket.getInputStream()); 
     498        } catch (IOException ioe) 
     499        { 
     500            throw new IOException("Exception in creating input " 
     501                    + "and output streams on socket."); 
     502        } 
     503 
     504    } 
     505 
     506    /** 
     507     * Construct the ParamicsCommunicator with the properties file path, either 
     508     * from the command line arguments or default. 
     509     * 
    430510     * @param args Command line arguments. 
    431511     */ 
    432     public static void main(String[] args) { 
    433  
    434         try 
    435         { 
    436             if(System.getProperty("PARAMICS_COMM_PROPERTIES") != null) 
     512    public static void main(String[] args) 
     513    { 
     514        System.setProperty("PARAMICS_COMM_PROPERTIES", "config/paramics_communicator_config.properties"); 
     515 
     516        try 
     517        { 
     518            if (System.getProperty("PARAMICS_COMM_PROPERTIES") != null) 
    437519            { 
    438520                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    439      
     521 
    440522                new Thread(new ParamicsCommunicator(System.getProperty( 
    441523                        "PARAMICS_COMM_PROPERTIES"))).start(); 
    442             } 
    443             else 
    444             { 
    445                 throw new Exception ("PARAMICS_COMM_PROPERTIES system property not defined."); 
    446             } 
    447         }  
    448         catch (Exception e)  
    449         { 
    450             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Main",  
     524            } else 
     525            { 
     526                throw new Exception("PARAMICS_COMM_PROPERTIES system property not defined."); 
     527            } 
     528        } catch (Exception e) 
     529        { 
     530            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Main", 
    451531                    "Error occured initializing application", e); 
    452532 
    453             JOptionPane.showMessageDialog(null, e.getMessage(),  
    454                     "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);   
    455              
     533            JOptionPane.showMessageDialog(null, e.getMessage(), 
     534                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     535 
    456536            System.exit(-1); 
    457537        } 
    458      
    459          
    460     }    
    461      
     538 
     539 
     540    } 
    462541} 
Note: See TracChangeset for help on using the changeset viewer.