org.apache.turbine.util.db
Class UUIdGenerator

java.lang.Object
  |
  +--org.apache.turbine.util.db.UUIdGenerator

public class UUIdGenerator
extends java.lang.Object

This class generates universally unique id's in the form of a String. The id has three parts. The first is supposed to be location dependent. The preferred location parameter is an ethernet (MAC) address, but an IP can be used as well. if none is supplied a Math.random generated number will be used. This part of the key will be 48 bits in length. The second part of the key is time related and will be the lower 48 bits of the long used to signify the time since Jan. 1, 1970. This will cause key rollover in the year 6429. The preceding 12 bytes are Base64 encoded with the characters / and * replaced by _ (underscore) and - (dash). Resulting in 16 characters. Finally a counter is used to hand out 4095 keys in between each timestamp. The resulting id is a String of 18 characters including: a-z,A-Z,0-9, and the previously mentioned - and _.

Note this class does not save any state information, so it is important that time only moves forward to keep the integrity of the ids. We might want to consider saving some state info.

To specify the MAC/Ethernet address, add a uuid.address= property to the TurbineResources.properties file.

Version:
$Id$
Author:
John D. McNally

Field Summary
private  byte[] address
           
private  java.lang.String baseId
           
private static char[] countChar
          characters used in the ID
private  int counter
           
private static java.lang.String errorString
           
 
Constructor Summary
UUIdGenerator()
          Constructor
 
Method Summary
private  void generateNewBaseId()
          Generates the new base id
 java.lang.String getId()
          Gets the id
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

errorString

private static final java.lang.String errorString

address

private byte[] address

baseId

private java.lang.String baseId

counter

private int counter

countChar

private static final char[] countChar
characters used in the ID
Constructor Detail

UUIdGenerator

public UUIdGenerator()
              throws TurbineException
Constructor
Method Detail

generateNewBaseId

private final void generateNewBaseId()
                              throws java.lang.Exception
Generates the new base id

getId

public java.lang.String getId()
                       throws java.lang.Exception
Gets the id


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.