Class StringSnowflakeId

java.lang.Object
me.ahoo.cosid.StringIdGeneratorDecorator
me.ahoo.cosid.snowflake.StringSnowflakeId
All Implemented Interfaces:
Decorator<IdGenerator>, IdGenerator, IdGeneratorDecorator, SnowflakeId, Statistical, StringIdGenerator
Direct Known Subclasses:
DefaultSnowflakeFriendlyId

public class StringSnowflakeId extends StringIdGeneratorDecorator implements SnowflakeId
String-based SnowflakeId wrapper.

Wraps a SnowflakeId with a string converter for generating string-based IDs while maintaining SnowflakeId properties.

  • Constructor Details

    • StringSnowflakeId

      public StringSnowflakeId(SnowflakeId actual, IdConverter idConverter)
      Creates a new StringSnowflakeId.
      Parameters:
      actual - the underlying SnowflakeId
      idConverter - the converter for string generation
  • Method Details

    • layout

      public SnowflakeLayout layout()
      Description copied from interface: SnowflakeId
      The bit layout of the ids.
      Specified by:
      layout in interface SnowflakeId
      Returns:
      the layout
    • getLastTimestamp

      public long getLastTimestamp()
      Description copied from interface: SnowflakeId
      Get the timestamp of the last ID that was generated.

      This is used for clock synchronization and to ensure proper ordering of generated IDs. It can also help detect clock drift.

      Specified by:
      getLastTimestamp in interface SnowflakeId
      Returns:
      The timestamp of the last generated ID
    • getLastTimestampAsMilliseconds

      public long getLastTimestampAsMilliseconds()
      Description copied from interface: SnowflakeId
      Get the last generated timestamp in milliseconds for clock synchronization.
      Specified by:
      getLastTimestampAsMilliseconds in interface SnowflakeId
      Returns:
      The last generated timestamp in milliseconds
    • getMachineId

      public int getMachineId()
      Description copied from interface: SnowflakeId
      Get the machine ID assigned to this generator.

      This is the unique identifier for the machine or instance that is generating IDs, which ensures global uniqueness across the distributed system.

      Specified by:
      getMachineId in interface SnowflakeId
      Returns:
      The machine ID
    • stat

      public IdGeneratorStat stat()
      Description copied from interface: SnowflakeId
      Get statistical information about this Snowflake ID generator.

      This method provides detailed information about the generator's configuration and current state, including all the key parameters that define its behavior.

      Specified by:
      stat in interface IdGenerator
      Specified by:
      stat in interface IdGeneratorDecorator
      Specified by:
      stat in interface SnowflakeId
      Specified by:
      stat in interface Statistical
      Specified by:
      stat in interface StringIdGenerator
      Returns:
      Statistical information about this Snowflake ID generator