otm:ordering_of_messages:discard_early

This is an old revision of the document!


Web applications typically update data from servers (eg. whether, time, streaming media, dollar rates, thread posts). Developers have to overcome the issue of using incorrect data due to an early response of a server. For example, consider a website that shows several thread with their first posts of a forum, and the user can click in the “read more” button to see the whole thread. Every post in the brief version of a thread is loaded dynamically using an independent ajax request. If responses of ajax requests are retrieved in wrong order, the discussion of thread cannot be read correctly because of the wrong order of posts. A solution could be to wait for all posts of the thread, however, this solution could delay to much the loading of the web page. A better solution is to discard the early posts to show the discussion correctly, and discarded posts can be read when the reader clicks the “read more” button . The DiscardEarly strategy discards the early responses of ajax requests. As an example, we present below only posts of thread (it is only one by simplicity). This example shows the effects that reproduce in the understanding of a thread when posts are showed in a random order.

When the “activate order” button is clicked, the discussion always is correctly showed (older to newer). When the “deactivate order” button is clicked, the discussion is randomly showed. NOTE: You have to wait until a new thread to see the effect.

The implementation follows: Toggle between the code and example

The DiscardEarly strategy is implemented as a TM advice, which is a JavaScript function, that is executed every time the response is retrieved:

var discardEarly = function(jp) { //jp represents the execution of a response
  if(!this.isEarly(jp)){     
    jp.proceed();
    this.updateCr(jp); //notifies that join point was executed.
  }
}

Go back the the parent page web page.

  • otm/ordering_of_messages/discard_early.1294793795.txt.gz
  • Last modified: 2011/01/11 20:56
  • by aspectscript