Skip to main content

Sequential sending of ajax calls. Can we make it concurrent?

2 replies [Last post]
erctheanda
Offline
Joined: 2011-09-20
Points: 0

We are using Liferay's Liferay.on & Liferay.fire javascript apis to get client side eventing without full page reload.
IceFaces 2.0.2 with Portlet Faces bridge are the frameworks used for all our portlets. For this use case, we have three portlets (Portlet A, Portlet B, Portlet C)
bundled in three different war files.

Use case
1. The Portlet A fires an event through Liferay.fire(event,data) javascript api.
2. Portlet B receives the event using Liferay.on(eventName,eventCallbackFunction,Liferay.Navigation) function.
3. Portlet C receives the event using Liferay.on(eventName,eventCallbackFunction,Liferay.Navigation) function.
4. Both Portlet B & Portlet C try to make ajax calls to server side to update their data after receiving the event(in pt. 2 & 3).
5. Portlet B and Portlet C uses IceFaces/Jsf's javascript api ( jsf.ajax.request() ) to send the request to server. (Also tried with <f:ajax>)
6. But it seems the ajax requests (partial submit requests) are sent in sequential manner to server. That means, the Portlet B's ajax request is sent
and the system waits for the response. Once the Portlet B's request is finised, Portlet C's request is sent to the server. Looks like some kind of
sequence is maintaining in the jsf.ajax javascript layer.
7. But as the Portlet B and Portlet C are in different war files, they should be able to send ajax requests to server concurrently.
8. Also as the Portlet B is the slowest portlet in the page, the other portlets has to wait for the Portlet B to finish.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
erctheanda
Offline
Joined: 2011-09-20
Points: 0

we have simplifed the issue, now we have 2 WAR files and 2 portlets (1 per WAR).

each of the portlets makes a call to jsf.ajax.request in a setTimeout function

Code:

setTimeout('autoSubmit(\''+namespace+'\','+parsedData+')',1)

autoSubmit() uses the jsf.ajax.request() function.

all java script requests fired in sequence.
however, at the backend, we find that the bean methods are fired this way.. the following are sample log statements that we placed at the beginning and end of the backing bean methods.

portlet A action start
portlet A action end
portlet A action start
portlet A action end
portlet A action start
portlet A action end
.. (repeats for a few times)
portlet B action start
portlet B action end

After which the front end is refreshed with new data.
Portlet A is the slower portlet.

After looking into the jsf.ajax.request code, we find the following:
Code:

        // if there is already a request on the queue waiting to be processed..
                     // just queue this request
                     if (!req.que.isEmpty()) {
                         if (!req.fromQueue) {
                             req.que.enqueue(req);
                             return;
                         }
                     }
                     // If the queue is empty, queue up this request and send
                     if (!req.fromQueue) {
                         req.que.enqueue(req);
                     }

the above is from jsf-uncompressed.js in the jsf-impl jar file.

Please correct me if i am wrong but it appears that the basis for icefaces ajax concurrent calls is a queue (FIFO)?

On another train of thought,
since the requests are different, does anyone know why the second request is not fired immediately after the first request is?

Thanks!

erctheanda
Offline
Joined: 2011-09-20
Points: 0

Anyone with a suggestion?