隨筆-6  評論-2  文章-0  trackbacks-0
          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 on 2006-04-25 15:58 Allen Young 閱讀(853) 評論(0)  編輯  收藏 所屬分類: SOA
          主站蜘蛛池模板: 嵊州市| 满洲里市| 华蓥市| 蓬莱市| 日照市| 吴桥县| 安达市| 垦利县| 阿荣旗| 通化市| 清水县| 电白县| 庆云县| 永靖县| 江北区| 三明市| 广灵县| 桃源县| 兰考县| 萨迦县| 扶余县| 仁化县| 清水县| 盘山县| 襄樊市| 大荔县| 齐齐哈尔市| 吴堡县| 琼中| 西宁市| 兴隆县| 云和县| 荆门市| 广宁县| 谷城县| 兴城市| 武清区| 青神县| 长葛市| 介休市| 且末县|