|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.almendra.commons.util.globalId.UniqueIdGenerator
public class UniqueIdGenerator
Generates globally unique ids. These ids contain the name of the local machine which is assumed to be unique within a network, a running counter and a timestamp. The timestamp is used to be sure that the id is unique even after the running counter has had overflow and therefore has been reset to 0. The counter has meanwhile been changed from an int to a BigInteger. Overflow is now very unlikely to occur. The timestamp is kept as there can be several JVMs on the same machine using the same code to generate unique ids.
Field Summary | |
---|---|
protected static java.math.BigInteger |
Count
The running counter which is part of an id. |
protected static java.lang.String |
HostName
The name of the local machine assumed unique within a network. |
protected static java.util.Random |
random
|
Constructor Summary | |
---|---|
UniqueIdGenerator()
Creates a new UniqueIdGenerator object. |
Method Summary | |
---|---|
protected static java.lang.String |
getHostName()
Retrieve the name of the local machine which is part of an id. |
static java.lang.String |
getMillisWithRandom()
Return a new counter that has not been used before. |
static java.lang.String |
getNewCount()
Return a new counter that has not been used before. |
static UniqueId |
next()
Return a new unique id. |
static UniqueId |
next(java.lang.String prefix)
Return a new unique id. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.math.BigInteger Count
protected static java.lang.String HostName
protected static java.util.Random random
Constructor Detail |
---|
public UniqueIdGenerator()
UniqueIdGenerator
object.
Method Detail |
---|
protected static java.lang.String getHostName()
public static UniqueId next()
public static UniqueId next(java.lang.String prefix)
prefix
- the id prefix used instead of the local machine name
public static java.lang.String getNewCount()
public static java.lang.String getMillisWithRandom()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |