您好,登录后才能下订单哦!
今天就跟大家聊聊有关NacosNamingService中getServicesOfServer的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
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 ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException { return serverProxy.getServiceList(pageNo, pageSize, Constants.DEFAULT_GROUP); } @Override public ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException { return getServicesOfServer(pageNo, pageSize, groupName, null); } @Override public ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException { return getServicesOfServer(pageNo, pageSize, Constants.DEFAULT_GROUP, selector); } @Override public ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException { return serverProxy.getServiceList(pageNo, pageSize, groupName, selector); } //...... }
getServicesOfServer方法请求的是serverProxy.getServiceList,其pageNo从1开始
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 List<String> serverList; private List<String> serversFromEndpoint = new ArrayList<String>(); private long lastSrvRefTime = 0L; private long vipSrvRefInterMillis = TimeUnit.SECONDS.toMillis(30); private Properties properties; //...... public ListView<String> getServiceList(int pageNo, int pageSize, String groupName) throws NacosException { return getServiceList(pageNo, pageSize, groupName, null); } public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException { Map<String, String> params = new HashMap<String, String>(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<String> listView = new ListView<String>(); listView.setCount(json.getInteger("count")); listView.setData(JSON.parseObject(json.getString("doms"), new TypeReference<List<String>>() { })); return listView; } //...... }
NamingProxy的getServiceList方法请求的是/service/list
接口,它将返还的数据组装为ListView结构
nacos-1.1.3/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ListView.java
public class ListView<T> { private List<T> data; private int count; public List<T> getData() { return data; } public void setData(List<T> 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的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。