IDEMPIERE-4154 ServerPush Adjustments. Logout should stop serverpush. Handle stop/abort in serverpush.js, add optional trace.

This commit is contained in:
hengsin 2020-02-09 21:47:44 +08:00
parent 70bb9041d2
commit 3abe35f1f3
3 changed files with 39 additions and 11 deletions

View File

@ -242,13 +242,16 @@ public class AtmosphereServerPush implements ServerPush {
return;
}
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();
} catch (IOException e) {
this.resource.set(null);
synchronized (schedules) {
schedules.clear();
}
if (Executions.getCurrent() != null) {
if (log.isDebugEnabled())
log.debug("Stopping server push for " + desktop);
Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.stopServerPush('" + desktop.getId() + "');"));
}
}
public void onRequest(AtmosphereResource resource) {

View File

@ -369,6 +369,10 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
*/
public void logout()
{
Desktop desktop = Executions.getCurrent().getDesktop();
if (desktop.isServerPushEnabled())
desktop.enableServerPush(false);
Session session = logout0();
DesktopCache desktopCache = ((SessionCtrl)session).getDesktopCache();
@ -383,6 +387,10 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
desktopCache.removeDesktop(Executions.getCurrent().getDesktop());
}
public void logoutAfterTabDestroyed(){
Desktop desktop = Executions.getCurrent().getDesktop();
if (desktop.isServerPushEnabled())
desktop.enableServerPush(false);
Session session = logout0();
//clear context, invalidate session
@ -392,7 +400,7 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
protected Session logout0() {
Session session = Executions.getCurrent().getDesktop().getSession();
Session session = Executions.getCurrent() != null ? Executions.getCurrent().getDesktop().getSession() : null;
if (keyListener != null) {
keyListener.detach();
@ -409,7 +417,8 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
getPage().removeComponents();
//clear session attributes
session.getAttributes().clear();
if (session != null)
session.getAttributes().clear();
//logout ad_session
AEnv.logout();

View File

@ -4,7 +4,9 @@
if (dt._serverpush)
dt._serverpush.stop();
var spush = new jawwa.atmosphere.ServerPush(dt, timeout);
//change to true to enable trace of execution
var trace = false;
var spush = new jawwa.atmosphere.ServerPush(dt, timeout, trace);
spush.start();
};
jawwa.atmosphere.stopServerPush = function(dtid) {
@ -18,6 +20,7 @@
delay: 10,
failures: 0,
timeout: 0,
trace: false,
ajaxOptions: {
url: zk.ajaxURI("/comet", {au: true}),
type: "GET",
@ -27,14 +30,17 @@
data: null,
dataType: "text"
},
$init: function(desktop, timeout) {
$init: function(desktop, timeout, trace) {
this.desktop = desktop;
this.timeout = timeout;
this.ajaxOptions.data = { dtid: this.desktop.id };
this.ajaxOptions.timeout = this.timeout;
this.trace = trace;
var me = this;
this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) {
if (textStatus != "timeout") {
if (me.trace)
console.log("error: " + textStatus + " dtid: " + me.desktop.id);
if (textStatus != "timeout" && textStatus != "abort") {
if (typeof console == "object") {
console.error(textStatus);
console.error(errorThrown);
@ -43,10 +49,14 @@
}
};
this.ajaxOptions.success = function(data) {
if (me.trace)
console.log("success" + " dtid: " + me.desktop.id);
zAu.cmd0.echo(this.desktop);
me.failures = 0;
};
this.ajaxOptions.complete = function() {
if (me.trace)
console.log("complete"+ " dtid: " + me.desktop.id);
me._schedule();
};
},
@ -62,16 +72,22 @@
if (!this.active)
return;
if (this.trace)
console.log("_send"+ " dtid: " + this.desktop.id);
var jqxhr = $.ajax(this.ajaxOptions);
this._req = jqxhr;
zAu.cmd0.echo(this.desktop);
},
start: function() {
if (this.trace)
console.log("start"+ " dtid: " + this.desktop.id);
this.desktop._serverpush = this;
this.active = true;
this._send();
},
stop: function() {
if (this.trace)
console.log("stop"+ " dtid: " + this.desktop.id);
this.active = false;
this.desktop._serverpush = null;
if (this._req) {