From 1080b5a654fbf337de5a3a12b3be7fc524b56696 Mon Sep 17 00:00:00 2001 From: hengsin Date: Fri, 31 Jan 2020 12:20:05 +0800 Subject: [PATCH] IDEMPIERE-4154 ServerPush Adjustments. Further refinement of the long polling serverpush implmentation. Add back zk-websocket-serverpush.xml --- .../zk/atmosphere/AtmosphereServerPush.java | 37 ++++++++++++++++--- .../src/web/js/jawwa/atmosphere/serverpush.js | 3 +- .../WEB-INF/zk-websocket-serverpush.xml | 13 +++++++ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 org.adempiere.ui.zk/WEB-INF/zk-websocket-serverpush.xml diff --git a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java index c42122f0a6..d2eb43c485 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java +++ b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java @@ -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 { diff --git a/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js b/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js index dd053a4db7..c7fe0bf790 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js +++ b/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js @@ -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 @@ } } }); -})(); \ No newline at end of file +})(); diff --git a/org.adempiere.ui.zk/WEB-INF/zk-websocket-serverpush.xml b/org.adempiere.ui.zk/WEB-INF/zk-websocket-serverpush.xml new file mode 100644 index 0000000000..e6a17efc6c --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/zk-websocket-serverpush.xml @@ -0,0 +1,13 @@ + + + + + + + + ajax + org.idempiere.ui.zk.websocket.WebSocketServerPush + + \ No newline at end of file