use of org.apache.dubbo.common.config.configcenter.ConfigChangedEvent in project dubbo by alibaba.
the class FileSystemDynamicConfiguration method fireConfigChangeEvent.
private void fireConfigChangeEvent(File configDirectory, File configFile, ConfigChangeType configChangeType) {
String key = configFile.getName();
String value = getConfig(configFile);
// fire ConfigChangeEvent one by one
getListeners(configFile).forEach(listener -> {
try {
listener.process(new ConfigChangedEvent(key, configDirectory.getName(), value, configChangeType));
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
}
}
});
}
use of org.apache.dubbo.common.config.configcenter.ConfigChangedEvent in project dubbo by alibaba.
the class TagRouter method notify.
@Override
public <T> void notify(List<Invoker<T>> invokers) {
if (CollectionUtils.isEmpty(invokers)) {
return;
}
Invoker<T> invoker = invokers.get(0);
URL url = invoker.getUrl();
String providerApplication = url.getParameter(CommonConstants.REMOTE_APPLICATION_KEY);
if (StringUtils.isEmpty(providerApplication)) {
logger.error("TagRouter must getConfig from or subscribe to a specific application, but the application " + "in this TagRouter is not specified.");
return;
}
synchronized (this) {
if (!providerApplication.equals(application)) {
if (!StringUtils.isEmpty(application)) {
ruleRepository.removeListener(application + RULE_SUFFIX, this);
}
String key = providerApplication + RULE_SUFFIX;
ruleRepository.addListener(key, this);
application = providerApplication;
String rawRule = ruleRepository.getRule(key, DynamicConfiguration.DEFAULT_GROUP);
if (StringUtils.isNotEmpty(rawRule)) {
this.process(new ConfigChangedEvent(key, DynamicConfiguration.DEFAULT_GROUP, rawRule));
}
}
}
}
use of org.apache.dubbo.common.config.configcenter.ConfigChangedEvent in project dubbo by alibaba.
the class ListenableRouter method init.
private synchronized void init(String ruleKey) {
if (StringUtils.isEmpty(ruleKey)) {
return;
}
String routerKey = ruleKey + RULE_SUFFIX;
ruleRepository.addListener(routerKey, this);
String rule = ruleRepository.getRule(routerKey, DynamicConfiguration.DEFAULT_GROUP);
if (StringUtils.isNotEmpty(rule)) {
this.process(new ConfigChangedEvent(routerKey, DynamicConfiguration.DEFAULT_GROUP, rule));
}
}
use of org.apache.dubbo.common.config.configcenter.ConfigChangedEvent in project dubbo by alibaba.
the class CacheListener method dataChanged.
@Override
public void dataChanged(String path, Object value, EventType eventType) {
ConfigChangeType changeType;
if (EventType.NodeCreated.equals(eventType)) {
changeType = ConfigChangeType.ADDED;
} else if (value == null) {
changeType = ConfigChangeType.DELETED;
} else {
changeType = ConfigChangeType.MODIFIED;
}
String key = pathToKey(path);
ConfigChangedEvent configChangeEvent = new ConfigChangedEvent(key, getGroup(path), (String) value, changeType);
Set<ConfigurationListener> listeners = keyListeners.get(path);
if (CollectionUtils.isNotEmpty(listeners)) {
listeners.forEach(listener -> listener.process(configChangeEvent));
}
}
Aggregations