博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Netflix开源类库archaius(一)概述
阅读量:6036 次
发布时间:2019-06-20

本文共 3142 字,大约阅读时间需要 10 分钟。

hot3.png

Netflix开源类库archaius(一)概述 博客分类: java spring

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);// ...

更简洁的方式

DynamicIntProperty prop =     DynamicPropertyFactory.getInstance().getIntProperty("myProperty", DEFAULT_VALUE);// prop.get() may change value at runtimemyMethod(prop.get());

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

prop.addCallback(new Runnable() {    public void run() {        // ...    }});

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

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

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

目前框架核心默认实现了两种来源,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,支持高并发和组合配置

参考文献

 

http://blog.csdn.net/zhangfb95/article/details/48297907

转载于:https://my.oschina.net/xiaominmin/blog/1598742

你可能感兴趣的文章
Golang 如何从socket读出所有数据
查看>>
iOS开发使用半透明模糊效果方法整理
查看>>
一道图论小题目
查看>>
Hibernate拦截器(Interceptor)与事件监听器(Listener)
查看>>
关于android im
查看>>
CSS3 transforms 3D翻开
查看>>
利用传入的Type类型来调用范型方法的解决方案
查看>>
Top命令内存占用剖析
查看>>
转 网络IO模型:同步IO和异步IO,阻塞IO和非阻塞IO
查看>>
求带分数(蓝桥杯)
查看>>
Bootstrap系列 -- 11. 基础表单
查看>>
格拉西安《智慧书》中最有价值的23条法则
查看>>
7款经典炫酷的HTML5/jQuery动画应用示例及源码
查看>>
那些年我们一起追过的缓存写法(四)
查看>>
mssql手工注入
查看>>
zoj 3203 Light Bulb,三分之二的基本问题
查看>>
Oracle如何删除表中重复记录
查看>>
洛谷八月月赛Round1凄惨记
查看>>
Retrofit 入门学习
查看>>
【树莓派】树莓派网络配置:静态IP、无线网络、服务等
查看>>