public class Snowflake extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_TIME_OFFSET
默认回拨时间,2S
|
static long |
DEFAULT_TWEPOCH
默认的起始时间,为Thu, 04 Nov 2010 01:42:54 GMT
|
| Constructor and Description |
|---|
Snowflake() |
Snowflake(long workerId,
long dataCenterId) |
| Modifier and Type | Method and Description |
|---|---|
long |
getDataCenterId(long id)
根据Snowflake的ID,获取数据中心id
|
long |
getGenerateDateTime(long id)
根据Snowflake的ID,获取生成时间
|
long |
getWorkerId(long id)
根据Snowflake的ID,获取机器id
|
static long |
makeDataCenterId(long maxDatacenterId)
获取数据中心ID
数据中心ID依赖于本地网卡MAC地址。 |
static long |
makeWorkerId(long datacenterId,
long maxWorkerId)
获取机器ID,使用进程ID配合数据中心ID生成
机器依赖于本进程ID或进程名的Hash值。 |
long |
nextId()
下一个ID
|
String |
nextIdBase64() |
String |
nextIdHex() |
String |
nextIdStr()
下一个ID(字符串形式)
|
public static long DEFAULT_TWEPOCH
public static long DEFAULT_TIME_OFFSET
public Snowflake()
public Snowflake(long workerId,
long dataCenterId)
public static long makeWorkerId(long datacenterId,
long maxWorkerId)
此算法来自于mybatis-plus#Sequence
datacenterId - 数据中心IDmaxWorkerId - 最大的机器节点IDpublic static long makeDataCenterId(long maxDatacenterId)
此算法来自于mybatis-plus#Sequence
maxDatacenterId - 最大的中心IDpublic long getWorkerId(long id)
id - snowflake算法生成的idpublic long getDataCenterId(long id)
id - snowflake算法生成的idpublic long getGenerateDateTime(long id)
id - snowflake算法生成的idpublic long nextId()
public String nextIdStr()
public String nextIdHex()
public String nextIdBase64()
Copyright © 2024 江苏南大先腾信息产业股份有限公司. All rights reserved.