Sofa学习总结.pdf_第1页
Sofa学习总结.pdf_第2页
Sofa学习总结.pdf_第3页
Sofa学习总结.pdf_第4页
Sofa学习总结.pdf_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

S So of fa a 学学习习总总结结 作作者者版版本本时时间间 吕方V0 0 12008 11 13 1 搭建 sofa 平台运行环境 首先需要对从 confluence 中下载一个支持包 地址 8080 pages viewpage action pageId 3703045 或者直接使用链接 8080 download attachments 3703045 sofa core archetype zip 下载后解压工程 然后 Maven打包并 install 到本地资源仓库中 如果没有将这个小工程放到 Maven的本地资源仓 库中则后面操作都会有很多小麻烦 接下来开始建立一个小的 sofa 平台 step1 运行命令 E mvnarchetype generate DarchetypeCatalog local 运行后命令行内容提示如下 step2 根据提示 输入信息如下 Choose anumber 1 1 继续执行 提示输入内容如下 Define value forsofa app name demo 继续执行 提示输入内容如下 Define value forartifactId demo 继续执行 如果不想改变版本信息 就直接留空不用输入任何信息 直接往下执行 运行后命令行提示内容如下 step3 根据提示输入 Y 继续执行 执行成功后提示信息如下 step4 生成 eclispe 工程 导入 IDE 可以导入 9 个子工程 其中 demo test test 工程用于测试 step5 对 com alipay sofa demo test service TestDemoCalcFacade 类进行修改 找到代码 修改后如下 运行测试用例 进行环境测试 如果通过则说明平台搭建 OK 了 2 demo core engine 使用总结 a 关于 demo core engine xml 其中扩展点名字为 executor 在 生 成 好 的 demo 中 engine 向 下 提 供 了 一 个 扩 展 点 所 有 的 扩 展 点 都 被 封 装 成 了 一 个 com alipay sofa demo core engine api DemoCalcExecutorDescriptor对象 其中的 annotation为各个扩展提供了配置的节点关系及相关属性 如 DemoCalcExecutorDescriptor类中 其中 XObject executor 指明了扩展的节点类型为 executor 同时 该节点类型同时拥有 action 由 XNode action 定义 和 executor 由 XNodeSpring executor 定义 两个属性 对于 Annotation跟 Java 对象之间的对象对应关系则是交给了 XMap来处理 根据 DemoCalcExecutorDescriptor类中的定义 在各个扩展中需要定义一个节点如下结构 其中第二个 executor是 engine 向下提供的一个扩展接口 DemoCalcExecutor接口 底层通过该接口实现 上下层对接 以实现向上层提供服务 第一个executor则是节点类型 XObject executor 类型 而action 则用于执行期对应实例的调用过程 b 关于 DemoCalcComponent 的使用总结 DemoCalcComponent可以算是 engine部分的核心部分 其实现继承自 Extensible接口 Extensible接口提供 了两个方法 分别用来卸载和注册扩展点 这两个方法最终在 DefaultComponent中得到了一个默认实现 在 DemoCalcComponent的实现类 DemoCalcComponentImpl 中 根据需要又重新对注册扩展点的方法 registerExtension Extension extension 进 行 了 改 造 每 次 系 统 找 到 一 个 扩 展 点 最 后 都 会 去 DemoCalcComponentImpl 中执行一下注册扩展点的方法 registerExtension Extensionextension c 关于 DemoCalcExecutor DemoCalcExecutor是 engine 向下层提供的业务实现接口 供下层应用具体的业务实现实现 对 demo 中的 例子来说 他提供了加法和减法两个实现 分别位于 demo biz add和 demo biz sub两个子工程中 3 扩展 demo biz add a DemoCalcAddExecutor 继承扩展点提供接口 DemoCalcExecutor b 发布扩展 demo biz add extension xml 其中需要指出扩展点名 executor 关联的 Component 为 demoCalcComponent 声明扩展标志 action Add 其 值 定 义 在 demo core model 子 工 程 的 DemoActionEnum中 扩 展 对 应 的 实 现 为 demoCalcAddExecutor 4 利用 demo 中现有扩展点 创建一个乘法实例 a 增加一个扩展标志 Multi b 在 demo biz add xml 中发布实现 bean c 在 demo biz add extension xml 中发布扩展 d 在 demo service facade 的 DemoCalcFacade 中增加接口 并在 demo ext service 中对新增接口进行实现 DemoCalcFacade DemoCalcFacadeImpl e 在 TestDemoCalcFacade 类中增加测试用例 f 执行测试用例 5 对乘法实例进行改造 将其抽出 改造成为一个独立的工程 a 复制 demo biz add子工程 将其命名为 demo biz multi 修改 E demo demo biz multi 下 pom文件修改 artifactId为 demo biz multi 修改 E demo demo biz 下 pom文件 在 modules 字节点增加节点为 multi 修改 E demo 下 pom文件中增加依赖 在 demo test test 工程中增加依赖 重新构建 eclipse 工程 mvneclipse eclipse 修改 multi 工程下 demo biz add xml 为 demo biz multi xml 修改 multi 工程下 demo biz add extension xml 为 demo biz multi extension xml 删除 demo biz add工程中所有有关 multi 的内容 b 在 demo test test 工程 com alipay sofa demo test service BaseTestCase 类的 getConfigurationLocations 方法中增 加内容 c 执行测试用例 在日志中找到 20 24 54 397 main DEBUG DemoCalcMultiExecutor 执行乘法计算 1 2 2 则说明配置成功 6 在平台实现一个简单的 Try Catch Finally 框架 a 定义三个扩展点 b 三个类实现如下 AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api import mon xmap annotation XNode import mon xmap annotation XObject import mon xmap spring XNodeSpring 计算执行者描述器 version0 01 XObject try public class DemoCommExecutorDescriptor 计算的动作名称 XNode action private Stringaction 计算的执行者 XNodeSpring executor private DemoCommExecutorexecutor returnReturns the action public String getAction returnaction paramactionThe actionto set public voidsetAction String action this action action returnReturns the executor public DemoCommExecutorgetExecutor returnexecutor paramexecutorThe executorto set public voidsetExecutor DemoCommExecutorexecutor this executor executor AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api import mon xmap annotation XNode import mon xmap annotation XObject import mon xmap spring XNodeSpring 计算执行者描述器 version0 01 XObject catch public class DemoCatchExecutorDescriptor 计算的动作名称 XNode action private Stringaction 计算的执行者 XNodeSpring executor private DemoCatchExecutorexecutor returnReturns the action public String getAction returnaction paramactionThe actionto set public voidsetAction String action this action action returnReturns the executor public DemoCatchExecutorgetExecutor returnexecutor paramexecutorThe executorto set public voidsetExecutor DemoCatchExecutorexecutor this executor executor AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api import mon xmap annotation XNode import mon xmap annotation XObject import mon xmap spring XNodeSpring 计算执行者描述器 version0 01 XObject finally public class DemoFinallyExecutorDescriptor 计算的动作名称 XNode action private Stringaction 计算的执行者 XNodeSpring executor private DemoFinallyExecutorexecutor returnReturns the action public String getAction returnaction paramactionThe actionto set public voidsetAction String action this action action returnReturns the executor public DemoFinallyExecutorgetExecutor returnexecutor paramexecutorThe executorto set public voidsetExecutor DemoFinallyExecutorexecutor this executor executor c 定义三个扩展接口 AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api 计算执行者接口 version0 01 public interface DemoCommExecutor 执行计算 paramnum1 paramnum2 return long execute long num1 long num2 AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api 计算执行者接口 version0 01 public interface DemoCatchExecutor 执行计算 paramException return voidexecute Exceptione AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine api 计算执行者接口 version0 01 public interface DemoFinallyExecutor 执行计算 paramException return voidexecute Exceptione d 增加枚举参数如下 e 的 AInc Copyright c 2005 2008 All Rights Reserved package com alipay sofa demo core engine impl importjava util HashMap importjava util Map importorg nuxeo runtime model DefaultComponent importorg nuxeo runtime model Extension mon logging Logger mon logging LoggerFactory importcom alipay sofa demo core engine api DemoCalcComponent importcom alipay sofa demo core engine api DemoCatchExecutor importcom alipay sofa demo core engine api DemoCatchExecutorDescriptor importcom alipay sofa demo core engine api DemoCommExecutor importcom alipay sofa demo core engine api DemoCommExecutorDescriptor importcom alipay sofa demo core engine api DemoFinallyExecutor importcom alipay sofa demo core engine api DemoFinallyExecutorDescriptor importcom alipay sofa demo core model DemoActionEnum 计算组件接口的实现 version 0 01 public class DemoCalcComponentImpl extends DefaultComponentimplements DemoCalcComponent Logger private Loggerlogger LoggerFactory getLogger DemoCalcComponentImpl class 计算执行者 Map private MaptryerMap private MapcatcherMap private Map finallyerMap 初始化计算执行者 Map private DemoCalcComponentImpl super tryerMap new HashMap catcherMap new HashMap finallyerMap new HashMap non Javadoc seecom alipay sofa demo core engine api DemoCalcEngine doCalc long com alipay sofa demo core model DemoActionEnum public long doCalc long num1 long num2 DemoActionEnumaction throws Exception String str String valueOf action DemoCommExecutorexecutorTry tryerMap get str DemoCatchExecutorexecutorCatch catcherMap get str DemoFinallyExecutorexecutorFinally finallyerMap get str if executorTry null executorCatch null executorFinally null throw new Exception 没找到指定的计算执行者 action action 执行计算 Exceptionexception null long result 0L try result executorTry execute num1 num2 catch Exceptione exception e executorCatch execute e finally executorFinally execute exception 返回结果 returnresult non Javadoc see org nuxeo runtime model DefaultComponent deployCompletion Override public void deployCompletion throws Exception super deployCompletion if logger isDebugEnabled logger debug deployCompletion non Javadoc see org nuxeo runtime model DefaultComponent registerExtension org nuxeo runtime model Extension Override public voidregisterExtension Extensionextension throws Exception Object contribs extension getContributions if contribs length 0 return synchronized this for Objectcontrib contribs if contribinstanceof DemoCommExecutorDescriptor DemoCommExecutorDescriptordescriptor DemoCommExecutorDescriptor contrib String action descriptor getAction DemoCommExecutorexecutor descriptor getExecutor tryerMap put action executor if logger isDebugEnabled logger debug registerExtension action action if contribinstanceof DemoCatchExecutorDescriptor DemoCatchExecutorDescriptordescriptor DemoCatchExecutorDescriptor contrib String action descriptor getAction DemoCatchExecutorexecutor descriptor getExecutor catcherMap put action executor if logger isDebugEnabled logger debug registerExtension action action if contribinstanceof DemoFinallyExecutorDescriptor DemoFinallyExecutorDescriptordescriptor DemoFinallyExecutorDescriptor contrib String action descriptor getAction DemoFinallyExecutorexecutor descriptor getExecutor finallyerMap put action executor if logger isDebugEnabled logger debug registerExtension action action f 添加子工程 demo biz comm 分别实现 DemoCatchExecutor DemoCommExecutor DemoFinallyExecutor接 口 内容如下 AInc Copyright c 2005 2008 All Rights Reserved package m mon logging Logger mon logging LoggerFactory importcom alipay sofa demo core engine api DemoCommExecutor 加法的执行者 version0 01 public class DemoCommonExecutorimplements DemoCommExecutor Logger private Loggerlogger LoggerFactory getLogger DemoCommonExecutor class non Javadoc see com alipay sofa demo core engine api DemoCommonExecutor execute long long public long execute long num1 long num2 long result num1 num2 if logger isDebugEnabled logger debug 执行加法计算 num1 num2 result returnresult AInc Copyright c 2005 2008 All Rights Reserved package m mon logging Logger mon logging LoggerFactory importcom alipay sofa demo core engine api DemoCatchExecutor 加法的执行者 version0 01 public

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论