diff --git a/client/source/class/cv/io/Client.js b/client/source/class/cv/io/Client.js index 981469964fa..a0a492edb4f 100644 --- a/client/source/class/cv/io/Client.js +++ b/client/source/class/cv/io/Client.js @@ -73,9 +73,6 @@ qx.Class.define('cv.io.Client', { this.backendUrl = backendUrl; - this.watchdog = new cv.io.Watchdog(); - this.watchdog.setClient(this); - this.addresses = []; this.initialAddresses = []; this.filters = []; @@ -217,7 +214,6 @@ qx.Class.define('cv.io.Client', { ****************************************************** */ members: { - watchdog: null, backend: null, backendName: null, backendUrl: null, @@ -340,8 +336,6 @@ qx.Class.define('cv.io.Client', { if (this.loginSettings.loginOnly === true) { // connect to the backend this.getCurrentTransport().connect(); - // start the watchdog - this.watchdog.start(5); this.loginSettings.loginOnly = false; } else { @@ -563,8 +557,6 @@ qx.Class.define('cv.io.Client', { this.getCurrentTransport().handleSession(args, false); } else { this.getCurrentTransport().handleSession(args, true); - // once the connection is set up, start the watchdog - this.watchdog.start(5); } this.loginSettings.loggedIn = true; if (this.loginSettings.callbackAfterLoggedIn) { @@ -584,7 +576,6 @@ qx.Class.define('cv.io.Client', { this.getCurrentTransport().abort(); } this.loginSettings.loggedIn = false; - this.watchdog.stop(); }, /** @@ -665,4 +656,4 @@ qx.Class.define('cv.io.Client', { destruct: function() { this.stop(); } -}); \ No newline at end of file +}); diff --git a/client/source/class/cv/io/Watchdog.js b/client/source/class/cv/io/Watchdog.js index e2a044f18e0..11059936ab0 100644 --- a/client/source/class/cv/io/Watchdog.js +++ b/client/source/class/cv/io/Watchdog.js @@ -67,6 +67,9 @@ qx.Class.define("cv.io.Watchdog", { }, start: function (watchdogTimer) { + if (this.__id) { + this.stop(); + } this.__id = setInterval(this.aliveCheckFunction.bind(this), watchdogTimer * 1000); }, @@ -77,6 +80,10 @@ qx.Class.define("cv.io.Watchdog", { } }, + isActive: function() { + return !!this.__id; + }, + ping: function (fullReload) { this.last = new Date(); if (fullReload) { diff --git a/client/source/class/cv/io/transport/LongPolling.js b/client/source/class/cv/io/transport/LongPolling.js index 288c489de16..3eaa20b71e0 100644 --- a/client/source/class/cv/io/transport/LongPolling.js +++ b/client/source/class/cv/io/transport/LongPolling.js @@ -32,6 +32,8 @@ qx.Class.define('cv.io.transport.LongPolling', { */ construct: function(client) { this.client = client; + this.watchdog = new cv.io.Watchdog(); + this.watchdog.setClient(client); }, @@ -41,6 +43,7 @@ qx.Class.define('cv.io.transport.LongPolling', { ****************************************************** */ members: { + watchdog: null, doRestart: false, // are we currently in a restart, e.g. due to the watchdog xhr: null, // the ongoing AJAX request lastIndex: -1, // index returned by the last request @@ -84,7 +87,7 @@ qx.Class.define('cv.io.transport.LongPolling', { successCallback = this.handleRead; } this.__startReading(data, successCallback); - this.client.watchdog.start(5); + this.watchdog.start(5); }, __startReading: function(data, callback) { @@ -117,9 +120,13 @@ qx.Class.define('cv.io.transport.LongPolling', { } else { this.error("restarting XHR read requests in "+delay+" ms"); } + if (!this.watchdog.isActive()) { + // watchdog has been stopped in the abort function -> restart it + this.watchdog.start(5); + } qx.event.Timer.once(function () { this.__startReading(); - this.client.watchdog.ping(true); + this.watchdog.ping(true); }, this, delay); } return; @@ -143,7 +150,7 @@ qx.Class.define('cv.io.transport.LongPolling', { var url = this.xhr.getUrl().split("?").shift()+"?"+this.client.getQueryString(data); this.xhr.setUrl(url); this.xhr.send(); - this.client.watchdog.ping(); + this.watchdog.ping(); } }, @@ -153,7 +160,7 @@ qx.Class.define('cv.io.transport.LongPolling', { this.client.setDataReceived(false); if (this.running) { // retry initial request this.xhr.send(); - this.client.watchdog.ping(); + this.watchdog.ping(); } return; } @@ -179,7 +186,7 @@ qx.Class.define('cv.io.transport.LongPolling', { this.xhr.removeListener("success", this.handleReadStart, this); this.xhr.addListener("success", this.handleRead, this); this.xhr.send(); - this.client.watchdog.ping(); + this.watchdog.ping(); } }, @@ -290,6 +297,7 @@ qx.Class.define('cv.io.transport.LongPolling', { this.client.backend.hooks.onClose.bind(this); } } + this.watchdog.stop(); } } }); \ No newline at end of file diff --git a/client/source/class/cv/io/transport/Sse.js b/client/source/class/cv/io/transport/Sse.js index e3ca47cf1a9..7c59f354223 100644 --- a/client/source/class/cv/io/transport/Sse.js +++ b/client/source/class/cv/io/transport/Sse.js @@ -91,7 +91,6 @@ qx.Class.define('cv.io.transport.Sse', { this.debug("connection established"); this.client.setConnected(true); }.bind(this); - this.client.watchdog.start(5); }, /** @@ -101,7 +100,6 @@ qx.Class.define('cv.io.transport.Sse', { this.client.record("read", e.data); var json = JSON.parse(e.data); var data = json.d; - this.client.watchdog.ping(true); this.client.update(data); this.client.setDataReceived(true); }, @@ -160,12 +158,10 @@ qx.Class.define('cv.io.transport.Sse', { }, /** - * Restart the read request, e.g. when the watchdog kicks in - * - * + * Restart the read request */ restart: function (doFullReload) { - if (doFullReload || !this.isConnectionRunning()) { + if (doFullReload || this.eventSource.readyState === EventSource.CLOSED) { this.abort(); this.connect(); }