本篇文章为大家展示了dubbo中ConfigChangeEvent的作用是什么,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
为榆中等地区用户提供了全套网页设计制作服务,及榆中网站建设行业解决方案。主营业务为做网站、成都网站制作、榆中网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
dubbo-2.7.3/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java
public class ConfigChangeEvent { private final String key; private final String value; private final ConfigChangeType changeType; public ConfigChangeEvent(String key, String value) { this(key, value, ConfigChangeType.MODIFIED); } public ConfigChangeEvent(String key, String value, ConfigChangeType changeType) { this.key = key; this.value = value; this.changeType = changeType; } public String getKey() { return key; } public String getValue() { return value; } public ConfigChangeType getChangeType() { return changeType; } @Override public String toString() { return "ConfigChangeEvent{" + "key='" + key + '\'' + ", value='" + value + '\'' + ", changeType=" + changeType + '}'; } }
ConfigChangeEvent定义了key、value、changeType三个属性
dubbo-2.7.3/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeType.java
public enum ConfigChangeType { /** * A config is created. */ ADDED, /** * A config is updated. */ MODIFIED, /** * A config is deleted. */ DELETED }
ConfigChangeType定义了ADDED、MODIFIED、DELETED三种类型
dubbo-2.7.3/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigurationListener.java
public interface ConfigurationListener { /** * Listener call back method. Listener gets notified by this method once there's any change happens on the config * the listener listens on. * * @param event config change event */ void process(ConfigChangeEvent event); }
ConfigurationListener定义了process方法来处理ConfigChangeEvent
dubbo-2.7.3/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
public abstract class AbstractConfiguratorListener implements ConfigurationListener { private static final Logger logger = LoggerFactory.getLogger(AbstractConfiguratorListener.class); protected List<Configurator> configurators = Collections.emptyList(); protected final void initWith(String key) { DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); dynamicConfiguration.addListener(key, this); String rawConfig = dynamicConfiguration.getRule(key, DynamicConfiguration.DEFAULT_GROUP); if (!StringUtils.isEmpty(rawConfig)) { genConfiguratorsFromRawRule(rawConfig); } } @Override public void process(ConfigChangeEvent event) { if (logger.isInfoEnabled()) { logger.info("Notification of overriding rule, change type is: " + event.getChangeType() + ", raw config content is:\n " + event.getValue()); } if (event.getChangeType().equals(ConfigChangeType.DELETED)) { configurators.clear(); } else { if (!genConfiguratorsFromRawRule(event.getValue())) { return; } } notifyOverrides(); } private boolean genConfiguratorsFromRawRule(String rawConfig) { boolean parseSuccess = true; try { // parseConfigurators will recognize app/service config automatically. configurators = Configurator.toConfigurators(ConfigParser.parseConfigurators(rawConfig)) .orElse(configurators); } catch (Exception e) { logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + rawConfig, e); parseSuccess = false; } return parseSuccess; } protected abstract void notifyOverrides(); public List<Configurator> getConfigurators() { return configurators; } public void setConfigurators(List<Configurator> configurators) { this.configurators = configurators; } }
AbstractConfiguratorListener声明实现了ConfigurationListener接口,其process在event的changeType是ConfigChangeType.DELETED时会清空configurators;最后执行的notifyOverrides方法留给子类实现
ConfigChangeEvent定义了key、value、changeType三个属性;ConfigChangeType定义了ADDED、MODIFIED、DELETED三种类型;ConfigurationListener定义了process方法来处理ConfigChangeEvent
上述内容就是dubbo中ConfigChangeEvent的作用是什么,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
文章标题:dubbo中ConfigChangeEvent的作用是什么
新闻来源:https://www.cdcxhl.com/article28/jdcjcp.html
成都网站建设公司_创新互联,为您提供外贸建站、、网站设计公司、自适应网站、Google、网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联