本文整理了Java中org.dromara.soul.common.constant.ZkPathConstants
类的一些代码示例,展示了ZkPathConstants
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkPathConstants
类的具体详情如下:
包路径:org.dromara.soul.common.constant.ZkPathConstants
类名称:ZkPathConstants
[英]ZkPathConstants.
[中]ZkPathConstants。
代码示例来源:origin: Dromara/soul
List<PluginDO> pluginDOs = pluginMapper.selectByQuery(new PluginQuery());
if (CollectionUtils.isNotEmpty(pluginDOs)) {
List<String> pluginZKs = zkClient.getChildren(ZkPathConstants.buildPluginParentPath());
pluginDOs.forEach(pluginDO -> {
if (CollectionUtils.isNotEmpty(pluginZKs)) {
zkClient.delete(ZkPathConstants.buildPluginPath(pluginZK));
String selectorParentPath = ZkPathConstants.buildSelectorParentPath(pluginZK);
if (zkClient.exists(selectorParentPath)) {
zkClient.delete(selectorParentPath);
String ruleParentPath = ZkPathConstants.buildRuleParentPath(pluginZK);
if (zkClient.exists(ruleParentPath)) {
zkClient.delete(ruleParentPath);
代码示例来源:origin: Dromara/soul
String pluginPath = ZkPathConstants.buildPluginPath(pluginDO.getName());
if (!zkClient.exists(pluginPath)) {
zkClient.createPersistent(pluginPath, true);
List<String> selectorZKs = zkClient.getChildren(ZkPathConstants.buildSelectorParentPath(pluginDO.getName()));
selectorMapper.selectByQuery(new SelectorQuery(pluginDO.getId(), null)).forEach(selectorDO -> {
if (CollectionUtils.isNotEmpty(selectorZKs)) {
selectorZKs.remove(selectorDO.getId());
String selectorRealPath = ZkPathConstants.buildSelectorRealPath(pluginDO.getName(), selectorDO.getId());
if (!zkClient.exists(selectorRealPath)) {
zkClient.createPersistent(selectorRealPath, true);
List<String> ruleZKs = zkClient.getChildren(ZkPathConstants.buildRuleParentPath(pluginDO.getName()));
ruleMapper.selectByQuery(new RuleQuery(selectorDO.getId(), null)).forEach(ruleDO -> {
if (CollectionUtils.isNotEmpty(ruleZKs)) {
ruleZKs.remove(selectorDO.getId() + ZkPathConstants.SELECTOR_JOIN_RULE + ruleDO.getId());
String ruleRealPath = ZkPathConstants.buildRulePath(pluginDO.getName(), selectorDO.getId(), ruleDO.getId());
if (!zkClient.exists(ruleRealPath)) {
zkClient.createPersistent(ruleRealPath, true);
ruleZKs.forEach(ruleZK -> zkClient.delete(ZkPathConstants.buildRulePath(pluginDO.getName(), selectorDO.getId(), ruleZK)));
});
zkClient.delete(ZkPathConstants.buildSelectorRealPath(pluginDO.getName(), selectorZK));
String ruleParentPath = ZkPathConstants.buildRuleParentPath(pluginDO.getName());
zkClient.getChildren(ruleParentPath).forEach(selectorRulePath -> {
if (selectorRulePath.split(ZkPathConstants.SELECTOR_JOIN_RULE)[0].equals(selectorZK)) {
代码示例来源:origin: Dromara/soul
/**
* delete plugins.
*
* @param ids primary key.
* @return rows
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int delete(final List<String> ids) {
int pluginCount = 0;
for (String id : ids) {
PluginDO pluginDO = pluginMapper.selectById(id);
pluginCount += pluginMapper.delete(id);
String pluginPath = ZkPathConstants.buildPluginPath(pluginDO.getName());
if (zkClient.exists(pluginPath)) {
zkClient.delete(pluginPath);
}
String selectorParentPath = ZkPathConstants.buildSelectorParentPath(pluginDO.getName());
if (zkClient.exists(selectorParentPath)) {
zkClient.delete(selectorParentPath);
}
String ruleParentPath = ZkPathConstants.buildRuleParentPath(pluginDO.getName());
if (zkClient.exists(ruleParentPath)) {
zkClient.delete(ruleParentPath);
}
}
return pluginCount;
}
代码示例来源:origin: Dromara/soul
String ruleParentPath = ZkPathConstants.buildRuleParentPath(pluginDO.getName());
if (!zkClient.exists(ruleParentPath)) {
zkClient.createPersistent(ruleParentPath, true);
String ruleRealPath = ZkPathConstants.buildRulePath(pluginDO.getName(), selectorDO.getId(), ruleDO.getId());
if (!zkClient.exists(ruleRealPath)) {
zkClient.createPersistent(ruleRealPath, true);
代码示例来源:origin: Dromara/soul
/**
* buildRulePath.
*
* @param pluginName pluginName
* @param selectorId selectorId
* @param ruleId ruleId
* @return /soul/rule/pluginName/selectorId-ruleId
*/
public static String buildRulePath(final String pluginName, final String selectorId, final String ruleId) {
return String.join("/", buildRuleParentPath(pluginName), selectorId + SELECTOR_JOIN_RULE + ruleId);
}
代码示例来源:origin: Dromara/soul
String selectorParentPath = ZkPathConstants.buildSelectorParentPath(pluginDO.getName());
if (!zkClient.exists(selectorParentPath)) {
zkClient.createPersistent(selectorParentPath, true);
String selectorRealPath = ZkPathConstants.buildSelectorRealPath(pluginDO.getName(), selectorDO.getId());
if (!zkClient.exists(selectorRealPath)) {
zkClient.createPersistent(selectorRealPath, true);
代码示例来源:origin: Dromara/soul
private void loadWatcherPlugin() {
Arrays.stream(PluginEnum.values()).forEach(pluginEnum -> {
String pluginPath = ZkPathConstants.buildPluginPath(pluginEnum.getName());
if (!zkClient.exists(pluginPath)) {
zkClient.createPersistent(pluginPath, true);
}
PluginZkDTO data = zkClient.readData(pluginPath);
Optional.ofNullable(data).ifPresent(d -> PLUGIN_MAP.put(pluginEnum.getName(), data));
zkClient.subscribeDataChanges(pluginPath, new IZkDataListener() {
@Override
public void handleDataChange(final String dataPath, final Object data) {
Optional.ofNullable(data)
.ifPresent(o -> {
PluginZkDTO dto = (PluginZkDTO) o;
PLUGIN_MAP.put(dto.getName(), dto);
});
}
@Override
public void handleDataDeleted(final String dataPath) {
PLUGIN_MAP.remove(pluginEnum.getName());
}
});
});
}
代码示例来源:origin: Dromara/soul
private void loadWatcherSelector() {
Arrays.stream(PluginEnum.values()).forEach(pluginEnum -> {
//获取选择器的节点
String selectorParentPath =
ZkPathConstants.buildSelectorParentPath(pluginEnum.getName());
if (!zkClient.exists(selectorParentPath)) {
zkClient.createPersistent(selectorParentPath, true);
}
final List<String> childrenList = zkClient.getChildren(selectorParentPath);
if (CollectionUtils.isNotEmpty(childrenList)) {
childrenList.forEach(children -> {
String realPath = buildRealPath(selectorParentPath, children);
final SelectorZkDTO selectorZkDTO = zkClient.readData(realPath);
Optional.ofNullable(selectorZkDTO)
.ifPresent(dto -> {
final String key = dto.getPluginName();
setSelectorMapByKey(key, dto);
});
subscribeSelectorDataChanges(realPath);
});
}
zkClient.subscribeChildChanges(selectorParentPath, (parentPath, currentChilds) -> {
if (CollectionUtils.isNotEmpty(currentChilds)) {
final List<String> unsubscribePath = unsubscribePath(childrenList, currentChilds);
unsubscribePath.stream().map(p -> buildRealPath(parentPath, p))
.forEach(this::subscribeSelectorDataChanges);
}
});
});
}
代码示例来源:origin: Dromara/soul
String selectorRealPath = ZkPathConstants.buildSelectorRealPath(pluginDO.getName(), selectorDO.getId());
if (zkClient.exists(selectorRealPath)) {
zkClient.delete(selectorRealPath);
ruleConditionMapper.deleteByQuery(new RuleConditionQuery(ruleDO.getId()));
final String rulePath = ZkPathConstants.buildRulePath(pluginDO.getName(), id, ruleDO.getId());
if (zkClient.exists(rulePath)) {
zkClient.delete(rulePath);
代码示例来源:origin: Dromara/soul
/**
* delete application authorities.
*
* @param ids primary key.
* @return rows
*/
@Override
public int delete(final List<String> ids) {
int appAuthCount = 0;
for (String id : ids) {
AppAuthDO appAuthDO = appAuthMapper.selectById(id);
appAuthCount += appAuthMapper.delete(id);
String pluginPath = ZkPathConstants.buildAppAuthPath(appAuthDO.getAppKey());
if (zkClient.exists(pluginPath)) {
zkClient.delete(pluginPath);
}
}
return appAuthCount;
}
代码示例来源:origin: Dromara/soul
/**
* delete rules.
*
* @param ids primary key.
* @return rows
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int delete(final List<String> ids) {
for (String id : ids) {
RuleDO ruleDO = ruleMapper.selectById(id);
SelectorDO selectorDO = selectorMapper.selectById(ruleDO.getSelectorId());
PluginDO pluginDO = pluginMapper.selectById(selectorDO.getPluginId());
ruleMapper.delete(id);
ruleConditionMapper.deleteByQuery(new RuleConditionQuery(id));
String ruleRealPath = ZkPathConstants.buildRulePath(pluginDO.getName(), selectorDO.getId(), ruleDO.getId());
if (zkClient.exists(ruleRealPath)) {
zkClient.delete(ruleRealPath);
}
}
return ids.size();
}
代码示例来源:origin: Dromara/soul
private void loadWatcherRule() {
Arrays.stream(PluginEnum.values()).forEach(pluginEnum -> {
final String ruleParent = ZkPathConstants.buildRuleParentPath(pluginEnum.getName());
if (!zkClient.exists(ruleParent)) {
zkClient.createPersistent(ruleParent, true);
}
final List<String> childrenList = zkClient.getChildren(ruleParent);
if (CollectionUtils.isNotEmpty(childrenList)) {
childrenList.forEach(children -> {
String realPath = buildRealPath(ruleParent, children);
final RuleZkDTO ruleZkDTO = zkClient.readData(realPath);
Optional.ofNullable(ruleZkDTO)
.ifPresent(dto -> {
String key = dto.getSelectorId();
setRuleMapByKey(key, ruleZkDTO);
});
subscribeRuleDataChanges(realPath);
});
}
zkClient.subscribeChildChanges(ruleParent, (parentPath, currentChilds) -> {
if (CollectionUtils.isNotEmpty(currentChilds)) {
final List<String> unsubscribePath = unsubscribePath(childrenList, currentChilds);
//获取新增的节点数据,并对该节点进行订阅
unsubscribePath.stream().map(p -> buildRealPath(parentPath, p))
.forEach(this::subscribeRuleDataChanges);
}
});
});
}
代码示例来源:origin: Dromara/soul
/**
* create or update plugin.
*
* @param pluginDTO {@linkplain PluginDTO}
* @return rows
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int createOrUpdate(final PluginDTO pluginDTO) {
int pluginCount;
PluginDO pluginDO = PluginDO.buildPluginDO(pluginDTO);
if (StringUtils.isEmpty(pluginDTO.getId())) {
pluginCount = pluginMapper.insertSelective(pluginDO);
} else {
pluginCount = pluginMapper.updateSelective(pluginDO);
}
String pluginPath = ZkPathConstants.buildPluginPath(pluginDO.getName());
if (!zkClient.exists(pluginPath)) {
zkClient.createPersistent(pluginPath, true);
}
zkClient.writeData(pluginPath, new PluginZkDTO(pluginDO.getId(),
pluginDO.getName(), pluginDO.getEnabled()));
return pluginCount;
}
代码示例来源:origin: Dromara/soul
/**
* create or update application authority.
*
* @param appAuthDTO {@linkplain AppAuthDTO}
* @return rows
*/
@Override
public int createOrUpdate(final AppAuthDTO appAuthDTO) {
int appAuthCount;
AppAuthDO appAuthDO = AppAuthDO.buildAppAuthDO(appAuthDTO);
if (StringUtils.isEmpty(appAuthDTO.getId())) {
appAuthCount = appAuthMapper.insertSelective(appAuthDO);
} else {
appAuthCount = appAuthMapper.updateSelective(appAuthDO);
}
String appAuthPath = ZkPathConstants.buildAppAuthPath(appAuthDO.getAppKey());
if (!zkClient.exists(appAuthPath)) {
zkClient.createPersistent(appAuthPath, true);
}
zkClient.writeData(appAuthPath, new AppAuthZkDTO(appAuthDO.getAppKey(), appAuthDO.getAppSecret(), appAuthDO.getEnabled()));
return appAuthCount;
}
内容来源于网络,如有侵权,请联系作者删除!