org.jgroups.util

## Class UUID

- java.lang.Object
- - org.jgroups.util.UUID

All Implemented Interfaces:
  java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Address>, Address, Streamable

Direct Known Subclasses:
  AdditionalDataUUID, PayloadUUID, TopologyUUID

    public class UUID
    extends java.lang.Object
    implements Address, Streamable, java.lang.Comparable<Address>

Logical address which is unique over space and time.
Copied from java.util.UUID, but unneeded fields from the latter have been removed. UUIDs needs to have a small memory footprint.

Author:
  Bela Ban
See Also:
  Serialized Form

### Field Summary

Fields
`protected byte[]` `additional_data`
`protected static LazyRemovalCache<Address,java.lang.String>` `cache` Keeps track of associations between logical addresses (UUIDs) and logical names
`protected long` `leastSigBits`
`protected long` `mostSigBits`
`protected static java.security.SecureRandom` `numberGenerator` The random number generator used by this class to create random based UUIDs
`protected static LazyRemovalCache.Printable<Address,java.lang.String>` `print_function`
`protected static boolean` `print_uuids`
`protected static int` `SIZE`

### Fields inherited from interface org.jgroups.Address

`IP_ADDR, NULL, UUID_ADDR`

### Constructor Summary

Constructors
`` `UUID()`
`protected` `UUID(byte[] data)` Private constructor which uses a byte array to construct the new UUID
`` `UUID(long mostSigBits, long leastSigBits)`

### Method Summary

Methods
`static void` `add(Address uuid, java.lang.String logical_name)`
`static void` `add(java.util.Map<Address,java.lang.String> map)`
`java.lang.Object` `clone()`
`int` `compareTo(Address other)` Compares this UUID with the specified UUID.
`protected static java.lang.String` `digits(long val, int digits)` Returns val represented by the specified number of hex digits.
`boolean` `equals(java.lang.Object obj)` Compares this object to the specified object.
`static java.lang.String` `get(Address logical_addr)`
`byte[]` `getAdditionalData()` Deprecated. Will be removed in 3.0. This was only added to be backwards compatible with 2.7
`static java.util.Map<Address,java.lang.String>` `getContents()` Returns a copy of the cache's contents
`long` `getLeastSignificantBits()`
`long` `getMostSignificantBits()` Returns the most significant 64 bits of this UUID's 128 bit value.
`int` `hashCode()` Returns a hash code for this `UUID`.
`boolean` `isMulticastAddress()` Checks whether this is an address that represents multiple destinations; e.g., a class D address in the Internet.
`static java.lang.String` `printCache()`
`static UUID` `randomUUID()` Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
`void` `readExternal(java.io.ObjectInput in)`
`void` `readFrom(java.io.DataInputStream in)` Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed
`static void` `remove(Address addr)`
`static void` `removeAll(java.util.Collection<Address> mbrs)`
`static void` `retainAll(java.util.Collection<Address> logical_addrs)`
`void` `setAdditionalData(byte[] additional_data)` Deprecated. Will be removed in 3.0. This was only added to be backwards compatible with 2.7
`int` `size()` Returns serialized size of this address
`java.lang.String` `toString()`
`java.lang.String` `toStringLong()` Returns a `String` object representing this `UUID`.
`void` `writeExternal(java.io.ObjectOutput out)`
`void` `writeTo(java.io.DataOutputStream out)` Write the entire state of the current object (including superclasses) to outstream.

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### mostSigBits

    protected long mostSigBits

#### leastSigBits

    protected long leastSigBits

#### additional_data

    protected byte[] additional_data

#### numberGenerator

    protected static volatile java.security.SecureRandom numberGenerator

The random number generator used by this class to create random based UUIDs

#### cache

    protected static LazyRemovalCache<Address,java.lang.String> cache

Keeps track of associations between logical addresses (UUIDs) and logical names

#### print_uuids

    protected static boolean print_uuids

#### SIZE

    protected static final int SIZE

See Also:
  Constant Field Values

#### print_function

    protected static final LazyRemovalCache.Printable<Address,java.lang.String> print_function

### Constructor Detail

#### UUID

    public UUID()

#### UUID

    public UUID(long mostSigBits,
        long leastSigBits)

#### UUID

    protected UUID(byte[] data)

Private constructor which uses a byte array to construct the new UUID

### Method Detail

#### add

    public static void add(Address uuid,
           java.lang.String logical_name)

#### add

    public static void add(java.util.Map<Address,java.lang.String> map)

#### get

    public static java.lang.String get(Address logical_addr)

#### getContents

    public static java.util.Map<Address,java.lang.String> getContents()

Returns a copy of the cache's contents

#### remove

    public static void remove(Address addr)

#### removeAll

    public static void removeAll(java.util.Collection<Address> mbrs)

#### retainAll

    public static void retainAll(java.util.Collection<Address> logical_addrs)

#### printCache

    public static java.lang.String printCache()

#### getAdditionalData

    public final byte[] getAdditionalData()

Deprecated. Will be removed in 3.0. This was only added to be backwards compatible with 2.7
Returns the additional_data.

Returns:
  byte[]
Since:
  2.8

#### setAdditionalData

    public final void setAdditionalData(byte[] additional_data)

Deprecated. Will be removed in 3.0. This was only added to be backwards compatible with 2.7
Sets the additional_data.

Parameters:
  `additional_data` - The additional_data to set
Since:
  2.8

#### randomUUID

    public static UUID randomUUID()

Static factory to retrieve a type 4 (pseudo randomly generated) UUID. The `UUID` is generated using a cryptographically strong pseudo random number generator.

Returns:
  A randomly generated `UUID`

#### getLeastSignificantBits

    public long getLeastSignificantBits()

#### getMostSignificantBits

    public long getMostSignificantBits()

Returns the most significant 64 bits of this UUID's 128 bit value.

Returns:
  The most significant 64 bits of this UUID's 128 bit value

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### toStringLong

    public java.lang.String toStringLong()

Returns a `String` object representing this `UUID`.

The UUID string representation is as described by this BNF:

>      UUID                   = <time_low> "-" <time_mid> "-"
>                               <time_high_and_version> "-"
>                               <variant_and_sequence> "-"
>                               <node>
>      time_low               = 4*<hexOctet>
>      time_mid               = 2*<hexOctet>
>      time_high_and_version  = 2*<hexOctet>
>      variant_and_sequence   = 2*<hexOctet>
>      node                   = 6*<hexOctet>
>      hexOctet               = <hexDigit><hexDigit>
>      hexDigit               =
>            "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
>            | "a" | "b" | "c" | "d" | "e" | "f"
>            | "A" | "B" | "C" | "D" | "E" | "F"

Returns:
  A string representation of this `UUID`

#### digits

    protected static java.lang.String digits(long val,
                          int digits)

Returns val represented by the specified number of hex digits.

#### hashCode

    public int hashCode()

Returns a hash code for this `UUID`.

Overrides:
  `hashCode` in class `java.lang.Object`
Returns:
  A hash code value for this `UUID`

#### equals

    public boolean equals(java.lang.Object obj)

Compares this object to the specified object. The result is `true` if and only if the argument is not `null`, is a `UUID` object, has the same variant, and contains the same value, bit for bit, as this `UUID`.

Overrides:
  `equals` in class `java.lang.Object`
Parameters:
  `obj` - The object to be compared
Returns:
  `true` if the objects are the same; `false` otherwise

#### compareTo

    public int compareTo(Address other)

Compares this UUID with the specified UUID.

The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ is greater for the first UUID.

Specified by:
  `compareTo` in interface `java.lang.Comparable<Address>`
Parameters:
  `other` - `UUID` to which this `UUID` is to be compared
Returns:
  -1, 0 or 1 as this `UUID` is less than, equal to, or greater than `val`

#### writeTo

    public void writeTo(java.io.DataOutputStream out)
                 throws java.io.IOException

Description copied from interface: `Streamable`
Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed

Specified by:
  `writeTo` in interface `Streamable`
Throws:
  `java.io.IOException`

#### readFrom

    public void readFrom(java.io.DataInputStream in)
                  throws java.io.IOException,
                         java.lang.IllegalAccessException,
                         java.lang.InstantiationException

Description copied from interface: `Streamable`
Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed

Specified by:
  `readFrom` in interface `Streamable`
Throws:
  `java.io.IOException`
  `java.lang.IllegalAccessException`
  `java.lang.InstantiationException`

#### isMulticastAddress

    public boolean isMulticastAddress()

Description copied from interface: `Address`
Checks whether this is an address that represents multiple destinations; e.g., a class D address in the Internet.

Specified by:
  `isMulticastAddress` in interface `Address`
Returns:
  true if this is a multicast address, false if it is a unicast address

#### size

    public int size()

Description copied from interface: `Address`
Returns serialized size of this address

Specified by:
  `size` in interface `Address`

#### clone

    public java.lang.Object clone()
                           throws java.lang.CloneNotSupportedException

Overrides:
  `clone` in class `java.lang.Object`
Throws:
  `java.lang.CloneNotSupportedException`

#### writeExternal

    public void writeExternal(java.io.ObjectOutput out)
                       throws java.io.IOException

Specified by:
  `writeExternal` in interface `java.io.Externalizable`
Throws:
  `java.io.IOException`

#### readExternal

    public void readExternal(java.io.ObjectInput in)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException

Specified by:
  `readExternal` in interface `java.io.Externalizable`
Throws:
  `java.io.IOException`
  `java.lang.ClassNotFoundException`