ZKit.java
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.crossoverjie.cim.server.kit;
import com.crossoverjie.cim.server.config.AppConfiguration;
import org.I0Itec.zkclient.ZkClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Function: Zookeeper 工具
*
* @author crossoverJie
* Date: 2018/8/19 00:33
* @since JDK 1.8
*/
@Component
public class ZKit {
private static Logger logger = LoggerFactory.getLogger(ZKit.class);
@Autowired
private ZkClient zkClient;
@Autowired
private AppConfiguration appConfiguration ;
/**
* 创建父级节点
*/
public void createRootNode(){
boolean exists = zkClient.exists(appConfiguration.getZkRoot());
if (exists){
return;
}
//创建 root
zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}
/**
* 写入指定节点 临时目录
*
* @param path
* @param value
*/
public void createNode(String path, String value) {
zkClient.createEphemeral(path, value);
}
}