NacosNamingService中getServicesOfServer的作用是什么
今天就跟大家聊聊有关NacosNamingService中getServicesOfServer的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
创新互联是专业的商南网站建设公司,商南接单;提供成都网站制作、成都做网站、外贸营销网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行商南网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
NacosNamingService
nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java
public class NacosNamingService implements NamingService { private static final String DEFAULT_PORT = "8080"; private static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(5); /** * Each Naming instance should have different namespace. */ private String namespace; private String endpoint; private String serverList; private String cacheDir; private String logName; private HostReactor hostReactor; private BeatReactor beatReactor; private EventDispatcher eventDispatcher; private NamingProxy serverProxy; //...... @Override public ListViewgetServicesOfServer(int pageNo, int pageSize) throws NacosException { return serverProxy.getServiceList(pageNo, pageSize, Constants.DEFAULT_GROUP); } @Override public ListView getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException { return getServicesOfServer(pageNo, pageSize, groupName, null); } @Override public ListView getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException { return getServicesOfServer(pageNo, pageSize, Constants.DEFAULT_GROUP, selector); } @Override public ListView getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException { return serverProxy.getServiceList(pageNo, pageSize, groupName, selector); } //...... }
getServicesOfServer方法请求的是serverProxy.getServiceList,其pageNo从1开始
NamingProxy
nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java
public class NamingProxy { private static final int DEFAULT_SERVER_PORT = 8848; private int serverPort = DEFAULT_SERVER_PORT; private String namespaceId; private String endpoint; private String nacosDomain; private ListserverList; private List serversFromEndpoint = new ArrayList (); private long lastSrvRefTime = 0L; private long vipSrvRefInterMillis = TimeUnit.SECONDS.toMillis(30); private Properties properties; //...... public ListView getServiceList(int pageNo, int pageSize, String groupName) throws NacosException { return getServiceList(pageNo, pageSize, groupName, null); } public ListView getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException { Map params = new HashMap (4); params.put("pageNo", String.valueOf(pageNo)); params.put("pageSize", String.valueOf(pageSize)); params.put(CommonParams.NAMESPACE_ID, namespaceId); params.put(CommonParams.GROUP_NAME, groupName); if (selector != null) { switch (SelectorType.valueOf(selector.getType())) { case none: break; case label: ExpressionSelector expressionSelector = (ExpressionSelector) selector; params.put("selector", JSON.toJSONString(expressionSelector)); break; default: break; } } String result = reqAPI(UtilAndComs.NACOS_URL_BASE + "/service/list", params); JSONObject json = JSON.parseObject(result); ListView listView = new ListView (); listView.setCount(json.getInteger("count")); listView.setData(JSON.parseObject(json.getString("doms"), new TypeReference >() { })); return listView; } //...... }
NamingProxy的getServiceList方法请求的是
/service/list
接口,它将返还的数据组装为ListView结构
ListView
nacos-1.1.3/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ListView.java
public class ListView{ private List data; private int count; public List getData() { return data; } public void setData(List data) { this.data = data; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } @Override public String toString() { return JSON.toJSONString(this); } }
ListView包含了count属性及List类型的data属性
小结
NacosNamingService的getServicesOfServer方法请求的是serverProxy.getServiceList,其pageNo从1开始;NamingProxy的getServiceList方法请求的是/service/list
接口,它将返还的数据组装为ListView结构;ListView包含了count属性及List类型的data属性
看完上述内容,你们对NacosNamingService中getServicesOfServer的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
当前文章:NacosNamingService中getServicesOfServer的作用是什么
网页地址:http://scyanting.com/article/jghsde.html