dubbo源码分析11——服务暴露2_doExport()方法分析
- protected synchronized void doExport() {
//如果是已经解除暴露的接口则抛出异常- if (unexported) {
- throw new IllegalStateException("Already unexported!");
- }
//如果已经暴露则不需要重复暴露- if (exported) {
- return;
- }
- exported = true;
- if (interfaceName == null || interfaceName.length() == 0) {
- throw new IllegalStateException("<dubbo:service interface=\"\" /> interface not allow null!");
- }
- checkDefault();
- if (provider != null) {
- if (application == null) {
- application = provider.getApplication();
- }
- if (module == null) {
- module = provider.getModule();
- }
- if (registries == null) {
- registries = provider.getRegistries();
- }
- if (monitor == null) {
- monitor = provider.getMonitor();
- }
- if (protocols == null) {
- protocols = provider.getProtocols();
- }
- }
- if (module != null) {
- if (registries == null) {
- registries = module.getRegistries();
- }
- if (monitor == null) {
- monitor = module.getMonitor();
- }
- }
- if (application != null) {
- if (registries == null) {
- registries = application.getRegistries();
- }
- if (monitor == null) {
- monitor = application.getMonitor();
- }
- }
// ref是接口实现类引用,GenericService是泛接口,这个方式主要用于服务器端没有API接口及模型类元的情况,参数及返回值中的所有POJO均用Map表示,通常用于框架集成,比如:实现一个通用的远程服务Mock框架,可通过实现GenericService接口处理所有服务请求。- if (ref instanceof GenericService) {
- interfaceClass = GenericService.class;
- if (StringUtils.isEmpty(generic)) {
- generic = Boolean.TRUE.toString();
- }
- } else {
- try {
- interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
- .getContextClassLoader());
- } catch (ClassNotFoundException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- checkInterfaceAndMethods(interfaceClass, methods);
- checkRef();
- generic = Boolean.FALSE.toString();
- }
//local属性已被弃用,由stub属性替代- if(local !=null){
- if(local=="true"){
- local=interfaceName+"Local";
- }
- Class<?> localClass;
- try {
- localClass = ClassHelper.forNameWithThreadContextClassLoader(local);
- } catch (ClassNotFoundException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- if(!interfaceClass.isAssignableFrom(localClass)){
- throw new IllegalStateException("The local implemention class " + localClass.getName() + " not implement interface " + interfaceName);
- }
- }
//stub设为true,表示使用缺省代理类名,即:接口名 + Local后缀,服务接口客户端本地代理类名,用于在客户端执行本地逻辑,如本地缓存等,该本地代理类的构造函数必须允许传入远程代理对象,构造函数如:public XxxServiceLocal(XxxService xxxService)- if(stub !=null){
- if(stub=="true"){
- stub=interfaceName+"Stub";
- }
- Class<?> stubClass;
- try {
- stubClass = ClassHelper.forNameWithThreadContextClassLoader(stub);
- } catch (ClassNotFoundException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- if(!interfaceClass.isAssignableFrom(stubClass)){
- throw new IllegalStateException("The stub implemention class " + stubClass.getName() + " not implement interface " + interfaceName);
- }
- }
- checkApplication();
- checkRegistry();
- checkProtocol();
- appendProperties(this);
- checkStubAndMock(interfaceClass);
- if (path == null || path.length() == 0) {
- path = interfaceName;
- }
- doExportUrls();
- }
在doExport方法中,对要暴露的服务进行了一系列的检查,检查provider,application,module,registries,monitor这些参数是否为空,是否是GenericService类型的服务,检查要注册的bean的引用和方法等。在方法的最后会调用doExportUrls方法。
dubbo源码分析11——服务暴露2_doExport()方法分析的更多相关文章
- dubbo源码分析10——服务暴露1_export()方法分析
ServiceConfig类中的export()方法,是dubbo服务暴露的入口方法,被触发的时机有两个: 1. spring容器初始化完成所有的bean实例后,通过事件机制触发 2. 实现Initi ...
- dubbo源码分析12——服务暴露3_doExportUrls()方法分析
本文紧接上文,doExportUrls()方法位于ServiceConfig类中,代码入口如下: private void doExportUrls() { List<URL> regis ...
- dubbo源码学习(四):暴露服务的过程
dubbo采用的nio异步的通信,通信协议默认为 netty,当然也可以选择 mina,grizzy.在服务端(provider)在启动时主要是开启netty监听,在zookeeper上注册服务节点, ...
- Dubbo源码学习之-服务导出
前言 忙的时候,会埋怨学习的时间太少,缺少个人的空间,于是会争分夺秒的工作.学习.而一旦繁忙的时候过去,有时间了之后,整个人又会不自觉的陷入一种懒散的状态中,时间也显得不那么重要了,随便就可以浪费掉几 ...
- [dubbo 源码之 ]1. 服务提供方如何发布服务
服务发布 启动流程 1.ServiceConfig#export 服务提供方在启动部署时,dubbo会调用ServiceConfig#export来激活服务发布流程,如下所示: Java API: ` ...
- dubbo 源码学习1 服务发布机制
1.源码版本:2.6.1 源码demo中采用的是xml式的发布方式,在dubbo的 DubboNamespaceHandler 中定义了Spring Framework 的扩展标签,即 <dub ...
- dubbo源码阅读之服务导出
dubbo服务导出 常见的使用dubbo的方式就是通过spring配置文件进行配置.例如下面这样 <?xml version="1.0" encoding="UTF ...
- dubbo源码阅读之服务目录
服务目录 服务目录对应的接口是Directory,这个接口里主要的方法是 List<Invoker<T>> list(Invocation invocation) throws ...
- dubbo源码阅读之服务引入
服务引入 服务引入使用reference标签来对要引入的服务进行配置,包括服务的接口 ,名称,init,check等等配置属性. 在DubboNamespaceHandler中,我们可以看到refer ...
随机推荐
- 给笔记本更换SSD硬盘
给笔记本更换SSD硬盘... ---------- 给笔记本更换SSD硬盘 带活动字样的一个新的系统盘,一个之前的主分区的系统盘 ----------------------------
- Oracle 数据库分页查询与排序分页查询
一.分页查询 原始查询语句 SELECT * FROM NASLE_WFSHH 修改为分页查询语句,加上 ROWNUM 列.此处为查询第 1 页,每页 9 条数据 SELECT * FROM ( SE ...
- EL表达式遍历集合获取下标
如题,HTML页面很多时候需要循环遍历一个集合,并且获得集合元素得下标做判断,或者把下标传递给后台作为参数 那么我们就需要用到EL表达式的varStatus 代码一:<c:forEach var ...
- jQuery源码解析对象实例化与jQuery原型及整体构建模型分析(一)
//源码剖析都基于jQuery-2.0.3版本,主要考虑到兼容IE 一.关于jQuery对象实例化的逻辑: 整个jQuery程序被包裹在一个匿名自执行行数内: (function(window,und ...
- Spark Submitting Applications浅析
Submitting Applications提交应用程序 在spark的bin目录下spark-submit脚本被用于在集群中启动应用程序.它可以通过一个统一的接口来使用Spark支持的所有集群管理 ...
- Android弹出窗口
protected void PopUp() { final PopupWindow popup = new PopupWindow(TestActivity.this); View popView ...
- luogu 1268 树的重量
打眼一看就是最小生成树嘛,但经过板子wa掉的经历后得知,,emmmm,原来是, 构造! (虽然不知是什么但觉得听起来很厉害的样子...手动微笑) n=2的情况 自然就是g(1,2) n=3的情况,由于 ...
- aspnetpager使用介绍
AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化, 效果如下: 下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首 ...
- luogu P4385 [COCI2009]Dvapravca
传送门 我真的弱,正解都不会还打了个错的暴力 考虑平行线与x轴平行,那么可以按照y为第一关键字升序,x为第二关键字升序排序,然后合法的一段红点就是连续的一段,答案也就是最大的连续红色段 推广到一般情况 ...
- Kaldi的BaseLine训练过程
steps/train_mono.sh --nj "$train_nj" --cmd "$train_cmd" data/train data/lang exp ...