diff --git a/src/META-INF/application-template.xml b/src/META-INF/application-template.xml index b9ba481cd..e67a5398b 100644 --- a/src/META-INF/application-template.xml +++ b/src/META-INF/application-template.xml @@ -59,7 +59,6 @@ 一个group节点对应一个 Transport 对象。 name: 服务组ID,长度不能超过11个字节. 默认为空字符串。 注意: name不能包含$符号。 protocol: 值范围:UDP TCP, 默认TCP - subprotocol: 子协议,预留字段。默认值为空 注意: 一个node只能所属一个group。只要存在protocol=SNCP的Server节点信息, 就必须有group节点信息。 --> diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index b580b95f7..7c536640f 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -572,7 +572,7 @@ public final class Application { if (!"TCP".equalsIgnoreCase(protocol) && !"UDP".equalsIgnoreCase(protocol)) { throw new RuntimeException("Not supported Transport Protocol " + conf.getValue("protocol")); } - TransportGroupInfo ginfo = new TransportGroupInfo(group, protocol, conf.getValue("subprotocol", ""), new LinkedHashSet<>()); + TransportGroupInfo ginfo = new TransportGroupInfo(group, protocol, new LinkedHashSet<>()); for (AnyValue node : conf.getAnyValues("node")) { final InetSocketAddress addr = new InetSocketAddress(node.getValue("addr"), node.getIntValue("port")); ginfo.putAddress(addr); diff --git a/src/org/redkale/boot/ClusterAgent.java b/src/org/redkale/boot/ClusterAgent.java index c6b27ee1e..e804bc465 100644 --- a/src/org/redkale/boot/ClusterAgent.java +++ b/src/org/redkale/boot/ClusterAgent.java @@ -74,14 +74,13 @@ public abstract class ClusterAgent { register(ns, transportFactory, service); } Server server = ns.getServer(); - String subprotocol = server instanceof SncpServer ? ((SncpServer) server).getSubprotocol() : "TCP"; + String netprotocol = server instanceof SncpServer ? ((SncpServer) server).getNetprotocol() : Transport.DEFAULT_PROTOCOL; //远程模式加载IP列表, 只能是SNCP协议 for (Service service : remoteServices) { if (!Sncp.isSncpDyn(service)) continue; List addrs = queryAddress(ns, service); if (addrs != null && !addrs.isEmpty()) { - SncpClient client = Sncp.getSncpClient(service); - if (client != null) client.setRemoteGroupTransport(transportFactory.createTransport(Sncp.getResourceType(service).getName(), server.getProtocol(), subprotocol, ns.getSncpAddress(), addrs)); + Sncp.updateTransport(service, transportFactory, Sncp.getResourceType(service).getName() + "-" + Sncp.getResourceName(service), netprotocol, ns.getSncpAddress(), null, addrs); } } } diff --git a/src/org/redkale/net/Transport.java b/src/org/redkale/net/Transport.java index 21282366f..4e5b705e7 100644 --- a/src/org/redkale/net/Transport.java +++ b/src/org/redkale/net/Transport.java @@ -38,8 +38,6 @@ public final class Transport { protected final String name; //即的name属性 - protected final String subprotocol; //即的subprotocol属性 - protected final boolean tcp; protected final String protocol; @@ -58,18 +56,16 @@ public final class Transport { //负载均衡策略 protected final TransportStrategy strategy; - protected Transport(String name, String subprotocol, TransportFactory factory, final ObjectPool transportBufferPool, + protected Transport(String name, TransportFactory factory, final ObjectPool transportBufferPool, final AsynchronousChannelGroup transportChannelGroup, final SSLContext sslContext, final InetSocketAddress clientAddress, final Collection addresses, final TransportStrategy strategy) { - this(name, DEFAULT_PROTOCOL, subprotocol, factory, transportBufferPool, transportChannelGroup, sslContext, clientAddress, addresses, strategy); + this(name, DEFAULT_PROTOCOL, factory, transportBufferPool, transportChannelGroup, sslContext, clientAddress, addresses, strategy); } - protected Transport(String name, String protocol, String subprotocol, - final TransportFactory factory, final ObjectPool transportBufferPool, + protected Transport(String name, String protocol, final TransportFactory factory, final ObjectPool transportBufferPool, final AsynchronousChannelGroup transportChannelGroup, final SSLContext sslContext, final InetSocketAddress clientAddress, final Collection addresses, final TransportStrategy strategy) { this.name = name; - this.subprotocol = subprotocol == null ? "" : subprotocol.trim(); this.protocol = protocol; this.factory = factory; factory.transportReferences.add(new WeakReference<>(this)); @@ -138,10 +134,6 @@ public final class Transport { return name; } - public String getSubprotocol() { - return subprotocol; - } - public void close() { TransportNode[] nodes = this.transportNodes; if (nodes == null) return; @@ -198,6 +190,10 @@ public final class Transport { return group; } + public String getProtocol() { + return protocol; + } + public boolean isTCP() { return tcp; } diff --git a/src/org/redkale/net/TransportFactory.java b/src/org/redkale/net/TransportFactory.java index 3dd657ef9..cbc93c7e4 100644 --- a/src/org/redkale/net/TransportFactory.java +++ b/src/org/redkale/net/TransportFactory.java @@ -203,16 +203,11 @@ public class TransportFactory { } public Transport createTransportTCP(String name, final InetSocketAddress clientAddress, final Collection addresses) { - return new Transport(name, "TCP", "", this, this.bufferPool, this.channelGroup, this.sslContext, clientAddress, addresses, strategy); + return new Transport(name, "TCP", this, this.bufferPool, this.channelGroup, this.sslContext, clientAddress, addresses, strategy); } public Transport createTransport(String name, String protocol, final InetSocketAddress clientAddress, final Collection addresses) { - return new Transport(name, protocol, "", this, this.bufferPool, this.channelGroup, this.sslContext, clientAddress, addresses, strategy); - } - - public Transport createTransport(String name, String protocol, String subprotocol, - final InetSocketAddress clientAddress, final Collection addresses) { - return new Transport(name, protocol, subprotocol, this, this.bufferPool, this.channelGroup, this.sslContext, clientAddress, addresses, strategy); + return new Transport(name, protocol, this, this.bufferPool, this.channelGroup, this.sslContext, clientAddress, addresses, strategy); } public String findGroupName(InetSocketAddress addr) { @@ -251,7 +246,6 @@ public class TransportFactory { if (!checkName(info.name)) throw new RuntimeException("Transport.group.name only 0-9 a-z A-Z _ cannot begin 0-9"); TransportGroupInfo old = groupInfos.get(info.name); if (old != null && !old.protocol.equals(info.protocol)) throw new RuntimeException("Transport.group.name repeat but protocol is different"); - if (old != null && !old.subprotocol.equals(info.subprotocol)) throw new RuntimeException("Transport.group.name repeat but subprotocol is different"); for (InetSocketAddress addr : info.addresses) { if (!groupAddrs.getOrDefault(addr, info.name).equals(info.name)) throw new RuntimeException(addr + " repeat but different group.name"); } @@ -277,7 +271,7 @@ public class TransportFactory { } if (info == null) info = new TransportGroupInfo("TCP"); if (sncpAddress != null) addresses.remove(sncpAddress); - return new Transport(groups.stream().sorted().collect(Collectors.joining(";")), info.protocol, info.subprotocol, this, this.bufferPool, this.channelGroup, this.sslContext, sncpAddress, addresses, this.strategy); + return new Transport(groups.stream().sorted().collect(Collectors.joining(";")), info.protocol, this, this.bufferPool, this.channelGroup, this.sslContext, sncpAddress, addresses, this.strategy); } public ExecutorService getExecutor() { diff --git a/src/org/redkale/net/TransportGroupInfo.java b/src/org/redkale/net/TransportGroupInfo.java index 48885cf54..21975af1f 100644 --- a/src/org/redkale/net/TransportGroupInfo.java +++ b/src/org/redkale/net/TransportGroupInfo.java @@ -24,30 +24,27 @@ public class TransportGroupInfo { protected String protocol; //协议 取值范围: TCP、UDP - protected String subprotocol; //子协议,预留使用 - protected Set addresses; //地址列表, 对应 resources->group->node节点信息 public TransportGroupInfo() { } public TransportGroupInfo(String name, InetSocketAddress... addrs) { - this(name, "TCP", "", Utility.ofSet(addrs)); + this(name, "TCP", Utility.ofSet(addrs)); } public TransportGroupInfo(String name, Set addrs) { - this(name, "TCP", "", addrs); + this(name, "TCP", addrs); } - public TransportGroupInfo(String name, String protocol, String subprotocol, InetSocketAddress... addrs) { - this(name, protocol, subprotocol, Utility.ofSet(addrs)); + public TransportGroupInfo(String name, String protocol, InetSocketAddress... addrs) { + this(name, protocol, Utility.ofSet(addrs)); } - public TransportGroupInfo(String name, String protocol, String subprotocol, Set addrs) { + public TransportGroupInfo(String name, String protocol, Set addrs) { Objects.requireNonNull(name, "Transport.group.name can not null"); this.name = name; this.protocol = protocol == null ? "TCP" : protocol; - this.subprotocol = subprotocol == null ? "" : subprotocol; this.addresses = addrs; } @@ -68,15 +65,6 @@ public class TransportGroupInfo { this.protocol = protocol == null ? "TCP" : protocol; } - public String getSubprotocol() { - return subprotocol; - } - - public void setSubprotocol(String subprotocol) { - this.subprotocol = subprotocol == null ? "" : subprotocol; - this.subprotocol = subprotocol; - } - public Set getAddresses() { return addresses; } diff --git a/src/org/redkale/net/sncp/Sncp.java b/src/org/redkale/net/sncp/Sncp.java index a3ea643a2..766dae5ca 100644 --- a/src/org/redkale/net/sncp/Sncp.java +++ b/src/org/redkale/net/sncp/Sncp.java @@ -139,6 +139,20 @@ public abstract class Sncp { } } + public static boolean updateTransport(Service service, + final TransportFactory transportFactory, String name, String protocol, InetSocketAddress clientAddress, + final Set groups, final Collection addresses) { + if (!isSncpDyn(service)) return false; + SncpClient client = getSncpClient(service); + client.setRemoteGroups(groups); + if (client.getRemoteGroupTransport() != null) { + client.getRemoteGroupTransport().updateRemoteAddresses(addresses); + } else { + client.setRemoteGroupTransport(transportFactory.createTransport(name, protocol, clientAddress, addresses)); + } + return true; + } + static void checkAsyncModifier(Class param, Method method) { if (param == CompletionHandler.class) return; if (Modifier.isFinal(param.getModifiers())) { diff --git a/src/org/redkale/net/sncp/SncpServer.java b/src/org/redkale/net/sncp/SncpServer.java index 45c70f469..ca5ab1912 100644 --- a/src/org/redkale/net/sncp/SncpServer.java +++ b/src/org/redkale/net/sncp/SncpServer.java @@ -30,7 +30,7 @@ public class SncpServer extends Server getSncpServlets() {