本文整理了Java中com.gopush.common.utils.zk.ZkUtils
类的一些代码示例,展示了ZkUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkUtils
类的具体详情如下:
包路径:com.gopush.common.utils.zk.ZkUtils
类名称:ZkUtils
暂无
代码示例来源:origin: lee123lee123/GoPush
@PreDestroy
public void destory() {
zkUtils.destory();
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 设置节点数据
*
* @param path
* @param data
* @return
*/
public boolean setNodeData(String path, String data) {
return setNodeData(path, data.getBytes(Charsets.UTF_8), null);
}
代码示例来源:origin: lee123lee123/GoPush
private void initDataCenterPool() {
monitorDataCenterPool.clear();
Map<String, String> datas = zkUtils.readTargetChildsData(ZkGroupEnum.DATA_CENTER.getValue());
if (datas != null) {
datas.forEach((k, v) -> monitorDataCenterPool.put(k, JSON.parseObject(v, DataCenterInfo.class)));
}
}
代码示例来源:origin: lee123lee123/GoPush
@PostConstruct
public void init() {
zkUtils = new ZkUtils();
zkUtils.init(
zookeeperConfig.getServers(),
zookeeperConfig.getConnectionTimeout(),
zookeeperConfig.getSessionTimeout(),
zookeeperConfig.getMaxRetries(),
zookeeperConfig.getRetriesSleepTime(),
zookeeperConfig.getListenNamespace(),
new ZkStateListener() {
@Override
public void connectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterDiscovery 链接zk成功");
}
@Override
public void reconnectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterDiscovery 重新链接zk成功");
}
@Override
public void lostEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterDiscovery 链接zk丢失");
}
});
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 注册node-server服务
*/
private void registerNodeServer() {
if (!zkUtils.checkExists(ZkGroupEnum.NODE_SERVER.getValue())) {
boolean flag;
do {
flag = zkUtils.createNode(ZkGroupEnum.NODE_SERVER.getValue(), null, CreateMode.PERSISTENT);
} while (!flag);
}
registerNodeInfo();
}
代码示例来源:origin: lee123lee123/GoPush
private void listenNodeServer() {
zkUtils.listenerPathChildrenCache(ZkGroupEnum.NODE_SERVER.getValue(), ((zkclient, event) -> {
switch (event.getType()) {
case CHILD_ADDED:
addEvent(event);
break;
case CHILD_REMOVED:
removeEvent(event);
break;
case CHILD_UPDATED:
updateEvent(event);
break;
default:
break;
}
}));
}
代码示例来源:origin: lee123lee123/GoPush
private void registerNodeInfo() {
zkUtils.createNode(
ZKPaths.makePath(ZkGroupEnum.NODE_SERVER.getValue(), goPushNodeServerConfig.getName()),
JSON.toJSONString(watchdog.watch()),
CreateMode.EPHEMERAL);
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 删除节点
*
* @param path
* @return
*/
public boolean deleteNode(String path) {
return deleteNode(path, null);
}
代码示例来源:origin: lee123lee123/GoPush
@PostConstruct
public void init() {
zkUtils = new ZkUtils();
zkUtils.init(
zookeeperConfig.getServers(),
zookeeperConfig.getConnectionTimeout(),
zookeeperConfig.getSessionTimeout(),
zookeeperConfig.getMaxRetries(),
zookeeperConfig.getRetriesSleepTime(),
zookeeperConfig.getNamespace(),
new ZkStateListener() {
@Override
public void connectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterRegister 链接zk成功");
registerDataCenter();
}
@Override
public void reconnectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterRegister 重新链接zk成功");
registerDataCenter();
}
@Override
public void lostEvent(CuratorFramework curator, ConnectionState state) {
log.info("DataCenterRegister 链接zk丢失");
}
});
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 注册datacenter服务
*/
private void registerDataCenter() {
if (!zkUtils.checkExists(ZkGroupEnum.DATA_CENTER.getValue())) {
boolean flag;
do {
flag = zkUtils.createNode(ZkGroupEnum.DATA_CENTER.getValue(), null, CreateMode.PERSISTENT);
} while (!flag);
}
registerDataCenterInfo();
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 设置监听发生更新,更新缓存数据,发生新增,删除,更新
*/
private void listenDataCenter() {
zkUtils.listenerPathChildrenCache(ZkGroupEnum.DATA_CENTER.getValue(), ((client, event) -> {
switch (event.getType()) {
case CHILD_ADDED:
addEvent(event);
break;
case CHILD_REMOVED:
removeEvent(event);
break;
case CHILD_UPDATED:
updateEvent(event);
break;
default:
break;
}
}));
}
代码示例来源:origin: lee123lee123/GoPush
private void registerDataCenterInfo() {
zkUtils.createNode(
ZKPaths.makePath(ZkGroupEnum.DATA_CENTER.getValue(), goPushDataCenterConfig.getName()),
JSON.toJSONString(watchdog.watch()),
CreateMode.EPHEMERAL);
}
代码示例来源:origin: lee123lee123/GoPush
@PostConstruct
public void init() {
zkUtils = new ZkUtils();
zkUtils.init(
zookeeperConfig.getServers(),
zookeeperConfig.getConnectionTimeout(),
zookeeperConfig.getSessionTimeout(),
zookeeperConfig.getMaxRetries(),
zookeeperConfig.getRetriesSleepTime(),
zookeeperConfig.getNamespace(),
new ZkStateListener() {
@Override
public void connectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("NodeServerRegister 链接zk成功");
registerNodeServer();
}
@Override
public void reconnectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("NodeServerRegister 重新链接zk成功");
registerNodeServer();
}
@Override
public void lostEvent(CuratorFramework curator, ConnectionState state) {
log.info("NodeServerRegister 链接zk丢失");
}
});
}
代码示例来源:origin: lee123lee123/GoPush
@PreDestroy
public void destory() {
nodeServerPool.clear();
zkUtils.destory();
}
代码示例来源:origin: lee123lee123/GoPush
public void postNewData(DataCenterInfo data) {
zkUtils.setNodeData(
ZKPaths.makePath(ZkGroupEnum.DATA_CENTER.getValue(), goPushDataCenterConfig.getName()),
JSON.toJSONString(data));
}
代码示例来源:origin: lee123lee123/GoPush
private void initNodeServerPool() {
monitorNodeServerPool.clear();
Map<String, String> datas = zkUtils.readTargetChildsData(ZkGroupEnum.NODE_SERVER.getValue());
if (datas != null) {
datas.forEach((k, v) -> monitorNodeServerPool.put(k, JSON.parseObject(v, NodeServerInfo.class)));
}
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 设置监听发生更新,更新缓存数据,发生新增,删除,更新
*/
private void listenNodeServerDiscovery() {
zkUtils.listenerPathChildrenCache(ZkGroupEnum.NODE_SERVER.getValue(), ((client, event) -> {
switch (event.getType()) {
case CHILD_ADDED:
addEvent(event);
break;
case CHILD_REMOVED:
removeEvent(event);
break;
case CHILD_UPDATED:
updateEvent(event);
break;
default:
break;
}
}));
}
代码示例来源:origin: lee123lee123/GoPush
@PostConstruct
public void init() {
zkUtils = new ZkUtils();
zkUtils.init(
zookeeperConfig.getServers(),
zookeeperConfig.getConnectionTimeout(),
zookeeperConfig.getSessionTimeout(),
zookeeperConfig.getMaxRetries(),
zookeeperConfig.getRetriesSleepTime(),
zookeeperConfig.getListenNamespaceNodeServer(),
new ZkStateListener() {
@Override
public void connectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("MonitorNodeServer 链接zk成功");
initNodeServerPool();
}
@Override
public void reconnectedEvent(CuratorFramework curator, ConnectionState state) {
log.info("MonitorNodeServer 重新链接zk成功");
initNodeServerPool();
}
@Override
public void lostEvent(CuratorFramework curator, ConnectionState state) {
log.info("MonitorNodeServer 链接zk丢失");
monitorNodeServerPool.clear();
}
});
listenNodeServer();
}
代码示例来源:origin: lee123lee123/GoPush
@PreDestroy
public void destory() {
zkUtils.destory();
}
代码示例来源:origin: lee123lee123/GoPush
/**
* 提交最新的数据
*
* @param data
*/
public void postNewData(NodeServerInfo data) {
zkUtils.setNodeData(
ZKPaths.makePath(ZkGroupEnum.NODE_SERVER.getValue(), goPushNodeServerConfig.getName()),
JSON.toJSONString(data));
}
内容来源于网络,如有侵权,请联系作者删除!