Tanzu GemFire Distributed Types Java API Reference
Interface DSnowflakeId
- All Superinterfaces:
DType
The layout of IDs is as follows:
- timestamp (41 bits by default)
- machine ID (10 bits by default)
- sequence number (12 bits by default)
The timestamp is stored relative to a specific epoch start which, by default, is 1 Jan, 2020
(DEFAULT_EPOCH_START).
The default bit sizes allow for generating 4096 (2^12) sequence IDs per millisecond. If that rate is exceeded, generation will block until the next millisecond.
The current implementation generates the default machine ID from the nanosecond timestamp on the system. Thus, DSnowflakeIds created on the same system, will have different machine IDs. If required, a custom machine ID can be provided.
A builder pattern is used to create custom DSnowflakeId instance:
DSnowflakeId flake = DSnowflakeId.builder()
.withEpochStart(1_000_000)
.withMachineId(37)
.withSequenceBits(15)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder used to create custom DSnowflakeIds. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default epoch start - 1 Jan, 2020static final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic DSnowflakeId.Builderbuilder()Provides a Builder used to create customized DSnowflakeIds.default voiddestroy()This is a no-op for DSnowflakeIds.longnextId()Generate a new ID.long[]parse(long sequence) Parse a sequence ID into its individual components based on the configured bit lengths.
-
Field Details
-
DEFAULT_MACHINE_BITS
static final int DEFAULT_MACHINE_BITS- See Also:
-
DEFAULT_SEQUENCE_BITS
static final int DEFAULT_SEQUENCE_BITS- See Also:
-
DEFAULT_EPOCH_START
static final long DEFAULT_EPOCH_STARTThe default epoch start - 1 Jan, 2020- See Also:
-
-
Method Details
-
nextId
long nextId()Generate a new ID.- Returns:
- the next ID
-
parse
long[] parse(long sequence) Parse a sequence ID into its individual components based on the configured bit lengths. Note that the timestamp will be adjusted by the epoch start to reflect the 'correct' time.- Parameters:
sequence- the sequence ID to parse- Returns:
- a long[3] array consisting of timestamp, machine ID and sequence number
-
destroy
default void destroy()This is a no-op for DSnowflakeIds. Since nothing is distributed or stored for this type, there are no additional resources to release. -
builder
Provides a Builder used to create customized DSnowflakeIds.- Returns:
- a new Builder
-