This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
<!--
|
<!--
|
||||||
【节点全局唯一】
|
【节点全局唯一】
|
||||||
所有服务所需的资源
|
所有服务所需的资源
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<!--
|
<!--
|
||||||
【节点全局唯一】
|
【节点全局唯一】
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
</group>
|
</group>
|
||||||
<!--
|
<!--
|
||||||
【节点全局唯一】
|
【节点全局唯一】
|
||||||
全局的参数配置, 可以通过@Resource(name="property.xxxxxx") 进行注入, 被注解的字段类型只能是String、primitive class
|
全局的参数配置, 可以通过@Resource(name="property.xxxxxx") 进行注入<property>的信息, 被注解的字段类型只能是String、primitive class
|
||||||
如果name是system.property.开头的值将会在进程启动时进行System.setProperty("yyyy", "YYYYYY")操作。
|
如果name是system.property.开头的值将会在进程启动时进行System.setProperty("yyyy", "YYYYYY")操作。
|
||||||
如果name是mimetype.property.开头的值将会在进程启动时进行MimeType.add("yyyy", "YYYYYY")操作。
|
如果name是mimetype.property.开头的值将会在进程启动时进行MimeType.add("yyyy", "YYYYYY")操作。
|
||||||
load: 加载文件,多个用;隔开。
|
load: 加载文件,多个用;隔开。
|
||||||
@@ -70,6 +70,8 @@
|
|||||||
System.setProperty("convert.bson.pool.size", "128");
|
System.setProperty("convert.bson.pool.size", "128");
|
||||||
System.setProperty("convert.json.writer.buffer.defsize", "4096");
|
System.setProperty("convert.json.writer.buffer.defsize", "4096");
|
||||||
System.setProperty("convert.bson.writer.buffer.defsize", "4096");
|
System.setProperty("convert.bson.writer.buffer.defsize", "4096");
|
||||||
|
|
||||||
|
<properties>节点下也可包含非<property>节点,其节点可以通过@Resource(name="properties.xxxxxx")进行注入, 被注解的字段类型只能是AnyValue、AnyValue[]
|
||||||
-->
|
-->
|
||||||
<properties load="config.properties">
|
<properties load="config.properties">
|
||||||
<property name="system.property.yyyy" value="YYYYYY"/>
|
<property name="system.property.yyyy" value="YYYYYY"/>
|
||||||
@@ -77,6 +79,7 @@
|
|||||||
<property name="xxxxxx" value="XXXXXXXX"/>
|
<property name="xxxxxx" value="XXXXXXXX"/>
|
||||||
<property name="xxxxxx" value="XXXXXXXX"/>
|
<property name="xxxxxx" value="XXXXXXXX"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
<!--
|
<!--
|
||||||
protocol: required server所启动的协议,Redkale内置的有HTTP、SNCP,SNCP使用TCP实现;
|
protocol: required server所启动的协议,Redkale内置的有HTTP、SNCP,SNCP使用TCP实现;
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ public final class Application {
|
|||||||
//全局根ResourceFactory
|
//全局根ResourceFactory
|
||||||
final ResourceFactory resourceFactory = ResourceFactory.root();
|
final ResourceFactory resourceFactory = ResourceFactory.root();
|
||||||
|
|
||||||
|
//服务配置项
|
||||||
|
final AnyValue config;
|
||||||
|
|
||||||
//临时计数器
|
//临时计数器
|
||||||
CountDownLatch servicecdl; //会出现两次赋值
|
CountDownLatch servicecdl; //会出现两次赋值
|
||||||
|
|
||||||
@@ -134,9 +137,6 @@ public final class Application {
|
|||||||
//日志
|
//日志
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
//服务配置项
|
|
||||||
private final AnyValue config;
|
|
||||||
|
|
||||||
//服务启动时间
|
//服务启动时间
|
||||||
private final long startTime = System.currentTimeMillis();
|
private final long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,31 @@ public abstract class NodeServer {
|
|||||||
final NodeServer self = this;
|
final NodeServer self = this;
|
||||||
//---------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------
|
||||||
final ResourceFactory appResFactory = application.getResourceFactory();
|
final ResourceFactory appResFactory = application.getResourceFactory();
|
||||||
|
//------------------------------------- 注册Resource --------------------------------------------------------
|
||||||
|
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||||
|
try {
|
||||||
|
Resource res = field.getAnnotation(Resource.class);
|
||||||
|
if (res == null || !res.name().startsWith("properties.")) return;
|
||||||
|
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||||
|
Class type = field.getType();
|
||||||
|
if (type != AnyValue.class && type != AnyValue[].class) return;
|
||||||
|
Object resource = null;
|
||||||
|
final AnyValue resources = application.config.getAnyValue("resources");
|
||||||
|
final AnyValue properties = resources == null ? null : resources.getAnyValue("properties");
|
||||||
|
if (properties != null && type == AnyValue.class) {
|
||||||
|
resource = properties.getAnyValue(res.name().substring("properties.".length()));
|
||||||
|
appResFactory.register(resourceName, AnyValue.class, resource);
|
||||||
|
} else if (properties != null && type == AnyValue[].class) {
|
||||||
|
resource = properties.getAnyValues(res.name().substring("properties.".length()));
|
||||||
|
appResFactory.register(resourceName, AnyValue[].class, resource);
|
||||||
|
}
|
||||||
|
field.set(src, resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||||
|
}
|
||||||
|
}, AnyValue.class, AnyValue[].class);
|
||||||
|
|
||||||
|
//------------------------------------- 注册DataSource --------------------------------------------------------
|
||||||
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||||
try {
|
try {
|
||||||
if (field.getAnnotation(Resource.class) == null) return;
|
if (field.getAnnotation(Resource.class) == null) return;
|
||||||
@@ -220,6 +245,8 @@ public abstract class NodeServer {
|
|||||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||||
}
|
}
|
||||||
}, DataSource.class);
|
}, DataSource.class);
|
||||||
|
|
||||||
|
//------------------------------------- 注册CacheSource --------------------------------------------------------
|
||||||
resourceFactory.register((ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
resourceFactory.register((ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
||||||
try {
|
try {
|
||||||
if (field.getAnnotation(Resource.class) == null) return;
|
if (field.getAnnotation(Resource.class) == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user