certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] jcerti/src/certi rti/impl/CertiRtiAmbassador.ja...


From: CERTI CVS commits
Subject: [certi-cvs] jcerti/src/certi rti/impl/CertiRtiAmbassador.ja...
Date: Tue, 16 Oct 2012 07:51:06 +0000

CVSROOT:        /sources/certi
Module name:    jcerti
Changes by:     Eric NOULARD <erk>      12/10/16 07:51:06

Modified files:
        src/certi/rti/impl: CertiRtiAmbassador.java 
Added files:
        src/certi/logging: StreamListener.java 

Log message:
        Consume stdour and stderr from RTIA in order to avoid deadlock.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/certi/logging/StreamListener.java?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/certi/rti/impl/CertiRtiAmbassador.java?cvsroot=certi&r1=1.5&r2=1.6

Patches:
Index: rti/impl/CertiRtiAmbassador.java
===================================================================
RCS file: /sources/certi/jcerti/src/certi/rti/impl/CertiRtiAmbassador.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- rti/impl/CertiRtiAmbassador.java    16 Dec 2011 07:34:33 -0000      1.5
+++ rti/impl/CertiRtiAmbassador.java    16 Oct 2012 07:51:06 -0000      1.6
@@ -22,6 +22,7 @@
 import certi.communication.*;
 import certi.communication.messages.*;
 import certi.logging.HtmlFormatter;
+import certi.logging.StreamListener;
 import hla.rti.*;
 import hla.rti.jlc.RTIambassadorEx;
 import java.io.File;
@@ -137,7 +138,14 @@
         try {
             String rtiaPathString = properties.getProperty("rtiaPath") != null 
? properties.getProperty("rtiaPath") : "";
 
-            Runtime.getRuntime().exec(rtiaPathString + "rtia -p " + 
serverSocket.getLocalPort());
+            Process rtiaProcess = Runtime.getRuntime().exec(rtiaPathString + 
"rtia -p " + 
+                                                            
serverSocket.getLocalPort());
+            // Read error and output streams, so that in case debugging is 
enabled for RTIA
+            // the process will not block because stream buffers are full 
+            StreamListener outListener = new 
StreamListener(rtiaProcess.getInputStream());
+            StreamListener errListener = new 
StreamListener(rtiaProcess.getErrorStream());
+            outListener.start();
+            errListener.start();
         } catch (IOException exception) {
             throw new RTIinternalError("RTI Ambassador executable not found. " 
+ exception.getLocalizedMessage());
         }

Index: logging/StreamListener.java
===================================================================
RCS file: logging/StreamListener.java
diff -N logging/StreamListener.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ logging/StreamListener.java 16 Oct 2012 07:51:06 -0000      1.1
@@ -0,0 +1,54 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA Run Time Infrastructure
+// Copyright (C) 2012 Jan-Patrick Osterloh
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+package certi.logging;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.logging.Logger;
+
+import certi.rti.impl.CertiRtiAmbassador;
+
+public class StreamListener extends Thread {
+       private InputStream is;
+       private final static Logger LOGGER = 
Logger.getLogger(CertiRtiAmbassador.class.getName());
+       
+
+       public StreamListener(InputStream is) {
+               this.is = is;
+       }
+       
+       public void run() {
+               try {
+                       InputStreamReader isr = new InputStreamReader(is);
+                       BufferedReader br = new BufferedReader(isr);
+                       String line = null;
+                       while ((line = br.readLine()) != null) {
+                           LOGGER.info(line);
+                       }
+                       br.close();
+                       isr.close();
+               } catch (IOException ioe) {
+                       ioe.printStackTrace();
+               }
+       }
+
+}
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]