home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / net / www / http / ClientVector.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.8 KB  |  91 lines

  1. package sun.net.www.http;
  2.  
  3. import java.util.Stack;
  4. import java.util.Vector;
  5.  
  6. class ClientVector extends Stack implements Runnable {
  7.    private int num = 0;
  8.    private KeepAliveCache cache;
  9.    private KeepAliveKey key;
  10.    HttpClient[] inUse;
  11.    private int nap;
  12.  
  13.    ClientVector(KeepAliveCache var1, KeepAliveKey var2, int var3) {
  14.       this.cache = var1;
  15.       this.key = var2;
  16.       this.nap = var3;
  17.       this.inUse = new HttpClient[KeepAliveCache.getMaxConnections()];
  18.    }
  19.  
  20.    synchronized HttpClient get() {
  21.       if (((Stack)this).empty()) {
  22.          return null;
  23.       } else {
  24.          HttpClient var1 = (HttpClient)((Stack)this).pop();
  25.          if (this.inUse.length == this.num) {
  26.             HttpClient[] var2 = new HttpClient[this.inUse.length * 2];
  27.             System.arraycopy(this.inUse, 0, var2, 0, this.inUse.length);
  28.             this.inUse = var2;
  29.          }
  30.  
  31.          this.inUse[this.num++] = var1;
  32.          return var1;
  33.       }
  34.    }
  35.  
  36.    synchronized void put(HttpClient var1) {
  37.       if (this.num > 0) {
  38.          --this.num;
  39.       }
  40.  
  41.       for(int var2 = 0; var2 < this.inUse.length; ++var2) {
  42.          if (this.inUse[var2] == var1) {
  43.             this.inUse[var2] = null;
  44.             break;
  45.          }
  46.       }
  47.  
  48.       ((Stack)this).push(var1);
  49.       this.notifyAll();
  50.    }
  51.  
  52.    public void run() {
  53.       int var1;
  54.       do {
  55.          try {
  56.             Thread.sleep((long)this.nap);
  57.          } catch (InterruptedException var10) {
  58.          }
  59.  
  60.          KeepAliveCache var3 = this.cache;
  61.          synchronized(var3) {
  62.             synchronized(this) {
  63.                for(int var5 = 0; var5 < ((Vector)this).size(); ++var5) {
  64.                   HttpClient var2 = (HttpClient)((Vector)this).elementAt(var5);
  65.                   var2.closeServer();
  66.                }
  67.  
  68.                ((Vector)this).removeAllElements();
  69.                if (this.num == 0) {
  70.                   this.cache.removeVector(this.key);
  71.                   return;
  72.                }
  73.             }
  74.          }
  75.  
  76.          for(int var4 = 0; var4 < this.inUse.length; ++var4) {
  77.             HttpClient var13;
  78.             if ((var13 = this.inUse[var4]) != null && var13.kas.hurry()) {
  79.                this.put(var13);
  80.             }
  81.          }
  82.  
  83.          synchronized(this) {
  84.             var1 = this.num + ((Vector)this).size();
  85.          }
  86.       } while(var1 > 0);
  87.  
  88.       this.cache.removeVector(this.key);
  89.    }
  90. }
  91.