home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / net / www / http / ClientVector.class (.txt) next >
Encoding:
Java Class File  |  1997-07-08  |  2.1 KB  |  96 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;
  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.MAXCONNS];
  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 var13) {
  58.          }
  59.  
  60.          synchronized(this){}
  61.  
  62.          try {
  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.          } catch (Throwable var14) {
  74.             throw var14;
  75.          }
  76.  
  77.          for(int var3 = 0; var3 < this.inUse.length; ++var3) {
  78.             HttpClient var15;
  79.             if ((var15 = this.inUse[var3]) != null && var15.kas.hurry()) {
  80.                this.put(var15);
  81.             }
  82.          }
  83.  
  84.          synchronized(this){}
  85.  
  86.          try {
  87.             var1 = this.num + ((Vector)this).size();
  88.          } catch (Throwable var12) {
  89.             throw var12;
  90.          }
  91.       } while(var1 > 0);
  92.  
  93.       this.cache.removeVector(this.key);
  94.    }
  95. }
  96.