Changeset 73

Show
Ignore:
Timestamp:
09/23/06 12:39:37 (2 years ago)
Author:
ajtack
Message:

Clarified some style issues and added an extended documentation comment to overhaul_handler.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/overhaul_handler.js

    r69 r73  
    1 //* 
    2 //* Overhaul Handler 
    3 //* 
    4 //* The overhaul handler object is instantiated as soon as we are in 
    5 //*     overhaul mode.  The constructor arranges all information such that 
    6 //*     the object will run in an event-driven fashion, completing the 
    7 //*     process and displaying the web page to the user. 
    8 //* 
    9  
    10  
    11  
    12 function overhaul_handler(clientHostArray, clientPortArray, url , filename, chunks_held, md5_list,numChunk){ 
     1/** 
     2 * Overhaul Handler 
     3 * 
     4 * The overhaul handler object is instantiated as soon as we are in 
     5 * overhaul mode.  The constructor arranges all information such that 
     6 * the object will run in an event-driven fashion, completing the 
     7 * process and displaying the web page to the user. 
     8 * 
     9 * Parameters: 
     10 *      clientHostArray - An array of host IP addresses. 
     11 *      clientPortArray - An array of host Ports, where each index corresponds 
     12 *                        with the same host's IP address in clientHostArray. 
     13 *      url - The fully-qualified URL of the page being loaded. 
     14 *      filename - the name of the file being loaded. 
     15 *      chunks_held - An array of boolean values: false means that the indexed 
     16 *                        chunk number is not present on this client, true means 
     17 *                        it is present. 
     18 *      md5_list - The list of MD5 checksums for each chunk of the complete 
     19 *                        document. 
     20 */ 
     21function overhaul_handler(clientHostArray, clientPortArray, url, filename,  
     22                              chunks_held, md5_list)                    { 
    1323        var self = this; 
    1424         
    15         // counter for the raw datas 
     25        var receivedDataArray = new Array();         // The content of the page, in chunks 
     26        overhaul_replyer(receivedDataArray); 
     27                 
     28        var availableList;                           // Tracks remote availability of chunks 
     29        availableList = new overhaul_info(clientHostArray, clientPortArray, url, this); 
     30        availableList.sendInfoRequests(); 
     31         
     32        // Loop until web page is complete 
     33        var numChunk = md5_list.size(); 
    1634        var countChunk; 
    17          
    18         //raw data(unmodified) and GROBAL 
    19         var receivedDataArray=new Array(); 
    20         overhaul_replyer(receivedDataArray); 
    21         //modified data 
    22         //please WAIT!! 
    23          
    24         var availableList=new Array(); 
    25          
    26         //get double array which client have which chunks 
    27         var info= new overhaul_info(clientHostArray,clientPortArray, url, this); 
    28         info.sendInfoRequests(); 
    29          
    30         //loop until all of the data get 
    31         for(countChunk=0;countChunk<numChunk;countChunk++){ 
    32                 if(chunks_held[countChunk]!=null){ 
    33                         receivedDataArray[countChunk]=chunks_held[countChunk]; 
    34                         break; 
    35                 } 
    36                 else{ 
     35        for(countChunk = 0; countChunk < numChunk; countChunk++)        { 
     36                if(chunks_held[countChunk] != null) 
     37                        receivedDataArray[countChunk] = chunks_held[countChunk]; 
     38                else    { 
    3739                         
    38                         var host=null; 
    39                         var port=null; 
    40                         var thrdDimChunk=0 
     40                        var host = null; 
     41                        var port = null; 
     42                        var thrdDimChunk = 0; 
    4143                         
    42                         while((host==null)||thrdDimChunk<2){   //while loop begins 
     44                        while((host == null) || thrdDimChunk < 2)      { 
    4345                                //get available host from the bottom 
    4446                                var sndDimChunk=availableList.size()-1; 
     
    5153                                } 
    5254                                if(host==null){ 
    53                                         availableList=overhaul_info(clientHostArray,clientPortArray); 
     55                                        availableList = overhaul_info(clientHostArray, clientPortArray); 
    5456                                } 
    5557                                thrdDimChunk++; 
    56                         }//while loop ends 
     58                        } 
    5759 
    5860                        if((host!=null)||(port!=null)){ 
     
    9294                                create_scriptable_input_stream(stream); 
    9395                                bind_stream_to_listener(dataListener, stream); 
    94                                 /* 
    95                                 BLOCK REMOVED - code moved to bind_stream_to_listener 
    96                                 in overhaul_util.js 
    97                                  
    98                                 var instream = Components.classes["@mozilla.org/scriptableinputstream;1"] 
    99                                                 .createInstance(Components.interfaces.nsIScriptableInputStream); 
    100                                 instream.init(stream); 
    101  
    102                                 var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]. 
    103                                                 createInstance(Components.interfaces.nsIInputStreamPump); 
    104                                 pump.init(stream, -1, -1, 0, 0, true); 
    105                                 pump.asyncRead(dataListener,null); 
    106                                 */ 
    10796                        } 
    10897                        else