X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.webapp%2Fsrc%2Fmain%2Fwebapp%2Fargeo-ria-src%2Fclass%2Forg%2Fargeo%2Fria%2Fremote%2FJmsClient.js;h=eceaceff0c7585997672cb6e16df8fd1f167c5f2;hb=86f06959d772c750a516780b448d5cbfa16cd48e;hp=bcf6e3a6d90d3e46fd431e84ed25b295c584760d;hpb=2763531f63462f90eded750b81bd43208844957b;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/remote/JmsClient.js b/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/remote/JmsClient.js index bcf6e3a6d..eceaceff0 100644 --- a/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/remote/JmsClient.js +++ b/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/remote/JmsClient.js @@ -1,3 +1,7 @@ +/** + * A standard client for sending/receiving JMS message. + * It is based on ActiveMQ Ajax implementation. + */ qx.Class.define("org.argeo.ria.remote.JmsClient", { type : "singleton", @@ -8,7 +12,7 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { }, members : { // The URI of the MessageListenerServlet - uri : '../amqMessage', + uri : '../amq', // Polling. Set to true (default) if waiting poll for messages is needed poll : true, @@ -20,9 +24,17 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { _pollDelay : 0, _first : true, + /** + * Trigger at each poll event. + * @param first {Boolean} Whether it is the first event to be triggered. + */ _pollEvent : function(first) {}, _handlers : new Array(), + /** + * Parses the XML response to a message POST. + * @param response {qx.io.remote.Response} The query response + */ _messageHandler : function(response) { var doc = response.getContent(); var messages = org.argeo.ria.util.Element.selectNodes(doc, "//response"); @@ -34,6 +46,10 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { } }, + /** + * Parses the empty response of a poll GET query. + * @param response {qx.io.remote.Response} The query response + */ _pollHandler : function(response) { try { this._messageHandler(response); @@ -49,6 +65,10 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { this._sendPoll(); }, + /** + * Send a poll query : GET query and no paramter at all. + * @param request {qx.io.remote.Request} A request object + */ _sendPoll : function(request) { if(this.interrupt) return; var request = new qx.io.remote.Request(this.uri, "GET", "application/xml"); @@ -57,9 +77,13 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { request.send(); }, - // Add a function that gets called on every poll response, after all received - // messages have been handled. The poll handler is past a boolean that indicates - // if this is the first poll for the page. + /** + * Add a function that gets called on every poll response, after all received + * messages have been handled. The poll handler is past a boolean that indicates + * if this is the first poll for the page. + * + * @param func {Function} The handler to be called. + */ addPollHandler : function(func) { var old = this._pollEvent; this._pollEvent = function(first) { @@ -68,24 +92,47 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { } }, - // Send a JMS message to a destination (eg topic://MY.TOPIC). Message should be xml or encoded - // xml content. + /** + * Send a JMS message to a destination (eg topic://MY.TOPIC). + * Message should be xml or encoded xml content. + * + * @param destination {String} The topic destination + * @param message {String} XML encoded message + * @param properties {Map} A map of additional parameters to add to the query. + */ sendMessage : function(destination, message, properties) { this._sendMessage(destination, message, 'send', properties); }, - // Listen on a channel or topic. handler must be a function taking a message arguement + /** + * Listen on a channel or topic. handler must be a function taking a message arguement + * @param id {String} A unique identifier for this handler + * @param destination {String} The topic to listen to (topic://MY.TOPIC) + * @param handler {Function} The handler to trigger when receiving a message + * @param context {Object} An object to bind on the handler. + */ addListener : function(id, destination, handler, context) { this._handlers[id] = qx.lang.Function.bind(handler, context); this._sendMessage(destination, id, 'listen'); }, - // remove Listener from channel or topic. + /** + * Remove Listener from channel or topic. + * @param id {String} identifier of the handler to remove. + * @param destination {String} The topic to listen to (topic://MY.TOPIC) + */ removeListener : function(id, destination) { this._handlers[id] = null; this._sendMessage(destination, id, 'unlisten'); }, - + + /** + * Send a message of a given type. + * @param destination {String} The topic to listen to (topic://MY.TOPIC) + * @param message {String} XML encoded message + * @param type {String} The JMS-Type of message (listen, unlisten, send). + * @param properties {Map} A map of additional parameters to add to the query. + */ _sendMessage : function(destination, message, type, properties) { var req = new qx.io.remote.Request(this.uri, "POST", "text/plain"); req.setParameter("destination", destination); @@ -100,6 +147,9 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { req.send(); }, + /** + * Starts a poll on the JMS server. + */ startPolling : function() { if (this.poll){ this.interrupt = false; @@ -110,6 +160,9 @@ qx.Class.define("org.argeo.ria.remote.JmsClient", { } }, + /** + * Stops polling the JMS server. + */ stopPolling : function(){ this.interrupt = true; }