提交 89a27ce1 编写于 作者: L liangfei0201

DUBBO-469 调整Filter链顺序

上级 40984fd0
......@@ -34,6 +34,8 @@ import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.support.RpcUtils;
/**
* MonitorFilter. (SPI, Singleton, ThreadSafe)
......@@ -82,12 +84,7 @@ public class MonitorFilter implements Filter {
int concurrent = getConcurrent(invoker, invocation).get(); // 当前并发数
String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY);
String service = invoker.getInterface().getName(); // 获取服务名称
String method = invocation.getMethodName(); // 获取方法名
if (Constants.$INVOKE.equals(method)
&& invocation.getArguments().length > 0
&& invocation.getArguments()[0] instanceof String) {
method = (String) invocation.getArguments()[0];
}
String method = RpcUtils.getMethodName(invocation); // 获取方法名
URL url = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY);
Monitor monitor = monitorFactory.getMonitor(url);
int localPort;
......
......@@ -111,7 +111,7 @@ public class RpcInvocation implements Invocation, Serializable {
public void setInvoker(Invoker<?> invoker) {
this.invoker = invoker;
}
public String getMethodName() {
return methodName;
}
......
......@@ -29,7 +29,7 @@ import com.alibaba.dubbo.rpc.RpcResult;
*
* @author william.liangf
*/
@Activate(group = Constants.PROVIDER)
@Activate(group = Constants.PROVIDER, order = -110000)
public class EchoFilter implements Filter {
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
......
......@@ -35,7 +35,7 @@ import com.alibaba.dubbo.rpc.service.GenericException;
*
* @author william.liangf
*/
@Activate(group = Constants.PROVIDER)
@Activate(group = Constants.PROVIDER, order = -100000)
public class GenericFilter implements Filter {
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
......
......@@ -39,7 +39,7 @@ import com.alibaba.dubbo.rpc.service.GenericException;
*
* @author william.liangf
*/
@Activate(group = Constants.CONSUMER, value = Constants.GENERIC_KEY)
@Activate(group = Constants.CONSUMER, value = Constants.GENERIC_KEY, order = 100000)
public class GenericImplFilter implements Filter {
private static final Logger logger = LoggerFactory.getLogger(GenericImplFilter.class);
......
......@@ -112,17 +112,41 @@ public class RpcUtils {
}
public static String getMethodName(Invocation invocation){
String methodName;
if(Constants.$INVOKE.equals(invocation.getMethodName())
&& invocation.getArguments() != null
&& invocation.getArguments().length >0
&& invocation.getArguments()[0] != null){
//the frist argument must be real method name;
methodName = invocation.getArguments()[0].toString();
}else {
methodName = invocation.getMethodName();
&& invocation.getArguments().length > 0
&& invocation.getArguments()[0] instanceof String){
return (String) invocation.getArguments()[0];
}
return methodName;
return invocation.getMethodName();
}
public static Object[] getArguments(Invocation invocation){
if(Constants.$INVOKE.equals(invocation.getMethodName())
&& invocation.getArguments() != null
&& invocation.getArguments().length > 2
&& invocation.getArguments()[2] instanceof Object[]){
return (Object[]) invocation.getArguments()[2];
}
return invocation.getArguments();
}
public static Class<?>[] getParameterTypes(Invocation invocation){
if(Constants.$INVOKE.equals(invocation.getMethodName())
&& invocation.getArguments() != null
&& invocation.getArguments().length > 1
&& invocation.getArguments()[1] instanceof String[]){
String[] types = (String[]) invocation.getArguments()[1];
if (types == null) {
return new Class<?>[0];
}
Class<?>[] parameterTypes = new Class<?>[types.length];
for (int i = 0; i < types.length; i ++) {
parameterTypes[i] = ReflectUtils.forName(types[0]);
}
return parameterTypes;
}
return invocation.getParameterTypes();
}
public static boolean isAsync(URL url, Invocation inv) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册