Both sides previous revision
Previous revision
Next revision
|
Previous revision
Next revision
Both sides next revision
|
otm:ordering_of_messages:fifo [2011/01/10 16:10] aspectscript |
otm:ordering_of_messages:fifo [2011/01/24 18:59] aspectscript |
Every day, [[http://en.wikipedia.org/wiki/Mashup_%28web_application_hybrid%29|mashup]] applications are more present. These applications are created with requests to several servers. Developers have to overcome the issue of creating wrong page due to an unexpected order of executions of responses. For instance, consider a website that creates a web page from two requests (see below web page). If the second response is executed before the first response, the web page is created incorrectly. Instead, the if the first response is executed before the second response, the web page is created correctly. The use of the **Fifo** strategy can ensure the web page is always created correctly. | Every day, [[http://en.wikipedia.org/wiki/Mashup_%28web_application_hybrid%29|mashup]] applications are more present. These applications are created with requests to several servers. Developers have to overcome the issue of creating a wrong page due to an unexpected order of executions of responses. For instance, consider a website that creates a web page from two ajax requests. If the second response is executed before the first response, the web page is created incorrectly. Instead, the if the first response is executed before the second response, the web page is created correctly. The use of the **Fifo** strategy can ensure, which executes the response in the same order that are sent the requests, the web page is always created correctly. |
| |
When the "activate order" button is clicked, the web page always is created correctly. When the "deactivate order" button is clicked, the web page can be created incorrectly. | When the "activate order" button is clicked, the web page is created correctly. When the "deactivate order" button is clicked, the web page could create incorrectly. **NOTE:** Please first watch the application without clicking the "activate order" button to appreciate clearly the aforementioned issue. |
| |
<html> | <html> |
<link href="/aspectscript/external/otm/paperExample-SPE/style.css" rel="stylesheet" type="text/css"/> | <link href="/aspectscript/external/otm/paperExample-SPE/style.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" language="javascript" src="/aspectscript/external/otm/paperExample-SPE/lib.js"> </script> |
<iframe id="example" src="/aspectscript/external/otm/paperExample-SPE/order/fifo" width="810" height="470"></iframe> | <iframe id="example" src="/aspectscript/external/otm/paperExample-SPE/order/fifo" width="810" height="470"></iframe> |
<iframe id="code" style="display:none" src="/aspectscript/external/otm/paperExample-SPE/order/fifo/script.js" width="810" height="470"></iframe> | <iframe id="code" style="display:none" src="/aspectscript/external/otm/paperExample-SPE/order/fifo/script.js" width="810" height="470"></iframe> |
</html> | </html> |
| |
The Fifo strategy is implemented as a TM advice, which a JavaScript function, that is executed every time a response is retrieved: | The Fifo strategy is implemented as a TM advice, which is a JavaScript function, that is executed every time a response is retrieved: |
| |
<code javascript> | <code javascript> |
var fifo = function(jp){ //jp represents the execution of a response | var fifo = function(jp){ //jp represents the execution of a response |
if(this.isEarly(jp)){ | if(this.isEarly(jp)){ |
this.queue.push(jp); | this.queue.push(jp); //if the response is retrieved early, then it is stored and not executed |
} | } |
else{ | else{ |
jp.proceed(); | jp.proceed(); |
this.updateCr(jp); | this.updateCr(jp); |
this.queue.executeEarlyJPs(); | this.queue.executeEarlyJPs(); //check if now other responses can be executed |
} | } |
}; | }; |