zoukankan      html  css  js  c++  java
  • archaius(3) 配置管理器

      基于上一节介绍的配置源,我们来继续了解配置管理器。配置源只是抽象了配置的获取来源,配置管理器是基于配置源的基础上对这些配置项进行管理。配置管理器的主要功能是将配置从目标位置加载到内存中,并且管理内存配置项,实现读取配置项,动态更新内存配置项,监听器功能

      archaius的配置管理器继承了Apache Commons Configuration的配置管理器,Apache Commons Configuration的AbstractConfiguration主要提供获取配置项和监听配置事件的功能,但是他不是线程安全的,archaius的ConcurrentMapConfiguration继承了AbstractConfiguration并且实现了线程安全(内部其实使用了一个ConcurrentHashMap存储配置项)。

      achaius提供了三个配置管理器:

    类路径配置管理器(ClasspathPropertiesConfiguration)

      用于加载jar下的配置文件,ClasspathPropertiesConfiguration不直接管理配置项,而是通过ConfigurationManager加载类路径下的META-INF/conf/config.properties。

    public class ClasspathPropertiesConfiguration extends ConcurrentMapConfiguration
    {static String propertiesResourceRelativePath = "META-INF/conf/config.properties";
        static ClasspathPropertiesConfiguration instance = null;
    public static void initialize() { try { instance = new ClasspathPropertiesConfiguration(); loadResources(propertiesResourceRelativePath); } catch (Exception e) { throw new RuntimeException( "failed to read configuration properties from classpath", e); } } private static void loadResources(String resourceName) throws Exception { ConfigurationManager.loadPropertiesFromResources(resourceName); } }

     

    动态配置管理器(DynamicConfiguration)

      DynamicConfiguration实现动态更新配置,内部使用PolledConfigurationSource作为配置源,使用AbstractPollingScheduler来定时从配置源获取配置然后再更新到DynamicConfiguration中。

     

      子类DynamicURLConfiguration继承DynamicConfiguration,内部使用URLConfigurationSource和FixedDelayPollingScheduler作为配置源和定时执行器。

    监听配置源动态配置管理器

      DynamicWatchedConfiguration实现WatchedUpdateListener,通过监听WatchedConfigurationSource,实现动态配置项管理。

    复合配置管理器

      

    类图结构

     

     

     

      

      

  • 相关阅读:
    项目1:即时标记
    每天一个小程序—0000题(python图像处理)
    每天一个小程序—0004题(统计单词出现次数)
    每天一个小程序—第0001题(uuid模块)
    python实现八皇后问题
    2018/01/05——时间会改变一切!
    HDU 6249 Alice’s Stamps(dp)
    51nod 1422 沙拉酱前缀
    【转】DSP动态内存分配函数的使用
    优秀人的博客
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8335970.html
Copyright © 2011-2022 走看看