IDEMPIERE-174 Performance: Use Executions.schedule instead of the Executions.activate and Executions.deactivate pair
This commit is contained in:
parent
3e59a45fd2
commit
413e7214ca
|
@ -17,6 +17,8 @@ import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.zkoss.zk.ui.Desktop;
|
import org.zkoss.zk.ui.Desktop;
|
||||||
import org.zkoss.zk.ui.DesktopUnavailableException;
|
import org.zkoss.zk.ui.DesktopUnavailableException;
|
||||||
import org.zkoss.zk.ui.Executions;
|
import org.zkoss.zk.ui.Executions;
|
||||||
|
import org.zkoss.zk.ui.event.Event;
|
||||||
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zk UI update must be done in either UI thread or using server push. This class help to implement
|
* Zk UI update must be done in either UI thread or using server push. This class help to implement
|
||||||
|
@ -40,30 +42,26 @@ public class ServerPushTemplate {
|
||||||
* Execute callback in UI thread
|
* Execute callback in UI thread
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
public void execute(IServerPushCallback callback) {
|
public void execute(final IServerPushCallback callback) {
|
||||||
boolean inUIThread = Executions.getCurrent() != null;
|
boolean inUIThread = Executions.getCurrent() != null;
|
||||||
boolean desktopActivated = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!inUIThread) {
|
if (!inUIThread) {
|
||||||
//10 minutes timeout
|
EventListener<Event> task = new EventListener<Event>() {
|
||||||
if (Executions.activate(desktop, 10 * 60 * 1000)) {
|
@Override
|
||||||
desktopActivated = true;
|
public void onEvent(Event event) throws Exception {
|
||||||
} else {
|
callback.updateUI();
|
||||||
throw new DesktopUnavailableException("Timeout activating desktop.");
|
}
|
||||||
}
|
};
|
||||||
|
Executions.schedule(desktop, task, new Event("onExecute"));
|
||||||
|
} else {
|
||||||
|
callback.updateUI();
|
||||||
}
|
}
|
||||||
callback.updateUI();
|
|
||||||
} catch (DesktopUnavailableException de) {
|
} catch (DesktopUnavailableException de) {
|
||||||
throw de;
|
throw de;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AdempiereException("Failed to update client in server push worker thread.", e);
|
throw new AdempiereException("Failed to update client in server push worker thread.", e);
|
||||||
} finally {
|
|
||||||
if (!inUIThread && desktopActivated) {
|
|
||||||
Executions.deactivate(desktop);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue