otm:ordering_of_messages:discard_early

The Discard Early Strategy

Another issue in the visualization arises due to the processing of early server responses. For example, consider a forum Web page that is frequently updated with threads from a server using Ajax, i.e. this Web page only increases with more threads that are located on the top. Every thread is shown with its title and its first posts, and the reader can click on a button “read more” to see the whole discussion of a given thread. Every post that is below the thread title is loaded dynamically using an independent Ajax request. If server responses, which contain the posts, are retrieved and displayed in an incorrect order, the beginning of the discussion of the thread could be misunderstood. A solution could be to wait for all late posts of every thread. However, this solution could seriously delay the updating of the forum Web page. A better solution is to discard the early posts in order to correctly show the first posts of the thread. The discarded posts can be fetched later when the reader clicks the given “read more” button1). A Discard Early strategy, which discards early server responses, can ensure the beginning of the discussion of every thread is read in a correct order.

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 Discard Early strategy is implemented as a piece of advice, which is a JavaScript function, that is executed every time a server response is received:

var discardEarly = function(jp) { //jp represents the execution of a response
  if(!this.isEarly(jp)){     
    jp.proceed();
     this.idServerRespExpected = request.idServerResp + 1; 
  }
}
 
var discardEarlyCallback = function(callback) {
  return function(jp,env) {
    //invoke the discard Early strategy
 
    var request = jp.target;
   //Is it discarded?
   if (this.idServerRespExpected < request.idServerResp)
     callback(jp,env) ;
  } 
};

Go back the parent Web page..


1)
In this toy Web application, this button does nothing.
  • otm/ordering_of_messages/discard_early.txt
  • Last modified: 2012/02/06 18:49
  • by aspectscript