Search in sources :

Example 1 with ConfigChangedEvent

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);
            }
        }
    });
}
Also used : FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) ConfigChangedEvent(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent)

Example 2 with ConfigChangedEvent

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));
            }
        }
    }
}
Also used : URL(org.apache.dubbo.common.URL) ConfigChangedEvent(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent)

Example 3 with ConfigChangedEvent

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));
    }
}
Also used : ConfigChangedEvent(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent)

Example 4 with ConfigChangedEvent

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));
    }
}
Also used : ConfigurationListener(org.apache.dubbo.common.config.configcenter.ConfigurationListener) ConfigChangeType(org.apache.dubbo.common.config.configcenter.ConfigChangeType) ConfigChangedEvent(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent)

Aggregations

ConfigChangedEvent (org.apache.dubbo.common.config.configcenter.ConfigChangedEvent)4 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)1 URL (org.apache.dubbo.common.URL)1 ConfigChangeType (org.apache.dubbo.common.config.configcenter.ConfigChangeType)1 ConfigurationListener (org.apache.dubbo.common.config.configcenter.ConfigurationListener)1