summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqidaijie <[email protected]>2019-08-09 16:50:12 +0800
committerqidaijie <[email protected]>2019-08-09 16:50:12 +0800
commit0da2d582e046695456a148959bd9400662b3a70e (patch)
tree227015f3369eb0420c558ed7cb139a7ce1c2932f
parent739c8fdb6e64d5a8771020f99100383cfad70694 (diff)
更新部分位置代码
-rw-r--r--SnowFlake/SnowflakeId.java5
-rw-r--r--Zookeeper/ZookeeperUtils.java9
2 files changed, 7 insertions, 7 deletions
diff --git a/SnowFlake/SnowflakeId.java b/SnowFlake/SnowflakeId.java
index e697202..5f77996 100644
--- a/SnowFlake/SnowflakeId.java
+++ b/SnowFlake/SnowflakeId.java
@@ -105,11 +105,12 @@ public class SnowflakeId {
if (tmpWorkerId > maxWorkerId || tmpWorkerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
- if (FlowWriteConfig.DATA_CENTER_ID_NUM > maxDataCenterId || FlowWriteConfig.DATA_CENTER_ID_NUM < 0) {
+ int dataCenterId = FlowWriteConfig.DATA_CENTER_ID_NUM;
+ if (dataCenterId > maxDataCenterId || dataCenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDataCenterId));
}
this.workerId = tmpWorkerId;
- this.dataCenterId = FlowWriteConfig.DATA_CENTER_ID_NUM;
+ this.dataCenterId = dataCenterId;
}
// ==============================Methods==========================================
diff --git a/Zookeeper/ZookeeperUtils.java b/Zookeeper/ZookeeperUtils.java
index 612c4e7..639b50c 100644
--- a/Zookeeper/ZookeeperUtils.java
+++ b/Zookeeper/ZookeeperUtils.java
@@ -41,7 +41,7 @@ public class ZookeeperUtils implements Watcher {
createNode("/Snowflake/" + FlowWriteConfig.KAFKA_TOPIC, "0".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE);
int workerId;
try {
- connectZookeeper(FlowWriteConfig.ZOOKEEPER_SERVERS);
+ connectZookeeper();
Stat stat = zookeeper.exists(path, true);
workerId = Integer.parseInt(getNodeDate(path));
if (workerId > 55) {
@@ -68,11 +68,10 @@ public class ZookeeperUtils implements Watcher {
/**
* 连接zookeeper
*
- * @param host 地址
*/
- private void connectZookeeper(String host) {
+ private void connectZookeeper() {
try {
- zookeeper = new ZooKeeper(host, SESSION_TIME_OUT, this);
+ zookeeper = new ZooKeeper(FlowWriteConfig.ZOOKEEPER_SERVERS, SESSION_TIME_OUT, this);
countDownLatch.await();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
@@ -118,7 +117,7 @@ public class ZookeeperUtils implements Watcher {
*/
private void createNode(String path, byte[] date, List<ACL> acls) {
try {
- connectZookeeper(FlowWriteConfig.ZOOKEEPER_SERVERS);
+ connectZookeeper();
Stat exists = zookeeper.exists(path, true);
if (exists == null) {
zookeeper.create(path, date, acls, CreateMode.PERSISTENT);