SCA
Module是緊耦合component的最大的組合物,同時(shí)也是松耦合SCA
System中的基本單元,也就是說(shuō),很多緊耦合的東東組成Module,然后很多Module組成松耦合的System。我們都知道一味的緊耦合及松耦
合都是不好的,過(guò)分的緊耦合會(huì)降低系統(tǒng)的靈活性、可重用性等,而過(guò)分的松耦合會(huì)導(dǎo)致系統(tǒng)性能的下降、開(kāi)發(fā)難度增加、代碼不直觀、測(cè)試難做等,因此,選擇一
個(gè)合適的緊耦合和松耦合之間的臨界點(diǎn)是很重要的,而Module就是這個(gè)臨界點(diǎn)。
Module有如下幾個(gè)標(biāo)準(zhǔn)特性:
-
定義了Component可見(jiàn)性的邊界,Component不可以在Module之外直接被引用。
-
在同一個(gè)Module內(nèi),Service的本地調(diào)用采用by-reference語(yǔ)義(除了聲明為remotable的接口)。在Module之間,Service的遠(yuǎn)程調(diào)用采用by-value語(yǔ)義。
-
定義了部署的單元。Module用來(lái)為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的名字,在一個(gè)SCA System中是唯一的。這個(gè)名字不能包含/或#字符。
<
module
/>
包含0或n個(gè)
<
entryPoint
/>
、
<
component
/>
、
<
externalService
/>
、?
<wire />元素,這些元素的含義在之前的隨筆中
已經(jīng)說(shuō)過(guò)。Component包含Module的業(yè)務(wù)邏輯,Wire描述Component之間的Service的連接,Entry
Point定義Module提供的、可供外部訪問(wèn)的public service,External
Service表示Module對(duì)外部Service的依賴。
Component
Component
是Implementation的配置實(shí)例,它即提供
Service也消費(fèi)Service。多個(gè)Component可以使用并配置同一個(gè)Implementation,只要每個(gè)Component都采用不同
的配置。Implementation通過(guò)component
type來(lái)定義可由Component配置的aspect。SCA支持多種不同的實(shí)現(xiàn)技術(shù),如Java、BEPL、C++。SCA定義了一種可擴(kuò)展機(jī)制來(lái)
引入新類型的Implementation。目前的規(guī)范不指定必須被SCA
runtime支持的實(shí)現(xiàn)技術(shù),供應(yīng)商可以選擇他們認(rèn)為重要的技術(shù)予以支持。我們來(lái)看一下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屬性表示這個(gè)component的名字,它必須在當(dāng)前module中是唯一的。另外,當(dāng)前module中的entry point和external servic不可以和component重名。
<component />必
須有一個(gè)implementation子元素,它指向component的具體實(shí)現(xiàn)。implementation元素的名字由兩部分組成:
"implementation"+代表implementation-type的限定詞,例如:implementation.java表示是由
Java來(lái)實(shí)現(xiàn),implementation.bepl表示是由BPEL來(lái)實(shí)現(xiàn)。
<implementation.java?class="services.myvalue.MyValueServiceImpl"/>
<implementation.bpel?process="…"/>
Component Type
Component
Type表示一個(gè)Implementation的可配置的東東,它由Implementation提供的Service、可設(shè)置的關(guān)聯(lián)到其他
Service的Reference和可設(shè)置的屬性組成。屬性和Reference將在使用這個(gè)Implementation的Component中具體
配置。
確定一個(gè)Component Type需要兩個(gè)步驟:
- 從Implementation自身獲得信息(例如:從code annotation獲得信息)
- 從SCA component type文件獲得信息(XML配置文件)
這是時(shí)下流行的做法,既可以從code annotation進(jìn)行配置,也可以從XML進(jìn)行配置,如果兩者同時(shí)使用,code annotation的優(yōu)先級(jí)高,但是兩者的配置要統(tǒng)一。
SCA component type文件的擴(kuò)展名為".componentType",其中通過(guò)componentType元素來(lái)進(jìn)行配置,我們來(lái)看看它的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 />表示這個(gè)Component Type提供的Service,可以通過(guò)<interface.interface-type />設(shè)置其為remotable。<reference />表示這個(gè)Component Type依賴的其他Service,也可以通過(guò)<interface.interface-type />設(shè)置其為remotable,multiplicity屬性表示可以關(guān)聯(lián)到這個(gè)Reference的Wire的數(shù)量。<property />表示這個(gè)Component Type可配置的屬性。
讓我們來(lái)看一個(gè)例子,Java文件MyValueServiceImpl是這個(gè)例子中的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>
相應(yīng)的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的功能相同,兩者取一個(gè)使用就夠了。
????@Property
????private?String?currency?=?"USD";
????@Reference
????private?CustomerService?customerService;
????@Reference
????private?StockQuoteService?stockQuoteService;
????public?void?calculate()?{
????????//?do?your?real?business?logic?here.
????}
}
Implementation
Implementation
是業(yè)務(wù)邏輯的具體實(shí)現(xiàn),這些業(yè)務(wù)邏輯會(huì)提供或消費(fèi)Service。SCA支持多種實(shí)現(xiàn)技術(shù),如Java、BPEL或C++。我們已經(jīng)知道,
Service、Reference和Property是Implementation中關(guān)于配置的東東,他們組成Component
Type。在運(yùn)行時(shí),Implementation
Instance是Implementation的實(shí)例化,它提供的業(yè)務(wù)邏輯和Implementation中的相同,但Property和
Reference則取決于Component中的配置。下圖描述了Component
Type、Component、Implementation和Implementation Instance之間的關(guān)系:


Interface
Interface
負(fù)責(zé)定義一個(gè)或多個(gè)business function。這些business
function通過(guò)Service提供給外部,外部通過(guò)Reference使用它們。Service由自己實(shí)現(xiàn)的Interface定義。SCA支持如
下3種Interface:
- Java interfaces
- WSDL 1.1 portTypes
- WSDL 2.0 interfaces
我們一個(gè)一個(gè)來(lái)看:
<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方法的傳入?yún)?shù)和返回值可以使用Java class或Primitive type。最好使用SDO生成的Java class,因?yàn)樗鼈兒蚗ML之間做了整合。(SDO也是IBM推出的一個(gè)SOA系列的標(biāo)準(zhǔn)。)
如果使用WSDL,Service方法的傳入?yún)?shù)和返回值則使用XML schema描述。XML schema種描述的參數(shù)以SDO DataObject的形式暴露給開(kāi)發(fā)者。
一
個(gè)Component
Implementation的Service是否是remotable的是由Service的Interface定義的。如果使用Java,為
Interface添加@Remotable
annotation可以把Service聲明為remotable。WSDL定義的interface永遠(yuǎn)是remotable的。
典型的remoteable interface是粗力度的,用于松耦合的交互。Remotable Service Interface不允許函數(shù)重載。無(wú)論是在 Module之外還是在Module內(nèi)的其他Component中使用remotable Service,數(shù)據(jù)交換都采用by-value語(yǔ)義。
Remotable
Serviced的Implementation可能會(huì)在Service調(diào)用過(guò)程中或調(diào)用之后改變傳入?yún)?shù),也可能在調(diào)用之后修改返回值。如果
remotable Service被locally或remotely調(diào)用,SCA
container會(huì)保證傳入?yún)?shù)及返回值的改變對(duì)Service的調(diào)用者是不可見(jiàn)的(這就是by-value語(yǔ)義)。下面是一個(gè)remotable
java interface的例子:
package?services.hello;
@Remotable
//?@AllowsPassByReference
public?interface?HelloService?{
????public?String?sayHello(String?message);
}
由External
Service提供的Service永遠(yuǎn)是remotable的??梢允褂?#64;AllowsPassByReference
annotation允許一個(gè)remotable
Service在被同一Module中的其他Component調(diào)用時(shí)使用by-reference語(yǔ)義,這樣可以提高性能。
由local Interface提供的Service只能在同一Module中使用,它們不能通過(guò)Entry
Point發(fā)布到外部。如果不聲明@Remotable,Java interface默認(rèn)為local。典型的local
Interface是細(xì)粒度的,用于緊耦合的交互。它允許方法重載,并采用by-reference語(yǔ)義。
posted on 2006-04-25 15:58
Allen Young 閱讀(850)
評(píng)論(0) 編輯 收藏 所屬分類:
SOA