Class LongUuid

java.lang.Object
io.clonecloudstore.common.standard.guid.LongUuid

public final class LongUuid extends Object
UUID Generator but limited to 1 Long (64 bits), compatible multi instances (through the PID, but not multi servers, neither multi-sites due to lack of Mac address/Platform Id.

Inspired from com.groupon locality-uuid which used combination of internal counter value, process id and Timestamp. see https://github.com/groupon/locality-uuid.java

Benchmark shows about 20 millions/s generated LongUuid, 8 M/s getId().
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that generates a new UUID using the current process id and MAC address, timestamp and a counter
    LongUuid(byte[] bytes)
    Constructor that takes a byte array as UUID's content
    LongUuid(long value)
     
    LongUuid(String idsource)
    Constructor that takes a String representation of a UUID in Base 16
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    byte[]
    copy the uuid of this UUID, so that it can't be changed, and return it
     
    static short
     
    long
     
    static long
     
    int
    Extract process id from raw UUID bytes and return as int
    long
    Extract timestamp from raw UUID bytes and return as int
    int
     
     

    Methods inherited from class java.lang.Object

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

    • LongUuid

      public LongUuid()
      Constructor that generates a new UUID using the current process id and MAC address, timestamp and a counter
    • LongUuid

      public LongUuid(long value)
    • LongUuid

      public LongUuid(byte[] bytes)
      Constructor that takes a byte array as UUID's content
      Parameters:
      bytes - UUID content
    • LongUuid

      public LongUuid(String idsource)
      Constructor that takes a String representation of a UUID in Base 16
      Parameters:
      idsource - UUID content as String
  • Method Details

    • getLongUuid

      public static long getLongUuid()
      Returns:
      a new Uuid as long
    • getKeySize

      public static short getKeySize()
      Returns:
      the LongUuid size in bytes
    • getBytes

      public byte[] getBytes()
      copy the uuid of this UUID, so that it can't be changed, and return it
      Returns:
      raw byte array of UUID
    • getProcessId

      public int getProcessId()
      Extract process id from raw UUID bytes and return as int
      Returns:
      id of process that generated the UUID
    • getTimestamp

      public long getTimestamp()
      Extract timestamp from raw UUID bytes and return as int
      Returns:
      millisecond UTC timestamp from generation of the UUID
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the Base 16 representation
    • getId

      public String getId()
      Returns:
      the Base 16 representation
    • getLong

      public long getLong()
      Returns:
      the equivalent UUID as long