CHAPTER 10 (Affordable web hosting) INFINITE DATA PATTERN between SendData1

CHAPTER 10 INFINITE DATA PATTERN between SendData1 and SendData2 is that one function uses the identifier 1, and the other uses the identifier 2. For those readers who are cringing because of using the hard-coded numeric identifiers 1 and 2, well, you are right. There is a better way of writing the code, but it will not be illustrated here because that would make the explanation of the pattern more difficult. Here is the implementation of SendData1: function SendData1() { transactionIdentifier1Counter ++; document.getElementById( “result1″).innerHTML = “No Result”; var buffer = GenerateActionData( “1_” + transactionIdentifier1Counter, document.getElementById( ‘Number1′).value); client.send( “application/xml”, buffer.length, buffer); } Calling SendData1 means creating a new task on the server, thus invalidating the results of the old tasks that may be executing. The implementation of SendData1 begins with the incrementing of the first task transaction identifier (transactionIdentifier1Counter). Using a static random transaction identifier would result in the scenario where multiple requests would be sending results with the same transaction identifier, thus corrupting the results. As a new task is being created, the content of the result span element (result1) is cleared. The XML buffer that is sent is created by using the function GenerateActionData. The function GenerateActionData has two parameters; the first parameter is the transaction identifier, and the second parameter is the maximum number to calculate all primes for. The generated XML buffer is sent to the server by using the method client.send. Following is the implementation of GenerateActionData that generates the XML buffer: function GenerateActionData( transactionIdentifier, number) { return “” + “” + transactionIdentifier + “” + “” + number + “” + ““; } The implementation of GenerateActionData is a straightforward string concatenation. When the buffer is sent by using the client.send method, the server is responsible for translating the XML buffer into a task. The client.send method does not wait for a response and returns immediately without a response. The caller of client.send does not know if the task has been started or is working. The caller assumes everything went okay and will expect some results in the receiving part of the HTML page. Deciphering the Protocol The receiving of the results is started when the method client.start() is called as per the explanation in the Persistent Communications pattern. When a result is retrieved, the method reference of client.listen is called, which is implemented as follows:
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply