otm:ordering_of_messages:discard_early

This is an old revision of the document!


Web applications typically update data from servers (eg. whether, time, animations, dollar rates, thread posts). Developers has to overcome the issue of using correct data due to a early response of a server. For example, consider a website that shows an the posts of a thread of a forum, every post is loaded dynamically using an independent ajax request. If responses of ajax requests are retrieved in wrong order, the discussion of thread cannot readable correctly because the posts are read in a wrong order. 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 discarding early posts because these posts can be read when the reader pushes the button “read more”. The DiscardEarly strategy discards the early responses of ajax requests.

When the activate order is clicked, the discussion always is correctly showed (older to newer). When the deactivate order is clicked, the discussion is randomly showed.

The implementation follows: Toggle between the code and example

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

var discardEarly = function(jp) {
  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.1294553368.txt.gz
  • Last modified: 2011/01/09 06:09
  • by aspectscript