IDEMPIERE-4154 ServerPush Adjustments. Further refinement of the long polling serverpush implmentation. Add back zk-websocket-serverpush.xml

This commit is contained in:
hengsin 2020-01-31 12:20:05 +08:00
parent 4a81373e9d
commit 1080b5a654
3 changed files with 47 additions and 6 deletions

View File

@ -184,11 +184,27 @@ public class AtmosphereServerPush implements ServerPush {
synchronized (schedules) {
schedules.add(new Schedule(task, event, scheduler));
}
boolean ok = false;
try {
commitResponse();
ok = commitResponse();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
if (!ok) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {}
if (schedules.size() > 0) {
try {
ok = commitResponse();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
if (!ok) {
log.warn("Failed to resume long polling resource");
}
}
}
} else {
//in event listener thread, can schedule immediately
scheduler.schedule(task, event);
@ -204,11 +220,16 @@ public class AtmosphereServerPush implements ServerPush {
return;
}
log.debug("Starting server push for " + desktop);
Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.startServerPush('" + desktop.getId() + "', " + timeout
+ ");"));
if (log.isDebugEnabled())
log.debug("Starting server push for " + desktop);
startClientPush(desktop);
}
private void startClientPush(Desktop desktop) {
Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.startServerPush('" + desktop.getId() + "', " + timeout
+ ");"));
}
@Override
public void stop() {
Desktop desktop = this.desktop.getAndSet(null);
@ -217,7 +238,8 @@ public class AtmosphereServerPush implements ServerPush {
return;
}
log.debug("Stopping server push for " + desktop);
if (log.isDebugEnabled())
log.debug("Stopping server push for " + desktop);
Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.stopServerPush('" + desktop.getId() + "');"));
try {
commitResponse();
@ -263,6 +285,11 @@ public class AtmosphereServerPush implements ServerPush {
@Override
public void resume() {
if (desktop == null || desktop.get() == null) {
throw new IllegalStateException(
"ServerPush cannot be resumed without desktop, or has been stopped!call #start(desktop)} instead");
}
startClientPush(desktop.get());
}
private class Schedule<T extends Event> {

View File

@ -64,6 +64,7 @@
var jqxhr = $.ajax(this.ajaxOptions);
this._req = jqxhr;
zAu.cmd0.echo(this.desktop);
},
start: function() {
this.desktop._serverpush = this;
@ -79,4 +80,4 @@
}
}
});
})();
})();

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE zk>
<!--
zk.xml Copyright (C) 2006 Potix Corporation. All Rights Reserved.
-->
<zk>
<device-config>
<device-type>ajax</device-type>
<server-push-class>org.idempiere.ui.zk.websocket.WebSocketServerPush</server-push-class>
</device-config>
</zk>