]>
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
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 messages
= org
.argeo
.ria
.util
.Element
.selectNodes(doc
, "//response");
29 for(var i
=0;i
<messages
.length
;i
++){
30 var id
= messages
[i
].getAttribute("id");
31 if(id
&& this._handlers
[id
]){
32 this._handlers
[id
](messages
[i
]);
37 _pollHandler : function(response
) {
39 this._messageHandler(response
);
40 this._pollEvent(this._first
);
46 if (this._pollDelay
> 0)
47 qx
.event
.Timer
.once(this._sendPoll
, this, this._pollDelay
);
52 _sendPoll : function(request
) {
53 if(this.interrupt
) return;
54 var request
= new qx
.io
.remote
.Request(this.uri
, "GET", "application/xml");
55 request
.setTimeout(this.pollTimeout
*1000+5000);
56 request
.addListener("completed", this._pollHandler
, this);
60 // Add a function that gets called on every poll response, after all received
61 // messages have been handled. The poll handler is past a boolean that indicates
62 // if this is the first poll for the page.
63 addPollHandler : function(func
) {
64 var old
= this._pollEvent
;
65 this._pollEvent = function(first
) {
71 // Send a JMS message to a destination (eg topic://MY.TOPIC). Message should be xml or encoded
73 sendMessage : function(destination
, message
) {
74 this._sendMessage(destination
, message
, 'send');
77 // Listen on a channel or topic. handler must be a function taking a message arguement
78 addListener : function(id
, destination
, handler
, context
) {
79 this._handlers
[id
] = qx
.lang
.Function
.bind(handler
, context
);
80 this._sendMessage(destination
, id
, 'listen');
83 // remove Listener from channel or topic.
84 removeListener : function(id
, destination
) {
85 this._handlers
[id
] = null;
86 this._sendMessage(destination
, id
, 'unlisten');
89 _sendMessage : function(destination
, message
, type
) {
90 var req
= new qx
.io
.remote
.Request(this.uri
, "POST", "text/plain");
91 req
.setParameter("destination", destination
);
92 req
.setParameter("message", message
);
93 req
.setParameter("type", type
);
94 //req.addListener("completed", this.endBatch, this);
98 startPolling : function() {
100 this.interrupt
= false;
101 var req
= new qx
.io
.remote
.Request(this.uri
, "GET", "application/xml");
102 req
.setParameter("timeout", "10");
103 req
.addListener("completed", this._pollHandler
, this);
108 stopPolling : function(){
109 this.interrupt
= true;