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 have to overcome the issue of using incorrect data due to a early response of a server. For example, consider a website that shows the posts of thread posts 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 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 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. 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.1294666682.txt.gz
  • Last modified: 2011/01/10 09:38
  • by aspectscript