Appearance
OrderedIdGenerator Class
Definition
Generates compact, time-ordered 64-bit identifiers using a fixed bit layout: 41-bit timestamp (milliseconds since a custom epoch), 10-bit node id, and 12-bit sequence.
- Namespace:
JASE - Assembly:
JASE.IdGenerator.dll
Constructors
| Name | Description |
|---|---|
OrderedIdGenerator(int nodeId, DateTime epochUtc, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null) | Initializes a new generator with explicit node id, custom epoch, and clock mode. |
OrderedIdGenerator(int nodeId, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null) | Initializes a new generator using DefaultEpoch. |
Fields
| Name | Description |
|---|---|
NodeBits | Number of bits used for the node id field. |
NodeMask | Bitmask for extracting the 10-bit node id field. |
NodeShift | Bit shift for the node id field (sequence is the least-significant field). |
SequenceBits | Number of bits used for the per-millisecond sequence field |
SequenceMask | Bitmask for extracting the 12-bit sequence field. |
TimestampBits | Number of bits used for the timestamp field. |
TimestampMax | Maximum representable timestamp value (41 bits). |
TimestampShift | Bit shift for the timestamp field (timestamp is the most-significant field). |
Properties
| Name | Description |
|---|---|
DefaultEpoch | JASE snowflake epoch (2025-07-11 UTC). Encoded timestamps are milliseconds since this instant. |
Epoch | The epoch for this generator instance. |
NodeId | Node identifier encoded into generated IDs (0..1023). |
TwitterEpoch | Twitter Snowflake / IdGen default epoch (2010-11-04 01:42:54.657 UTC). |
Methods
| Name | Description |
|---|---|
OrderedIdValue Decode(long id) | Decodes an identifier into its component fields (timestamp, node id, sequence). |
OrderedIdGenerator FromEnvironment(DateTime epochUtc, OrderedIdClockMode mode = null, int maxLogicalSkewMS = null) | Creates a generator using a custom epoch and the node id from JASE_ID_GENERATOR_NODE (0..1023). |
OrderedIdGenerator FromEnvironment(OrderedIdClockMode mode = null, int maxLogicalSkewMS = null) | Creates a generator using DefaultEpoch and the node id from JASE_ID_GENERATOR_NODE (0..1023). |
bool IsOrderedId(long value) | Determines whether a value conforms to the OrderedId bit layout and decodes to a plausible timestamp for this generator instance. |
long NextId() | Generates the next ordered identifier. |
Remarks
This generator produces IDs that are monotonically increasing per generator instance (per node), with ordering primarily determined by the timestamp component.
The timestamp is stored as a 41-bit millisecond offset from Epoch. The remaining bits encode the node id and an intra-millisecond sequence counter.
Clock behavior is controlled by OrderedIdClockMode:
WallClock is Snowflake-compatible: the ID timestamp tracks real UTC time. If the clock moves backwards or the sequence overflows within a millisecond, generation will wait. LogicalClock is a bounded logical clock optimized for throughput: it avoids blocking on minor clock rollback and may advance the logical timestamp slightly ahead of real time up to a configured bound.
Time source note: this implementation uses a monotonic stopwatch-based clock with periodic resynchronization to real UTC to mitigate system clock adjustments (NTP steps, VM time jumps, manual changes).