Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.utils
Class GuidGenerator

    java.lang.Object
      org.jasig.portal.utils.GuidGenerator

    public class GuidGenerator

extends java.lang.Object

Creates a Global/Universal Unique ID, per DCE RPC specification. Requires seed of MAC address/node identifier (12-digit hex string) for uniqueness. Specification found at the OpenGroup.Org web site.

Version:
  $Revision: 1.7 $
Author:
  Michael Ivanov

Field Summary
`private static short` | `CLOCKMOD` CLOCKMOD constitutes the net value range for the clock counter per RFC.
`private static java.lang.String` | `clockSeq` clockSeq holds the static clock sequence string used in fourth element of Guid per RFC.
`private static long` | `lastMilliTime` lastMilliTime holds the static last millisecond time requested in order to provide determination if nanoCounter needs to be adjusted.
`private java.lang.String` | `macbase` macbase holds the instance initialization string denoting fifth element of Guid per RFC
`private static long` | `nanoCounter` nanoCounter holds static iteration value for unique nanosecond value when two Guid values requested within clock resolution (one millisecond).
`private static short` | `NANOS` NANOS is the conversion from millisecond timer to 100 nanoseconds per RFC.
`private static java.util.Random` | `random`
`private java.lang.String` | `timebase` timebase holds the instance string denoting elements one thru four of Guid per RFC

Constructor Summary
`GuidGenerator()` GuidGenerator() - default constructor
`GuidGenerator(java.lang.String newMAC)` GuidGenerator(String) - seeded constructor

Method Summary
`private static void` | `bytesToHex(byte[] bytes, java.lang.StringBuffer buffer)` Returns the hexidecimal representation of byte values in the array.
`(package private) static java.lang.String` | `getClockSeq()` getClockSeq returns the RFC clock sequence string
`(package private) static long` | `getLastTime()` getLastTime accesses lastMilliTime for return
`(package private) static long` | `getMilliTime()` getMilliTime accesses the system clock
`(package private) static long` | `getNano()`
`java.lang.String` | `getNewGuid()` getNewGuid calls set to generate a new GUID
`private void` | `initGuid(java.lang.String newMAC)` getNano atomically increments and returns nanoCounter
`static void` | `main(java.lang.String[] args)` main is the unit testing interface that creates a new Guid instance and prints result of getNewGuid to System.out
`(package private) static void` | `nanoBump()` nanoBump increments nanoCounter
`(package private) static void` | `nanoReset()` nanoReset zeroes nanoCounter
`void` | `set()` set is where all the work is done
`(package private) static void` | `setClockSeq()` setClockSeq sets the RFC clock sequence string
`(package private) static void` | `setLastTime(long lastTime)` setLastTime sets the new value of lastMilliTime
`java.lang.String` | `toString()` toString returns the current values as a single string per RFC

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### CLOCKMOD

    private static final short CLOCKMOD

  CLOCKMOD constitutes the net value range for the clock counter per RFC.

  See Also:
    `setClockSeq()`, Constant Field Values

### NANOS

    private static final short NANOS

  NANOS is the conversion from millisecond timer to 100 nanoseconds per RFC.

  See Also:
    `getMilliTime()`, Constant Field Values

### nanoCounter

    private static long nanoCounter

  nanoCounter holds static iteration value for unique nanosecond value when two Guid values requested within clock resolution (one millisecond).

  See Also:
    `getNano()`, `nanoBump()`, `nanoReset()`, `set()`

### clockSeq

    private static java.lang.String clockSeq

  clockSeq holds the static clock sequence string used in fourth element of Guid per RFC.

  See Also:
    `setClockSeq()`

### lastMilliTime

    private static long lastMilliTime

  lastMilliTime holds the static last millisecond time requested in order to provide determination if nanoCounter needs to be adjusted.

  See Also:
    `getLastTime()`, `setLastTime(long)`, `set()`

### macbase

    private java.lang.String macbase

  macbase holds the instance initialization string denoting fifth element of Guid per RFC

  See Also:
    `GuidGenerator(String)`, `toString()`

### timebase

    private java.lang.String timebase

  timebase holds the instance string denoting elements one thru four of Guid per RFC

  See Also:
    `GuidGenerator(String)`, `set()`

### random

    private static java.util.Random random

Constructor Detail

### GuidGenerator

    public GuidGenerator()

  GuidGenerator() - default constructor

  Throws:
    `java.net.UnknownHostException`

### GuidGenerator

    public GuidGenerator(java.lang.String newMAC)
                  throws java.lang.IllegalArgumentException

  GuidGenerator(String) - seeded constructor

  Parameters:
    `newMAC` - as the seed value for fifth element of string GUID
  Throws:
    `java.lang.IllegalArgumentException`

Method Detail

### bytesToHex

    private static final void bytesToHex(byte[] bytes,
                                         java.lang.StringBuffer buffer)

  Returns the hexidecimal representation of byte values in the array. Uses Integer.toHexString on each byte, so is relatively expensive. This could easily be ameliorated with some trivial byte-packing but for now I'm just going to do the Simplest Thing Possible.

### initGuid

    private void initGuid(java.lang.String newMAC)
                   throws java.lang.IllegalArgumentException

  getNano atomically increments and returns nanoCounter

  Throws:
    `java.lang.IllegalArgumentException`

### getNano

    static long getNano()

### nanoBump

    static void nanoBump()

  nanoBump increments nanoCounter

### nanoReset

    static void nanoReset()

  nanoReset zeroes nanoCounter

### getLastTime

    static long getLastTime()

  getLastTime accesses lastMilliTime for return

  Returns:
    the current value of lastMilliTime

### setLastTime

    static void setLastTime(long lastTime)

  setLastTime sets the new value of lastMilliTime

  Parameters:
    `lastTime` - the value to which to set lastMilliTime
  See Also:
    `set()`

### getMilliTime

    static long getMilliTime()

  getMilliTime accesses the system clock

  Returns:
    the last system time converted to 100 nanosecond intervals

### getClockSeq

    static java.lang.String getClockSeq()

  getClockSeq returns the RFC clock sequence string

  Returns:
    clockSeq value

### setClockSeq

    static void setClockSeq()

  setClockSeq sets the RFC clock sequence string

  See Also:
    `GuidGenerator(String)`

### getNewGuid

    public java.lang.String getNewGuid()

  getNewGuid calls set to generate a new GUID

  Returns:
    the latest GUID

### toString

    public java.lang.String toString()

  toString returns the current values as a single string per RFC

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    the timebase from set() concatenated to the initialization string

### set

    public void set()

  set is where all the work is done

### main

    public static void main(java.lang.String[] args)

  main is the unit testing interface that creates a new Guid instance and prints result of getNewGuid to System.out

  Parameters:
    `args` - array for input arguments

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD