Merge branch 'merge-3.x' of https://github.com/chickenlj/incubator-dubbo into merge-3.x

This commit is contained in:
ken.lj 2019-10-10 08:40:50 +08:00
commit e88242c0be
37 changed files with 534 additions and 42 deletions

View File

@ -34,6 +34,11 @@ import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
*/
public class MockDirInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
public String getMethodName() {
return "echo";
}

View File

@ -668,6 +668,13 @@ public class ExtensionLoader<T> {
urls = ClassLoader.getSystemResources(fileName);
}
if (urls != null) {
if (!urls.hasMoreElements()) {
// try to load from ExtensionLoader's ClassLoader
ClassLoader extensionLoaderClassLoader = this.getClass().getClassLoader();
if (ClassLoader.getSystemClassLoader() != extensionLoaderClassLoader) {
urls = extensionLoaderClassLoader.getResources(fileName);
}
}
while (urls.hasMoreElements()) {
java.net.URL resourceURL = urls.nextElement();
loadResource(extensionClasses, classLoader, resourceURL);

View File

@ -18,7 +18,6 @@ package org.apache.dubbo.common.bytecode;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MixinTest {

View File

@ -20,7 +20,6 @@ package org.apache.dubbo.common.threadlocal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -51,6 +51,11 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation {
this.delegate = invocation;
}
@Override
public String getTargetServiceUniqueName() {
return delegate.getTargetServiceUniqueName();
}
@Override
public String getMethodName() {
return delegate.getMethodName();

View File

@ -24,7 +24,6 @@ import com.alibaba.dubbo.cache.CacheFactory;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -49,6 +48,11 @@ public class CacheTest {
}
static class NullInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
@Override
public String getMethodName() {
return null;

View File

@ -41,6 +41,11 @@ public class LegacyInvocation implements Invocation {
this.arg0 = arg0;
}
@Override
public String getTargetServiceUniqueName() {
return null;
}
public String getMethodName() {
return "echo";
}

View File

@ -40,6 +40,11 @@ public class MockInvocation implements Invocation {
this.arg0 = arg0;
}
@Override
public String getTargetServiceUniqueName() {
return null;
}
public String getMethodName() {
return "echo";
}

View File

@ -867,6 +867,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
public void setMetadataReportConfig(MetadataReportConfig metadataReportConfig) {
ConfigManager.getInstance().setMetadataReportConfig(metadataReportConfig);
this.metadataReportConfig = metadataReportConfig;
}

View File

@ -38,6 +38,7 @@ import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.cluster.support.RegistryAwareCluster;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerMethodModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.ServiceMetadata;
import org.apache.dubbo.rpc.model.ServiceModel;
@ -337,7 +338,11 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
map.put(methodConfig.getName() + ".retries", "0");
}
}
attributes.put(methodConfig.getName(), convertMethodConfig2AyncInfo(methodConfig));
ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = convertMethodConfig2AsyncInfo(methodConfig);
if (asyncMethodInfo != null) {
// consumerModel.getMethodModel(methodConfig.getName()).addAttribute(ASYNC_KEY, asyncMethodInfo);
attributes.put(methodConfig.getName(), asyncMethodInfo);
}
}
}
@ -351,10 +356,11 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
serviceMetadata.getAttachments().putAll(map);
ref = createProxy(map);
ServiceModel serviceModel = ApplicationModel.registerServiceModel(interfaceClass);
ApplicationModel.initConsumerModel(serviceMetadata.getServiceKey(), buildConsumerModel(attributes, serviceModel));
ref = createProxy(map);
serviceMetadata.setTarget(ref);
serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);
initialized = true;
@ -409,7 +415,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
}
} else { // assemble URL from register center's configuration
// if protocols not injvm checkRegistry
if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())){
if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())) {
checkRegistry();
List<URL> us = loadRegistries(false);
if (CollectionUtils.isNotEmpty(us)) {

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.config.AbstractConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.ProtocolConfig;
@ -79,6 +80,7 @@ public class ConfigManager {
private MonitorConfig monitor;
private ModuleConfig module;
private ConfigCenterConfig configCenter;
private MetadataReportConfig metadataReportConfig;
private Map<String, ProtocolConfig> protocols = new ConcurrentHashMap<>();
private Map<String, RegistryConfig> registries = new ConcurrentHashMap<>();
@ -137,6 +139,17 @@ public class ConfigManager {
}
}
public Optional<MetadataReportConfig> getMetadataReportConfig() {
return Optional.ofNullable(metadataReportConfig);
}
public void setMetadataReportConfig(MetadataReportConfig metadataReportConfig) {
if (metadataReportConfig != null) {
checkDuplicate(this.metadataReportConfig, metadataReportConfig);
this.metadataReportConfig = metadataReportConfig;
}
}
public Optional<ProviderConfig> getProvider(String id) {
return Optional.ofNullable(providers.get(id));
}

View File

@ -44,7 +44,6 @@ import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.service.GenericException;
import org.apache.dubbo.rpc.service.GenericService;
import org.junit.Assert;
@ -57,6 +56,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Collection;
import java.util.List;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_BEAN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -65,9 +66,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_BEAN;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
/**
* ConfigTest

View File

@ -17,7 +17,6 @@
package org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.api.HelloService;
import org.junit.Assert;

View File

@ -30,7 +30,6 @@ import org.yaml.snakeyaml.resolver.Resolver;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
/**

View File

@ -153,7 +153,7 @@
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
<portlet_version>2.0</portlet_version>
<maven_flatten_version>1.1.0</maven_flatten_version>
<revision>2.7.4-SNAPSHOT</revision>
<revision>2.7.4-hsf3-SNAPSHOT</revision>
</properties>
<dependencyManagement>

View File

@ -32,7 +32,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.7.4-SNAPSHOT</revision>
<revision>2.7.4-hsf3-SNAPSHOT</revision>
<maven_flatten_version>1.1.0</maven_flatten_version>
</properties>

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.rpc.cluster.Directory;
import java.util.List;
@ -29,7 +30,8 @@ public interface AddressListener {
*
* @param addresses provider address list
* @param registryDirectoryUrl
* @param registryDirectory
*/
List<URL> notify(List<URL> addresses, URL registryDirectoryUrl);
List<URL> notify(List<URL> addresses, URL registryDirectoryUrl, Directory registryDirectory);
}

View File

@ -0,0 +1,154 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import java.util.List;
public class ListenerRegistryWrapper implements Registry {
private static final Logger logger = LoggerFactory.getLogger(ListenerRegistryWrapper.class);
private final Registry registry;
private final List<RegistryServiceListener> listeners;
public ListenerRegistryWrapper(Registry registry, List<RegistryServiceListener> listeners) {
this.registry = registry;
this.listeners = listeners;
}
@Override
public URL getUrl() {
return registry.getUrl();
}
@Override
public boolean isAvailable() {
return registry.isAvailable();
}
@Override
public void destroy() {
registry.destroy();
}
@Override
public void register(URL url) {
try {
registry.register(url);
} finally {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (RegistryServiceListener listener : listeners) {
if (listener != null) {
try {
listener.onRegister(url);
} catch (RuntimeException t) {
logger.error(t.getMessage(), t);
exception = t;
}
}
}
if (exception != null) {
throw exception;
}
}
}
}
@Override
public void unregister(URL url) {
try {
registry.unregister(url);
} finally {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (RegistryServiceListener listener : listeners) {
if (listener != null) {
try {
listener.onUnregister(url);
} catch (RuntimeException t) {
logger.error(t.getMessage(), t);
exception = t;
}
}
}
if (exception != null) {
throw exception;
}
}
}
}
@Override
public void subscribe(URL url, NotifyListener listener) {
try {
registry.subscribe(url, listener);
} finally {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (RegistryServiceListener registryListener : listeners) {
if (registryListener != null) {
try {
registryListener.onSubscribe(url);
} catch (RuntimeException t) {
logger.error(t.getMessage(), t);
exception = t;
}
}
}
if (exception != null) {
throw exception;
}
}
}
}
@Override
public void unsubscribe(URL url, NotifyListener listener) {
try {
registry.unsubscribe(url, listener);
} finally {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (RegistryServiceListener registryListener : listeners) {
if (registryListener != null) {
try {
registryListener.onUnsubscribe(url);
} catch (RuntimeException t) {
logger.error(t.getMessage(), t);
exception = t;
}
}
}
if (exception != null) {
throw exception;
}
}
}
}
@Override
public List<URL> lookup(URL url) {
return registry.lookup(url);
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import java.util.Collections;
public class RegistryFactoryWrapper implements RegistryFactory {
private RegistryFactory registryFactory;
public RegistryFactoryWrapper(RegistryFactory registryFactory) {
this.registryFactory = registryFactory;
}
@Override
public Registry getRegistry(URL url) {
return new ListenerRegistryWrapper(registryFactory.getRegistry(url),
Collections.unmodifiableList(ExtensionLoader.getExtensionLoader(RegistryServiceListener.class)
.getActivateExtension(url, "registry.listeners")));
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;
@SPI
public interface RegistryServiceListener {
default void onRegister(URL url) {
}
default void onUnregister(URL url) {
}
default void onSubscribe(URL url) {
}
default void onUnsubscribe(URL url) {
}
}

View File

@ -236,7 +236,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
List<AddressListener> supportedListeners = addressListenerExtensionLoader.getActivateExtension(getUrl(), (String[]) null);
if (supportedListeners != null && !supportedListeners.isEmpty()) {
for (AddressListener addressListener : supportedListeners) {
providerURLs = addressListener.notify(providerURLs, getUrl());
providerURLs = addressListener.notify(providerURLs, getUrl(),this);
}
}
refreshOverrideAndInvoker(providerURLs);

View File

@ -0,0 +1 @@
wrapper=org.apache.dubbo.registry.RegistryFactoryWrapper

View File

@ -0,0 +1,55 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class RegistryFactoryWrapperTest {
private RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
@Test
public void test() throws Exception {
RegistryServiceListener listener1 = Mockito.mock(RegistryServiceListener.class);
RegistryServiceListener1.delegate = listener1;
RegistryServiceListener listener2 = Mockito.mock(RegistryServiceListener.class);
RegistryServiceListener2.delegate = listener2;
Registry registry = registryFactory.getRegistry(URL.valueOf("simple://localhost:8080/registry-service"));
URL url = URL.valueOf("dubbo://localhost:8081/simple.service");
registry.register(url);
Mockito.verify(listener1, Mockito.times(1)).onRegister(url);
Mockito.verify(listener2, Mockito.times(1)).onRegister(url);
registry.unregister(url);
Mockito.verify(listener1, Mockito.times(1)).onUnregister(url);
Mockito.verify(listener2, Mockito.times(1)).onUnregister(url);
registry.subscribe(url, Mockito.mock(NotifyListener.class));
Mockito.verify(listener1, Mockito.times(1)).onSubscribe(url);
Mockito.verify(listener2, Mockito.times(1)).onSubscribe(url);
registry.unsubscribe(url, Mockito.mock(NotifyListener.class));
Mockito.verify(listener1, Mockito.times(1)).onUnsubscribe(url);
Mockito.verify(listener2, Mockito.times(1)).onUnsubscribe(url);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
@Activate(order = 1)
public class RegistryServiceListener1 implements RegistryServiceListener {
static RegistryServiceListener delegate;
@Override
public void onRegister(URL url) {
delegate.onRegister(url);
}
@Override
public void onUnregister(URL url) {
delegate.onUnregister(url);
}
@Override
public void onSubscribe(URL url) {
delegate.onSubscribe(url);
}
@Override
public void onUnsubscribe(URL url) {
delegate.onUnsubscribe(url);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
@Activate(order = 2)
public class RegistryServiceListener2 implements RegistryServiceListener {
static RegistryServiceListener delegate;
@Override
public void onRegister(URL url) {
delegate.onRegister(url);
}
@Override
public void onUnregister(URL url) {
delegate.onUnregister(url);
}
@Override
public void onSubscribe(URL url) {
delegate.onSubscribe(url);
}
@Override
public void onUnsubscribe(URL url) {
delegate.onUnsubscribe(url);
}
}

View File

@ -0,0 +1,28 @@
/*
* 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.registry;
import org.apache.dubbo.common.URL;
import org.mockito.Mockito;
public class SimpleRegistryFactory implements RegistryFactory {
@Override
public Registry getRegistry(URL url) {
return Mockito.mock(Registry.class);
}
}

View File

@ -0,0 +1 @@
simple=org.apache.dubbo.registry.SimpleRegistryFactory

View File

@ -0,0 +1,2 @@
listener-one=org.apache.dubbo.registry.RegistryServiceListener1
listener-two=org.apache.dubbo.registry.RegistryServiceListener2

View File

@ -27,6 +27,8 @@ import java.util.Map;
*/
public interface Invocation {
String getTargetServiceUniqueName();
/**
* get method name.
*

View File

@ -44,6 +44,8 @@ public class RpcInvocation implements Invocation, Serializable {
private static final long serialVersionUID = -4355285085441097045L;
private String targetServiceUniqueName;
private String methodName;
private String serviceName;
@ -93,11 +95,13 @@ public class RpcInvocation implements Invocation, Serializable {
setAttachment(APPLICATION_KEY, url.getParameter(APPLICATION_KEY));
}
}
this.targetServiceUniqueName = invocation.getTargetServiceUniqueName();
}
public RpcInvocation(Invocation invocation) {
this(invocation.getMethodName(), invocation.getServiceName(), invocation.getParameterTypes(),
invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker());
this.targetServiceUniqueName = invocation.getTargetServiceUniqueName();
}
public RpcInvocation(Method method, String serviceName, Object[] arguments) {
@ -157,6 +161,15 @@ public class RpcInvocation implements Invocation, Serializable {
return attributes;
}
@Override
public String getTargetServiceUniqueName() {
return targetServiceUniqueName;
}
public void setTargetServiceUniqueName(String targetServiceUniqueName) {
this.targetServiceUniqueName = targetServiceUniqueName;
}
@Override
public String getMethodName() {
return methodName;

View File

@ -134,7 +134,11 @@ public class GenericFilter implements Filter, Filter.Listener {
args[0].getClass().getName());
}
}
return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args, inv.getAttachments(), inv.getAttributes()));
RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), args, inv.getAttachments(), inv.getAttributes());
rpcInvocation.setInvoker(inv.getInvoker());
rpcInvocation.setTargetServiceUniqueName(inv.getTargetServiceUniqueName());
return invoker.invoke(rpcInvocation);
} catch (NoSuchMethodException e) {
throw new RpcException(e.getMessage(), e);
} catch (ClassNotFoundException e) {

View File

@ -28,6 +28,8 @@ import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.support.ProtocolUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -92,4 +94,12 @@ public abstract class AbstractProtocol implements Protocol {
}
protected abstract <T> Invoker<T> protocolBindingRefer(Class<T> type, URL url) throws RpcException;
public Map<String, Exporter<?>> getExporterMap() {
return exporterMap;
}
public Collection<Exporter<?>> getExporters() {
return Collections.unmodifiableCollection(exporterMap.values());
}
}

View File

@ -38,20 +38,22 @@ public class InvokerInvocationHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
// Class<?>[] parameterTypes = method.getParameterTypes();
// if (method.getDeclaringClass() == Object.class) {
// return method.invoke(invoker, args);
// }
// if ("toString".equals(methodName) && parameterTypes.length == 0) {
// return invoker.toString();
// }
// if ("hashCode".equals(methodName) && parameterTypes.length == 0) {
// return invoker.hashCode();
// }
// if ("equals".equals(methodName) && parameterTypes.length == 1) {
// return invoker.equals(args[0]);
// }
Class<?>[] parameterTypes = method.getParameterTypes();
if (method.getDeclaringClass() == Object.class) {
return method.invoke(invoker, args);
}
if ("toString".equals(methodName) && parameterTypes.length == 0) {
return invoker.toString();
}
if ("hashCode".equals(methodName) && parameterTypes.length == 0) {
return invoker.hashCode();
}
if ("equals".equals(methodName) && parameterTypes.length == 1) {
return invoker.equals(args[0]);
}
RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), args);
rpcInvocation.setTargetServiceUniqueName(invoker.getUrl().getServiceKey());
return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args)).recreate();
return invoker.invoke(rpcInvocation).recreate();
}
}

View File

@ -34,6 +34,11 @@ import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
*/
public class MockInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
public String getMethodName() {
return "echo";
}

View File

@ -40,6 +40,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static org.apache.dubbo.common.URL.buildKey;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
@ -152,7 +154,10 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
}
setArguments(args);
String targetServiceName = buildKey((String) getAttachment(PATH_KEY),
(String) getAttachment(GROUP_KEY),
(String) getAttachment(VERSION_KEY));
setTargetServiceUniqueName(targetServiceName);
} catch (ClassNotFoundException e) {
throw new IOException(StringUtils.toString("Read invocation data failed.", e));
} finally {

View File

@ -232,14 +232,6 @@ public class DubboProtocol extends AbstractProtocol {
return Collections.unmodifiableCollection(serverMap.values());
}
public Collection<Exporter<?>> getExporters() {
return Collections.unmodifiableCollection(exporterMap.values());
}
Map<String, Exporter<?>> getExporterMap() {
return exporterMap;
}
private boolean isClientSide(Channel channel) {
InetSocketAddress address = channel.getRemoteAddress();
URL url = channel.getUrl();

View File

@ -125,7 +125,7 @@
<arguments />
<checkstyle.skip>true</checkstyle.skip>
<rat.skip>true</rat.skip>
<revision>2.7.4-SNAPSHOT</revision>
<revision>2.7.4-hsf3-SNAPSHOT</revision>
</properties>
<modules>