changes serve for 3.0

This commit is contained in:
ken.lj 2019-09-04 11:29:38 +08:00
parent de380d5169
commit 549f97ccf3
14 changed files with 67 additions and 9 deletions

View File

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

View File

@ -46,6 +46,11 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation {
this.delegate = invocation; this.delegate = invocation;
} }
@Override
public String getTargetServiceUniqueName() {
return delegate.getTargetServiceUniqueName();
}
@Override @Override
public String getMethodName() { public String getMethodName() {
return delegate.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.common.URL;
import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.Invoker;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -49,6 +48,11 @@ public class CacheTest {
} }
static class NullInvocation implements Invocation { static class NullInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
@Override @Override
public String getMethodName() { public String getMethodName() {
return null; return null;

View File

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

View File

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

View File

@ -356,9 +356,11 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
serviceMetadata.getAttachments().putAll(map); serviceMetadata.getAttachments().putAll(map);
ApplicationModel.initConsumerModel(URL.buildKey(interfaceName, group, version), buildConsumerModel(attributes, serviceMetadata));
ref = createProxy(map); ref = createProxy(map);
ApplicationModel.initConsumerModel(serviceMetadata.getServiceKey(), buildConsumerModel(attributes, serviceMetadata));
serviceMetadata.setTarget(ref); serviceMetadata.setTarget(ref);
serviceMetadata.addAttribute(PROXY_CLASS_REF, ref); serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);
initialized = true; initialized = true;
@ -417,7 +419,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
} }
} else { // assemble URL from register center's configuration } else { // assemble URL from register center's configuration
// if protocols not injvm checkRegistry // if protocols not injvm checkRegistry
if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())){ if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())) {
checkRegistry(); checkRegistry();
List<URL> us = loadRegistries(false); List<URL> us = loadRegistries(false);
if (CollectionUtils.isNotEmpty(us)) { if (CollectionUtils.isNotEmpty(us)) {

View File

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

View File

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

View File

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

View File

@ -41,6 +41,8 @@ public class RpcInvocation implements Invocation, Serializable {
private static final long serialVersionUID = -4355285085441097045L; private static final long serialVersionUID = -4355285085441097045L;
private String targetServiceUniqueName;
private String methodName; private String methodName;
private Class<?>[] parameterTypes; private Class<?>[] parameterTypes;
@ -86,11 +88,13 @@ public class RpcInvocation implements Invocation, Serializable {
setAttachment(APPLICATION_KEY, url.getParameter(APPLICATION_KEY)); setAttachment(APPLICATION_KEY, url.getParameter(APPLICATION_KEY));
} }
} }
this.targetServiceUniqueName = invocation.getTargetServiceUniqueName();
} }
public RpcInvocation(Invocation invocation) { public RpcInvocation(Invocation invocation) {
this(invocation.getMethodName(), invocation.getParameterTypes(), this(invocation.getMethodName(), invocation.getParameterTypes(),
invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker());
this.targetServiceUniqueName = invocation.getTargetServiceUniqueName();
} }
public RpcInvocation(Method method, Object[] arguments) { public RpcInvocation(Method method, Object[] arguments) {
@ -141,6 +145,15 @@ public class RpcInvocation implements Invocation, Serializable {
return attributes; return attributes;
} }
@Override
public String getTargetServiceUniqueName() {
return targetServiceUniqueName;
}
public void setTargetServiceUniqueName(String targetServiceUniqueName) {
this.targetServiceUniqueName = targetServiceUniqueName;
}
@Override @Override
public String getMethodName() { public String getMethodName() {
return methodName; return methodName;

View File

@ -138,7 +138,10 @@ public class GenericFilter extends ListenableFilter {
args[0].getClass().getName()); args[0].getClass().getName());
} }
} }
return invoker.invoke(new RpcInvocation(method, args, inv.getAttachments(), inv.getAttributes())); RpcInvocation rpcInvocation = new RpcInvocation(method, args, inv.getAttachments(), inv.getAttributes());
rpcInvocation.setTargetServiceUniqueName(inv.getTargetServiceUniqueName());
return invoker.invoke(rpcInvocation);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new RpcException(e.getMessage(), e); throw new RpcException(e.getMessage(), e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {

View File

@ -51,7 +51,9 @@ public class InvokerInvocationHandler implements InvocationHandler {
if ("equals".equals(methodName) && parameterTypes.length == 1) { if ("equals".equals(methodName) && parameterTypes.length == 1) {
return invoker.equals(args[0]); return invoker.equals(args[0]);
} }
RpcInvocation rpcInvocation = new RpcInvocation(method, args);
rpcInvocation.setTargetServiceUniqueName(invoker.getUrl().getServiceKey());
return invoker.invoke(new RpcInvocation(method, 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 { public class MockInvocation implements Invocation {
@Override
public String getTargetServiceUniqueName() {
return null;
}
public String getMethodName() { public String getMethodName() {
return "echo"; return "echo";
} }

View File

@ -37,10 +37,12 @@ import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
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.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument;
public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable { public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable {
@ -138,7 +140,10 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
} }
setArguments(args); setArguments(args);
String targetServiceName = buildKey((String) getAttachment(PATH_KEY),
(String) getAttachment(GROUP_KEY),
(String) getAttachment(VERSION_KEY));
setTargetServiceUniqueName(targetServiceName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new IOException(StringUtils.toString("Read invocation data failed.", e)); throw new IOException(StringUtils.toString("Read invocation data failed.", e));
} finally { } finally {