CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN The property

CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN The property instances is assigned an Array instance, but notice that the property instances is associated with the prototype property. This means that whenever ClientCommunicatoris instantiated, all instances will share the same Array instances. The result is that whatever the ClientCommunicator instance references, the property prototype. instances will manipulate the same array. Of course, the property instances could have been a global variable, but using the prototype property is object oriented. The other property, instanceCount, is an example of where the global variable concept does not work. I am going to backtrack a bit on my assertion that the property prototype is object oriented. Let me restate the assertion and say that the effect is object oriented. When defining a property associated with prototype, the values of the properties are copied from the property prototype to the property of the ClientCommunicator instance. When the property is a value type such as an integer or a double value, each ClientCommunicator instance will have its own value. If the property is a reference, the reference value is copied. Hence the property instanceCount must refer to a JavaScript reference type. The property index is the index reference for each ClientCommunicator instance. Following is the source code for the ClientCommunicator.start implementation, which is used to start the polling of the reading stream: function ClientCommunicator_start() { if(this.baseURL != null) { this.doLoop = true; window.setTimeout(”PrivateLoop(” + this.index + “)”, this.callDelay); } else { throw new Error(”Must specify baseURL before starting communications”); } } The method ClientCommunicator_start will start the polling only if the property baseURL is assigned. If the property is assigned, a polling operation is started by calling the method setTimeout with the index (this.index) of the ClientCommunicator instance. If the property is not assigned, an Error exception is generated. When the setTimeout method expires, the function PrivateLoop is called and used to perform physical reading from the reading stream. The implementation of PrivateLoop is as follows: function PrivateLoop(index) { var tempReference = ClientCommunicator.prototype.instances[ index]; tempReference.server2Client.openCallback = function(xmlhttp) { xmlhttp.setRequestHeader(”Accept”, tempReference.preferredTypes); } tempReference.server2Client.complete = function(status, statusText, responseText, responseXML) { if(status == 200) { if(tempReference.listen != null) { tempReference.listen(status, statusText, responseText, responseXML); } }
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply