This commit is contained in:
@@ -85,8 +85,8 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
//远程模式加载IP列表, 只能是SNCP协议
|
//远程模式加载IP列表, 只能是SNCP协议
|
||||||
for (Service service : remoteServices) {
|
for (Service service : remoteServices) {
|
||||||
updateTransport(ns, protocol, service);
|
|
||||||
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
|
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
|
||||||
|
updateTransport(entry);
|
||||||
remoteEntrys.put(entry.serviceid, entry);
|
remoteEntrys.put(entry.serviceid, entry);
|
||||||
}
|
}
|
||||||
afterRegister(ns, protocol);
|
afterRegister(ns, protocol);
|
||||||
@@ -105,7 +105,7 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取远程服务的可用ip列表
|
//获取远程服务的可用ip列表
|
||||||
protected abstract Collection<InetSocketAddress> queryAddress(NodeServer ns, String protocol, Service service);
|
protected abstract Collection<InetSocketAddress> queryAddress(ClusterEntry entry);
|
||||||
|
|
||||||
//注册服务
|
//注册服务
|
||||||
protected abstract void register(NodeServer ns, String protocol, Service service);
|
protected abstract void register(NodeServer ns, String protocol, Service service);
|
||||||
@@ -114,21 +114,18 @@ public abstract class ClusterAgent {
|
|||||||
protected abstract void deregister(NodeServer ns, String protocol, Service service);
|
protected abstract void deregister(NodeServer ns, String protocol, Service service);
|
||||||
|
|
||||||
//格式: protocol:classtype-resourcename
|
//格式: protocol:classtype-resourcename
|
||||||
protected void updateTransport(NodeServer ns, String protocol, Service service) {
|
protected void updateTransport(ClusterEntry entry) {
|
||||||
Server server = ns.getServer();
|
Service service = entry.serviceref.get();
|
||||||
String netprotocol = server instanceof SncpServer ? ((SncpServer) server).getNetprotocol() : Transport.DEFAULT_PROTOCOL;
|
if (service == null) return;
|
||||||
if (!Sncp.isSncpDyn(service)) return;
|
Collection<InetSocketAddress> addrs = queryAddress(entry);
|
||||||
Collection<InetSocketAddress> addrs = queryAddress(ns, protocol, service);
|
Sncp.updateTransport(service, transportFactory, Sncp.getResourceType(service).getName() + "-" + Sncp.getResourceName(service), entry.netprotocol, entry.address, null, addrs);
|
||||||
if (addrs != null && !addrs.isEmpty()) {
|
|
||||||
Sncp.updateTransport(service, transportFactory, Sncp.getResourceType(service).getName() + "-" + Sncp.getResourceName(service), netprotocol, ns.getSncpAddress(), null, addrs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: protocol:classtype-resourcename
|
//格式: protocol:classtype-resourcename
|
||||||
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
||||||
if (!Sncp.isSncpDyn(service)) return protocol.toLowerCase() + ":" + service.getClass().getName();
|
if (!Sncp.isSncpDyn(service)) return protocol.toLowerCase() + ":" + service.getClass().getName();
|
||||||
String name = Sncp.getResourceName(service);
|
String resname = Sncp.getResourceName(service);
|
||||||
return protocol.toLowerCase() + ":" + Sncp.getResourceType(service).getName() + (name.isEmpty() ? "" : ("-" + name));
|
return protocol.toLowerCase() + ":" + Sncp.getResourceType(service).getName() + (resname.isEmpty() ? "" : ("-" + resname));
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: protocol:classtype-resourcename:nodeid
|
//格式: protocol:classtype-resourcename:nodeid
|
||||||
@@ -217,6 +214,8 @@ public abstract class ClusterAgent {
|
|||||||
|
|
||||||
public String protocol;
|
public String protocol;
|
||||||
|
|
||||||
|
public String netprotocol;
|
||||||
|
|
||||||
public WeakReference<Service> serviceref;
|
public WeakReference<Service> serviceref;
|
||||||
|
|
||||||
public InetSocketAddress address;
|
public InetSocketAddress address;
|
||||||
@@ -229,6 +228,8 @@ public abstract class ClusterAgent {
|
|||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
this.address = ns.getSocketAddress();
|
this.address = ns.getSocketAddress();
|
||||||
this.serviceref = new WeakReference(service);
|
this.serviceref = new WeakReference(service);
|
||||||
|
Server server = ns.getServer();
|
||||||
|
this.netprotocol = server instanceof SncpServer ? ((SncpServer) server).getNetprotocol() : Transport.DEFAULT_PROTOCOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user