Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
38dce08d
R
ribbon
项目概览
thythm
/
ribbon
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
ribbon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
38dce08d
编写于
5月 16, 2019
作者:
E
elandau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config: Dynamic properties that are only scoped to the client (no default)
上级
7c60ae77
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
6 deletion
+37
-6
ribbon-core/src/main/java/com/netflix/client/config/IClientConfig.java
...rc/main/java/com/netflix/client/config/IClientConfig.java
+7
-0
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
...ava/com/netflix/client/config/ReloadableClientConfig.java
+18
-6
ribbon-core/src/test/java/com/netflix/client/config/ClientConfigTest.java
...test/java/com/netflix/client/config/ClientConfigTest.java
+12
-0
未找到文件。
ribbon-core/src/main/java/com/netflix/client/config/IClientConfig.java
浏览文件 @
38dce08d
...
...
@@ -141,6 +141,13 @@ public interface IClientConfig {
*/
<
T
>
Property
<
T
>
getDynamicProperty
(
IClientConfigKey
<
T
>
key
);
/**
* @return Get a property that is only scoped to this client.
*/
default
<
T
>
Property
<
T
>
getScopedProperty
(
IClientConfigKey
<
T
>
key
)
{
throw
new
UnsupportedOperationException
();
}
/**
* @return Return a dynamically updated property that is a mapping of all properties prefixed by the key name to an
* object with static method valueOf(Map{@literal <}String, String{@literal >})
...
...
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
浏览文件 @
38dce08d
...
...
@@ -198,10 +198,10 @@ public abstract class ReloadableClientConfig implements IClientConfig {
public
final
<
T
>
Property
<
T
>
getGlobalProperty
(
IClientConfigKey
<
T
>
key
)
{
LOG
.
debug
(
"Get global property {} default {}"
,
key
.
key
(),
key
.
defaultValue
());
return
createProperty
(
return
(
Property
<
T
>)
dynamicProperties
.
computeIfAbsent
(
key
,
ignore
->
createProperty
(
()
->
resolver
.
get
(
key
.
key
(),
key
.
type
()),
key:
:
defaultValue
,
true
);
true
)
)
;
}
interface
ReloadableProperty
<
T
>
extends
Property
<
T
>
{
...
...
@@ -241,12 +241,16 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return
value
;
}
value
=
resolveDefaultProperty
(
key
);
return
resolveDefaultProperty
(
key
);
}
private
<
T
>
Optional
<
T
>
resolverScopedProperty
(
IClientConfigKey
<
T
>
key
)
{
Optional
<
T
>
value
=
resolver
.
get
(
clientName
+
"."
+
getNameSpace
()
+
"."
+
key
.
key
(),
key
.
type
());
if
(
value
.
isPresent
())
{
return
value
;
}
return
Optional
.
empty
(
);
return
resolveDefaultProperty
(
key
);
}
protected
<
T
>
Optional
<
T
>
resolveDefaultProperty
(
IClientConfigKey
<
T
>
key
)
{
...
...
@@ -295,12 +299,20 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return
getClientDynamicProperty
(
key
,
true
);
}
@Override
public
<
T
>
Property
<
T
>
getScopedProperty
(
IClientConfigKey
<
T
>
key
)
{
return
(
Property
<
T
>)
dynamicProperties
.
computeIfAbsent
(
key
,
ignore
->
createProperty
(
()
->
resolverScopedProperty
(
key
),
key:
:
defaultValue
,
isDynamic
));
}
@Override
public
<
T
>
Property
<
T
>
getPrefixMappedProperty
(
IClientConfigKey
<
T
>
key
)
{
return
createProperty
(
return
(
Property
<
T
>)
dynamicProperties
.
computeIfAbsent
(
key
,
ignore
->
createProperty
(
getPrefixedMapPropertySupplier
(
key
),
key:
:
defaultValue
,
isDynamic
);
isDynamic
)
)
;
}
private
<
T
>
Supplier
<
Optional
<
T
>>
getPrefixedMapPropertySupplier
(
IClientConfigKey
<
T
>
key
)
{
...
...
ribbon-core/src/test/java/com/netflix/client/config/ClientConfigTest.java
浏览文件 @
38dce08d
...
...
@@ -191,5 +191,17 @@ public class ClientConfigTest {
Property
<
CustomValueOf
>
prop
=
clientConfig
.
getDynamicProperty
(
CUSTOM_KEY
);
Assert
.
assertEquals
(
"value"
,
prop
.
getOrDefault
().
getValue
());
}
@Test
public
void
testScopedProperty
()
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ribbon.foo.ScopePropertyTimeout"
,
"2000"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"testScopedProperty.ribbon.foo.ScopePropertyTimeout"
,
"1000"
);
DefaultClientConfigImpl
clientConfig
=
new
DefaultClientConfigImpl
();
clientConfig
.
setClientName
(
"testScopedProperty"
);
Property
<
Integer
>
prop
=
clientConfig
.
getScopedProperty
(
new
CommonClientConfigKey
<
Integer
>(
"foo.ScopePropertyTimeout"
,
0
)
{});
Assert
.
assertEquals
(
1000
,
prop
.
get
().
get
().
intValue
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录