From 547aca87cca477bc2149361e87c80e22bd7916ea Mon Sep 17 00:00:00 2001 From: mka Date: Fri, 20 Sep 2013 09:16:30 +0000 Subject: [PATCH] Applet's fix. Now the alert shows before starting the SALOME. --- .../src/org/splat/launcher/ToolbarApplet.java | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java b/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java index 015da70..31600d9 100644 --- a/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java +++ b/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java @@ -184,6 +184,56 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener error.printStackTrace(); // RKV: NOPMD: Applet output } } + + /** + * The class that reads output of the process passed in constructor in a separate thread. + * (a quick fix to the problem that we need to read bash script + * output in order for it to proceed correctly). + */ + class ScriptOutputReader implements Runnable { + + /** + * A quick fix to the problem that we need to read bash script output in order for it to proceed correctly. + */ + Process _proc; + + /** + * Constructor from process to take output from. + * @param proc + * the process to read from. + */ + public ScriptOutputReader(final Process proc) { + _proc = proc; + } + + /** + * {@inheritDoc} + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + try { + BufferedReader bri = new BufferedReader(new InputStreamReader( + _proc.getInputStream())); + BufferedReader bre = new BufferedReader(new InputStreamReader( + _proc.getErrorStream())); + String line = bri.readLine(); + while (line != null) { + System.out.println(line); // RKV: NOPMD: Applet output + line = bri.readLine(); + } + bri.close(); + line = bre.readLine(); + while (line != null) { + System.err.println(line); // RKV: NOPMD: Applet output + line = bre.readLine(); + } + bre.close(); + } catch(Exception e) { + // NOPMD: empty catch block - nothing really to do here. + } + } + } /** * Checkout a scenario and start Salome with it. @@ -252,22 +302,10 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener cmd.toArray(new String[] {}), null, new File(SALOME_HOME)); - BufferedReader bri = new BufferedReader(new InputStreamReader( - proc.getInputStream())); - BufferedReader bre = new BufferedReader(new InputStreamReader( - proc.getErrorStream())); - String line = bri.readLine(); - while (line != null) { - System.out.println(line); // RKV: NOPMD: Applet output - line = bri.readLine(); - } - bri.close(); - line = bre.readLine(); - while (line != null) { - System.err.println(line); // RKV: NOPMD: Applet output - line = bre.readLine(); - } - bre.close(); + // Read script's output in separate thread. + ScriptOutputReader appletOutputReader = new ScriptOutputReader(proc); + Thread thread = new Thread(appletOutputReader); + thread.start(); } else { // Checkout of the scenario is failed at the beginning. if (response != null) { -- 2.39.2