BF [2749008 ] Error in Task Management from webui

* Task should stop if desktop is no longer available.
* Reduce logging level from WARNING and SEVERE to FINE, too verbose.
* OSTask.java - display exception to client.
This commit is contained in:
Heng Sin Low 2009-04-22 09:35:49 +00:00
parent 1a2dd723b2
commit 0da67d98e8
2 changed files with 29 additions and 26 deletions

View File

@ -50,7 +50,7 @@ public class OSTask extends Thread
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(OSTask.class); private static CLogger log = CLogger.getCLogger(OSTask.class);
/** Read Out */ /** Read Out */
private Thread m_outReader = new Thread() private Thread m_outReader = new Thread()
{ {
@ -116,9 +116,9 @@ public class OSTask extends Thread
return; return;
m_outReader.start(); m_outReader.start();
m_errReader.start(); m_errReader.start();
Integer exitValue = null; Integer exitValue = null;
while(exitValue == null) while(exitValue == null)
{ {
// //
try try
@ -140,6 +140,7 @@ public class OSTask extends Thread
catch (IOException ioe) catch (IOException ioe)
{ {
log.log(Level.SEVERE, "(ioe)", ioe); log.log(Level.SEVERE, "(ioe)", ioe);
m_err.append(ioe.getLocalizedMessage());
} }
} // run } // run
@ -204,5 +205,5 @@ public class OSTask extends Thread
{ {
return m_inStream; return m_inStream;
} // getInStream } // getInStream
} // Task } // Task

View File

@ -43,13 +43,13 @@ import org.zkoss.zul.Html;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: ATask.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $ * @version $Id: ATask.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
* *
* @author Low Heng Sin * @author Low Heng Sin
*/ */
public class WTask extends Window implements EventListener public class WTask extends Window implements EventListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = -1235619876719378703L; private static final long serialVersionUID = -1235619876719378703L;
@ -67,7 +67,7 @@ public class WTask extends Window implements EventListener
private Thread taskThread; private Thread taskThread;
/************************************************************************** /**************************************************************************
* Full Constructor * Full Constructor
* @param title title * @param title title
@ -80,18 +80,18 @@ public class WTask extends Window implements EventListener
try try
{ {
zkInit(); zkInit();
setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
// //
m_task = task; m_task = task;
if (task.isServerProcess()) if (task.isServerProcess())
info.setContent("Executing on Server ..."); info.setContent("Executing on Server ...");
else else
info.setContent("Executing locally ..."); info.setContent("Executing locally ...");
SessionManager.getAppDesktop().showWindow(this); SessionManager.getAppDesktop().showWindow(this);
Events.echoEvent("executeTask", this, null); Events.echoEvent("executeTask", this, null);
} }
catch(Exception e) catch(Exception e)
{ {
@ -108,20 +108,20 @@ public class WTask extends Window implements EventListener
String cmd = Msg.parseTranslation(Env.getCtx(), m_task.getOS_Command()).trim(); String cmd = Msg.parseTranslation(Env.getCtx(), m_task.getOS_Command()).trim();
if (cmd == null || cmd.equals("")) if (cmd == null || cmd.equals(""))
info.setContent("Cannot execute '" + m_task.getOS_Command() + "'"); info.setContent("Cannot execute '" + m_task.getOS_Command() + "'");
OSTask osTask = new OSTask(cmd); OSTask osTask = new OSTask(cmd);
osTask.start(); osTask.start();
while (true) { while (true) {
try { try {
Thread.sleep(500); Thread.sleep(500);
Executions.activate(desktop); Executions.activate(desktop);
try { try {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(osTask.getOut()) sb.append(osTask.getOut())
.append("<br>-----------<br>") .append("<br>-----------<br>")
.append(osTask.getErr()) .append(osTask.getErr())
.append("<br>-----------"); .append("<br>-----------");
info.setContent(sb.toString().replace("\n", "<br>")); info.setContent(sb.toString().replace("\n", "<br>"));
if (!osTask.isAlive()) if (!osTask.isAlive())
{ {
@ -134,14 +134,16 @@ public class WTask extends Window implements EventListener
Executions.deactivate(desktop); Executions.deactivate(desktop);
} }
} catch (DesktopUnavailableException e) { } catch (DesktopUnavailableException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e); log.log(Level.FINE, e.getLocalizedMessage(), e);
} catch (InterruptedException e) {
log.log(Level.WARNING, e.getLocalizedMessage(), e);
osTask.interrupt(); osTask.interrupt();
break; break;
} } catch (InterruptedException e) {
log.log(Level.FINE, e.getLocalizedMessage(), e);
osTask.interrupt();
break;
}
} }
} }
}; };
taskThread = new Thread(runnable); taskThread = new Thread(runnable);
taskThread.start(); taskThread.start();
@ -173,15 +175,15 @@ public class WTask extends Window implements EventListener
div.appendChild(info); div.appendChild(info);
center.appendChild(div); center.appendChild(div);
center.setFlex(true); center.setFlex(true);
South south = new South(); South south = new South();
layout.appendChild(south); layout.appendChild(south);
south.setStyle("border: none"); south.setStyle("border: none");
south.appendChild(confirmPanel); south.appendChild(confirmPanel);
// //
confirmPanel.addActionListener(this); confirmPanel.addActionListener(this);
confirmPanel.getOKButton().setEnabled(false); confirmPanel.getOKButton().setEnabled(false);
LayoutUtils.sendDeferLayoutEvent(layout, 100); LayoutUtils.sendDeferLayoutEvent(layout, 100);
} // jbInit } // jbInit
@ -194,7 +196,7 @@ public class WTask extends Window implements EventListener
{ {
if (taskThread != null && taskThread.isAlive()) if (taskThread != null && taskThread.isAlive())
taskThread.interrupt(); taskThread.interrupt();
SessionManager.getAppDesktop().closeActiveWindow(); SessionManager.getAppDesktop().closeActiveWindow();
} // actionPerformed } // actionPerformed