Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
ca547c45
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ca547c45
编写于
10月 25, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the codes of modulization core.
上级
66e553a4
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
424 addition
and
11 deletion
+424
-11
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ApplicationConfiguration.java
.../apm/collector/modulization/ApplicationConfiguration.java
+23
-1
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/Module.java
...ava/org/skywalking/apm/collector/modulization/Module.java
+1
-1
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ModuleManager.java
.../skywalking/apm/collector/modulization/ModuleManager.java
+1
-1
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ModuleProvider.java
...skywalking/apm/collector/modulization/ModuleProvider.java
+13
-8
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ApplicationConfigurationTest.java
.../collector/modulization/ApplicationConfigurationTest.java
+41
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/BaseModuleA.java
...rg/skywalking/apm/collector/modulization/BaseModuleA.java
+40
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/BaseModuleB.java
...rg/skywalking/apm/collector/modulization/BaseModuleB.java
+40
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleAProvider.java
...kywalking/apm/collector/modulization/ModuleAProvider.java
+54
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleBProvider.java
...kywalking/apm/collector/modulization/ModuleBProvider.java
+54
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleManagerTest.java
...walking/apm/collector/modulization/ModuleManagerTest.java
+37
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/TestModule.java
...org/skywalking/apm/collector/modulization/TestModule.java
+32
-0
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/TestModuleProvider.java
...alking/apm/collector/modulization/TestModuleProvider.java
+46
-0
apm-collector/apm-collector-modulization-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.modulization.Module
...services/org.skywalking.apm.collector.modulization.Module
+21
-0
apm-collector/apm-collector-modulization-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.modulization.ModuleProvider
.../org.skywalking.apm.collector.modulization.ModuleProvider
+21
-0
未找到文件。
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ApplicationConfiguration.java
浏览文件 @
ca547c45
...
...
@@ -21,6 +21,11 @@ package org.skywalking.apm.collector.modulization;
import
java.util.HashMap
;
import
java.util.Properties
;
/**
* Modulization configurations. The {@link ModuleManager} is going to start, lookup, init modules based on this.
*
* @author wu-sheng
*/
public
class
ApplicationConfiguration
{
private
HashMap
<
String
,
ModuleConfiguration
>
modules
=
new
HashMap
<>();
...
...
@@ -44,8 +49,17 @@ public class ApplicationConfiguration {
public
class
ModuleConfiguration
{
private
HashMap
<
String
,
ProviderConfiguration
>
providers
=
new
HashMap
<>();
private
ModuleConfiguration
()
{
}
public
Properties
getProviderConfiguration
(
String
name
)
{
return
providers
.
get
(
name
).
properties
;
return
providers
.
get
(
name
).
getProperties
();
}
public
ModuleConfiguration
addProviderConfiguration
(
String
name
,
Properties
properties
)
{
ProviderConfiguration
newProvider
=
new
ProviderConfiguration
(
properties
);
providers
.
put
(
name
,
newProvider
);
return
this
;
}
}
...
...
@@ -54,5 +68,13 @@ public class ApplicationConfiguration {
*/
public
class
ProviderConfiguration
{
private
Properties
properties
;
ProviderConfiguration
(
Properties
properties
)
{
this
.
properties
=
properties
;
}
public
Properties
getProperties
()
{
return
properties
;
}
}
}
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/Module.java
浏览文件 @
ca547c45
...
...
@@ -48,7 +48,7 @@ public abstract class Module {
* @throws ProviderNotFoundException when even don't find a single one providers.
*/
void
prepare
(
ModuleManager
moduleManager
,
ApplicationConfiguration
.
ModuleConfiguration
configuration
)
throws
ProviderNotFoundException
{
ApplicationConfiguration
.
ModuleConfiguration
configuration
)
throws
ProviderNotFoundException
,
ServiceNotProvidedException
{
ServiceLoader
<
ModuleProvider
>
moduleProviderLoader
=
ServiceLoader
.
load
(
ModuleProvider
.
class
);
boolean
providerExist
=
false
;
for
(
ModuleProvider
provider
:
moduleProviderLoader
)
{
...
...
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ModuleManager.java
浏览文件 @
ca547c45
...
...
@@ -54,7 +54,7 @@ public class ModuleManager {
throw
new
ModuleNotFoundException
(
e
);
}
newInstance
.
prepare
(
this
,
applicationConfiguration
.
getModuleConfiguration
(
moduleName
));
loadedModules
.
put
(
moduleName
,
modul
e
);
loadedModules
.
put
(
moduleName
,
newInstanc
e
);
moduleList
.
remove
(
moduleName
);
}
}
...
...
apm-collector/apm-collector-modulization-core/src/main/java/org/skywalking/apm/collector/modulization/ModuleProvider.java
浏览文件 @
ca547c45
...
...
@@ -60,14 +60,14 @@ public abstract class ModuleProvider {
*
* @param config from `application.yml`
*/
public
abstract
void
prepare
(
Properties
config
);
public
abstract
void
prepare
(
Properties
config
)
throws
ServiceNotProvidedException
;
/**
* In prepare stage, the module can interop with other modules.
*
* @param config from `application.yml`
*/
public
abstract
void
init
(
Properties
config
);
public
abstract
void
init
(
Properties
config
)
throws
ServiceNotProvidedException
;
/**
* @return module names which does this module require?
...
...
@@ -80,8 +80,13 @@ public abstract class ModuleProvider {
* @param serviceType
* @param service
*/
protected
void
registerServiceImplementation
(
Class
<?
extends
Service
>
serviceType
,
Service
service
)
{
this
.
services
.
put
(
serviceType
,
service
);
protected
void
registerServiceImplementation
(
Class
<?
extends
Service
>
serviceType
,
Service
service
)
throws
ServiceNotProvidedException
{
if
(
serviceType
.
isInstance
(
service
))
{
this
.
services
.
put
(
serviceType
,
service
);
}
else
{
throw
new
ServiceNotProvidedException
(
serviceType
+
" is not implemented by "
+
service
);
}
}
/**
...
...
@@ -94,14 +99,14 @@ public abstract class ModuleProvider {
if
(
requiredServices
==
null
)
return
;
if
(
requiredServices
.
length
!=
services
.
size
())
{
throw
new
ServiceNotProvidedException
(
"Haven't provided enough plugins."
);
}
for
(
Class
<?
extends
Service
>
service
:
requiredServices
)
{
if
(!
services
.
containsKey
(
service
))
{
throw
new
ServiceNotProvidedException
(
"Service:"
+
service
.
getName
()
+
" not provided"
);
}
}
if
(
requiredServices
.
length
!=
services
.
size
())
{
throw
new
ServiceNotProvidedException
(
"Provide more service implementations than Module requirements."
);
}
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ApplicationConfigurationTest.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
import
java.util.Properties
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
ApplicationConfigurationTest
{
@Test
public
void
testBuildConfig
()
{
ApplicationConfiguration
configuration
=
new
ApplicationConfiguration
();
Properties
p1
=
new
Properties
();
p1
.
setProperty
(
"p1"
,
"value1"
);
p1
.
setProperty
(
"p2"
,
"value2"
);
Properties
p2
=
new
Properties
();
p2
.
setProperty
(
"prop1"
,
"value1-prop"
);
p2
.
setProperty
(
"prop2"
,
"value2-prop"
);
configuration
.
addModule
(
"MO-1"
).
addProviderConfiguration
(
"MO-1-P1"
,
p1
).
addProviderConfiguration
(
"MO-1-P2"
,
p2
);
Assert
.
assertArrayEquals
(
new
String
[]
{
"MO-1"
},
configuration
.
moduleList
());
Assert
.
assertEquals
(
"value2-prop"
,
configuration
.
getModuleConfiguration
(
"MO-1"
).
getProviderConfiguration
(
"MO-1-P2"
).
getProperty
(
"prop2"
));
Assert
.
assertEquals
(
p1
,
configuration
.
getModuleConfiguration
(
"MO-1"
).
getProviderConfiguration
(
"MO-1-P1"
));
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/BaseModuleA.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
/**
* @author wu-sheng
*/
public
class
BaseModuleA
extends
Module
{
@Override
public
String
name
()
{
return
"BaseA"
;
}
@Override
public
Class
<?
extends
Service
>[]
services
()
{
return
new
Class
[]
{
ServiceABusiness1
.
class
,
ServiceABusiness2
.
class
};
}
public
interface
ServiceABusiness1
extends
Service
{
}
public
interface
ServiceABusiness2
extends
Service
{
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/BaseModuleB.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
/**
* @author wu-sheng
*/
public
class
BaseModuleB
extends
Module
{
@Override
public
String
name
()
{
return
"BaseB"
;
}
@Override
public
Class
<?
extends
Service
>[]
services
()
{
return
new
Class
[]
{
BaseModuleB
.
ServiceBBusiness1
.
class
,
BaseModuleB
.
ServiceBBusiness2
.
class
};
}
public
interface
ServiceBBusiness1
extends
Service
{
}
public
interface
ServiceBBusiness2
extends
Service
{
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleAProvider.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
import
java.util.Properties
;
/**
* @author wu-sheng
*/
public
class
ModuleAProvider
extends
ModuleProvider
{
@Override
public
String
name
()
{
return
"P-A"
;
}
@Override
public
Class
<?
extends
Module
>
module
()
{
return
BaseModuleA
.
class
;
}
@Override
public
void
prepare
(
Properties
config
)
throws
ServiceNotProvidedException
{
this
.
registerServiceImplementation
(
BaseModuleA
.
ServiceABusiness1
.
class
,
new
Business1
());
}
@Override
public
void
init
(
Properties
config
)
throws
ServiceNotProvidedException
{
this
.
registerServiceImplementation
(
BaseModuleA
.
ServiceABusiness2
.
class
,
new
Business2
());
}
@Override
public
String
[]
requiredModules
()
{
return
new
String
[
0
];
}
public
class
Business1
implements
BaseModuleA
.
ServiceABusiness1
{
}
public
class
Business2
implements
BaseModuleA
.
ServiceABusiness2
{
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleBProvider.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
import
java.util.Properties
;
/**
* @author wu-sheng
*/
public
class
ModuleBProvider
extends
ModuleProvider
{
@Override
public
String
name
()
{
return
"P-B"
;
}
@Override
public
Class
<?
extends
Module
>
module
()
{
return
BaseModuleB
.
class
;
}
@Override
public
void
prepare
(
Properties
config
)
throws
ServiceNotProvidedException
{
this
.
registerServiceImplementation
(
BaseModuleB
.
ServiceBBusiness1
.
class
,
new
Business1
());
}
@Override
public
void
init
(
Properties
config
)
throws
ServiceNotProvidedException
{
this
.
registerServiceImplementation
(
BaseModuleB
.
ServiceBBusiness2
.
class
,
new
Business2
());
}
@Override
public
String
[]
requiredModules
()
{
return
new
String
[
0
];
}
public
class
Business1
implements
BaseModuleB
.
ServiceBBusiness1
{
}
public
class
Business2
implements
BaseModuleB
.
ServiceBBusiness2
{
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/ModuleManagerTest.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
import
org.junit.Test
;
/**
* @author wu-sheng
*/
public
class
ModuleManagerTest
{
@Test
public
void
testInit
()
throws
ServiceNotProvidedException
,
ModuleNotFoundException
,
ProviderNotFoundException
{
ApplicationConfiguration
configuration
=
new
ApplicationConfiguration
();
configuration
.
addModule
(
"Test"
).
addProviderConfiguration
(
"TestModule-Provider"
,
null
);
configuration
.
addModule
(
"BaseA"
).
addProviderConfiguration
(
"P-A"
,
null
);
configuration
.
addModule
(
"BaseB"
).
addProviderConfiguration
(
"P-B"
,
null
);
ModuleManager
manager
=
new
ModuleManager
();
manager
.
init
(
configuration
);
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/TestModule.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
/**
* @author wu-sheng
*/
public
class
TestModule
extends
Module
{
@Override
public
String
name
()
{
return
"Test"
;
}
@Override
public
Class
<?
extends
Service
>[]
services
()
{
return
new
Class
[
0
];
}
}
apm-collector/apm-collector-modulization-core/src/test/java/org/skywalking/apm/collector/modulization/TestModuleProvider.java
0 → 100644
浏览文件 @
ca547c45
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.collector.modulization
;
import
java.util.Properties
;
/**
* @author wu-sheng
*/
public
class
TestModuleProvider
extends
ModuleProvider
{
@Override
public
String
name
()
{
return
"TestModule-Provider"
;
}
@Override
public
Class
<?
extends
Module
>
module
()
{
return
TestModule
.
class
;
}
@Override
public
void
prepare
(
Properties
config
)
{
}
@Override
public
void
init
(
Properties
config
)
{
}
@Override
public
String
[]
requiredModules
()
{
return
new
String
[]
{
"BaseA"
,
"BaseB"
};
}
}
apm-collector/apm-collector-modulization-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.modulization.Module
0 → 100644
浏览文件 @
ca547c45
#
# Copyright 2017, OpenSkywalking Organization All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Project repository: https://github.com/OpenSkywalking/skywalking
#
org
.
skywalking
.
apm
.
collector
.
modulization
.
TestModule
org
.
skywalking
.
apm
.
collector
.
modulization
.
BaseModuleA
org
.
skywalking
.
apm
.
collector
.
modulization
.
BaseModuleB
\ No newline at end of file
apm-collector/apm-collector-modulization-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.modulization.ModuleProvider
0 → 100644
浏览文件 @
ca547c45
#
# Copyright 2017, OpenSkywalking Organization All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Project repository: https://github.com/OpenSkywalking/skywalking
#
org.skywalking.apm.collector.modulization.TestModuleProvider
org.skywalking.apm.collector.modulization.ModuleAProvider
org.skywalking.apm.collector.modulization.ModuleBProvider
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录