提交 fa5b5a4b 编写于 作者: W william.liangf

DUBBO-141 Invocation增加getUrl(),代替Channel上的getUrl()

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@687 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 f0678537
......@@ -54,9 +54,7 @@ public class ChannelWrappedInvoker<T> extends AbstractInvoker<T> {
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
RpcInvocation inv = new RpcInvocation(invocation.getMethodName(),
invocation.getParameterTypes(), invocation.getArguments(),
invocation.getAttachments());
RpcInvocation inv = new RpcInvocation(invocation);
//拿不到client端export 的service path.约定为interface的名称.
inv.setAttachment(Constants.PATH_KEY, getInterface().getName());
inv.setAttachment(RpcConstants.CALLBACK_SERVICE_KEY, serviceKey);
......
......@@ -68,8 +68,7 @@ public class DubboInvoker<T> extends AbstractInvoker<T> {
//the frist argument must be real method name;
methodName = invocation.getArguments()[0].toString();
}else {
inv = new RpcInvocation(invocation.getMethodName(), invocation.getParameterTypes(),
invocation.getArguments(), invocation.getAttachments());
inv = new RpcInvocation(invocation);
methodName = invocation.getMethodName();
}
inv.setAttachment(Constants.PATH_KEY, getUrl().getPath());
......
......@@ -16,6 +16,8 @@
package com.alibaba.dubbo.rpc;
import java.util.Map;
import com.alibaba.dubbo.common.URL;
/**
* Rpc invocation. (API, Prototype, ThreadSafe)
......@@ -26,7 +28,14 @@ import java.util.Map;
* @author qian.lei
* @author william.liangf
*/
public interface Invocation {
public interface Invocation {
/**
* get the url.
*
* @return url.
*/
URL getUrl();
/**
* get method name.
......
......@@ -21,6 +21,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.common.URL;
/**
* Rpc invocation.
*
......@@ -38,29 +40,49 @@ public class RpcInvocation implements Invocation, Serializable {
private Object[] arguments;
private Map<String, String> attachments;
private transient URL url;
public RpcInvocation() {
}
public RpcInvocation(Invocation invocation) {
this(invocation.getMethodName(), invocation.getParameterTypes(),
invocation.getArguments(), invocation.getAttachments(), invocation.getUrl());
}
public RpcInvocation(Method method, Object[] arguments) {
this(method.getName(), method.getParameterTypes(), arguments, null);
this(method.getName(), method.getParameterTypes(), arguments, null, null);
}
public RpcInvocation(Method method, Object[] arguments, Map<String, String> attachment) {
this(method.getName(), method.getParameterTypes(), arguments, attachment);
this(method.getName(), method.getParameterTypes(), arguments, attachment, null);
}
public RpcInvocation(String methodName, Class<?>[] parameterTypes, Object[] arguments) {
this(methodName, parameterTypes, arguments, null);
this(methodName, parameterTypes, arguments, null, null);
}
public RpcInvocation(String methodName, Class<?>[] parameterTypes, Object[] arguments, Map<String, String> attachments) {
this.methodName = methodName;
this.parameterTypes = parameterTypes == null ? new Class<?>[0] : parameterTypes;
this.arguments = arguments == null ? new Object[0] : arguments;
this.attachments = attachments == null ? new HashMap<String, String>() : attachments;
this(methodName, parameterTypes, arguments, attachments, null);
}
public RpcInvocation(String methodName, Class<?>[] parameterTypes, Object[] arguments, Map<String, String> attachments, URL url) {
this.methodName = methodName;
this.parameterTypes = parameterTypes == null ? new Class<?>[0] : parameterTypes;
this.arguments = arguments == null ? new Object[0] : arguments;
this.attachments = attachments == null ? new HashMap<String, String>() : attachments;
this.url = url;
}
public URL getUrl() {
return url;
}
public void setUrl(URL url) {
this.url = url;
}
public String getMethodName() {
return methodName;
}
......@@ -124,5 +146,5 @@ public class RpcInvocation implements Invocation, Serializable {
+ Arrays.toString(parameterTypes) + ", arguments=" + Arrays.toString(arguments)
+ ", attachments=" + attachments + "]";
}
}
\ No newline at end of file
......@@ -53,7 +53,7 @@ public class GenericFilter implements Filter {
args = new Object[params.length];
}
args = PojoUtils.realize(args, params);
Result result = invoker.invoke(new RpcInvocation(method, args));
Result result = invoker.invoke(new RpcInvocation(method, args, inv.getAttachments()));
if (result.hasException()) {
return new RpcResult(new GenericException(result.getException()));
}
......
......@@ -123,7 +123,8 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
+ " use dubbo version " + Version.getVersion()
+ " is DESTROYED, can not be invoked any more!");
}
RpcInvocation invocation = (RpcInvocation) inv;
RpcInvocation invocation = (RpcInvocation) inv;
invocation.setUrl(getUrl());
Map<String, String> attachments = new HashMap<String, String>();
if (attachment != null && attachment.size() > 0) {
attachments.putAll(attachment);
......
......@@ -19,6 +19,7 @@ import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
/**
......@@ -51,4 +52,8 @@ public class MockInvocation implements Invocation {
return attachments;
}
public URL getUrl() {
return null;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册