From 2ca814fab2dc9b5b11f67e6e01459da90a692f03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com>
Date: Fri, 27 Mar 2015 09:58:52 +0800
Subject: [PATCH]
---
src/com/wentch/redkale/boot/Application.java | 75 +++++++-
.../redkale/net/AsyncDatagramChannel.java | 4 +-
src/com/wentch/redkale/net/Response.java | 4 +-
src/com/wentch/redkale/net/SSLBuilder.java | 111 ++++++++++++
src/com/wentch/redkale/net/Transport.java | 4 +
.../redkale/net/http/HttpPrepareServlet.java | 4 +-
.../wentch/redkale/net/http/HttpResponse.java | 96 +++++++++-
.../wentch/redkale/net/http/HttpServer.java | 53 +++++-
.../wentch/redkale/net/sncp/SncpClient.java | 2 +-
.../service/DataCacheListenerService.java | 166 +++++++++++++-----
src/com/wentch/redkale/service/Service.java | 6 +-
.../wentch/redkale/source/DataJDBCSource.java | 4 +-
.../wentch/redkale/util/ResourceFactory.java | 68 +++++--
13 files changed, 516 insertions(+), 81 deletions(-)
diff --git a/src/com/wentch/redkale/boot/Application.java b/src/com/wentch/redkale/boot/Application.java
index bdd2fa872..e727dc754 100644
--- a/src/com/wentch/redkale/boot/Application.java
+++ b/src/com/wentch/redkale/boot/Application.java
@@ -23,6 +23,7 @@ import java.nio.*;
import java.nio.channels.*;
import java.nio.file.*;
import java.util.*;
+import java.util.AbstractMap.SimpleEntry;
import java.util.concurrent.*;
import java.util.logging.*;
import javax.annotation.*;
@@ -31,7 +32,7 @@ import org.w3c.dom.*;
/**
* 编译时需要加入: -XDignore.symbol.file=true
- *
+ *
* 进程启动类,程序启动后读取application.xml,进行classpath扫描动态加载Service与Servlet,
* 再进行Service、Servlet与其他资源之间的依赖注入。
*
@@ -39,14 +40,28 @@ import org.w3c.dom.*;
*/
public final class Application {
+ //进程启动的时间, 类型: long
public static final String RESNAME_TIME = "APP_TIME";
+ //本地进程的根目录, 类型:String
public static final String RESNAME_HOME = "APP_HOME";
+ //本地节点的名称, 类型:String
public static final String RESNAME_NODE = "APP_NODE";
+ //本地节点的所属组, 类型:String、Map>、Map>>
+ public static final String RESNAME_GROUP = "APP_GROUP";
+
+ //本地节点的所属组所有节点名, 类型:Set 、List>包含自身节点名
+ public static final String RESNAME_INGROUP = "APP_INGROUP";
+
+ //除本地节点的所属组外其他所有组的所有节点名, 类型:Map>、Map>>
+ public static final String RESNAME_OUTGROUP = "APP_OUTGROUP";
+
+ //本地节点的IP地址, 类型:InetAddress、String
public static final String RESNAME_ADDR = "APP_ADDR";
-
+
+ //application.xml 文件中resources节点的内容, 类型: AnyValue
public static final String RESNAME_GRES = "APP_GRES";
protected final ResourceFactory factory = ResourceFactory.root();
@@ -61,6 +76,8 @@ public final class Application {
protected final InetAddress localAddress = Utility.localInetAddress();
+ protected String nodeGroup = "";
+
protected String nodeName = "";
//--------------------------------------------------------------------------------------------
@@ -92,7 +109,12 @@ public final class Application {
}
final File logconf = new File(root, "conf/logging.properties");
this.nodeName = config.getValue("node", "");
+ this.nodeGroup = config.getValue("group", "");
this.factory.register(RESNAME_NODE, this.nodeName);
+ this.factory.register(RESNAME_GROUP, this.nodeGroup);
+ System.setProperty(RESNAME_NODE, this.nodeName);
+ System.setProperty(RESNAME_GROUP, this.nodeGroup);
+
this.factory.register(RESNAME_ADDR, this.localAddress.getHostAddress());
this.factory.register(RESNAME_ADDR, InetAddress.class, this.localAddress);
if (logconf.isFile() && logconf.canRead()) {
@@ -415,14 +437,25 @@ public final class Application {
//------------------------------------------------------------------------
final String host = this.localAddress.getHostAddress();
+ final Map> groups = new HashMap<>();
+ final Map>> groups2 = new HashMap<>();
for (AnyValue conf : resources.getAnyValues("remote")) {
final String name = conf.getValue("name");
+ final String group = conf.getValue("group", "");
if (name == null) throw new RuntimeException("remote name is null");
String protocol = conf.getValue("protocol", "UDP").toUpperCase();
if (!"TCP".equalsIgnoreCase(protocol) && !"UDP".equalsIgnoreCase(protocol)) {
throw new RuntimeException("Not supported Transport Protocol " + conf.getValue("protocol"));
}
+ {
+ Set set = groups.get(group);
+ if (set == null) {
+ set = new HashSet<>();
+ groups.put(group, set);
+ }
+ set.add(name);
+ }
AnyValue[] addrs = conf.getAnyValues("address");
InetSocketAddress[] addresses = new InetSocketAddress[addrs.length];
int i = -1;
@@ -430,17 +463,51 @@ public final class Application {
addresses[++i] = new InetSocketAddress(addr.getValue("addr"), addr.getIntValue("port"));
}
if (addresses.length < 1) throw new RuntimeException("Transport(" + name + ") have no address ");
- Transport transport = new Transport(name, protocol, watch, 100, addresses[0]);
+ {
+ List> list = groups2.get(group);
+ if (list == null) {
+ list = new ArrayList<>();
+ groups2.put(group, list);
+ }
+ list.add(new SimpleEntry<>(name, addresses));
+ }
+ Transport transport = new Transport(name, protocol, watch, 100, addresses);
factory.register(name, Transport.class, transport);
if (this.nodeName.isEmpty() && host.equals(addrs[0].getValue("addr"))) {
this.nodeName = name;
+ this.nodeGroup = group;
this.factory.register(RESNAME_NODE, this.nodeName);
+ this.factory.register(RESNAME_GROUP, this.nodeGroup);
+ System.setProperty(RESNAME_NODE, this.nodeName);
+ System.setProperty(RESNAME_GROUP, this.nodeGroup);
}
}
+
+ this.factory.register(RESNAME_GROUP, new TypeToken