public abstract class AbstractSequenceIdGenerator extends Object implements IIdGenerator
| Modifier and Type | Field and Description |
|---|---|
private int |
BUFFER_SIZE |
static org.slf4j.Logger |
LOG
日志.
|
private Map<String,Queue<Long>> |
longIdBuffer
批量生成id缓冲
|
private org.apache.zookeeper.ZooKeeper |
zk |
| Constructor and Description |
|---|
AbstractSequenceIdGenerator(org.apache.curator.framework.CuratorFramework curatorClient,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
private int[] |
_genClusterUniqueIntIdBatch(String clusterName,
String name,
int batchSize,
long seed)
生成n个int型的数值
|
private long[] |
_genClusterUniqueLongIdBatch(String clusterName,
String name,
int batchSize,
long seed)
生成n个long型的数值
|
private long |
_genId(String clusterName,
String name,
long seed) |
void |
checkAndSetPrimaryKey(long pk,
String clusterName,
String name)
校验给定的主键值是否比当前zookeeper中的值大, 如果大则设置为给定的主键值.
|
int |
genClusterUniqueIntId(String clusterName,
String name)
生成全局唯一的int id.
|
int |
genClusterUniqueIntId(String clusterName,
String name,
long seed) |
int[] |
genClusterUniqueIntIdBatch(String clusterName,
String name,
int batchSize)
批量生成全局唯一主键.
|
int[] |
genClusterUniqueIntIdBatch(String clusterName,
String name,
int batchSize,
long seed) |
long |
genClusterUniqueLongId(String clusterName,
String name)
生成全局唯一的long id.
|
long |
genClusterUniqueLongId(String clusterName,
String name,
long seed) |
long[] |
genClusterUniqueLongIdBatch(String clusterName,
String name,
int batchSize)
批量生成全局唯一主键.
|
long[] |
genClusterUniqueLongIdBatch(String clusterName,
String name,
int batchSize,
long seed) |
private String |
getBufferKey(String clusterName,
String name) |
abstract Lock |
getLock(String lockName)
获取集群锁
|
public static final org.slf4j.Logger LOG
private int BUFFER_SIZE
private org.apache.zookeeper.ZooKeeper zk
public AbstractSequenceIdGenerator(org.apache.curator.framework.CuratorFramework curatorClient,
int bufferSize)
public void checkAndSetPrimaryKey(long pk,
String clusterName,
String name)
IIdGeneratorcheckAndSetPrimaryKey in interface IIdGeneratorpk - 被校验的主键值clusterName - 集群名name - 保存主键值的node名称public int genClusterUniqueIntId(String clusterName, String name)
IIdGeneratorgenClusterUniqueIntId in interface IIdGeneratorclusterName - zookeeper目录name - id生成的名字public int genClusterUniqueIntId(String clusterName, String name, long seed)
genClusterUniqueIntId in interface IIdGeneratorpublic long genClusterUniqueLongId(String clusterName, String name)
IIdGeneratorgenClusterUniqueLongId in interface IIdGeneratorclusterName - zookeeper目录name - id生成的名字public long genClusterUniqueLongId(String clusterName, String name, long seed)
genClusterUniqueLongId in interface IIdGeneratorpublic int[] genClusterUniqueIntIdBatch(String clusterName, String name, int batchSize)
IIdGeneratorgenClusterUniqueIntIdBatch in interface IIdGeneratorclusterName - zookeeper目录name - id生成的名字batchSize - 批量数public int[] genClusterUniqueIntIdBatch(String clusterName, String name, int batchSize, long seed)
genClusterUniqueIntIdBatch in interface IIdGeneratorpublic long[] genClusterUniqueLongIdBatch(String clusterName, String name, int batchSize)
IIdGeneratorgenClusterUniqueLongIdBatch in interface IIdGeneratorclusterName - zookeeper目录name - id生成的名字batchSize - 批量数public long[] genClusterUniqueLongIdBatch(String clusterName, String name, int batchSize, long seed)
genClusterUniqueLongIdBatch in interface IIdGeneratorprivate int[] _genClusterUniqueIntIdBatch(String clusterName, String name, int batchSize, long seed)
clusterName - name - batchSize - seed - 当seed大于当前值则使用seed作为起点private long[] _genClusterUniqueLongIdBatch(String clusterName, String name, int batchSize, long seed)
clusterName - name - batchSize - seed - 当seed大于当前值则使用seed作为起点Copyright © 2015. All rights reserved.