Class Uuid

java.lang.Object
org.apache.kafka.common.Uuid
All Implemented Interfaces:
Comparable<Uuid>

public class Uuid
extends Object
implements Comparable<Uuid>
This class defines an immutable universally unique identifier (UUID). It represents a 128-bit value. More specifically, the random UUIDs generated by this class are variant 2 (Leach-Salz) version 4 UUIDs. This is the same type of UUID as the ones generated by java.util.UUID. The toString() method prints using the base64 string encoding. Likewise, the fromString method expects a base64 string encoding.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static Uuid METADATA_TOPIC_ID
    A UUID for the metadata topic in KRaft mode.
    static Uuid ZERO_UUID
    A UUID that represents a null or empty UUID.
  • Constructor Summary

    Constructors
    Constructor Description
    Uuid​(long mostSigBits, long leastSigBits)
    Constructs a 128-bit type 4 UUID where the first long represents the most significant 64 bits and the second long represents the least significant 64 bits.
  • Method Summary

    Modifier and Type Method Description
    int compareTo​(Uuid other)  
    boolean equals​(Object obj)
    Returns true iff obj is another Uuid represented by the same two long values.
    static Uuid fromString​(String str)
    Creates a UUID based on a base64 string encoding used in the toString() method.
    long getLeastSignificantBits()
    Returns the least significant bits of the UUID's 128 value.
    long getMostSignificantBits()
    Returns the most significant bits of the UUID's 128 value.
    int hashCode()
    Returns a hash code for this UUID
    static Uuid randomUuid()
    Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
    String toString()
    Returns a base64 string encoding of the UUID.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • METADATA_TOPIC_ID

      public static final Uuid METADATA_TOPIC_ID
      A UUID for the metadata topic in KRaft mode. Will never be returned by the randomUuid method.
    • ZERO_UUID

      public static final Uuid ZERO_UUID
      A UUID that represents a null or empty UUID. Will never be returned by the randomUuid method.
  • Constructor Details

    • Uuid

      public Uuid​(long mostSigBits, long leastSigBits)
      Constructs a 128-bit type 4 UUID where the first long represents the most significant 64 bits and the second long represents the least significant 64 bits.
  • Method Details

    • randomUuid

      public static Uuid randomUuid()
      Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
    • getMostSignificantBits

      public long getMostSignificantBits()
      Returns the most significant bits of the UUID's 128 value.
    • getLeastSignificantBits

      public long getLeastSignificantBits()
      Returns the least significant bits of the UUID's 128 value.
    • equals

      public boolean equals​(Object obj)
      Returns true iff obj is another Uuid represented by the same two long values.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code for this UUID
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a base64 string encoding of the UUID.
      Overrides:
      toString in class Object
    • fromString

      public static Uuid fromString​(String str)
      Creates a UUID based on a base64 string encoding used in the toString() method.
    • compareTo

      public int compareTo​(Uuid other)
      Specified by:
      compareTo in interface Comparable<Uuid>