SCA 之Tuscany 1 ——helloworld
2011-10-10 10:02
197 查看
SCA可看做是和Spring有诸多共同点的框架,使用的时候应该相互比较异同。
本系列文章是使用Tuscany Getting Started 实例学习之用。想下载这些实例的源码和Tuscany的开源代码请google之。
下面提供本系列文章的Guide:
Tuscany Getting Started Guide
- contribution + runtime
- helloworld sample
- contributions
-zip, jar
-.composite, web.composite
- meta-inf/sca-contribution
-deployables
-import/export
-jars within contribution
- extensions
-bindings
-implementations
-databindings
- running tuscany
-TuscanyRuntime+ Node
-dependencies
-base , x-*-runtime
- webapp
-standalone
- shell
- junit
- distributed domain
学习Tuscany最好的书籍就是:
和其他所有的框架一样。只要玩转几个example就容易理解了。下面是sca的组件定义框架,需要在demo中好好的思考,这个模型如何被使用:
Service和Reference是Component和外界交互的接口。和Spring一样,SCA中都是针对接口编程的,叫法在业务上有一个不同。虽然两大平台都是针对接口,但SCA在逻辑层称向外和向内的接口为“服务”。
Service是这个Composite提供给其他Composite。
Reference是这个Composite使用其他Composite。
而具体的协议就是依靠其中定义的Binding实现的,binging的协议囊括了各种同步、异步的类型。这就是SCA倡导的“服务型架构”。它实现了:实现和接口的分离!
Properties是通过内部Component提升得到的。可以得到如何使用该composite的信息。
下面讲解一下Tuscany最简单的例子:
Hello World!
一、定义SCA域
域是服务之间的划分范围,不同的服务使用的范围要受到限制。有的服务只可以在域内应用,有的则可跨域操作。
二、定义helloworld composite
这里有默认的选项,如没有直接申明,binding就是sca等。
三、实现 java
接口:
按照SCA的原理,接口类并不是必须的,因为可以从class中抽象出来,这是和Spring一个很大的不同。
class:
四、测试
主要是使用node进行访问。
五、整体分支
六、运行情况
七、测试
Test set: sample.HelloworldTestCase
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23.594 sec
本系列文章是使用Tuscany Getting Started 实例学习之用。想下载这些实例的源码和Tuscany的开源代码请google之。
下面提供本系列文章的Guide:
Tuscany Getting Started Guide
- contribution + runtime
- helloworld sample
- contributions
-zip, jar
-.composite, web.composite
- meta-inf/sca-contribution
-deployables
-import/export
-jars within contribution
- extensions
-bindings
-implementations
-databindings
- running tuscany
-TuscanyRuntime+ Node
-dependencies
-base , x-*-runtime
- webapp
-standalone
- shell
- junit
- distributed domain
学习Tuscany最好的书籍就是:
和其他所有的框架一样。只要玩转几个example就容易理解了。下面是sca的组件定义框架,需要在demo中好好的思考,这个模型如何被使用:
Service和Reference是Component和外界交互的接口。和Spring一样,SCA中都是针对接口编程的,叫法在业务上有一个不同。虽然两大平台都是针对接口,但SCA在逻辑层称向外和向内的接口为“服务”。
Service是这个Composite提供给其他Composite。
Reference是这个Composite使用其他Composite。
而具体的协议就是依靠其中定义的Binding实现的,binging的协议囊括了各种同步、异步的类型。这就是SCA倡导的“服务型架构”。它实现了:实现和接口的分离!
Properties是通过内部Component提升得到的。可以得到如何使用该composite的信息。
下面讲解一下Tuscany最简单的例子:
Hello World!
一、定义SCA域
<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:sample="http://sample"> <deployable composite="sample:helloworld-contribution" /> </contribution>
域是服务之间的划分范围,不同的服务使用的范围要受到限制。有的服务只可以在域内应用,有的则可跨域操作。
二、定义helloworld composite
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" targetNamespace="http://sample" name="helloworld-contribution"> <component name="HelloworldComponent"> <implementation.java class="sample.HelloworldImpl"/> </component> </composite>composite非常像我们在Spring中使用的application-context.xml。因为这是一个helloworld的文件,所以,并没有全部展示所有的配置要素。
这里有默认的选项,如没有直接申明,binding就是sca等。
三、实现 java
接口:
package sample; import org.oasisopen.sca.annotation.Remotable; @Remotable public interface Helloworld { String sayHello(String name); }
按照SCA的原理,接口类并不是必须的,因为可以从class中抽象出来,这是和Spring一个很大的不同。
class:
package sample; public class HelloworldImpl implements Helloworld { public String sayHello(String name) { return "Hello " + name; } }
四、测试
package sample; import org.junit.Assert; import org.apache.tuscany.sca.Node; import org.apache.tuscany.sca.TuscanyRuntime; import org.junit.Test; import org.oasisopen.sca.NoSuchServiceException; public class HelloworldTestCase { @Test public void testSayHello() throws NoSuchServiceException { // Run the SCA composite in a Tuscany runtime Node node = TuscanyRuntime.runComposite("helloworld.composite", "target/classes"); try { // Get the Helloworld service proxy Helloworld helloworld = node.getService(Helloworld.class, "HelloworldComponent"); // test that it works as expected Assert.assertEquals("Hello Amelia", helloworld.sayHello("Amelia")); } finally { // Stop the Tuscany runtime Node node.stop(); } } }
主要是使用node进行访问。
五、整体分支
六、运行情况
七、测试
Test set: sample.HelloworldTestCase
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23.594 sec
相关文章推荐
- SCA 之Tuscany 8 ——helloworld JSONP和JSONRPC
- Tuscany是什么?为什么要用Tuscany命名SCA规范的实现?
- Tuscany SCA启动过程分析
- SCA 之Tuscany 11 ——Tuscany小记注意事项
- Tuscany SCA 引导和装配的过程 .
- Tuscany SCA案例分析(一)(连载中...)
- 基于SCA(tuscany)的SOA实践之一(发布服务是如此的简单)
- TUSCANY SCA JAVA (五) 用其他脚本语言实现组件服务
- Tuscany SCA Core实现的SPI机制
- SCA 之Tuscany 2 ——helloworld JAX-RS
- tuscany-sca绑定jms协议
- Apache Tuscany中文论坛开通: http://groups.google.com/group/tuscany-sca-chinese
- Apache Tuscany SCA 用户指南
- 使用 Tuscany 域管理器部署 SCA 应用程序
- SCA 之Tuscany 3 ——helloworld WebApp
- Tuscany Java SCA 1.3版本预览
- SCA 之Tuscany 4 ——helloworld Webservice
- Tuscany SCA以独立应用方式运行的简单例子
- SCA 之Tuscany 5 ——helloworld Spring Bean
- call-helloworld在tuscany-extension上运行失败,需要预处理!