随笔-6  评论-2  文章-0  trackbacks-0
  2006年5月12日
转载自Rinso的专栏

原文
posted @ 2006-05-12 10:26 Allen Young 阅读(393) | 评论 (1)编辑 收藏
  2006年4月25日
SCA Module是紧耦合component的最大的组合物,同时也是松耦合SCA System中的基本单元,也就是说,很多紧耦合的东东组成Module,然后很多Module组成松耦合的System。我们都知道一味的紧耦合及松耦 合都是不好的,过分的紧耦合会降低系统的灵活性、可重用性等,而过分的松耦合会导致系统性能的下降、开发难度增加、代码不直观、测试难做等,因此,选择一 个合适的紧耦合和松耦合之间的临界点是很重要的,而Module就是这个临界点。

Module有如下几个标准特性:
  1. 定义了Component可见性的边界,Component不可以在Module之外直接被引用。
  2. 在同一个Module内,Service的本地调用采用by-reference语义(除了声明为remotable的接口)。在Module之间,Service的远程调用采用by-value语义。
  3. 定义了部署的单元。Module用来为SCA System提供business service。
Module由sca.module中的module元素定义。下面是module的schema:
<?xml version="1.0" encoding="ASCII"?>
<module xmlns=”http://www.osoa.org/xmlns/sca/0.9”
    
xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" name="xs:NCName">

    <entryPoint name="xs:NCName" multiplicity="0..1 or 1..1 or 0..n or 1..n" ?>*
        
<interface.interface-type />
        
<binding.binding-type uri="xs:anyURI" />+
        
<reference>wire-target-URI</reference>
    
</entryPoint>

    <component name="xs:NCName">*
        
<implementation.implementation-type />
        
<properties>?
            
<v:property-name>property-value</v:property-name>+
        
</properties>
        
<references>?
            
<v:reference-name>wire-target-URI</v:reference-name>+
        
</references>
    
</component>

    <externalService name="xs:NCName">*
        
<interface.interface-type />+
        
<binding.binding-type uri="xs:anyURI" />*
    
</externalService>

    <wire>*
        
<source.uri>wire-source-URI</source.uri>
        
<target.uri>wire-target-URI</target.uri>
    
</wire>

</module>

< module /> 的name属性表示module的名字,在一个SCA System中是唯一的。这个名字不能包含/或#字符。
< module /> 包含0或n个 < entryPoint /> < component /> < externalService />  <wire />元素,这些元素的含义在之前的随笔中 已经说过。Component包含Module的业务逻辑,Wire描述Component之间的Service的连接,Entry Point定义Module提供的、可供外部访问的public service,External Service表示Module对外部Service的依赖。

Component

Component 是Implementation的配置实例,它即提供 Service也消费Service。多个Component可以使用并配置同一个Implementation,只要每个Component都采用不同 的配置。Implementation通过component type来定义可由Component配置的aspect。SCA支持多种不同的实现技术,如Java、BEPL、C++。SCA定义了一种可扩展机制来 引入新类型的Implementation。目前的规范不指定必须被SCA runtime支持的实现技术,供应商可以选择他们认为重要的技术予以支持。我们来看一下Component的schema:
<component name="xs:NCName">*
   
<implementation.implementation-type />
   
<properties>?
       
<v:property-name>property-value</v:property-name>+
   
</properties>
   
<references>?
       
<v:reference-name>wire-target-URI</v:reference-name>+
   
</references>
</component>
<component />的name属性表示这个component的名字,它必须在当前module中是唯一的。另外,当前module中的entry point和external servic不可以和component重名。
<component />必 须有一个implementation子元素,它指向component的具体实现。implementation元素的名字由两部分组成: "implementation"+代表implementation-type的限定词,例如:implementation.java表示是由 Java来实现,implementation.bepl表示是由BPEL来实现。
<implementation.java class="services.myvalue.MyValueServiceImpl"/>
<implementation.bpel process="…"/>

Component Type

Component Type表示一个Implementation的可配置的东东,它由Implementation提供的Service、可设置的关联到其他 Service的Reference和可设置的属性组成。属性和Reference将在使用这个Implementation的Component中具体 配置。
确定一个Component Type需要两个步骤:
  1. 从Implementation自身获得信息(例如:从code annotation获得信息)
  2. 从SCA component type文件获得信息(XML配置文件)
这是时下流行的做法,既可以从code annotation进行配置,也可以从XML进行配置,如果两者同时使用,code annotation的优先级高,但是两者的配置要统一。
SCA component type文件的扩展名为".componentType",其中通过componentType元素来进行配置,我们来看看它的schema:
<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" >
    <service name="xs:NCName">*
        <interface.interface-type/>
    </service>
    <reference name="xs:NCName" multiplicity="0..1 or 1..1 or 0..n or 1..n"?>*
        <interface.interface-type/>
    </reference>
    <property name="xs:NCName" type="xs:QName" many="xs:boolean"? default="xs:string"? required="xs:boolean"?/>*
</componentType>
<service />表示这个Component Type提供的Service,可以通过<interface.interface-type />设置其为remotable。<reference />表示这个Component Type依赖的其他Service,也可以通过<interface.interface-type />设置其为remotable,multiplicity属性表示可以关联到这个Reference的Wire的数量。<property />表示这个Component Type可配置的属性。
让我们来看一个例子,Java文件MyValueServiceImpl是这个例子中的Implementation,其SCA component type如下:
<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9">
    <service name="MyValueService">
        <interface.java interface="services.myvalue.MyValueService"/>
    </service>
    <reference name="customerService">
        <interface.java interface="services.customer.CustomerService"/>
    </reference>
    <reference name="stockQuoteService">
        <interface.java interface="services.stockquote.StockQuoteService"/>
    </reference>
    <property name="currency" type="xsd:string" default="USD"/>
</componentType>

相应的Java代码如下:

// MyValueService interface.
package services.myvalue;

public interface MyValueService {
    
public void calculate();
}

// MyValueServiceImpl class
package services.myvalue;

import services.customer.CustomerService;
import services.stockquote.StockQuoteService;

public class MyValueServiceImpl implements MyValueService {

    
// Code annotation. 和XML的功能相同,两者取一个使用就够了。
    @Property
    
private String currency = "USD";

    @Reference
    
private CustomerService customerService;

    @Reference
    
private StockQuoteService stockQuoteService;

    
public void calculate() {
        
// do your real business logic here.
    }
}

Implementation

Implementation 是业务逻辑的具体实现,这些业务逻辑会提供或消费Service。SCA支持多种实现技术,如Java、BPEL或C++。我们已经知道, Service、Reference和Property是Implementation中关于配置的东东,他们组成Component Type。在运行时,Implementation Instance是Implementation的实例化,它提供的业务逻辑和Implementation中的相同,但Property和 Reference则取决于Component中的配置。下图描述了Component Type、Component、Implementation和Implementation Instance之间的关系:
SCA-relationship-between-implementation-and-implementation-instance.PNG

Interface

Interface 负责定义一个或多个business function。这些business function通过Service提供给外部,外部通过Reference使用它们。Service由自己实现的Interface定义。SCA支持如 下3种Interface:
  • Java interfaces
  • WSDL 1.1 portTypes
  • WSDL 2.0 interfaces
我们一个一个来看:

<interface.java interface="NCName" … />
其中interface属性为Java interface的全名(包括package)。例如:
<interface.java interface="services.stockquote.StockQuoteService" />

<interface.wsdl interface="xs:anyURI" … />
其中interface属性为portType/interface的URI,其格式为<WSDL-namespace-URI>#wsdl.interface(<portType or Interface-name>)。例如:
<interface.wsdl interface="http://www.stockquote.org/StockQuoteService#wsdl.interface(StockQuote)"/>

如果使用Java interface,Service方法的传入参数和返回值可以使用Java class或Primitive type。最好使用SDO生成的Java class,因为它们和XML之间做了整合。(SDO也是IBM推出的一个SOA系列的标准。)
如果使用WSDL,Service方法的传入参数和返回值则使用XML schema描述。XML schema种描述的参数以SDO DataObject的形式暴露给开发者。

一 个Component Implementation的Service是否是remotable的是由Service的Interface定义的。如果使用Java,为 Interface添加@Remotable annotation可以把Service声明为remotable。WSDL定义的interface永远是remotable的。
典型的remoteable interface是粗力度的,用于松耦合的交互。Remotable Service Interface不允许函数重载。无论是在 Module之外还是在Module内的其他Component中使用
remotable Service,数据交换都采用by-value语义。
Remotable Serviced的Implementation可能会在Service调用过程中或调用之后改变传入参数,也可能在调用之后修改返回值。如果 remotable Service被locally或remotely调用,SCA container会保证传入参数及返回值的改变对Service的调用者是不可见的(这就是by-value语义)。下面是一个remotable java interface的例子:
package services.hello;

@Remotable
// @AllowsPassByReference
public interface HelloService {
    
public String sayHello(String message);
}
由External Service提供的Service永远是remotable的。可以使用@AllowsPassByReference annotation允许一个remotable Service在被同一Module中的其他Component调用时使用by-reference语义,这样可以提高性能。

由local Interface提供的Service只能在同一Module中使用,它们不能通过Entry Point发布到外部。如果不声明@Remotable,Java interface默认为local。典型的local Interface是细粒度的,用于紧耦合的交互。它允许方法重载,并采用by-reference语义。
posted @ 2006-04-25 15:58 Allen Young 阅读(822) | 评论 (0)编辑 收藏
SCA Assembly Model涵盖了两种model:
  • 用来组装紧耦合服务的model
  • 用来组装松耦合面向服务系统的model

SCA Assembly Model由一系列的artifact组成,这些artifact由XML文件中的element定义。下面先给出这些artifact的名词:
  • Module
  • Service
  • Component
  • Entry Point
  • Reference
  • External Service
  • Wire
  • Implementation
  • SCA System
  • Subsystem
  • Module Component
最基本的artifact是Module,它是SCA的部署单元,用来保存可以被 remote访问的Service。一个Module包含一个或几个Component,这些Component包含了这个Module所要提供的 business function。Component把这些function以Service的形式提供给外界,这些Service即可以被同一Model中的其他 Component使用,也可以通过Entry Point在Module之外使用。Component也可以依赖于其他Component提供的Service,这些依赖叫做Reference。 Reference即可以是对同一Module内其他Component提供的Service的link,也可以是对Module外Service(其他 Module提供的Service)的link。连接到Module外部Service的Reference在其Module中被定义为External Service。Reference和Service之间的连接也包含在这个Module中,用Wire来表示。

一个Component由一个配置好的Implementation组成,这个Implementation就是实现business function的那段程序。Component使用具体的值来配置Implementation中声明的可配置的属性,Component也可以把 Implementation中声明的wiring of reference配置到具体的目标Service上去。

Module部署在SCA System中。一个SCA System往往表示一组相关Service的集合。为了方便建立和配置SCA System,Subsystem可以用来对Module进行分组和配置。Subsystem包含Module Component(Module的配置好了的实例),和Module一样,它也有Entry Point、External Service和Wire。

下面附上两张图来展示这些artifact之间的关系。
SCA-module-assembly-diagram.PNG
SCA-system-assembly-diagram.PNG
posted @ 2006-04-25 14:34 Allen Young 阅读(587) | 评论 (1)编辑 收藏
SOA and Web services 新手入门,转自IBM DeveloperWorks,它的SOA and Web Service专区是学习SOA的很好的资源中心。本文章的内容如下:

  1. 什么是面向服务的体系结构(SOA)?
  2. 我可以用面向服务的体系结构做什么?
  3. 构成 SOA 的技术是什么?
  4. SOA 与其他技术的关系如何?
  5. 我可以如何构建 SOA 系统?
  6. 我可以如何提高我的 SOA 技能?
  7. IBM 的什么工具和产品可用于 SOA?
IBM肯定会为自己做广告,呵呵,各位保持清醒就是了。
posted @ 2006-04-25 11:09 Allen Young 阅读(353) | 评论 (0)编辑 收藏
Elune Team由Allen Young,atlanta,Helena和silver.sun组成,近期目标为参加2006 IBM杯中国高校SOA应用大赛,因此会在比赛期间在BlogJava SOA Team Blog进行相关讨论,内容以SOA为主,会涉及参赛项目管理,团队文化等。
posted @ 2006-04-25 10:23 Allen Young 阅读(283) | 评论 (0)编辑 收藏
欢迎各位对SOA感兴趣的朋友加入讨论BlogJava SOA Team Blog,下面是个人的几点声明,各位可以给我建议或补充。

  1. 随笔要与Team Blog主题相关,否则将删除。
  2. 做一个Critical Thinker,对自己的言论负责。
  3. 欢迎各种观点(我们需要不同的声音),欢迎争论,不欢迎争吵。
  4. 随笔请用Courier New字体,2号字,以便保持整体风格一致。

SOA是一种态度,而不是一种技术。
posted @ 2006-04-25 10:17 Allen Young 阅读(240) | 评论 (0)编辑 收藏
仅列出标题