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 forum that the first posts of only one thread (by simplicity)shows several thread titles with their first posts (say 4), and the user can click in the “read more” button to see the whole discussion of the thread. Every post that is under of the thread title is loaded dynamically using an independent ajax request. If responses of ajax requests are retrieved in a 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 first posts of every thread, however, this solution could delay to much the loading of the web page of the forum. A better solution is to discard the early posts in order to show correctly the first opinions (posts) of the thread, and the discarded posts can be read later when the reader clicks the “read more” button1). The DiscardEarly strategy discards the early responses (posts) of ajax requests to ensure the well understanding the beginning of the discussion of every thread. By simplicity, this example shows the first posts of only one thread.

When the “activate order” button is clicked, the discussion is correctly shown. When the “deactivate order” button is clicked, the discussion could show incorrectly. NOTE: Please first watch the application without clicking the “activate order” button to appreciate clearly the aforementioned issue.

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.


1)
In this toy Web application, this button does nothing.
  • otm/ordering_of_messages/discard_early.1294822845.txt.gz
  • Last modified: 2011/01/12 05:00
  • by aspectscript