您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。