From 554932201b2a54ebced74b02830926cddfbd4bbc Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 26 Aug 2016 06:37:47 +0800 Subject: [PATCH] --- src/org/redkale/boot/Application.java | 8 ++++++++ src/org/redkale/boot/NodeServer.java | 6 +++--- src/org/redkale/net/Transport.java | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index 2e3be8378..1b6cf69dc 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -67,6 +67,8 @@ public final class Application { final Map> globalGroups = new HashMap<>(); + final Map globalGroupKinds = new HashMap<>(); + final Map globalGroupProtocols = new HashMap<>(); final InetAddress localAddress; @@ -335,6 +337,7 @@ public final class Application { if (addrs == null) { addrs = new LinkedHashSet<>(); globalGroupProtocols.put(group, protocol); + globalGroupKinds.put(group, conf.getValue("kind", "")); globalGroups.put(group, addrs); } for (AnyValue node : conf.getAnyValues("node")) { @@ -577,6 +580,11 @@ public final class Application { return globalGroupProtocols.get(group); } + String findGroupKind(String group) { + if (group == null) return null; + return globalGroupKinds.get(group); + } + Set findGlobalGroup(String group) { if (group == null) return null; Set set = globalGroups.get(group); diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java index d71723daa..5acc7bc7c 100644 --- a/src/org/redkale/boot/NodeServer.java +++ b/src/org/redkale/boot/NodeServer.java @@ -53,7 +53,7 @@ public abstract class NodeServer { //日志是否为FINEST级别 protected final boolean finest; - + //进程主类 protected final Application application; @@ -403,7 +403,7 @@ public abstract class NodeServer { transports.forEach(t -> addrs.addAll(Arrays.asList(t.getRemoteAddresses()))); Transport first = transports.get(0); Transport newTransport = new Transport(groupid, application.findGroupProtocol(first.getName()), application.getWatchFactory(), - application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs); + application.findGroupKind(first.getName()), application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs); synchronized (application.resourceFactory) { transport = application.resourceFactory.find(groupid, Transport.class); if (transport == null) { @@ -428,7 +428,7 @@ public abstract class NodeServer { Set addrs = application.findGlobalGroup(group); if (addrs == null) throw new RuntimeException("Not found = " + group + " on "); transport = new Transport(group, application.findGroupProtocol(group), application.getWatchFactory(), - application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs); + application.findGroupKind(group), application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs); application.resourceFactory.register(group, transport); } return transport; diff --git a/src/org/redkale/net/Transport.java b/src/org/redkale/net/Transport.java index 33d4a5c7a..b63f4beaf 100644 --- a/src/org/redkale/net/Transport.java +++ b/src/org/redkale/net/Transport.java @@ -44,6 +44,8 @@ public final class Transport { protected final String name; //即的name属性 + protected final String kind; //即的kind属性 + protected final boolean tcp; protected final String protocol; @@ -54,21 +56,22 @@ public final class Transport { protected final InetSocketAddress clientAddress; - protected InetSocketAddress[] remoteAddres = new InetSocketAddress[0]; + protected InetSocketAddress[] remoteAddres = new InetSocketAddress[0]; protected final ObjectPool bufferPool; protected final ConcurrentHashMap> connPool = new ConcurrentHashMap<>(); - public Transport(String name, WatchFactory watch, final ObjectPool transportBufferPool, - final AsynchronousChannelGroup transportChannelGroup, final InetSocketAddress clientAddress, final Collection addresses) { - this(name, DEFAULT_PROTOCOL, watch, transportBufferPool, transportChannelGroup, clientAddress, addresses); + public Transport(String name, WatchFactory watch, String kind, final ObjectPool transportBufferPool, + final AsynchronousChannelGroup transportChannelGroup, final InetSocketAddress clientAddress, final Collection addresses) { + this(name, DEFAULT_PROTOCOL, watch, kind, transportBufferPool, transportChannelGroup, clientAddress, addresses); } - public Transport(String name, String protocol, WatchFactory watch, final ObjectPool transportBufferPool, - final AsynchronousChannelGroup transportChannelGroup, final InetSocketAddress clientAddress, final Collection addresses) { + public Transport(String name, String protocol, WatchFactory watch, String kind, final ObjectPool transportBufferPool, + final AsynchronousChannelGroup transportChannelGroup, final InetSocketAddress clientAddress, final Collection addresses) { this.name = name; this.watch = watch; + this.kind = kind == null ? "" : kind.trim(); this.protocol = protocol; this.tcp = "TCP".equalsIgnoreCase(protocol); this.group = transportChannelGroup; @@ -87,6 +90,7 @@ public final class Transport { //必须按字母排列顺序确保,相同内容的transport列表组合的name相同,而不会因为list的顺序不同产生不同的name this.name = tmpgroup.stream().sorted().collect(Collectors.joining(";")); this.watch = first.watch; + this.kind = first.kind; this.protocol = first.protocol; this.tcp = "TCP".equalsIgnoreCase(first.protocol); this.group = first.group; @@ -114,6 +118,10 @@ public final class Transport { return name; } + public String getKind() { + return kind; + } + public void close() { connPool.forEach((k, v) -> v.forEach(c -> c.dispose())); }