use of org.noear.solon.cloud.service.CloudConfigObserverEntity in project solon by noear.
the class CloudConfigServiceWaterImp method attention.
@Override
public void attention(String group, String key, CloudConfigHandler observer) {
if (observerMap.containsKey(observer)) {
return;
}
if (Utils.isEmpty(group)) {
group = Solon.cfg().appGroup();
if (Utils.isEmpty(group)) {
group = DEFAULT_GROUP;
}
}
CloudConfigObserverEntity entity = new CloudConfigObserverEntity(group, key, observer);
observerMap.put(observer, entity);
}
use of org.noear.solon.cloud.service.CloudConfigObserverEntity in project solon by noear.
the class CloudConfigServiceZkImp method attention.
@Override
public void attention(String group, String key, CloudConfigHandler observer) {
if (observerMap.containsKey(observer)) {
return;
}
if (Utils.isEmpty(group)) {
group = Solon.cfg().appGroup();
}
CloudConfigObserverEntity entity = new CloudConfigObserverEntity(group, key, observer);
observerMap.put(observer, entity);
client.watchNodeData(String.format("%s/%s/%s", PATH_ROOT, group, key), event -> {
entity.handle(pull(entity.group, entity.key));
});
}
use of org.noear.solon.cloud.service.CloudConfigObserverEntity in project solon by noear.
the class CloudConfigServiceConsulImpl method run0.
private void run0() {
Map<String, Config> cfgTmp = new HashMap<>();
for (Map.Entry<CloudConfigHandler, CloudConfigObserverEntity> kv : observerMap.entrySet()) {
CloudConfigObserverEntity entity = kv.getValue();
String cfgKey = entity.group + "/" + entity.key;
GetValue newV = real.getKVValue(cfgKey, token).getValue();
if (newV != null) {
Config oldV = configMap.get(cfgKey);
if (oldV == null) {
oldV = new Config(entity.group, entity.key, newV.getDecodedValue(), newV.getModifyIndex());
configMap.put(cfgKey, oldV);
cfgTmp.put(cfgKey, oldV);
} else if (newV.getModifyIndex() > oldV.version()) {
oldV.updateValue(newV.getDecodedValue(), newV.getModifyIndex());
cfgTmp.put(cfgKey, oldV);
}
}
}
for (Config cfg2 : cfgTmp.values()) {
observerMap.forEach((k, v) -> {
if (cfg2.group().equals(v.group) && cfg2.key().equals(v.key)) {
v.handle(cfg2);
}
});
}
}
use of org.noear.solon.cloud.service.CloudConfigObserverEntity in project solon by noear.
the class CloudConfigServiceNacosImp method attention.
/**
* 关注配置
*/
@Override
public void attention(String group, String key, CloudConfigHandler observer) {
if (observerMap.containsKey(observer)) {
return;
}
if (Utils.isEmpty(group)) {
group = Solon.cfg().appGroup();
}
CloudConfigObserverEntity entity = new CloudConfigObserverEntity(group, key, observer);
observerMap.put(observer, entity);
try {
group = groupReview(group);
real.addListener(key, group, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String value) {
entity.handle(new Config(entity.group, entity.key, value, 0));
}
});
} catch (NacosException ex) {
throw new RuntimeException(ex);
}
}
Aggregations