本文整理了Java中com.ucar.datalink.common.zookeeper.ZkClientX.readData()
方法的一些代码示例,展示了ZkClientX.readData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClientX.readData()
方法的具体详情如下:
包路径:com.ucar.datalink.common.zookeeper.ZkClientX
类名称:ZkClientX
方法名:readData
暂无
代码示例来源:origin: ucarGroup/DataLink
@Override
public ManagerMetaData load(String key) throws Exception {
byte[] bytes = DLinkZkUtils.get().zkClient().readData(DLinkZkPathDef.ManagerActiveNode, true);
if (bytes != null) {
return JSON.parseObject(bytes, ManagerMetaData.class);
}
return null;
}
});
代码示例来源:origin: ucarGroup/DataLink
@Override
public Position getPosition(String taskId) {
DLinkZkUtils zkUtils = DLinkZkUtils.get();
String path = DLinkZkPathDef.getTaskPositionNode(taskId);
byte[] data = zkUtils.zkClient().readData(path, true);
if (data == null || data.length == 0) {
return null;
}
return JSON.parseObject(data, Position.class);
}
}
代码示例来源:origin: ucarGroup/DataLink
@Override
public Collection<TaskStatus> getAll() {
DLinkZkUtils zkUtils = DLinkZkUtils.get();
List<TaskStatus> result = new ArrayList<>();
for (String taskId : tasks()) {
byte[] bytes = zkUtils.zkClient().readData(DLinkZkPathDef.getTaskStatusNode(taskId), true);
if (bytes != null) {
result.add(JSON.parseObject(bytes, TaskStatus.class));
}
}
return result;
}
代码示例来源:origin: ucarGroup/DataLink
public List<ManagerMetaData> getAllAliveManagers() {
List<ManagerMetaData> result = Lists.newArrayList();
List<String> childrenPath = zkUtils.zkClient().getChildren(DLinkZkPathDef.ManagerClusterRoot);
if (childrenPath != null) {
for (String path : childrenPath) {
String fullPath = DLinkZkPathDef.getManagerClusterNode(path);
result.add(JSON.parseObject((byte[]) zkUtils.zkClient().readData(fullPath, true), ManagerMetaData.class));
}
}
return result;
}
}
代码示例来源:origin: ucarGroup/DataLink
@Override
public TaskStatus getStatus(String taskId) {
DLinkZkUtils zkUtils = DLinkZkUtils.get();
byte[] bytes = zkUtils.zkClient().readData(DLinkZkPathDef.getTaskStatusNode(taskId), true);
if (bytes != null) {
return JSON.parseObject(bytes, TaskStatus.class);
} else {
return null;
}
}
代码示例来源:origin: ucarGroup/DataLink
private synchronized void initRunning() {
if (!isStarted.get()) {
return;
}
String path = DLinkZkPathDef.ManagerActiveNode;
// 序列化
byte[] bytes = JSON.toJSONBytes(thisManagerMetaData);
try {
setActive(null);
zkUtils.zkClient().create(path, bytes, CreateMode.EPHEMERAL);
setActive(thisManagerMetaData);
} catch (ZkNodeExistsException e) {
bytes = zkUtils.zkClient().readData(path, true);
if (bytes == null) {
initRunning();
} else {
setActive(JSON.parseObject(bytes, ManagerMetaData.class));
}
} catch (ZkNoNodeException e) {
zkUtils.zkClient().createPersistent(DLinkZkPathDef.ManagerRoot, true); // 尝试创建父节点
initRunning();
}
}
代码示例来源:origin: ucarGroup/DataLink
@Override
public void addStatus(TaskStatus status) throws TaskConflictException {
DLinkZkUtils zkUtils = DLinkZkUtils.get();
String statusPath = DLinkZkPathDef.getTaskStatusNode(status.getId());
byte[] bytes = JSON.toJSONBytes(status);
try {
zkUtils.zkClient().createPersistent(DLinkZkPathDef.getTaskNode(status.getId()), true);
zkUtils.zkClient().create(statusPath, bytes, CreateMode.EPHEMERAL);
} catch (ZkNodeExistsException e) {
byte[] data = zkUtils.zkClient().readData(statusPath, true);
if (data != null) {
TaskStatus otherTaskStatus = JSON.parseObject(data, TaskStatus.class);
throw new TaskConflictException(status.getId(), status.getWorkerId(), otherTaskStatus.getWorkerId(),
status.getExecutionId(), otherTaskStatus.getExecutionId());
} else {
addStatus(status);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!