本文整理了Java中com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource
类的一些代码示例,展示了ZookeeperDataSource
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperDataSource
类的具体详情如下:
包路径:com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource
类名称:ZookeeperDataSource
[英]A read-only DataSource with ZooKeeper backend.
[中]带有ZooKeeper后端的只读数据源。
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
@Override
public ZookeeperDataSource getObject() throws Exception {
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
// the path will be /{groupId}/{dataId}
return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
} else {
// using path directly
return new ZookeeperDataSource(serverAddr, path, converter);
}
}
代码示例来源:origin: alibaba/Sentinel
/**
* This constructor is Nacos-style.
*/
public ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId,
Converter<String, T> parser) {
super(parser);
if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(groupId) || StringUtil.isBlank(dataId)) {
throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], groupId=[%s], dataId=[%s]", serverAddr, groupId, dataId));
}
this.path = getPath(groupId, dataId);
init(serverAddr);
}
代码示例来源:origin: alibaba/Sentinel
private void loadInitialConfig() {
try {
T newValue = loadConfig();
if (newValue == null) {
RecordLog.warn("[ZookeeperDataSource] WARN: initial config is null, you may have to check your data source");
}
getProperty().updateValue(newValue);
} catch (Exception ex) {
RecordLog.warn("[ZookeeperDataSource] Error when loading initial config", ex);
}
}
代码示例来源:origin: alibaba/Sentinel
private void init(final String serverAddr) {
initZookeeperListener(serverAddr);
loadInitialConfig();
}
代码示例来源:origin: alibaba/Sentinel
public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) {
super(parser);
if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) {
throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path));
}
this.path = path;
init(serverAddr);
}
代码示例来源:origin: alibaba/Sentinel
@Override
public void nodeChanged() {
String configInfo = null;
ChildData childData = nodeCache.getCurrentData();
if (null != childData && childData.getData() != null) {
configInfo = new String(childData.getData());
}
RecordLog.info(String.format("[ZookeeperDataSource] New property value received for (%s, %s): %s",
serverAddr, path, configInfo));
T newValue = ZookeeperDataSource.this.parser.convert(configInfo);
// Update the new value to the property.
getProperty().updateValue(newValue);
}
};
代码示例来源:origin: com.alibaba.csp/sentinel-datasource-zookeeper
private void init(final String serverAddr) {
initZookeeperListener(serverAddr);
loadInitialConfig();
}
代码示例来源:origin: com.alibaba.csp/sentinel-datasource-zookeeper
public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) {
super(parser);
if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) {
throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path));
}
this.path = path;
init(serverAddr);
}
代码示例来源:origin: com.alibaba.csp/sentinel-datasource-zookeeper
@Override
public void nodeChanged() {
String configInfo = null;
ChildData childData = nodeCache.getCurrentData();
if (null != childData && childData.getData() != null) {
configInfo = new String(childData.getData());
}
RecordLog.info(String.format("[ZookeeperDataSource] New property value received for (%s, %s): %s",
serverAddr, path, configInfo));
T newValue = ZookeeperDataSource.this.parser.convert(configInfo);
// Update the new value to the property.
getProperty().updateValue(newValue);
}
};
代码示例来源:origin: alibaba/Sentinel
private static void loadRules() {
final String remoteAddress = "127.0.0.1:2181";
final String path = "/Sentinel-Demo/SYSTEM-CODE-DEMO-FLOW";
ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<>(remoteAddress, path,
source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
}
代码示例来源:origin: com.alibaba.csp/sentinel-datasource-zookeeper
private void loadInitialConfig() {
try {
T newValue = loadConfig();
if (newValue == null) {
RecordLog.warn("[ZookeeperDataSource] WARN: initial config is null, you may have to check your data source");
}
getProperty().updateValue(newValue);
} catch (Exception ex) {
RecordLog.warn("[ZookeeperDataSource] Error when loading initial config", ex);
}
}
代码示例来源:origin: com.alibaba.csp/sentinel-datasource-zookeeper
/**
* This constructor is Nacos-style.
*/
public ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId,
Converter<String, T> parser) {
super(parser);
if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(groupId) || StringUtil.isBlank(dataId)) {
throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], groupId=[%s], dataId=[%s]", serverAddr, groupId, dataId));
}
this.path = getPath(groupId, dataId);
init(serverAddr);
}
代码示例来源:origin: alibaba/Sentinel
private static void loadRules2() {
final String remoteAddress = "127.0.0.1:2181";
// 引入groupId和dataId的概念,是为了方便和Nacos进行切换
final String groupId = "Sentinel-Demo";
final String flowDataId = "SYSTEM-CODE-DEMO-FLOW";
// final String degradeDataId = "SYSTEM-CODE-DEMO-DEGRADE";
// final String systemDataId = "SYSTEM-CODE-DEMO-SYSTEM";
// 规则会持久化到zk的/groupId/flowDataId节点
// groupId和和flowDataId可以用/开头也可以不用
// 建议不用以/开头,目的是为了如果从Zookeeper切换到Nacos的话,只需要改数据源类名就可以
ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<>(remoteAddress, groupId, flowDataId,
source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
// ReadableDataSource<String, List<DegradeRule>> degradeRuleDataSource = new ZookeeperDataSource<>(remoteAddress, groupId, degradeDataId,
// source -> JSON.parseObject(source, new TypeReference<List<DegradeRule>>() {}));
// DegradeRuleManager.register2Property(degradeRuleDataSource.getProperty());
//
// ReadableDataSource<String, List<SystemRule>> systemRuleDataSource = new ZookeeperDataSource<>(remoteAddress, groupId, systemDataId,
// source -> JSON.parseObject(source, new TypeReference<List<SystemRule>>() {}));
// SystemRuleManager.register2Property(systemRuleDataSource.getProperty());
}
}
内容来源于网络,如有侵权,请联系作者删除!