use of org.zkoss.zk.ui.DesktopUnavailableException in project adempiere by adempiere.
the class ServerPushTemplate method execute.
/**
* Execute callback in UI thread
* @param callback
*/
public void execute(IServerPushCallback callback) {
boolean inUIThread = Executions.getCurrent() != null;
boolean desktopActivated = false;
try {
if (!inUIThread) {
//10 minutes timeout
if (Executions.activate(desktop, 10 * 60 * 1000)) {
desktopActivated = true;
} else {
throw new DesktopUnavailableException("Timeout activating desktop.");
}
}
callback.updateUI();
} catch (DesktopUnavailableException de) {
throw de;
} catch (Exception e) {
throw new AdempiereException("Failed to update client in server push worker thread.", e);
} finally {
if (!inUIThread && desktopActivated) {
Executions.deactivate(desktop);
}
}
}
use of org.zkoss.zk.ui.DesktopUnavailableException in project adempiere by adempiere.
the class WTask method executeTask.
// ATask
public void executeTask() {
Runnable runnable = new Runnable() {
public void run() {
//get full control of desktop
org.zkoss.zk.ui.Desktop desktop = WTask.this.getDesktop();
String cmd = Msg.parseTranslation(Env.getCtx(), m_task.getOS_Command()).trim();
if (cmd == null || cmd.equals(""))
info.setContent("Cannot execute '" + m_task.getOS_Command() + "'");
OSTask osTask = new OSTask(cmd);
osTask.start();
while (true) {
try {
Thread.sleep(500);
Executions.activate(desktop, 500);
try {
StringBuffer sb = new StringBuffer();
sb.append(osTask.getOut()).append("<br>-----------<br>").append(osTask.getErr()).append("<br>-----------");
info.setContent(sb.toString().replace("\n", "<br>"));
if (!osTask.isAlive()) {
confirmPanel.getButton(ConfirmPanel.A_CANCEL).setEnabled(false);
confirmPanel.getOKButton().setEnabled(true);
break;
}
} finally {
//release full control of desktop
Executions.deactivate(desktop);
}
} catch (DesktopUnavailableException e) {
log.log(Level.FINE, e.getLocalizedMessage(), e);
osTask.interrupt();
break;
} catch (InterruptedException e) {
log.log(Level.FINE, e.getLocalizedMessage(), e);
osTask.interrupt();
break;
}
}
}
};
taskThread = new Thread(runnable);
taskThread.start();
}
Aggregations