Search Wiki:
CallQueue Introduction
In AJAX based applications its common that user might end up breaking your AJAX calls by clicking on numerous places in very short interval of time. Let us assume there is a page where there are several of hyperlinks which make WebService calls and do some stuffs on callback. If user clicks on five hyperlinks being impatient or may be just for fun, there will be five different WebService calls made. All of those calls had the same parameters or UI state while they were invoked. But on completion of one or more WebService calls it may happen that the UI state or data passed to the rest of the WebServices calls no longer exist or expired, thus will be result in inconsistent UI behaviour and/or invalid data. This is one of the important scenarios an AJAX developer should consider when he designs an application.


The Specification
To address the scenario, I would prefer implementing a Sequential WebService Calls Queue which will be able to schedule the tasks/WebService calls and help keeping UI and data consistent over the AJAX calls. We should achieve the following features from this queue:
  1. Enqueue any WebService call anytime in the application.
  2. Dequeue any previously queued call regardless of currently executing call and location in the application.
  3. Each WebService call should have an identifier so that we can track the call and dequeue anytime later by SSQ.dq(call_id).
  4. Each call should have a timeout value which will determine the maximum amount of time we will consider for that particular call before we invoke the next call, after that we will remove from the queue.
  5. A timer will act as scheduler but will not run forever. It should run only when necessary.
  6. Each call should be able to declare its completion at any time by notifyCompleted, so that the scheduler timer will not wait for the prior task and should dequeue the next call.
  7. notifyCompleted should also be optional. The currently running call should automatically be dequeued from the scheduler queue after the timeout of its own.
  8. Each call should be able to mark as replaceIfExists so that if user`s any activity already enqueued this call, should be replaced by the current one.
  9. The queue instance should be exclusively available to the user and all over the page, meaning that the same queue class will be used to serve the functionality in one page per user basis.

I have written article about how the code works, check it out: http://tanzimsaqib.com/callqueue-implementing-a-sequential-web-service-call-queue-for-ajax-application/
For continued development keep an eye on my blog: http://TanzimSaqib.com
Last edited Nov 19 2008 at 1:04 PM  by TanzimSaqib, version 10
Updating...
Page view tracker