chickenlj commented on code in PR #13747: URL: https://github.com/apache/dubbo/pull/13747#discussion_r1505551333
########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); Review Comment: ConcurrentHashMap needed here ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); + + private final Map<String, Set<XdsDirectory>> cdsListeners = new HashMap<>(); + + protected PilotExchanger(URL url) { + // xdsChannel = new XdsChannel(url); + int pollingTimeout = url.getParameter("pollingTimeout", 10); + this.applicationModel = url.getOrDefaultApplicationModel(); + adsObserver = new AdsObserver(url, NodeBuilder.build()); + + // rds 资源回调函数,将 RdsProtocol 的资源存放起来 + Consumer<List<XdsRouteConfiguration>> rdsCallback = (xdsRouteConfigurations) -> { + System.out.println(xdsRouteConfigurations); + xdsRouteConfigurations.forEach(xdsRouteConfiguration -> { + xdsRouteConfiguration.getVirtualHosts().forEach((serviceName, xdsVirtualHost) -> { + this.xdsVirtualHostMap.put(serviceName, xdsVirtualHost); + // 回调更新 + if (rdsListeners.containsKey(serviceName)) { + for (XdsDirectory listener : rdsListeners.get(serviceName)) { + listener.onRdsChange(serviceName, xdsVirtualHost); + } + } + }); + }); + }; + + // eds 资源回调函数 + Consumer<List<XdsCluster>> edsCallback = (xdsClusters) -> { + System.out.println(xdsClusters); Review Comment: delete console outputs ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); + + private final Map<String, Set<XdsDirectory>> cdsListeners = new HashMap<>(); + + protected PilotExchanger(URL url) { + // xdsChannel = new XdsChannel(url); + int pollingTimeout = url.getParameter("pollingTimeout", 10); + this.applicationModel = url.getOrDefaultApplicationModel(); + adsObserver = new AdsObserver(url, NodeBuilder.build()); + + // rds 资源回调函数,将 RdsProtocol 的资源存放起来 + Consumer<List<XdsRouteConfiguration>> rdsCallback = (xdsRouteConfigurations) -> { + System.out.println(xdsRouteConfigurations); + xdsRouteConfigurations.forEach(xdsRouteConfiguration -> { + xdsRouteConfiguration.getVirtualHosts().forEach((serviceName, xdsVirtualHost) -> { + this.xdsVirtualHostMap.put(serviceName, xdsVirtualHost); + // 回调更新 + if (rdsListeners.containsKey(serviceName)) { + for (XdsDirectory listener : rdsListeners.get(serviceName)) { + listener.onRdsChange(serviceName, xdsVirtualHost); + } + } + }); + }); + }; + + // eds 资源回调函数 + Consumer<List<XdsCluster>> edsCallback = (xdsClusters) -> { + System.out.println(xdsClusters); + xdsClusters.forEach(xdsCluster -> { + this.xdsClusterMap.put(xdsCluster.getName(), xdsCluster); + if (cdsListeners.containsKey(xdsCluster.getName())) { + for (XdsDirectory listener : cdsListeners.get(xdsCluster.getName())) { + listener.onCdsChange(xdsCluster.getName(), xdsCluster); + } + } + }); + }; + + this.ldsProtocol = new LdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + this.rdsProtocol = new RdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, rdsCallback); + this.edsProtocol = new EdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, edsCallback); + this.cdsProtocol = new CdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + + // lds 回调函数,在回调函数中监听所有的 rds 资源 + Consumer<Set<String>> ldsCallback = (routes) -> { + rdsProtocol.getResource(routes); + }; + + ldsProtocol.setUpdateCallback(ldsCallback); + + ldsProtocol.getListeners(); + + // cds 回调函数,在回调函数中监听所有的 eds 资源 + Consumer<Set<String>> cdsCallback = (clusters) -> { + edsProtocol.getResource(clusters); Review Comment: also don't have receiver ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); + + private final Map<String, Set<XdsDirectory>> cdsListeners = new HashMap<>(); + + protected PilotExchanger(URL url) { + // xdsChannel = new XdsChannel(url); + int pollingTimeout = url.getParameter("pollingTimeout", 10); + this.applicationModel = url.getOrDefaultApplicationModel(); + adsObserver = new AdsObserver(url, NodeBuilder.build()); + + // rds 资源回调函数,将 RdsProtocol 的资源存放起来 + Consumer<List<XdsRouteConfiguration>> rdsCallback = (xdsRouteConfigurations) -> { + System.out.println(xdsRouteConfigurations); + xdsRouteConfigurations.forEach(xdsRouteConfiguration -> { + xdsRouteConfiguration.getVirtualHosts().forEach((serviceName, xdsVirtualHost) -> { + this.xdsVirtualHostMap.put(serviceName, xdsVirtualHost); + // 回调更新 + if (rdsListeners.containsKey(serviceName)) { + for (XdsDirectory listener : rdsListeners.get(serviceName)) { + listener.onRdsChange(serviceName, xdsVirtualHost); + } + } + }); + }); + }; + + // eds 资源回调函数 + Consumer<List<XdsCluster>> edsCallback = (xdsClusters) -> { + System.out.println(xdsClusters); + xdsClusters.forEach(xdsCluster -> { + this.xdsClusterMap.put(xdsCluster.getName(), xdsCluster); + if (cdsListeners.containsKey(xdsCluster.getName())) { + for (XdsDirectory listener : cdsListeners.get(xdsCluster.getName())) { + listener.onCdsChange(xdsCluster.getName(), xdsCluster); + } + } + }); + }; + + this.ldsProtocol = new LdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + this.rdsProtocol = new RdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, rdsCallback); + this.edsProtocol = new EdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, edsCallback); + this.cdsProtocol = new CdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + + // lds 回调函数,在回调函数中监听所有的 rds 资源 + Consumer<Set<String>> ldsCallback = (routes) -> { + rdsProtocol.getResource(routes); + }; + + ldsProtocol.setUpdateCallback(ldsCallback); + + ldsProtocol.getListeners(); Review Comment: What is this call for? seems to be a read operation but with no receiver. ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); + + private final Map<String, Set<XdsDirectory>> cdsListeners = new HashMap<>(); + + protected PilotExchanger(URL url) { + // xdsChannel = new XdsChannel(url); + int pollingTimeout = url.getParameter("pollingTimeout", 10); + this.applicationModel = url.getOrDefaultApplicationModel(); + adsObserver = new AdsObserver(url, NodeBuilder.build()); + + // rds 资源回调函数,将 RdsProtocol 的资源存放起来 + Consumer<List<XdsRouteConfiguration>> rdsCallback = (xdsRouteConfigurations) -> { + System.out.println(xdsRouteConfigurations); + xdsRouteConfigurations.forEach(xdsRouteConfiguration -> { + xdsRouteConfiguration.getVirtualHosts().forEach((serviceName, xdsVirtualHost) -> { + this.xdsVirtualHostMap.put(serviceName, xdsVirtualHost); + // 回调更新 + if (rdsListeners.containsKey(serviceName)) { + for (XdsDirectory listener : rdsListeners.get(serviceName)) { + listener.onRdsChange(serviceName, xdsVirtualHost); + } + } + }); + }); + }; + + // eds 资源回调函数 + Consumer<List<XdsCluster>> edsCallback = (xdsClusters) -> { + System.out.println(xdsClusters); + xdsClusters.forEach(xdsCluster -> { + this.xdsClusterMap.put(xdsCluster.getName(), xdsCluster); + if (cdsListeners.containsKey(xdsCluster.getName())) { + for (XdsDirectory listener : cdsListeners.get(xdsCluster.getName())) { + listener.onCdsChange(xdsCluster.getName(), xdsCluster); + } + } + }); + }; + + this.ldsProtocol = new LdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + this.rdsProtocol = new RdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, rdsCallback); + this.edsProtocol = new EdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout, edsCallback); + this.cdsProtocol = new CdsProtocol(adsObserver, NodeBuilder.build(), pollingTimeout); + + // lds 回调函数,在回调函数中监听所有的 rds 资源 + Consumer<Set<String>> ldsCallback = (routes) -> { + rdsProtocol.getResource(routes); + }; + + ldsProtocol.setUpdateCallback(ldsCallback); + + ldsProtocol.getListeners(); + + // cds 回调函数,在回调函数中监听所有的 eds 资源 + Consumer<Set<String>> cdsCallback = (clusters) -> { + edsProtocol.getResource(clusters); + }; + + cdsProtocol.setUpdateCallback(cdsCallback); + + cdsProtocol.getClusters(); + + } + + public static Map<String, XdsVirtualHost> getXdsVirtualHostMap() { + return xdsVirtualHostMap; + } + + public static Map<String, XdsCluster> getXdsClusterMap() { + return xdsClusterMap; + } + + public void subscribeRds(String applicationName, XdsDirectory listener) { + rdsListeners.computeIfAbsent(applicationName, key -> new ConcurrentHashSet<>()); + rdsListeners.get(applicationName).add(listener); + if (xdsVirtualHostMap.containsKey(applicationName)) { Review Comment: when will `xdsVirtualHostMap` be initialized? `subscribeRds` will finish with no action if `xdsVirtualHostMap` is empty, is that expected? ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/XdsDirectory.java: ########## @@ -0,0 +1,165 @@ +package org.apache.dubbo.rpc.cluster.directory; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Protocol; +import org.apache.dubbo.rpc.cluster.Directory; +import org.apache.dubbo.rpc.cluster.RouterChain; +import org.apache.dubbo.rpc.cluster.SingleRouterChain; +import org.apache.dubbo.rpc.cluster.router.state.BitList; +import org.apache.dubbo.rpc.cluster.xds.PilotExchanger; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsClusterWeight; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsEndpoint; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRoute; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteAction; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +public class XdsDirectory<T> extends AbstractDirectory<T>{ + + private final URL url; + + private final Class<T> serviceType; + + private final String applicationName; + + private final String protocolName; + + PilotExchanger pilotExchanger = PilotExchanger.getInstance(); + + private Set<String> subscribeApplications; + + protected RouterChain<T> routerChain; + + protected List<Invoker<T>> invokers; + private Protocol protocol; + + private final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private final Map<String, XdsCluster<T>> xdsClusterMap = new ConcurrentHashMap<>(); Review Comment: What's this field designed and used for? ########## dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/xds/PilotExchanger.java: ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster.xds; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ConcurrentHashSet; +import org.apache.dubbo.rpc.cluster.directory.XdsDirectory; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.CdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.EdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.LdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.protocol.impl.RdsProtocol; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsCluster; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsRouteConfiguration; +import org.apache.dubbo.rpc.cluster.xds.resource.XdsVirtualHost; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class PilotExchanger { + + // protected final XdsChannel xdsChannel; + + protected final AdsObserver adsObserver; + + protected final LdsProtocol ldsProtocol; + + protected final RdsProtocol rdsProtocol; + + protected final EdsProtocol edsProtocol; + + protected final CdsProtocol cdsProtocol; + + + private final Set<String> domainObserveRequest = new ConcurrentHashSet<String>(); + + private static PilotExchanger GLOBAL_PILOT_EXCHANGER = null; + + private final ApplicationModel applicationModel; + + private static final Map<String, XdsVirtualHost> xdsVirtualHostMap = new ConcurrentHashMap<>(); + + private static final Map<String, XdsCluster> xdsClusterMap = new ConcurrentHashMap<>(); + + private final Map<String, Set<XdsDirectory>> rdsListeners = new HashMap<>(); Review Comment: Embedded set must also be thread-safe. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
