Dubbo 学习记录


1    ExtensionLoader对于每个扩展点都是唯一的,也就是每个扩展点一个ExtensionLoader对象,里面有各种缓存对象,用于缓存配置文件中定义的配置。包括

    private final ConcurrentMap<Class<?>, String> cachedNames = new ConcurrentHashMap<Class<?>, String>();
    
    private final Holder<Map<String, Class<?>>> cachedClasses = new Holder<Map<String,Class<?>>>();

    private final Map<String, Activate> cachedActivates = new ConcurrentHashMap<String, Activate>();

    private volatile Class<?> cachedAdaptiveClass = null;

    private final ConcurrentMap<String, Holder<Object>> cachedInstances = new ConcurrentHashMap<String, Holder<Object>>();

    private String cachedDefaultName;

    private final Holder<Object> cachedAdaptiveInstance = new Holder<Object>();
    private volatile Throwable createAdaptiveInstanceError;

    private Set<Class<?>> cachedWrapperClasses;
    
    private Map<String, IllegalStateException> exceptions = new ConcurrentHashMap<String, IllegalStateException>();

2    Dubbo的Wrapper机制

        在加载SPI方式的FILE后,去加载一个扩展点的时候,获取对应文件,以Protocol为例

registry=com.alibaba.dubbo.registry.integration.RegistryProtocol
filter=com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper
listener=com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper
mock=com.alibaba.dubbo.rpc.support.MockProtocol
injvm=com.alibaba.dubbo.rpc.protocol.injvm.InjvmProtocol
dubbo=com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol
rmi=com.alibaba.dubbo.rpc.protocol.rmi.RmiProtocol
hessian=com.alibaba.dubbo.rpc.protocol.hessian.HessianProtocol
com.alibaba.dubbo.rpc.protocol.http.HttpProtocol
com.alibaba.dubbo.rpc.protocol.webservice.WebServiceProtocol
thrift=com.alibaba.dubbo.rpc.protocol.thrift.ThriftProtocol
memcached=memcom.alibaba.dubbo.rpc.protocol.memcached.MemcachedProtocol
redis=com.alibaba.dubbo.rpc.protocol.redis.RedisProtocol


在加载上面的类时,会处理以下几种情况

1  如果扩展点实现类包括了Adaptive的注解,则设置为该扩展点的适配实现,对应设置为cachedAdaptiveClass

2  如果不符合1,则扩展点实现类是否能执行clazz.getConstructor(type);如果可以,则说明此实现类是包装类,则放入cachedWrapperClasses

3  如果执行clazz.getConstructor(type)报错则看是否在文件中配置了key,例如上述中的com.alibaba.dubbo.rpc.protocol.http.HttpProtocol就没有对应的key,如果有key,则看扩展点实现类是否包括Activate的注解,如果有则放入对应的缓存变量cachedActivates,如果没有注解,则记录对应的cachedNames和extensionClasses








阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页