otm:ordering_of_messages:discard_early

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
otm:ordering_of_messages:discard_early [2011/01/12 05:01]
aspectscript
otm:ordering_of_messages:discard_early [2012/02/06 18:49] (current)
aspectscript
Line 1: Line 1:
-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 (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" button((In this toy Web application, this button does nothing.)). 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. +====== The Discard Early Strategy ======
  
-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. +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" button((In this toy Web application, this button does nothing.)). 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:  The implementation follows: 
Line 12: Line 16:
 </html> </html>
  
-The DiscardEarly strategy is implemented as a TM advice, which is a JavaScript function, that is executed every time the response is retrieved+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
  
 <code javascript> <code javascript>
Line 18: Line 22:
   if(!this.isEarly(jp)){        if(!this.isEarly(jp)){     
     jp.proceed();     jp.proceed();
-    this.updateCr(jp); //notifies that join point was executed.+     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) ;
 +  } 
 +};
 </code> </code>
  
-Go back the [[otm/ordering_of_messages|the parent page]] web page.+Go back [[otm/ordering_of_messages|the parent Web page.]].
  • otm/ordering_of_messages/discard_early.1294822874.txt.gz
  • Last modified: 2011/01/12 05:01
  • by aspectscript