Skip to content

Commit 15f4a7d

Browse files
authored
Revert "Local references support mergeable (#9645)" (#10707)
This reverts commit 72326f4.
1 parent c374c0e commit 15f4a7d

File tree

9 files changed

+23
-181
lines changed

9 files changed

+23
-181
lines changed

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ private void createInvokerForLocal(Map<String, String> referenceParameters) {
448448
URL url = new ServiceConfigURL(LOCAL_PROTOCOL, LOCALHOST_VALUE, 0, interfaceClass.getName(), referenceParameters);
449449
url = url.setScopeModel(getScopeModel());
450450
url = url.setServiceModel(consumerModel);
451-
invoker = protocolSPI.refer(interfaceClass, url);
451+
Invoker<?> withFilter = protocolSPI.refer(interfaceClass, url);
452+
// Local Invoke ( Support Cluster Filter / Filter )
453+
List<Invoker<?>> invokers = new ArrayList<>();
454+
invokers.add(withFilter);
455+
invoker = Cluster.getCluster(url.getScopeModel(), Cluster.DEFAULT).join(new StaticDirectory(url, invokers), true);
452456

453457
if (logger.isInfoEnabled()) {
454458
logger.info("Using in jvm service " + interfaceClass.getName());

dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,10 @@ public void testCreateInvokerForLocalRefer() {
477477
.initialize();
478478

479479
referenceConfig.init();
480-
Invoker<?> withFilter = ((ListenerInvokerWrapper<?>) referenceConfig.getInvoker()).getInvoker();
481-
withFilter = ((MockClusterInvoker<?>) withFilter).getDirectory().getAllInvokers().get(0);
482-
Assertions.assertTrue(withFilter instanceof InjvmInvoker);
480+
Assertions.assertTrue(referenceConfig.getInvoker() instanceof MockClusterInvoker);
481+
Invoker<?> withFilter = ((MockClusterInvoker<?>) referenceConfig.getInvoker()).getDirectory().getAllInvokers().get(0);
482+
Assertions.assertTrue(withFilter instanceof ListenerInvokerWrapper);
483+
Assertions.assertTrue(((ListenerInvokerWrapper<?>) withFilter).getInvoker() instanceof InjvmInvoker);
483484
URL url = withFilter.getUrl();
484485
Assertions.assertEquals("application1", url.getParameter("application"));
485486
Assertions.assertEquals("value1", url.getParameter("key1"));

dubbo-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public List<String> getEffectReferenceRegistryURLs() {
253253

254254
protected static class MultipleNotifyListenerWrapper implements NotifyListener {
255255

256-
Map<URL, SingleNotifyListener> registryMap = new ConcurrentHashMap<>(4);
256+
Map<URL, SingleNotifyListener> registryMap = new ConcurrentHashMap<URL, SingleNotifyListener>(4);
257257
NotifyListener sourceNotifyListener;
258258

259259
public MultipleNotifyListenerWrapper(NotifyListener sourceNotifyListener) {

dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import java.lang.reflect.Type;
4444
import java.util.HashMap;
45+
import java.util.Map;
4546
import java.util.Objects;
4647
import java.util.concurrent.CompletableFuture;
4748
import java.util.concurrent.ExecutorService;
@@ -62,18 +63,18 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
6263

6364
private final String key;
6465

65-
private final Exporter<?> exporter;
66+
private final Map<String, Exporter<?>> exporterMap;
6667

6768
private final ExecutorRepository executorRepository;
6869

6970
private final ParamDeepCopyUtil paramDeepCopyUtil;
7071

7172
private final boolean shouldIgnoreSameModule;
7273

73-
InjvmInvoker(Class<T> type, URL url, String key, Exporter<?> exporter) {
74+
InjvmInvoker(Class<T> type, URL url, String key, Map<String, Exporter<?>> exporterMap) {
7475
super(type, url);
7576
this.key = key;
76-
this.exporter = exporter;
77+
this.exporterMap = exporterMap;
7778
this.executorRepository = url.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
7879
this.paramDeepCopyUtil = url.getOrDefaultFrameworkModel().getExtensionLoader(ParamDeepCopyUtil.class)
7980
.getExtension(url.getParameter(CommonConstants.INJVM_COPY_UTIL_KEY, DefaultParamDeepCopyUtil.NAME));
@@ -82,6 +83,7 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
8283

8384
@Override
8485
public boolean isAvailable() {
86+
InjvmExporter<?> exporter = (InjvmExporter<?>) exporterMap.get(key);
8587
if (exporter == null) {
8688
return false;
8789
} else {
@@ -91,6 +93,7 @@ public boolean isAvailable() {
9193

9294
@Override
9395
public Result doInvoke(Invocation invocation) throws Throwable {
96+
Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
9497
if (exporter == null) {
9598
throw new RpcException("Service [" + key + "] not found.");
9699
}

dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,19 @@
1818

1919
import org.apache.dubbo.common.URL;
2020
import org.apache.dubbo.common.utils.CollectionUtils;
21-
import org.apache.dubbo.common.utils.StringUtils;
2221
import org.apache.dubbo.common.utils.UrlUtils;
2322
import org.apache.dubbo.rpc.Exporter;
2423
import org.apache.dubbo.rpc.Invoker;
2524
import org.apache.dubbo.rpc.Protocol;
2625
import org.apache.dubbo.rpc.RpcException;
27-
import org.apache.dubbo.rpc.cluster.Cluster;
28-
import org.apache.dubbo.rpc.cluster.ClusterInvoker;
29-
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
30-
import org.apache.dubbo.rpc.cluster.support.MergeableCluster;
3126
import org.apache.dubbo.rpc.model.ScopeModel;
3227
import org.apache.dubbo.rpc.protocol.AbstractProtocol;
3328
import org.apache.dubbo.rpc.support.ProtocolUtils;
3429

35-
import java.util.ArrayList;
36-
import java.util.List;
3730
import java.util.Map;
3831

3932
import static org.apache.dubbo.common.constants.CommonConstants.BROADCAST_CLUSTER;
4033
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
41-
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
42-
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
43-
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
4434
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
4535
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
4636
import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
@@ -79,7 +69,7 @@ static Exporter<?> getExporter(Map<String, Exporter<?>> map, URL key) {
7969
if (result == null) {
8070
return null;
8171
} else if (ProtocolUtils.isGeneric(
82-
result.getInvoker().getUrl().getParameter(GENERIC_KEY))) {
72+
result.getInvoker().getUrl().getParameter(GENERIC_KEY))) {
8373
return null;
8474
} else {
8575
return result;
@@ -98,15 +88,7 @@ public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
9888

9989
@Override
10090
public <T> Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url) throws RpcException {
101-
// group="a,b" or group="*"
102-
String group = url.getParameter(GROUP_KEY);
103-
if (StringUtils.isNotEmpty(group)) {
104-
if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) {
105-
return doCreateInvoker(url, Cluster.getCluster(url.getScopeModel(), MergeableCluster.NAME), serviceType);
106-
}
107-
}
108-
Cluster cluster = Cluster.getCluster(url.getScopeModel(), url.getParameter(CLUSTER_KEY));
109-
return doCreateInvoker(url, cluster, serviceType);
91+
return new InjvmInvoker<T>(serviceType, url, url.getServiceKey(), exporterMap);
11092
}
11193

11294
public boolean isInjvmRefer(URL url) {
@@ -134,34 +116,4 @@ public boolean isInjvmRefer(URL url) {
134116
return false;
135117
}
136118
}
137-
138-
@SuppressWarnings({"unchecked", "rawtypes"})
139-
protected <T> ClusterInvoker<T> doCreateInvoker(URL url, Cluster cluster, Class<T> type) {
140-
StaticDirectory directory = new StaticDirectory(url, getInvokers(exporterMap, url, type));
141-
return (ClusterInvoker<T>) cluster.join(directory, true);
142-
}
143-
144-
private <T> List<Invoker<T>> getInvokers(Map<String, Exporter<?>> map, URL url, Class<T> type) {
145-
List<Invoker<T>> result = new ArrayList<>();
146-
147-
if (!url.getServiceKey().contains("*")) {
148-
Exporter<?> exporter = map.get(url.getServiceKey());
149-
InjvmInvoker<T> invoker = new InjvmInvoker<>(type, url, url.getServiceKey(), exporter);
150-
result.add(invoker);
151-
} else {
152-
if (CollectionUtils.isNotEmptyMap(map)) {
153-
for (Exporter<?> exporter : map.values()) {
154-
if (UrlUtils.isServiceKeyMatch(url, exporter.getInvoker().getUrl())) {
155-
URL providerUrl = exporter.getInvoker().getUrl();
156-
URL consumerUrl = url.addParameter(GROUP_KEY, providerUrl.getGroup())
157-
.addParameter(VERSION_KEY, providerUrl.getVersion());
158-
InjvmInvoker<T> invoker = new InjvmInvoker<>(type, consumerUrl, consumerUrl.getServiceKey(), exporter);
159-
result.add(invoker);
160-
}
161-
}
162-
}
163-
}
164-
165-
return result;
166-
}
167119
}

dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/Hello1ServiceImpl.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/Hello2ServiceImpl.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/HelloService.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@
2929
import org.junit.jupiter.api.Test;
3030

3131
import java.util.ArrayList;
32+
import java.util.HashMap;
3233
import java.util.List;
3334

34-
import static org.apache.dubbo.common.constants.CommonConstants.*;
35+
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
36+
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
37+
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
3538
import static org.apache.dubbo.rpc.Constants.ASYNC_KEY;
3639
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
3740
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
3841
import static org.apache.dubbo.rpc.Constants.SCOPE_KEY;
3942
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
4043
import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
41-
import static org.apache.dubbo.rpc.Constants.MERGER_KEY;
4244
import static org.junit.jupiter.api.Assertions.assertEquals;
4345
import static org.junit.jupiter.api.Assertions.assertFalse;
4446
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -74,7 +76,7 @@ public void testLocalProtocol() throws Exception {
7476
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
7577
service.invoke("injvm://127.0.0.1/TestService", "invoke");
7678

77-
InjvmInvoker<?> injvmInvoker = new InjvmInvoker<>(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService"), null, null);
79+
InjvmInvoker<?> injvmInvoker = new InjvmInvoker<>(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService"), null, new HashMap<>());
7880
assertFalse(injvmInvoker.isAvailable());
7981

8082
}
@@ -135,36 +137,4 @@ public void testLocalProtocolAsync() throws Exception {
135137
assertNull(service.getAsyncResult());
136138
}
137139

138-
@Test
139-
public void testLocalProtocolForMergeResult() throws Exception {
140-
HelloService helloService1 = new Hello1ServiceImpl();
141-
URL url = URL.valueOf("injvm://127.0.0.1/HelloService")
142-
.addParameter(INTERFACE_KEY, HelloService.class.getName())
143-
.addParameter(APPLICATION_KEY, "consumer")
144-
.addParameter(GROUP_KEY, "g1");
145-
Invoker<?> invoker1 = proxy.getInvoker(helloService1, HelloService.class, url);
146-
assertTrue(invoker1.isAvailable());
147-
Exporter<?> exporter1 = protocol.export(invoker1);
148-
exporters.add(exporter1);
149-
150-
URL url2 = URL.valueOf("injvm://127.0.0.1/HelloService")
151-
.addParameter(INTERFACE_KEY, HelloService.class.getName())
152-
.addParameter(APPLICATION_KEY, "consumer")
153-
.addParameter(GROUP_KEY, "g2");
154-
HelloService helloService2 = new Hello2ServiceImpl();
155-
Invoker<?> invoker2 = proxy.getInvoker(helloService2, HelloService.class, url2);
156-
assertTrue(invoker2.isAvailable());
157-
Exporter<?> exporter2 = protocol.export(invoker2);
158-
exporters.add(exporter2);
159-
160-
161-
URL referUrl = URL.valueOf("injvm://127.0.0.1/HelloService")
162-
.addParameter(INTERFACE_KEY, HelloService.class.getName())
163-
.addParameter(APPLICATION_KEY, "consumer")
164-
.addParameter(GROUP_KEY, "*")
165-
.addParameter(MERGER_KEY, "list");
166-
List<String> list = proxy.getProxy(protocol.refer(HelloService.class, referUrl)).hellos();
167-
assertEquals(2, list.size());
168-
}
169-
170140
}

0 commit comments

Comments
 (0)