通过组件调用接口

1     Level 1 Design Description第一层设计描述

1.1  System Architecture系统结

智动运维平台及其组件都是运行在同一个tomcat进程中,现阶段组件与组件间的接口调用都是借助于WbService技术完成。WebService技术底层实现本质是RPCHTTP+XML),以下是RPC的调用示意图:

1)服务消费方(client)调用以本地调用方式调用服务;

2clientstub接收到调用后负责将方法、参数等组装成能够进行网络传输的消息体;

3clientstub找到服务地址,并将消息发送到服务端;

4serverstub收到消息后进行解码;

5serverstub根据解码结果调用本地的服务;

6)本地服务执行并将结果返回给serverstub

7serverstub将返回结果打包成消息并发送至消费方;

8clientstub接收到消息,并进行解码;

9)服务消费方得到最终结果。

WebService技术不适用于智动运维平台的组件间的调用场景,主要有如下两点考虑:

a.     WebService技术底层借助HTTP协议完成接口间调用,适合进程间程序调用;

b.    WebService技术借助XML进行程序间的调用数据传输,性能略低。

1.1.1 Description of the Architecture系统结构描述

接口注册模块主要职能是改善组件间借助WebService技术实现同tomcat进程中接口调用现状,并实现组件的对外接口由平台统一管理,由平台管理的接口可直接供其他组件调用。同时在平台统一管理组件对外接口的基础上,平台可根据组件需要将指定接口作为智动运维平台的北向接口对外统一发布。

接口注册模块完成上述功能需要做的主要有2方面:

1)通过接口注册机制获取到所有组件的对外接口,统一管理;

2)通过接口请求转发机制实现组件间的相互调用需求。

1.1.2 Representation of the BusinessFlow业务流程说明

1.   接口注册

组件按照平台的对外接口发布规则,在指定对外接口类上加上注解“@InterfaceRegister”即可,在项目启动阶段借助Spring的依赖注入机制将所有组件带有注解“@InterfaceRegister”的接口类中所有接口注入平台统一接口管理中。

2.   接口调用

组件通过平台的统一接口调用代理管理器获得要调用的接口代理对象,通过接口代理对象再调用指定的接口获取返回值。

1.2     Decomposition Description分解描述

1.2.1    Module/Subsystem 1 Description接口注册描述

通过接口注册模块的规范及机制,让所有的组件对外接口都完成注册,并在接口注册模块由平台统一管理。

1.2.2    Module/Subsystem 1 Description接口调用描述

通过接口转发机制来实现组件间的接口调用。

1.2.3    Data Design数据设计

1.    Data Entity 1Description数据实体1描述

1.3     Dependency Description依赖性描述

1.4     Interface Description接口描述

1.4.1 Module/Subsystem 1  Interface Description模块/子系统1的接口描述

Name名称:创建默认版本的接口实现类代理对象

Description说明:接口注册模块提供;供调用者调用来创建目标接口实现类代理对象,主要参数为(interfaceClassFullName:接口类的全限定类名,methodName:方法名称,parameterType:参数类型,parameter:参数),返回调用目标组件的返回结果。

Definition定义:public Object call(final StringinterfaceClassFullName, final String methodName, final Class<?>[]parameterTypes,final Object...parameters) throws MapNotExistInterfaceBeanException,InvokeMethodParameterException, MethodNameOrParameterTypeError{}

 

2     Level 2 Design Description第二层设计描述

2.1     接口注册模块

接口注册模块主要是按照一定的规范实现一种机制,让所有组件借助该机制将接口注册到平台,供平台接口注册模块统一管理。

 

2.1.1    Design Description模块设计描述

规范
1.   组件接口规范

使用  组件名+Service 形式定义组件接口的接口名称。

方法由组件定义但是参数和返回值要有一定规范

方法参数:为基本类型, 若果是封装类型将其拆分封装为JSon对象。

返回值:为基本类型,若果是封装类型将其拆分封装为JSon对象。

2.   组件接口实现类规范

使用  组件名+ServiceImpl 的形式定义组件接口实现类的名称。并在类明上加上注解@InterfaceRegister(组件名+Service.class)。

方法由组件实现。

3.   调用时的规范

调用平台代理器的call方法时需要传入相应参数:

String interfaceClassFullName 接口类的全限定类名

       String methodName:调用组件的方法名称

Class<?>[] parameterType:方法中参数类型

Object[] parameter:方法参数

4.   返回值的规范

如果参数传入有误则向组件抛出相应异常,如果为正确的值则返回组件想要得到的结果。

类名传入错误异常:MapNotExistInterfaceBeanException

方法名或参数类型异常:MethodNameOrParameterTypeError

参数异常:InvokeMethodParameterException

返回值:根据调用组件方法的返回值进行类型转换。

组件调用时可根据对应异常做出相应处理。

       优点:

              可以解耦组件之间的直接联系,将组件接口的具体实现类纳入spring容器中统一管理,只要组件在spring中注册,其他组件便可以使用,提高了项目的灵活性,使项目便于管理。

       缺点:

              调用时比较麻烦,组建间需要事先约定知晓调用组件接口类的全限定名,方法名称,参数类型,参数,将以上参数传入组件接口代理类中的方法来实现调用其他组件的方法。而且返回值为Object类型,不知道具体类型,返回值需要组件间约定为基本类型的对象。在传入数据有误时,需要给每个参数定义一个异常类型,用于向上层抛出,最后调用者使用try-catch处理相应异常。

使用技术

1.     使用了动态代理和CGLib反射调用组件接口方法。

2.     使用Spring注解的放式,通过自定义注解,为组件实现的接口类做标注,注入到Spring容器中。

3.     创建相应的Map属性,为其赋值,key为通过Spring容器获取自定义注解对象的全限定类的类名,value为相应组件接口的Bean对象。

5.   InterfaceRegister  接口注册注解(标注在服务实现类上)

     标注组件对外提供的具体实现类,便于Spring扫描管理。其中定义服务接口类和服务版本号。

 

2.1.2    Function Illustration功能实现说明

2.2     接口调用模块

2.2.1    Design Description模块设计描述

1.   InterfaceManager  统一接口管理器

a)    在该类中定义一个存放服务名服务对象之间映射关系的Map属性。

b)   实现ApplicationContextAware接口,用于在加载Spring配置文件时,会自动调用

ApplicationContextAware 接口中的public void setApplicationContext(ApplicationContext context) throwsBeansException方法,在该方法中为Map赋值--将服务名(组件实现类的全限定类名)作为Key,将组件实现类的对象作为Value存放到Map中。

c)     handle(..)方法,用于CGLib执行反射调用,获取相应组件方法的返回值。

2.   PlatInterfaceProxy  组件接口代理类

该类属于组件调用的直接使用对象,组件调用该类的public Object call(final String interfaceClassFullName, final StringmethodName, final Class<?>[] parameterTypes,final Object... parameters) 方法,传入指定参数,获取相应数据。

a)      在该类中定义一个InterfaceManager对象作为属性,用InterfaceManager对象中handle

方法来执行具体的CGLib执行反射调用。

b)      定义的call方法用于转发调用者传入的参数,调用者调用该方法获取想要的返回值时,如果传入的值有误,则需要定义返回值格式,便于区别传入参数是否正确,想要的结果是否得到。

3.   组件A  组件调用 B组件的方法

A组件类中有一个调用B组件的测试方法,该方法通过传入类的全限定类名、方法名、参数类型、参数来调用PlatInterfaceProxy类中的call方法。

调用方法,调用组件的具体实现方法。

2.2.2    Function Illustration功能实现说明

 

 

3     Database Design(Optional)数据库设计(可选)

This section could listall the entities such as data stores (tables, stored procedures, triggers,etc.); a verbose description of what that entity pertains to and list of allits attributes. For each of the attributes, its database, the data size,specific constraints and a verbose description of that attribute should bespecified. All specific constraints for that entity and its relationship withother entities should also be noted.

本节列出所有的数据存储类的实体(表、存储过程、触发器等),详细描述实体的内容和并列出全部属性。对每个属性,详细描述其数据库、数据大小、特定约束。实体的所有约束及实体间的关系也要注明。

3.1     Entities Definition实体定义

3.1.1    Decomposition Description分解描述

Represent the designconsiderations and constraint rules.

The key tables, viewsand the items, functions, storage requirements, integrity constraints andstresses should be defined here. The initial setup data should be consideredconcerning the static tables.

阐述设计思路及约束规则。

详细定义每个关键数据表、视图中的各个字段属性、存储要求、完整性约束、功能、注意事项,静态数据表可考虑定义初始配置记录。

 

3.1.2    Internal Dependency Description内部依赖性描述

E-R diagrams could beused to depict the relationships between the entities, and the requirements ofthe storage spaces, performances and integrity should be analyzed.

使用E-R图描述实体间的关联依赖关系,分析对存取空间、性能、完整性的要求。

 

3.2     Behaviors Definition行为定义

3.2.1    Decomposition Description分解描述

The stored proceduresand triggers should be classified according to its functions, etc., to bedescribed in detail and decomposed. The main functions of every sort of SPs ortriggers should also be represented.

Recount the functions,input, output, return value, return set, the depended tables and storedprocedures, and special requirements such as transactions.

根据功能或其他方式对存储过程/触发器进行归类,便于进一步细化和分解,并说明每类存储过程/触发器主要功能。

详细定义每个存储过程(触发器)的功能、输入输出参数、返回值、返回的记录集、依赖的数据表和存储过程,以及一些特殊要求(比如需要启用事务等)。

 

3.2.2    External Dependency Description外部依赖性描述

Represent thedependency with the external modules.

描述与其它模块之间的依赖关系。

 

3.2.3    Internal Dependency Description内部依赖性描述

Represent thedependency between the internal stored procedures, triggers, tables and views.

描述存储过程间、存储过程和数据表/视图间依赖关系。

 

4     Component View组件视图

4.1     Executable Components系统运行组件

Component diagrams areused to represent executable components, including executable files (EXE),Dynamic Link Libraries (DLL), etc.

Deployment diagrams areused to show the mapping of processes to hardware.

使用Component图、deployment图来描述系统的运行组件(EXE文件、DLL等),及其网络部署情况。

 

4.2     Source Code Directories文件组织形式

A directory tree isused to show how the source files are organized.

描述源代码文件的目录结构(文件夹中各个目录下应存放什么文件)。

 

5     Process View进程视图

This section describesthe system's decomposition into lightweight processes (single threads ofcontrol) and heavyweight processes (groupings of lightweight processes).Organize the section by groups of processes that communicate or interact.Describe the main modes of communication between processes, such as messagepassing, interrupts, and rendezvous.

本节描述将系统分解为轻量级进程(单个控制线程)和重量级进程(成组的轻量级进程)的过程。本节按照各个通信或交互的进程组来加以组织。说明进程之间的主要通信模式,例如消息传递、中断和会合。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值