Dubbo服务者
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
創(chuàng)建代理對(duì)象
com.alibaba.dubbo.config.ServiceConfig#export通過(guò)消費(fèi)者export()方法可以找到以上方法,消費(fèi)者需要根據(jù)配置的接口生成代理對(duì)象。 ###生成Invoker
以上通過(guò)工廠生成服務(wù)者的Invoker,Wrapper.getWrapper里面通過(guò)接口生成新Wrapper及接口的實(shí)現(xiàn)。 生成的具體代碼 public class AClass$sw1 extends Wrapper {public static String[] pns;public static Map pts;public static String[] mns;public static String[] dmns;public static Class[] mts0;public static Class[] mts1;public AClass$sw1() {}public String[] getPropertyNames(){ return pns; }public boolean hasProperty(String n){ return pts.containsKey(n); }public Class getPropertyType(String n){ return (Class)pts.get(n); }public String[] getMethodNames(){ return mns; }public String[] getDeclaredMethodNames(){ return dmns; }public void setPropertyValue(Object o, String n, Object v){ AClass w; try{ w = ((AClass)o); }catch(Throwable e){ throw new IllegalArgumentException(e); }if( n.equals("field1") ){ w.field1=((Boolean) v).booleanValue(); return; }if( n.equals("field2") ){ w.field2=((Boolean) v).booleanValue(); return; }throw new NoSuchPropertyException("Not found property $2 filed or setter method in class AClass."); }public Object getPropertyValue(Object o, String n){AClass w; try{ w = ((AClass)o); }catch(Throwable e){ throw new IllegalArgumentException(e); }if( n.equals("field1") ){ return ($w)w.field1; }if( n.equals("field2") ){ return ($w)w.field2; }// getField11if( n.equals("field11") ){ return ($w)w.getField11(); }// isField21|hasField21|canField21if( n.equals("field21") ){ return ($w)w.isField21(); }throw new NoSuchPropertyException("Not found property $2 filed or setter method in class AClass."); }public Object invokeMethod(Object o, String n, Class[] p, Object[] v) throws InvocationTargetException {AClass w; try{ w = ((AClass)o); }catch(Throwable e){ throw new IllegalArgumentException(e); }try{if( "method1".equals( n ) && p.length == && p[0].getName().equals("Boolean") && p[1].getName().equals("Integer") ) { return ($w)w.method1(((Boolean)v[0]).booleanValue(), ((Number)v[1]).intValue());}} catch(Throwable e) {throw new java.lang.reflect.InvocationTargetException(e); }throw new NoSuchMethodException("Not found method n in class AClass."); } }服務(wù)者生成了對(duì)應(yīng)的Invoker,通過(guò)DubboProtocol暴露Exporter。
轉(zhuǎn)載于:https://my.oschina.net/u/1269959/blog/751755
總結(jié)
- 上一篇: Challenge: Machine L
- 下一篇: Dependence Inversion