org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class UUID

java.lang.Object
  extended by org.netbeans.mdr.persistence.btreeimpl.btreestorage.UUID
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class UUID
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

UUID is a DCE UUID, that is, a 128-bit universally unique identifier.

The UUID has the following fields:

  1. timeLow(ui4) - the low 32 bits of the current time
  2. timeMid(ui2) - the next 16 bits of the current time
  3. timeHiAndVersion(ui2) - the high 12 bits of the current time, or'ed with UUID version information, which occupies the top 4 bits.
  4. clockSeqHiAndReserved(ui1) - the top 6 bits of the 'Clock Sequence', which is a random number. The top two bits of this field must be '10' to be a valid variant 1 UUID.
  5. clockSeqLow(ui1) - the low 8 bits of the Clock Sequence
  6. nodeId (u_i1[6]) - intended to be the Ethernet address, which is guaranteed unique in the world.

Time is expressed as in VMS, i.e. 100's of nanoseconds since a base date, but the base dat is 10/15/1582, rather than VMS's 1858. Since 100 nanoseconds is probably much smaller than the system clock resolution, implementations are allowed to construct many UUIDs per clock tick by keeping track of a 'time adjustment', which is bumped for each UUID constructed during a clock tick and added into the UUID's time fields.

The intent of the UUID algorithm is to generate a globally unique ID. The reasoning goes:

  1. First of all, the nodeId is globally unique, so the only possible duplications will come from the same machine.
  2. Second, the time value will be unique for each producer of UUIDs on a given machine.
  3. Third (not explicitly stated anywhere I can find), different producers on a single machine will have different Clock Sequence values. The implmentations of Clock Sequence I've seen use pid as an input to the random number generator.

Java has one large problem using this logic: the Ethernet address is not findable in any documented way. The DCE implementation on SunOS evidently has had the same problem, since they use the Internet address instead of the Ethernet address as four bytes of their node ID (they set the fifth and sixth bytes not to conflict with any true Ethernet address.)

Forte's version of UUID generation, implemented in the UUID.UUIDGenerator class, is:

  1. nodeId: Generate a 4-byte random number. Like DCE on SunOS, set bytes 5 and 6 to values illegal for an Ethernet address.
  2. time: Get a 32-bit time value from System.currentTimeMills(), and convert it to VMS-like format. Since the conversion from milliseconds to hundreds of nanoseconds is a multiplication by 10**4, this leaves the result always 0 mod 10**4. We add a randomly generated 12-bit number to this, which leaves room to generate at least 10**4 - 2**12 or about 6000 UUIDs in the current millisecond.
  3. clock sequence: A 14-bit random number

See Also:
Serialized Form

Field Summary
static int STRING_LENGTH
          the length of a UUID converted to a string
 
Constructor Summary
UUID()
          Generate a new UUID
UUID(java.lang.String str)
          Create a UUID from a string
 
Method Summary
 int compareTo(java.lang.Object o)
          Orders UUIDs by their field values
 boolean equals(java.lang.Object o)
          Two UUIDs are equal if all of their fields are equal
 int hashCode()
          Use timeLow for the hashCode, so equal UUIDs hash equal
 java.lang.String toString()
          Convert a UUID to a string in standard form:
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_LENGTH

public static final int STRING_LENGTH
the length of a UUID converted to a string

See Also:
Constant Field Values
Constructor Detail

UUID

public UUID()
Generate a new UUID


UUID

public UUID(java.lang.String str)
     throws java.lang.NumberFormatException
Create a UUID from a string

Parameters:
str - A string in standard UUID format
Throws:
java.lang.NumberFormatException - Thrown if the string isn't a valid UUID.
Method Detail

toString

public java.lang.String toString()
Convert a UUID to a string in standard form:

XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

timeLow-timeMid-timeHiAndVersion-clockSeqAndReserved-nodeId

Overrides:
toString in class java.lang.Object
Returns:
String version of UUID

equals

public boolean equals(java.lang.Object o)
Two UUIDs are equal if all of their fields are equal

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Orders UUIDs by their field values

Specified by:
compareTo in interface java.lang.Comparable

hashCode

public int hashCode()
Use timeLow for the hashCode, so equal UUIDs hash equal

Overrides:
hashCode in class java.lang.Object


Copyright © 2005-2009 Apache Software Foundation. All Rights Reserved.