home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 13 / FreelogHS13.iso / P To P / Emule24b_Morph_Mod_V4b-binary / Webserver / QueueHandling.js < prev    next >
Encoding:
Text File  |  2002-11-29  |  1.9 KB  |  89 lines

  1. function Queue(ExecCount)
  2. {
  3.     this.ExecCount=ExecCount;
  4.     this.Queue=new Array();
  5.     this.Active=false;
  6.     this.lastUsed=1;
  7.     this.queueStatus=new Array();
  8.     for(i=1;i<=ExecCount;i++)
  9.       this.queueStatus[i]=0;
  10.     
  11.     this.start=startQueue;
  12.     this.stop=stopQueue;
  13.     this.pop=enterCommand;
  14.     this.free=freeQueue;
  15.     this.debug=debug;
  16.     this.debugWin=false;
  17. }
  18.  
  19. function startQueue()
  20. {
  21.     if(this.Queue.length!=0)
  22.     {
  23.         var execindex=0;
  24.         var obj;
  25.         var foundEmpty=-1;
  26.       do
  27.         {
  28.             execindex++;
  29.       if(this.queueStatus[execindex]==0)
  30.         foundEmpty=execindex;
  31.         }
  32.         while(execindex<this.ExecCount && foundEmpty==-1);
  33.         if(foundEmpty!=-1)
  34.         {
  35.           this.queueStatus[foundEmpty]=1;
  36.             var page=this.Queue.shift();
  37.       obj=eval("queue"+foundEmpty);
  38.       obj.location.href=page;
  39.       this.Active=window.setTimeout("queue.start();",10);
  40.         }
  41.         else
  42.           this.Active=window.setTimeout("queue.start();",1000);
  43.     }
  44.     else
  45.         this.Active=window.setTimeout("queue.start();",1000);
  46. }
  47.  
  48. function freeQueue(queue)
  49. {
  50.   var no=(queue.substring(5,queue.length))*1;
  51.   this.queueStatus[no]=0;
  52. }
  53.  
  54. function stopQueue()
  55. {
  56.     if(this.Active!=false)
  57.         window.clearTimeout(this.Active);
  58. }
  59.  
  60. function enterCommand(page)
  61. {
  62.   this.Queue.push(page);
  63. }
  64.  
  65. function debug()
  66. {
  67.   if(!this.debugWin)
  68.     this.debugWin=window.open("", "QueueDebug", "width=500,height=150,dependent=yes,resizable=yes");
  69.   var str='';
  70.   var execindex=0;
  71.     var obj;
  72.   str+="on Queue: "+this.Queue+"<br><br>\n"
  73.     do
  74.     {
  75.         execindex++;
  76.         str+=execindex+": "+this.queueStatus[execindex];
  77.         if(this.queueStatus[execindex]==1)
  78.         {
  79.           obj=eval("queue"+execindex);
  80.       str+=" "+obj.location.href;
  81.         }
  82.         str+="<br>\n";
  83.     }
  84.     while(execindex<this.ExecCount);
  85.     this.debugWin.document.open();
  86.     this.debugWin.document.write(str);
  87.     this.debugWin.document.close();
  88.   this.Active=window.setTimeout("queue.debug();",100);   
  89. }