
shz.id.IdInfo Maven / Gradle / Ivy
package shz.id;
import shz.msg.ServerFailureMsg;
public final class IdInfo {
/**
* 中心节点
*/
long datacenterId;
/**
* 工作节点
*/
long workerId;
/**
* 时间戳
*/
long timestamp;
/**
* 同一毫秒内的自增序列
*/
long sequence;
/**
* 中心节点位数(0-31)
*/
long datacenterIdBits = 5L;
/**
* 工作节点位数(0-31)
*/
long workerIdBits = 5L;
/**
* 时间戳位数(在id中有效值 2^41-1)
*/
long timestampBits = 41L;
/**
* 序列位数(0-4095)
*/
long sequenceBits = 12L;
public IdInfo(long datacenterId, long workerId) {
this.datacenterId = datacenterId;
this.workerId = workerId;
}
public IdInfo() {
}
public long getDatacenterId() {
return datacenterId;
}
public void setDatacenterId(long datacenterId) {
this.datacenterId = datacenterId;
}
public long getWorkerId() {
return workerId;
}
public void setWorkerId(long workerId) {
this.workerId = workerId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public long getSequence() {
return sequence;
}
public void setSequence(long sequence) {
this.sequence = sequence;
}
public long getDatacenterIdBits() {
return datacenterIdBits;
}
public void setDatacenterIdBits(long datacenterIdBits) {
ServerFailureMsg.requireNon(
datacenterIdBits > 12L || datacenterIdBits < 1L,
"中心节点位数取值范围:1-12"
);
this.datacenterIdBits = datacenterIdBits;
}
public long getWorkerIdBits() {
return workerIdBits;
}
public void setWorkerIdBits(long workerIdBits) {
ServerFailureMsg.requireNon(
workerIdBits > 12L || workerIdBits < 1L,
"工作节点位数取值范围:1-12"
);
this.workerIdBits = workerIdBits;
}
public long getTimestampBits() {
return timestampBits;
}
public void setTimestampBits(long timestampBits) {
ServerFailureMsg.requireNon(
timestampBits > 41L || timestampBits < 38L,
"时间戳位数取值范围:38-41"
);
this.timestampBits = timestampBits;
}
public long getSequenceBits() {
return sequenceBits;
}
public void setSequenceBits(long sequenceBits) {
ServerFailureMsg.requireNon(
sequenceBits > 23L || sequenceBits < 12L,
"序列位数取值范围:12-23"
);
this.sequenceBits = sequenceBits;
}
@Override
public String toString() {
return "IdInfo{" +
"datacenterId=" + datacenterId +
", workerId=" + workerId +
", timestamp=" + timestamp +
", sequence=" + sequence +
", datacenterIdBits=" + datacenterIdBits +
", workerIdBits=" + workerIdBits +
", timestampBits=" + timestampBits +
", sequenceBits=" + sequenceBits +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy