]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/remote/JmsClient.js
1 qx
.Class
.define("org.argeo.ria.remote.JmsClient", {
4 extend
: qx
.core
.Object
,
6 construct : function(){
10 // The URI of the MessageListenerServlet
11 uri
: '/org.argeo.slc.webapp/amq',
13 // Polling. Set to true (default) if waiting poll for messages is needed
18 // Poll delay. if set to positive integer, this is the time to wait in ms before
19 // sending the next poll after the last completes.
23 _pollEvent : function(first
) {},
24 _handlers
: new Array(),
26 _messageHandler : function(response
) {
27 var doc
= response
.getContent();
28 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
29 var messages
= org
.argeo
.ria
.util
.Element
.selectNodes(doc
, "//response", NSMap
);
30 for(var i
=0;i
<messages
.length
;i
++){
31 var id
= messages
[i
].getAttribute("id");
32 if(id
&& this._handlers
[id
]){
33 this._handlers
[id
](messages
[i
]);
38 _pollHandler : function(response
) {
40 this._messageHandler(response
);
41 this._pollEvent(this._first
);
47 if (this._pollDelay
> 0)
48 qx
.event
.Timer
.once(this._sendPoll
, this, this._pollDelay
);
53 _sendPoll : function(request
) {
54 if(this.interrupt
) return;
55 var request
= new qx
.io
.remote
.Request(this.uri
, "GET", "application/xml");
56 request
.setTimeout(this.pollTimeout
*1000+5000);
57 request
.addListener("completed", this._pollHandler
, this);
61 // Add a function that gets called on every poll response, after all received
62 // messages have been handled. The poll handler is past a boolean that indicates
63 // if this is the first poll for the page.
64 addPollHandler : function(func
) {
65 var old
= this._pollEvent
;
66 this._pollEvent = function(first
) {
72 // Send a JMS message to a destination (eg topic://MY.TOPIC). Message should be xml or encoded
74 sendMessage : function(destination
, message
) {
75 this._sendMessage(destination
, message
, 'send');
78 // Listen on a channel or topic. handler must be a function taking a message arguement
79 addListener : function(id
, destination
, handler
, context
) {
80 this._handlers
[id
] = qx
.lang
.Function
.bind(handler
, context
);
81 this._sendMessage(destination
, id
, 'listen');
84 // remove Listener from channel or topic.
85 removeListener : function(id
, destination
) {
86 this._handlers
[id
] = null;
87 this._sendMessage(destination
, id
, 'unlisten');
90 _sendMessage : function(destination
, message
, type
) {
91 var req
= new qx
.io
.remote
.Request(this.uri
, "POST", "text/plain");
92 req
.setParameter("destination", destination
);
93 req
.setParameter("message", message
);
94 req
.setParameter("type", type
);
95 //req.addListener("completed", this.endBatch, this);
99 startPolling : function() {
101 this.interrupt
= false;
102 var req
= new qx
.io
.remote
.Request(this.uri
, "GET", "application/xml");
103 req
.setParameter("timeout", "10");
104 req
.addListener("completed", this._pollHandler
, this);
109 stopPolling : function(){
110 this.interrupt
= true;