类 SnowFlake

java.lang.Object
cn.vorbote.core.utils.SnowFlake

public class SnowFlake extends Object
Distributed Sequence Generator.
  • 构造器概要

    构造器
    构造器
    说明
    SnowFlake(long workerId, long dataCentreId)
    Constructor can build a new SnowFlake instance.
    SnowFlake(long startEpoch, long workerId, long dataCentreId)
    Constructor can build a new SnowFlake instance.
  • 方法概要

    修饰符和类型
    方法
    说明
    protected long
    awaitToNextMillis(long lastTimestamp)
    Block until the next millisecond until a new timestamp is obtained.
    protected long
    Return current timestamp with the unit of millisecond.
    long
    Get next unique id.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • SnowFlake

      public SnowFlake(long workerId, long dataCentreId)
      Constructor can build a new SnowFlake instance.
      参数:
      workerId - The id of the server. (Should between 0 and 31)
      dataCentreId - The id of the data centre. (Should between 0 and 31)
    • SnowFlake

      public SnowFlake(long startEpoch, long workerId, long dataCentreId)
      Constructor can build a new SnowFlake instance.
      参数:
      startEpoch - The start epoch to calculate.
      workerId - The id of the server. (Should between 0 and 31)
      dataCentreId - The id of the data centre. (Should between 0 and 31)
  • 方法详细资料

    • nextId

      public long nextId()
      Get next unique id.
      返回:
      A unique id.
    • awaitToNextMillis

      protected long awaitToNextMillis(long lastTimestamp)
      Block until the next millisecond until a new timestamp is obtained.
      参数:
      lastTimestamp - The timestamp when id was created last time.
      返回:
      Current timestamp.
    • currentTimestamp

      protected long currentTimestamp()
      Return current timestamp with the unit of millisecond.
      返回:
      Current time.