/** * This can be triggered at the end of a IO Request. In that case, it contains * a data type as an identifier, and the request response itself. * Can be used this way to listen for data changes from various parts of the application. */ qx.Class.define("org.argeo.ria.remote.RemoteNotifier", { extend : qx.core.Object, construct : function(uri, pollService, addService, removeService){ this.base(arguments); this.setUri(uri); this.setPollService(pollService); this.setAddService(addService); this.setRemoveService(removeService); }, properties :{ uri : { check : "String" }, pollService : {check : "String"}, addService : {check : "String"}, removeService : {check : "String"}, eventParamName : {check : "String", init:"eventType"}, eventXPath : {check : "String", init:"//event"}, eventTypeXPath : {check : "String", init:"@type"}, eventDataXPath : {check : "String", init:"@data"}, timeout : { init : 20000 }, interrupt : { check : "Boolean", init : false } }, members : { addListener : function(eventType, eventParamName){ var req = this._getRequest(this.getAddService()); req.setParameter(this.getEventParamName(), eventType); req.send(); }, removeListener : function(eventType, eventParamName){ var req = this._getRequest(this.getRemoveService()); req.setParameter(this.getEventParamName(), eventType); req.send(); }, startPolling : function(){ this.setInterrupt(false); var req = this._getRequest(this.getPollService()); req.setParameter("timeout", "10"); req.addListener("completed", this._pollHandler, this); req.send(); }, stopPolling : function(){ this.setInterrupt(true); }, _poll : function(){ if(this.getInterrupt()) return; var req = this._getRequest(this.getPollService()); req.setParameter("timeout", this.getTimeout()); req.setTimeout(this.getTimeout() + 5000); req.addListener("completed", this._pollHandler, this); req.send(); }, _pollHandler : function(response){ // Parse response var messages = org.argeo.ria.util.Element.selectNodes(response.getContent(), this.getEventXPath()); if(messages){ for(var i=0;i