|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.safehaus.uuid.UUIDGenerator
public final class UUIDGenerator
UUIDGenerator is the class that contains factory methods for generating UUIDs using one of the three specified 'standard' UUID generation methods: (see draft-leach-uuids-guids-01.txt for details)
generateTimeBasedUUID() function.
| Method Summary | |
|---|---|
UUID |
generateNameBasedUUID(UUID nameSpaceUUID,
java.lang.String name)
Method similar to the previous one; the difference being that a shared MD5 digest instance will be used. |
UUID |
generateNameBasedUUID(UUID nameSpaceUUID,
java.lang.String name,
java.security.MessageDigest digest)
Method for generating name-based UUIDs, using the standard name-based generation method described in the UUID specs, and the caller supplied hashing method. |
UUID |
generateRandomBasedUUID()
Method for generating (pseudo-)random based UUIDs, using the default (shared) SecureRandom object. |
UUID |
generateRandomBasedUUID(java.util.Random randomGenerator)
Method for generating (pseudo-)random based UUIDs, using the specified SecureRandom object. |
UUID |
generateTagURIBasedUUID(TagURI name)
Method for generating UUIDs using tag URIs. |
UUID |
generateTagURIBasedUUID(TagURI name,
java.security.MessageDigest hasher)
Method for generating UUIDs using tag URIs. |
UUID |
generateTimeBasedUUID()
Method for generating time based UUIDs. |
UUID |
generateTimeBasedUUID(EthernetAddress addr)
Method for generating time based UUIDs. |
EthernetAddress |
getDummyAddress()
Method that returns a randomly generated dummy ethernet address. |
java.security.MessageDigest |
getHashAlgorithm()
|
static UUIDGenerator |
getInstance()
Method used for accessing the singleton generator instance. |
java.util.Random |
getRandomNumberGenerator()
Method for getting the shared random number generator used for generating the UUIDs. |
static void |
main(java.lang.String[] args)
A simple test harness is added to make (automated) testing of the class easier. |
void |
setRandomNumberGenerator(java.util.Random r)
Method that can be called to specify alternative random number generator to use. |
void |
synchronizeExternally(TimestampSynchronizer sync)
Method that can (and should) be called once right after getting the instance, to ensure that system time stamp values used are valid (with respect to values used earlier by JUG instances), and to use file-lock based synchronization mechanism to prevent multiple JVMs from running conflicting instances of JUG (first one to be started wins on contention). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static UUIDGenerator getInstance()
public void synchronizeExternally(TimestampSynchronizer sync)
throws java.io.IOException
Caller needs to instantiate an instance of
TimestampSynchronizer; currently the only standard
implementation is
FileBasedTimestampSynchronizer (which
is JDK 1.4+).
Note: since the generator instance is a singleton, calling this method will always cause all generation to be synchronized using the specified method.
sync - Synchronizer instance to use for synchronization.
java.io.IOExceptionpublic EthernetAddress getDummyAddress()
public java.util.Random getRandomNumberGenerator()
public void setRandomNumberGenerator(java.util.Random r)
SecureRandom that is used by default.
Note that to avoid first-time initialization penalty
of using SecureRandom, this method has to be called
before generating the first random-number based UUID.
public java.security.MessageDigest getHashAlgorithm()
public UUID generateRandomBasedUUID()
public UUID generateRandomBasedUUID(java.util.Random randomGenerator)
randomGenerator - Random number generator to use for getting the
random number from which UUID will be composed.
public UUID generateTimeBasedUUID()
Note that since the dummy address is only to be created once and shared from there on, there is some synchronization overhead.
public UUID generateTimeBasedUUID(EthernetAddress addr)
addr - Hardware address (802.1) to use for generating
spatially unique part of UUID. If system has more than one NIC,
any address is usable. If no NIC is available (or its address
not accessible; often the case with java apps), a randomly
generated broadcast address is acceptable. If so, use the
alternative method that takes no arguments.
public UUID generateNameBasedUUID(UUID nameSpaceUUID,
java.lang.String name,
java.security.MessageDigest digest)
nameSpaceUUID - UUID of the namespace, as defined by the
spec. UUID has 4 pre-defined "standard" name space strings
that can be passed to UUID constructor (see example below).
Note that this argument is optional; if no namespace is needed
(for example when name includes namespace prefix), null may be
passed.name - Name to base the UUID on; for example,
IP-name ("www.w3c.org") of the system for UUID.NAMESPACE_DNS,
URL ("http://www.w3c.org/index.html") for UUID.NAMESPACE_URL
and so on.digest - Instance of MessageDigest to use for hashing the name
value. hash.reset() will be called before calculating the has
value, to make sure digest state is not random and UUID will
not be randomised.
UUID uuid = gen.generateNameBasedUUID(
new UUID(UUID.NAMESPACE_DNS, "www.w3c.org"));
public UUID generateNameBasedUUID(UUID nameSpaceUUID,
java.lang.String name)
public UUID generateTagURIBasedUUID(TagURI name)
name - tag URI to base UUID on.
public UUID generateTagURIBasedUUID(TagURI name,
java.security.MessageDigest hasher)
name - tag URI to base UUID on.hasher - Hashing algorithm to use. Note that the caller has to
make sure that it's thread-safe to use 'hasher', either by never
calling this method from multiple threads, or by explicitly sync'ing
the calls.public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||