Package com.fayupable.snowflake.config
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
ConstructorsConstructorDescriptionSnowflakeConfig(long epoch, long datacenterId, long workerId, int timestampBits, int datacenterBits, int workerBits, int sequenceBits) Creates an instance of aSnowflakeConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thedatacenterBitsrecord component.longReturns the value of thedatacenterIdrecord component.static SnowflakeConfigdefaultConfig(long epoch, long datacenterId, long workerId) longepoch()Returns the value of theepochrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.longintnodeBits()longnodeId()intintReturns the value of thesequenceBitsrecord component.intReturns the value of thetimestampBitsrecord component.intfinal StringtoString()Returns a string representation of this record class.intReturns the value of theworkerBitsrecord component.longworkerId()Returns the value of theworkerIdrecord component.
-
Constructor Details
-
SnowflakeConfig
public SnowflakeConfig(long epoch, long datacenterId, long workerId, int timestampBits, int datacenterBits, int workerBits, int sequenceBits) Creates an instance of aSnowflakeConfigrecord class.- Parameters:
epoch- the value for theepochrecord componentdatacenterId- the value for thedatacenterIdrecord componentworkerId- the value for theworkerIdrecord componenttimestampBits- the value for thetimestampBitsrecord componentdatacenterBits- the value for thedatacenterBitsrecord componentworkerBits- the value for theworkerBitsrecord componentsequenceBits- the value for thesequenceBitsrecord component
-
-
Method Details
-
defaultConfig
-
maxSequence
public long maxSequence() -
nodeId
public long nodeId() -
nodeBits
public int nodeBits() -
nodeShift
public int nodeShift() -
timestampShift
public int timestampShift() -
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. -
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. -
equals
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 '=='. -
epoch
public long epoch()Returns the value of theepochrecord component.- Returns:
- the value of the
epochrecord component
-
datacenterId
public long datacenterId()Returns the value of thedatacenterIdrecord component.- Returns:
- the value of the
datacenterIdrecord component
-
workerId
public long workerId()Returns the value of theworkerIdrecord component.- Returns:
- the value of the
workerIdrecord component
-
timestampBits
public int timestampBits()Returns the value of thetimestampBitsrecord component.- Returns:
- the value of the
timestampBitsrecord component
-
datacenterBits
public int datacenterBits()Returns the value of thedatacenterBitsrecord component.- Returns:
- the value of the
datacenterBitsrecord component
-
workerBits
public int workerBits()Returns the value of theworkerBitsrecord component.- Returns:
- the value of the
workerBitsrecord component
-
sequenceBits
public int sequenceBits()Returns the value of thesequenceBitsrecord component.- Returns:
- the value of the
sequenceBitsrecord component
-