home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / rmi / server / UID.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.5 KB  |  100 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 int hostUnique = getHostUniqueNum();
  13.    private static long lastTime = System.currentTimeMillis();
  14.    private static short lastCount = Short.MIN_VALUE;
  15.    private static Object mutex = new Object();
  16.    private static long ONE_SECOND = 1000L;
  17.  
  18.    private static int getHostUniqueNum() {
  19.       return (new Object()).hashCode();
  20.    }
  21.  
  22.    public UID() {
  23.       Object var1 = mutex;
  24.       synchronized(var1){}
  25.  
  26.       try {
  27.          if (lastCount == 32767) {
  28.             boolean var3 = false;
  29.  
  30.             while(!var3) {
  31.                this.time = System.currentTimeMillis();
  32.                if (this.time < lastTime + ONE_SECOND) {
  33.                   try {
  34.                      Thread.currentThread();
  35.                      Thread.sleep(ONE_SECOND);
  36.                   } catch (InterruptedException var6) {
  37.                   }
  38.                } else {
  39.                   lastTime = this.time;
  40.                   lastCount = Short.MIN_VALUE;
  41.                   var3 = true;
  42.                }
  43.             }
  44.          } else {
  45.             this.time = lastTime;
  46.          }
  47.  
  48.          this.unique = hostUnique;
  49.          short var10001 = lastCount;
  50.          lastCount = (short)(var10001 + 1);
  51.          this.count = var10001;
  52.       } catch (Throwable var7) {
  53.          throw var7;
  54.       }
  55.  
  56.    }
  57.  
  58.    public UID(short var1) {
  59.       this.unique = 0;
  60.       this.time = 0L;
  61.       this.count = var1;
  62.    }
  63.  
  64.    private UID(int var1, long var2, short var4) {
  65.       this.unique = var1;
  66.       this.time = var2;
  67.       this.count = var4;
  68.    }
  69.  
  70.    public int hashCode() {
  71.       return (int)this.time + this.count;
  72.    }
  73.  
  74.    public boolean equals(Object var1) {
  75.       if (var1 != null && var1 instanceof UID) {
  76.          UID var2 = (UID)var1;
  77.          return this.unique == var2.unique && this.count == var2.count && this.time == var2.time;
  78.       } else {
  79.          return false;
  80.       }
  81.    }
  82.  
  83.    public String toString() {
  84.       return Integer.toString(this.unique, 16) + ":" + Long.toString(this.time, 16) + ":" + Integer.toString(this.count, 16);
  85.    }
  86.  
  87.    public void write(DataOutput var1) throws IOException {
  88.       var1.writeInt(this.unique);
  89.       var1.writeLong(this.time);
  90.       var1.writeShort(this.count);
  91.    }
  92.  
  93.    public static UID read(DataInput var0) throws IOException {
  94.       int var1 = var0.readInt();
  95.       long var2 = var0.readLong();
  96.       short var4 = var0.readShort();
  97.       return new UID(var1, var2, var4);
  98.    }
  99. }
  100.