archaius是什么,能做什么?

archaius是Netflix公司开源项目之一,基于java的配置管理类库,主要用于多配置存储的动态获取。主要功能是对apache common configuration类库的扩展。在云平台开发中可以将其用作分布式配置管理依赖构件。同时,它有如下一些特性:

  • 动态类型化属性
  • 高效和线程安全的配置操作
  • 配置改变时的回调机制
  • jmx
  • 组合配置(核心内容)

At the heart of Archaius is the concept of a Composite Configuration which can hold one or more Configurations. Each Configuration can be sourced from a Configuration Source such as: JDBC, REST, .properties file etc. Configuration Sources can optionally be polled at runtime for changes (In the above diagram, the Persisted DB Configuration Source; an RDBMS containing properties in a table, is polled every so often for changes).

The final value of a property is determined based on the top most Configuration that contains that property. i.e. If a property is present in multiple configurations, the actual value seen by the application will be the value that is present in the topmost slot in the hierarchy of Configurations. The hierarchy can be configured.

动态属性(Dynamic properties)

String prop = System.getProperty("myProperty");
int x = DEFAULT_VALUE;
try {
x = Integer.parseInt(prop);
} catch (NumberFormatException e) {
// handle format issues
}
myMethod(x);
// ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

更简洁的方式

DynamicIntProperty prop =
DynamicPropertyFactory.getInstance().getIntProperty("myProperty", DEFAULT_VALUE);
// prop.get() may change value at runtime
myMethod(prop.get());
  • 1
  • 2
  • 3
  • 4

同时,我们可以加入事件回调

prop.addCallback(new Runnable() {
public void run() {
// ...
}
});
  • 1
  • 2
  • 3
  • 4
  • 5

动态属性如何实现动态,轮询框架

使用属性来源和定时器进行轮询

PolledConfigurationSource source = createMyOwnSource();
AbstractPollingScheduler scheduler = createMyOwnScheduler();
ConfigurationManager.install(new DynamicConfiguration(source, scheduler));
  • 1
  • 2
  • 3

目前框架核心默认实现了两种来源,JDBCConfigurationSource、URLConfigurationSource

发布上下文(Deployment context)

比如应用程序需要读取一个数据库配置文件database-*.properties,但是*可能是prod和test,我们要从中选一个,这时需要咨询发布上下文,我们可以调用发布上下文的一个方法DeploymentContext.getDeploymentEnvironment(),然后我们就可以取得实际的数据库配置文件database-${environment}.properties

Deployment context properties can be used in many ways. Archaius uses deployment context to load cascaded configuration files. Here is the use case:

Application defines a set of default properties
At runtime, those properties should be overridden by deployment context specific values.
For example, an application has a configuration file
database.properties, which contains default set of database properties.
It has two other properties file

database-prod.properties, which contains overridden values for “prod” environment
database-test.properties, which contains overridden values for “test” environment
To load any one of the above file, the ConfigurationManager will
consult with DeploymentContext object set with it to determine what
environment it is in (through
DeploymentContext.getDeploymentEnvironment() method), and load
additional database-${environment} file to override the default values.

高效和线程安全的配置

框架提供了高效和线程安全的config(apache common configuration),比如:ConcurrentMapConfiguration、ConcurrentCompositeConfiguration,支持高并发和组合配置

参考文献

https://github.com/Netflix/archaius

https://github.com/Netflix/archaius/wiki

http://www.tuicool.com/articles/uQRn6f

http://commons.apache.org/proper/commons-configuration/

http://commons.apache.org/proper/commons-configuration/userguide_v1.10/user_guide.html

Netflix开源类库archaius(一)概述的更多相关文章

  1. Atitit java onvif 开源类库 getProfiles getStreamUri

    Atitit java onvif 开源类库 getProfiles getStreamUri 1. ONVIF Java Library by Milgo1 1.1. https://github. ...

  2. 一些iOS高效开源类库

    因为iOS SDK相对比较底层,所以开发者就得受累多做一些体力活.不过幸运的是,有很多第三方的类库可以用来简化很多不必要的工作.笔者整理了一下在本人学习过程中用到的一些比较有用Objective-C开 ...

  3. dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...

  4. [转]C#常用开源类库收集

    .net PDF 类库 PDFsharp PDFsharp是一款可以让.NET框架支持的任何语言很容易的创建PDF文件的类库. ASP.NET FO PDF FO PDF 是一款C#编写类似于ASP. ...

  5. C#常用开源类库

    一.AOP框架        Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...

  6. Json序列化之.NET开源类库Newtonsoft.Json的研究

     一.Json简介 JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的文 ...

  7. 【转】java开源类库pinyin4j的使用

    最近CMS系统为了增加查询的匹配率,需要增加拼音检索字段,在网上找到了pinyin4j的java开源类库,提供中文转汉语拼音(并且支持多音字), 呵呵,看了看他的demo,决定就用它了,因为我在实际使 ...

  8. 使用CocoaPods管理第三方开源类库

    iOS开发中经常会用到许多第三方开源类库,比如AFNetworking.FMDB.JSONKit等等,使用CocoaPods这个工具就能很方便得对工程中用到的类库进行管理,包括自动下载配置以及更新. ...

  9. Java 的 JSON 开源类库选择比较(zz)

    在看了作者的介绍,然后我又到mvnrepository上去看了各个库的的使用数之后,发现只能在jackson和gson之间做选择. 以下是原文 有效选择七个关于Java的JSON开源类库 April  ...

随机推荐

  1. 【Java】 剑指offer(55-2) 平衡二叉树

      本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 输入一棵二叉树的根结点,判断该树是不是平衡二叉树.如果某二叉树 ...

  2. Python 导入requests报错No module named requests

    刚开始是在Pycharm里面,发现就是不对,导入老提示No module named requests这个错误.后面发现是指向的python.exe路径不对,到setting里面设置换一下路径就好.

  3. c# 深入探索之CLR

    概念: CLR : 公共语言运行时(Common Language Runtime) 是一个可由多种编程语言使用的"运行时",它负责资源管理(内存分配和垃圾收集等),并保证应用和底 ...

  4. 算法进阶面试题06——实现LFU缓存算法、计算带括号的公式、介绍和实现跳表结构

    接着第四课的内容,主要讲LFU.表达式计算和跳表 第一题 上一题实现了LRU缓存算法,LFU也是一个著名的缓存算法 自行了解之后实现LFU中的set 和 get 要求:两个方法的时间复杂度都为O(1) ...

  5. html/css实现阴影蒙版覆盖原网页并显示浮框的功能

    在提供用户修改资料/密码等功能的时候,往往希望给用户这样的使用体验,在不跳转,不弹框的情况下完成对这些功能的操作. 这可以通过一种效果来实现,在同一页面下阴影覆盖整个当前网页并使得原网页中元素无法使用 ...

  6. AGC015 C-Nuske vs Phantom Thnook AtCoder 思路 前缀和

    目录 题目链接 题解 代码 题目链接 AGC015 C-Nuske vs Phantom Thnook AtCoder 题解 树的性质有: 如果每个蓝色连通块都是树,那么连通块个数=总点数−总边数. ...

  7. 潭州课堂25班:Ph201805201 第十四课 异常,处理 (课堂笔记)

    程序难免会出现错误 : 语法错误 : 逻辑错误: AttributeError  -->>  试图访问一个对象没有的属性, IOError  ---->>  输入输出异常 In ...

  8. Windows 文件名的书写规范

    下面是不能用于文件名的: / \ : * " < > | windows系统下文件名长度为: 255个英文字符(DOS下8.3格式),包括文件名和扩展名在内,或者是255/2=1 ...

  9. jquery中ajax的写法

    方法一: $.ajax(url,data,fn); $('#btn').click(function(){ $.ajax({ url:"112.json", type:" ...

  10. C#获取类名为Internet_Explorer_Server控件的内容

    为了让大家都能够使用demo,我以IE为测试对象,另外为了突出重点,所以如何获取窗口句柄我就不做演示了(不清楚的童鞋,可以去Google下哈),句柄值我使用spy++获得 大家可以下载demo(附:s ...