1 架构及核心组件
为了便于理解,分析前所看一下整个架构及相关组件说明
这里直接看官方文档就了,介绍非常清晰
整体架构说明
http://dubbo.apache.org/books/dubbo-dev-book/design.html
集群容错
http://dubbo.apache.org/books/dubbo-user-book/demos/fault-tolerent-strategy.html
2 源码分析
分析源码前,必须贴一张官方的调用链图
为了方便分析服务集群路由,负载均衡,建议开多个几服务提供方;
接着上一编的代理始;
public class InvokerInvocationHandler implements InvocationHandler {
private final Invoker<?> invoker;
public InvokerInvocationHandler(Invoker<?> handler) {
this.invoker = handler;
}
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]);
}
//调用链始端
return invoker.invoke(new RpcInvocation(method, args)).recreate();
}
}