Changeset 808

Show
Ignore:
Timestamp:
2008-02-29 20:59:53 (9 months ago)
Author:
MaierMan
Message:

Some minor improvements
Scheduling algorithm that doesn't require the temps not there yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/serverswitcher/chrome/content/manager.js

    r742 r808  
    5050                        this._adjustButton(); 
    5151                } 
    52                 else if (prefName.substr(0, SSW_PREF_LIMITS.length) == SSW_PREF_LIMITS) { 
     52                else if (prefName.indexOf(SSW_PREF_LIMITS) == 0) { 
    5353                        this.loadLimits(); 
    5454                } 
     
    8787                } 
    8888        }, 
    89         // isn't accurate, but is good enough for this use case 
    90         getHost: function(host) { 
    91             var m = host.match(/([^.]+\.(?:[\w]{2,4}|museum)?(?:\.\w{2})?)$/); 
    92             if (m) {  
    93                 return m[1]; 
    94             } 
    95             return host; 
    96         },       
    9789        /*Dialog.*/startNext: function() { 
    9890                try { 
     
    114106                                                cset[host] = new SSWItem(host); 
    115107                                        } 
    116                                         ++cset[host].n; 
     108                                        else { 
     109                                                cset[host].inc(); 
     110                                        } 
    117111                                }, 
    118112                                this 
    119113                        ); 
    120                         // prepare the other tasks 
    121                         for (let d in Tree.all) { 
    122                                 if (!d.is(QUEUED)) { 
    123                                         continue; 
    124                                 } 
    125                                 let host = d._ssw_host; 
    126                                 if (!(host in cset)) { 
    127                                         cset[host] = new SSWItem(host); 
    128                                 } 
    129                                 cset[host].downloads.push(d); 
    130                         } 
    131114                        for (d in SSW._generator(cset)) { 
    132115                                if (this._running.length >= Prefs.maxInProgress) { 
     
    137120                        } 
    138121                        return rv; 
    139                 } catch(ex){ 
     122                } 
     123                catch(ex){ 
    140124                        Debug.log("ssw_startNext():", ex); 
    141125                } 
     
    143127        }, 
    144128        _generator: function(downloadSet) { 
     129                for (let d in Tree.all) { 
     130                        if (!d.is(QUEUED)) { 
     131                                continue; 
     132                        } 
     133                        let host = d._ssw_host; 
     134                        if (!(host in downloadSet)) { 
     135                                downloadSet[host] = new SSWItem(host); 
     136                                 
     137                                // this host got no item running, so we might simply yield it 
     138                                yield d; 
     139                                continue; 
     140                        } 
     141                        downloadSet[host].push(d); 
     142                } 
    145143                let sorted = []; 
    146144                for (let s in downloadSet) { 
    147                         sorted.push(downloadSet[s]); 
     145                        let c = downloadSet[s]; 
     146                        if (!c.available) { 
     147                                continue; 
     148                        } 
     149                        sorted.push(c); 
    148150                } 
    149151                while (sorted.length) { 
     
    151153                        for (i in sorted) { 
    152154                                let s = sorted[i]; 
    153                                 let limit = 0; 
    154                                 if (s.host in SSW._limits) { 
    155                                         limit = SSW._limits[s.host]; 
    156                                 } 
    157                                 if ((limit && s.n >= limit) || s.downloads.length == 0) { 
     155                                if (!s.available) { 
    158156                                        sorted.splice(i, 1); 
    159157                                        break; 
    160158                                } 
    161                                 yield s.downloads.shift(); 
    162                                 ++s.n; 
     159                                yield s.pop(); 
    163160                        } 
    164161                } 
     
    169166function SSWItem(host) { 
    170167        this.host = host; 
    171         this.n = 0; 
     168        this.limit = 0; 
     169        if (host in SSW._limits) { 
     170                this.limit = SSW._limits[host]; 
     171        } 
     172        this.n = 1; 
    172173        this.downloads = []; 
    173174}; 
     
    175176        cmp: function(a, b) { 
    176177                return a.n - b.n; 
     178        }, 
     179        get available() { 
     180                return (this.limit == 0 || this.limit < this.n) && this.downloads.length != 0; 
     181        }, 
     182        inc: function() { 
     183                return ++this.n; 
     184        }, 
     185        pop: function() { 
     186                return this.downloads.shift(); 
     187        }, 
     188        push: function(d) { 
     189                this.downloads.push(d); 
     190                ++this.n; 
     191        }, 
     192        toString: function() { 
     193                return this.host; 
    177194        } 
    178 } 
     195}; 
    179196 
    180197QueueItem.prototype.__defineGetter__( 
     
    182199        function() { 
    183200                if (!('_ssw_real_host' in this)) { 
    184                         this._ssw_real_host = SSW.getHost(IOService.newURI(this.urlManager.url, null, null).host); 
     201                        this._ssw_real_host = SSW_getBaseDomain(this.urlManager.url.toURI()); 
    185202                } 
    186203                return this._ssw_real_host; 
     
    190207Dialog.startNext = SSW.startNext; 
    191208 
    192 addEventListener('load', function() { return SSW.load(); }, false); 
     209addEventListener( 
     210        'load', 
     211        function() { 
     212                return SSW.load(); 
     213        }, 
     214        false 
     215); 
  • sandbox/serverswitcher/chrome/content/manager.xul

    r664 r808  
    4343]> 
    4444<overlay id="dtassw" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 
     45        <script type="application/javascript;version=1.7" src="chrome://dtassw/content/functions.js" /> 
    4546        <script type="application/javascript;version=1.7" src="chrome://dtassw/content/manager.js" /> 
     47 
    4648        <toolbar id="tools"> 
    4749                <toolbarbutton label="&ssw.switch.label;" tooltiptext="&ssw.switch.tip;" id="toolssw" onclick="SSW.toggle();" insertafter="toolmovebottom" /> 
  • sandbox/serverswitcher/chrome/content/paneServerSwitcher.xul

    r664 r808  
    5353                </prefpane> 
    5454                <stringbundle src="chrome://dtassw/locale/paneServerSwitcher.properties"/> 
     55                 
     56                <script type="application/javascript;version=1.7" src="chrome://dtassw/content/functions.js" /> 
    5557                <script type="application/javascript;version=1.7" src="chrome://dtassw/content/paneServerSwitcher.js"/> 
     58 
    5659        </prefwindow> 
    5760</overlay> 
  • sandbox/serverswitcher/install.rdf

    r742 r808  
    66                <name>DownThemAll! ServerSwitcher</name> 
    77                <description>Processes the queue trying to use different servers where possible</description> 
    8                 <version>0.3</version> 
     8                <version>0.4</version> 
    99 
    1010                <creator>Nils Maier</creator> 
     
    1818                        <rdf:Description> 
    1919                                <id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</id> 
    20                                 <minVersion>2.0</minVersion> 
    21                                 <maxVersion>3.0.*</maxVersion> 
     20                                <minVersion>2.0.0.8</minVersion> 
     21                                <maxVersion>3.0b3</maxVersion> 
    2222                        </rdf:Description> 
    2323                </targetApplication> 
     
    2727                        <rdf:Description> 
    2828                                <id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</id> 
    29                                 <minVersion>2.0a</minVersion> 
    30                                 <maxVersion>3.0</maxVersion> 
     29                                <minVersion>2.0a1</minVersion> 
     30                                <maxVersion>2.0a</maxVersion> 
    3131                        </rdf:Description> 
    3232                </targetApplication> 
     
    3636                        <rdf:Description> 
    3737                                <id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</id> 
    38                                 <minVersion>2.0</minVersion> 
    39                                 <maxVersion>3.0.*</maxVersion> 
     38                                <minVersion>2.0.0.0</minVersion> 
     39                                <maxVersion>3.0a1</maxVersion> 
    4040                        </rdf:Description> 
    4141                </targetApplication> 
     
    4545                  <rdf:Description> 
    4646                    <id>{a463f10c-3994-11da-9945-000d60ca027b}</id> 
    47                     <minVersion>0.8</minVersion> 
    48                     <maxVersion>1.0</maxVersion> 
     47                    <minVersion>1.0</minVersion> 
     48                    <maxVersion>1.0.*</maxVersion> 
    4949                  </rdf:Description> 
    5050                </targetApplication>             
     
    5353                        <rdf:Description> 
    5454                                <id>dta@downthemall.net</id> 
    55                                 <minVersion>1.0b2</minVersion> 
     55                                <minVersion>1.0</minVersion> 
    5656                                <maxVersion>1.1a*</maxVersion> 
    5757                        </rdf:Description>