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 shows several thread titles with their first posts, and the user can click in the “read more” button to see the whole discussion of the thread. Every post below of the thread title 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 first posts (say 4) of the 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 discussion, and discarded posts can be read later when the reader clicks the “read more” button1). The DiscardEarly strategy discards the early responses of ajax requests. As an example, we present first posts of only one thread (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. When the “deactivate order” button is clicked, the discussion is randomly showed. 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 Web application, this button does nothing.
  • otm/ordering_of_messages/discard_early.1294821322.txt.gz
  • Last modified: 2011/01/12 04:35
  • by aspectscript