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 / java / rmi / server / UID.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.0 KB  |  96 lines

  1. package java.rmi.server;
  2.  
  3. import java.io.DataInput;
  4. import java.io.DataOutput;
  5. import java.io.IOException;
  6. import java.io.Serializable;
  7.  
  8. public final class UID implements Serializable {
  9.    private int unique;
  10.    private long time;
  11.    private short count;
  12.    private static final long serialVersionUID = 1086053664494604050L;
  13.    private static int hostUnique = getHostUniqueNum();
  14.    private static long lastTime = System.currentTimeMillis();
  15.    private static short lastCount = Short.MIN_VALUE;
  16.    private static Object mutex = new Object();
  17.    private static long ONE_SECOND = 1000L;
  18.  
  19.    private static int getHostUniqueNum() {
  20.       return (new Object()).hashCode();
  21.    }
  22.  
  23.    public UID() {
  24.       Object var1 = mutex;
  25.       synchronized(var1) {
  26.          if (lastCount == 32767) {
  27.             boolean var2 = false;
  28.  
  29.             while(!var2) {
  30.                this.time = System.currentTimeMillis();
  31.                if (this.time < lastTime + ONE_SECOND) {
  32.                   try {
  33.                      Thread.currentThread();
  34.                      Thread.sleep(ONE_SECOND);
  35.                   } catch (InterruptedException var5) {
  36.                   }
  37.                } else {
  38.                   lastTime = this.time;
  39.                   lastCount = Short.MIN_VALUE;
  40.                   var2 = true;
  41.                }
  42.             }
  43.          } else {
  44.             this.time = lastTime;
  45.          }
  46.  
  47.          this.unique = hostUnique;
  48.          short var10001 = lastCount;
  49.          lastCount = (short)(var10001 + 1);
  50.          this.count = var10001;
  51.       }
  52.    }
  53.  
  54.    public UID(short var1) {
  55.       this.unique = 0;
  56.       this.time = 0L;
  57.       this.count = var1;
  58.    }
  59.  
  60.    private UID(int var1, long var2, short var4) {
  61.       this.unique = var1;
  62.       this.time = var2;
  63.       this.count = var4;
  64.    }
  65.  
  66.    public int hashCode() {
  67.       return (int)this.time + this.count;
  68.    }
  69.  
  70.    public boolean equals(Object var1) {
  71.       if (var1 != null && var1 instanceof UID) {
  72.          UID var2 = (UID)var1;
  73.          return this.unique == var2.unique && this.count == var2.count && this.time == var2.time;
  74.       } else {
  75.          return false;
  76.       }
  77.    }
  78.  
  79.    public String toString() {
  80.       return Integer.toString(this.unique, 16) + ":" + Long.toString(this.time, 16) + ":" + Integer.toString(this.count, 16);
  81.    }
  82.  
  83.    public void write(DataOutput var1) throws IOException {
  84.       var1.writeInt(this.unique);
  85.       var1.writeLong(this.time);
  86.       var1.writeShort(this.count);
  87.    }
  88.  
  89.    public static UID read(DataInput var0) throws IOException {
  90.       int var1 = var0.readInt();
  91.       long var2 = var0.readLong();
  92.       short var4 = var0.readShort();
  93.       return new UID(var1, var2, var4);
  94.    }
  95. }
  96.