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 3a33cf48bc..8b03c20341 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 @@ -34,7 +34,6 @@ import org.zkoss.zk.ui.UiException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.impl.ExecutionCarryOver; -import org.zkoss.zk.ui.sys.DesktopCtrl; import org.zkoss.zk.ui.sys.Scheduler; import org.zkoss.zk.ui.sys.ServerPush; import org.zkoss.zk.ui.util.Clients; @@ -126,12 +125,12 @@ public class AtmosphereServerPush implements ServerPush { private synchronized void onPush() throws IOException { AtmosphereResource resource = this.resource.get(); - if (resource != null) { + if (resource != null) { switch (resource.transport()) { - case JSONP: + case POLLING: case LONG_POLLING: if (resource.isSuspended()) - commitResponse(); + commitResponse(); break; case WEBSOCKET : case STREAMING: @@ -178,15 +177,12 @@ public class AtmosphereServerPush implements ServerPush { @Override public synchronized void schedule(EventListener task, T event, Scheduler scheduler) { - boolean pendingPush = ((DesktopCtrl)desktop.get()).scheduledServerPush(); scheduler.schedule(task, event); - if (!pendingPush || (this.resource.get() != null && this.resource.get().isSuspended())) { - try { - onPush(); - } catch (IOException e) { - log.warn(e.getLocalizedMessage(), e); - } - } + try { + onPush(); + } catch (IOException e) { + log.error(e.getLocalizedMessage(), e); + } } @Override @@ -222,25 +218,19 @@ public class AtmosphereServerPush implements ServerPush { public synchronized void onRequest(AtmosphereResource resource) { if (this.resource.get() != null) { AtmosphereResource aResource = this.resource.get(); - if (aResource.isSuspended()) { + if (aResource != resource) { try { - commitResponse(); + onPush(); } catch (IOException e) { - e.printStackTrace(); + log.error(e.getLocalizedMessage(), e); } } } - Desktop desktop = this.desktop.get(); - if (desktop != null && desktop instanceof DesktopCtrl) - { - if (((DesktopCtrl)desktop).scheduledServerPush()) - { - return; - } - } - this.resource.set(resource); + if (log.isTraceEnabled()) { + log.trace(resource.transport().name()); + } if (!resource.isSuspended()) { resource.suspend(-1, true); } 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 f04892d009..27e1015328 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 @@ -16,9 +16,8 @@ desktop: null, active: false, timeout: 300000, - delay: 1000, + delay: 100, failures: 0, - count: 0, $init: function(desktop, timeout) { this.desktop = desktop; @@ -37,40 +36,42 @@ return; var me = this; - var socket = $.atmosphere; var request = { url: zk.ajaxURI("/comet", { au: true }), logLevel : 'debug', - transport : 'streaming', - fallbackTransport: 'long-polling', + transport : 'long-polling', + fallbackTransport: 'streaming', method: "GET", cache: false, async: true, timeout: me.timeout, onError: function(response) { + if (typeof console == "object") { + console.error(response); + } me.failures += 1; - me.count--; - if (response.transport == 'long-polling' && me.count == 0) { - me._schedule(); - } else if (me.failures >= 10) { + if (me.failures < 10) { + if (response.transport == 'long-polling') { + me._schedule(); + } + } else { me.stop(); } }, onMessage: function(response) { zAu.cmd0.echo(me.desktop); me.failures = 0; - me.count--; - if (response.transport == 'long-polling' && me.count == 0) { - me._schedule(); - } + if (response.transport == 'long-polling') { + me._schedule(); + } } }; request.url = request.url+'?dtid='+me.desktop.id; - this.count++; + socket.unsubscribe(); socket.subscribe(request); }, start: function() {