Dubbo服务者

创建代理对象

com.alibaba.dubbo.config.ServiceConfig#export

通过消费者export()方法可以找到以上方法,消费者需要根据配置的接口生成代理对象。 ###生成Invoker 输入图片说明 输入图片说明

以上通过工厂生成服务者的Invoker,Wrapper.getWrapper里面通过接口生成新Wrapper及接口的实现。
生成的具体代码
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; 
        }
        // getField11
        if( n.equals("field11") ){ 
            return ($w)w.getField11(); 
        }
        // isField21|hasField21|canField21
        if( 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."); 
    }
}

服务者生成了对应的Invoker,通过DubboProtocol暴露Exporter。

评论

暂无评论