/** * get plugin enum by code. * * @param code plugin code. * @return plugin enum. */ public static PluginEnum getPluginEnumByCode(final int code) { return Arrays.stream(PluginEnum.values()) .filter(pluginEnum -> pluginEnum.getCode() == code) .findFirst().orElse(PluginEnum.GLOBAL); }
/** * get plugin enum by name. * * @param name plugin name. * @return plugin enum. */ public static PluginEnum getPluginEnumByName(final String name) { return Arrays.stream(PluginEnum.values()) .filter(pluginEnum -> pluginEnum.getName().equals(name)) .findFirst().orElse(PluginEnum.GLOBAL); } }
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()); } }); }); }
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); } }); }); }
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); } }); }); }
.map(paramTypeEnum -> new EnumVO(null, paramTypeEnum.getName(), paramTypeEnum.getSupport())).collect(Collectors.toList()); List<EnumVO> pluginEnums = Arrays.stream(PluginEnum.values()) .map(pluginEnum -> new EnumVO(pluginEnum.getCode(), pluginEnum.getName(), true)) .collect(Collectors.toList());