您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關(guān)NacosNamingService中g(shù)etServicesOfServer的作用是什么,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
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
接口,它將返還的數(shù)據(jù)組裝為ListView結(jié)構(gòu)
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
接口,它將返還的數(shù)據(jù)組裝為ListView結(jié)構(gòu);ListView包含了count屬性及List類型的data屬性
看完上述內(nèi)容,你們對NacosNamingService中g(shù)etServicesOfServer的作用是什么有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。