Record Class SnowflakeConfig

java.lang.Object
java.lang.Record
com.fayupable.snowflake.config.SnowflakeConfig

public record SnowflakeConfig(long epoch, long datacenterId, long workerId, int timestampBits, int datacenterBits, int workerBits, int sequenceBits) extends Record
Configuration for the Snowflake id layout. Bit layout (MSB to LSB): 1 unused sign bit | timestampBits | datacenterBits | workerBits | sequenceBits. Default: 41-bit timestamp (~69 years from epoch), 5-bit datacenter (up to 32 datacenters), 5-bit worker (up to 32 workers per datacenter), 12-bit sequence (up to 4096 ids per millisecond per worker).
  • Constructor Summary

    Constructors
    Constructor
    Description
    SnowflakeConfig(long epoch, long datacenterId, long workerId, int timestampBits, int datacenterBits, int workerBits, int sequenceBits)
    Creates an instance of a SnowflakeConfig record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the datacenterBits record component.
    long
    Returns the value of the datacenterId record component.
    defaultConfig(long epoch, long datacenterId, long workerId)
     
    long
    Returns the value of the epoch record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
     
    int
     
    long
     
    int
     
    int
    Returns the value of the sequenceBits record component.
    int
    Returns the value of the timestampBits record component.
    int
     
    final String
    Returns a string representation of this record class.
    int
    Returns the value of the workerBits record component.
    long
    Returns the value of the workerId record component.

    Methods inherited from class java.lang.Object

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

    • SnowflakeConfig

      public SnowflakeConfig(long epoch, long datacenterId, long workerId, int timestampBits, int datacenterBits, int workerBits, int sequenceBits)
      Creates an instance of a SnowflakeConfig record class.
      Parameters:
      epoch - the value for the epoch record component
      datacenterId - the value for the datacenterId record component
      workerId - the value for the workerId record component
      timestampBits - the value for the timestampBits record component
      datacenterBits - the value for the datacenterBits record component
      workerBits - the value for the workerBits record component
      sequenceBits - the value for the sequenceBits record component
  • Method Details

    • defaultConfig

      public static SnowflakeConfig defaultConfig(long epoch, long datacenterId, long workerId)
    • maxSequence

      public long maxSequence()
    • nodeId

      public long nodeId()
    • nodeBits

      public int nodeBits()
    • nodeShift

      public int nodeShift()
    • timestampShift

      public int timestampShift()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • epoch

      public long epoch()
      Returns the value of the epoch record component.
      Returns:
      the value of the epoch record component
    • datacenterId

      public long datacenterId()
      Returns the value of the datacenterId record component.
      Returns:
      the value of the datacenterId record component
    • workerId

      public long workerId()
      Returns the value of the workerId record component.
      Returns:
      the value of the workerId record component
    • timestampBits

      public int timestampBits()
      Returns the value of the timestampBits record component.
      Returns:
      the value of the timestampBits record component
    • datacenterBits

      public int datacenterBits()
      Returns the value of the datacenterBits record component.
      Returns:
      the value of the datacenterBits record component
    • workerBits

      public int workerBits()
      Returns the value of the workerBits record component.
      Returns:
      the value of the workerBits record component
    • sequenceBits

      public int sequenceBits()
      Returns the value of the sequenceBits record component.
      Returns:
      the value of the sequenceBits record component