Welcome to the Apache Tuscany SCA User guide. Here you will find information aimed to help you understand SCA concepts and an example walk through for building your own SCA application.
\\
{panel:title=Apache Tuscany SCA User Guide|borderStyle=solid|borderColor=#C3CDA1|titleBGColor=#C3CDA1|bgColor=#ECF4D1}
* [*Introduction*|#Intro]
* [*Quick Guide to SCA*|#Quick Guide to SCA]
* [*Getting Tuscany SCA Java*|#Getting Tuscany SCA Java]
* [*SCA Contributions and Composites*|#SCA Contributions and Composites]
* [*Tuscany SCA Node*|#Tuscany SCA Node]
* [*Host Embedded*|#Host Embedded]
* [*Tuscany SCA Node Implementation*|#Tuscany SCA Node Implementation]
* [*Hosting Tuscany SCA Nodes*|#Hosting Tuscany SCA Nodes]
* [*Tuscany SCA Domain*|#Tuscany SCA Domain]
* [*Tuscany web based Domain Manager Tool*|#Tuscany Domain Manager]
* [*Deploying as a web app.*|#deploy as web app] (To be done)
* [*Understanding Tuscany's Depedencies*|#Tuscany dependencies] (To be done)
* [*Tuscany SCA Extensions*|#Tuscany SCA Extensions]
** [The Extensible Runtime|#The Extensible Runtime]
** [Using Extensions|#Using Extensions]
* [*Tuscany SCA And IDEs*|#Tuscany SCA And IDEs]
** [Using The Samples In An IDE Without Maven|#Using The Samples In An IDE Without Maven]
** [Using The Samples In An IDE If You Have Maven|#Using The Samples In An IDE If You Have Maven]\\
{panel}
{note:title:Notification}
{center}This page is undergoing an update to catch up with the latest code. You are welcome to help review and complete it. Comments the dev list please
{center}
{note}
h2. {anchor:Intro}
{bgcolor:#C3CDA1}Introduction
{bgcolor}
This user guide will help you become familiar with SCA concepts and walks you through an example that demonstrates how to build an SCA application. It also describes the different environments that Tuscany supports (such as command line clients or web applications) and how to package up applications to run in these environments.
*There's nothing to it really\!* Building SCA applications is easy. One of the main goals of Tuscany and SCA is to avoid imposing rules and requirements on how people write applications. We want to let people write application code the way they want without being concerned about the environment in which it will be used. After all, writing code to handle plumbing just gets in the way of writing the interesting stuff. So basically, you write the code for interesting bits, and Tuscany provides the environment that lets it run. Therefore, this guide is just an example of how an SCA application can be developed and is not a rule.
h2. {anchor:Quick Guide to SCA}
{bgcolor:#C3CDA1}Quick Guide to SCA
{bgcolor}
The [*quick guide to SCA*|Quick Guide To SCA] gives you an overview of SCA concepts and prepares you to work on the example below. You can skip this step if you are already familiar with SCA.
For more details on SCA please refer to the specifications at [Open SOA web site|http://www.osoa.org].
h2. {anchor:Getting Tuscany SCA Java}
{bgcolor:#C3CDA1}Getting Started with Tuscany SCA Java
{bgcolor}
There are several guides that show you how to get started with Apache Tuscany SCA Java.
[Getting Started with Tuscany using a Tuscany Distribution from the Command Line|Getting Started with Tuscany ( using the Command Line)]
This is a quick getting started guide that shows you how to download the latest release, run the calculator sample and then how to use the calculator sample project as a basis for you own projects
[Getting Started with Tuscany using a Tuscany Distribution In Eclipse|Getting Started with Tuscany]
This is a quick getting started guide that go trough the steps of building the store scenario using the Tuscany SCA distribution manually installed into Eclipse
[Getting Started with Tuscany using the Tuscany Eclipse Plugin|Getting Started with Tuscany (using Tuscany Eclipse Plugin)]
This is a quick getting started guide that go trough the steps of building the store scenario using the Tuscany Eclipse plugin.
[First Steps - Building your first web services using Tuscany|Build your first Web Services with Tuscany]
This is a quick guide that go trough the steps of exposing your pojo component as web services.
h2. {anchor:SCA Contributions and Composites}
{bgcolor:#C3CDA1}SCA Contributions and Composites
{bgcolor}
You will have seen from working with the calculator sample ([Getting Started with Tuscany using a Tuscany Distribution from the Command Line|Getting Started with Tuscany ( using the Command Line)]) that an assembly of SCA components is described in a composite file, for example,
{code}
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://sample"
xmlns:sample="http://sample"
name="Calculator">
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService" target="AddServiceComponent" />
<reference name="subtractService" target="SubtractServiceComponent" />
<reference name="multiplyService" target="MultiplyServiceComponent" />
<reference name="divideService" target="DivideServiceComponent" />
</component>
<component name="AddServiceComponent">
<implementation.java class="calculator.AddServiceImpl"/>
</component>
<component name="SubtractServiceComponent">
<implementation.java class="calculator.SubtractServiceImpl"/>
</component>
<component name="MultiplyServiceComponent">
<implementation.java class="calculator.MultiplyServiceImpl"/>
</component>
<component name="DivideServiceComponent">
<implementation.java class="calculator.DivideServiceImpl"/>
</component>
</composite>
{code}
The composite describes how SCA components are implemented and how they are assembled by wiring references to targets. This composite file has some dependencies, in this case the Java class and interface files that are used to implement the SCA components that it defines. The collection of composite files and other artifacts that are required to run an SCA application are collected together into one or more SCA contributions. A contribution can be a simple as a directory in a file system or could be packaged in, for example, a Jar file. SCA does not mandate any particular packing scheme. For our calculator sample you can imagine the contribution holding the calculator composite and all of its dependencies. !calculator1.png|align=centre!
In fact if you look inside the jar file that the calculator sample produces, you will find the following
{code}
calculator/AddService.class
calculator/AddServiceImpl.class
calculator/CalculatorClient.class
calculator/CalculatorService.class
calculator/CalculatorServiceImpl.class
calculator/DivideService.class
calculator/DivideServiceImpl.class
calculator/MultiplyService.class
calculator/MultiplyServiceImpl.class
calculator/SubtractService.class
calculator/SubtractServiceImpl.class
Calculator.composite
{code}
Which are all the artifacts that are required to run the calculator sample. We just need to add this contribution to the Tuscany SCA java runtime and then call the services that will be enabled.
h2. {anchor:Tuscany SCA Node}
{bgcolor:#C3CDA1}Tuscany SCA Node
{bgcolor}
In order to run an SCA application Tuscany SCA Java provides a runtime that is wrapped up in a Node. The runtime itself is made up of many of the modules that are present in the modules directory of the Tuscany SCA Java distribution. As you might expect there are functions that read XML, create an in memory mode model of the SCA assembly, create the components and wire them together ready to process incoming messages. All of these functions are wrapped up in a Node. A node is configured using SCA contributions and will run a single composite. When running standalone the node also defines the scope of component services that references can target by name. SCA defines the term Domain to describe this scope. !calculator2.png|align=centre!
A node runs within a single JVM. A JVM can run many Nodes.
h2. {anchor:Host Embedded}
{bgcolor:#C3CDA1}Host Embedded
{bgcolor}
For a long time in Tuscany we have had a modules called [host.embedded|SCA JAVA host.embedded] that contains the code required to get the runtime up and running in standalone configuration. This was developed before the distributed domain support was added but the main interface here is called an SCADomain. It's just a very small domain with only one node inside it. You can't see the node and you configure and access it via the SCADomain interface. The majority of samples and tests use this today. However the new SCA Node implementation can work in both standalone and distributed configuration so may be more appropriate in situations other than the simple Tuscany samples and tests. We will convert more samples ant tests to this approach over time to show the benefit of using the node implementation.
h2. {anchor:Tuscany SCA Node Implementation}
{bgcolor:#C3CDA1}Tuscany SCA Node Implementation
{bgcolor}
Available from release 1.2 there is a new domain/node implementation. The node part of this can be run either stand alone or as part of a distributed domain. Most of the sample and test code has not started using this implementation yet and there may be more changes to the API.
h3. Creating and Configuring Node
Creating a node in code is straightforward. For example,
{code}
SCANode2 node = SCANode2Factory.newInstance().createSCANodeFromClassLoader("calculator.composite", null);
{code}
The node uses current classes classloader to located the named composite file. The location of the composite file is assumed to be the location if the SCA contribution. The assumption here is that only one contribution is required.
If more contributions must be loaded by the node the following interface can be used.
{code}
SCANode2 node = SCANode2Factory.newInstance().createSCANode("file:/C:/CalculatorContribution1/Calculator.composite",
new SCAContribution("CalculatorContribution1",
"file:/C:/CalculatorContribution1"),
new SCAContribution("CalculatorContribution2",
"file:/C:/CalculatorContribution2"));
{code}
Where
{code}
"file:/C:/CalculatorContribution1/Calculator.composite"
{code}
Is the explicit location of the composite file to be run and
{code}
new SCAContribution("CalculatorContribution1",
"file:/C:/CalculatorContribution1")
{code}
Shows how to provide contribution details. Multiple contributions can be specified. You might have multiple contributions if, for example, you have chosen to separate common artifacts from those specific to this composite. The contribution containing common artifacts can then be used in other SCA applications without change.
h3. Starting a Node
Once the node is created it is configured and ready for use. It can be started as follows.
{code}
node.start();
{code}
h3. Locating Services
A local service reference can be retrieved in the following way.
{code}
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
{code}
h3. Stopping a Node
If you are done with the node or need to stop is processing messages use the following.
{code}
node.stop();
{code}
h2. {anchor:Hosting Tuscany SCA Nodes}
{bgcolor:#C3CDA1}Hosting Tuscany SCA Nodes
{bgcolor}
You can run SCA applications in many different ways but the same underlying runtime is used but packaged in slightly different ways as follows
h3. Command Line
Most of the samples that are shipped with the Tuscany SCA Java distribution run from the command line by driving the Node API or old SCADomain API programmatically.
There is a pre-packaed launcher that has a mainline for starting nodes. When run from the command line it expects to be running in the context of the binary distribution where "modules" and "lib" directories are present.
It loads all of the jars from
1) the directory where the launcher class is found.
2) the ../modules directory
3) the ../libs directory
It then repeats the process looking for ../modules and ../lib dirs based on the contents of a TUSCANY_HOME environment variable
With the final list it creates a URLClassLoader with the current classloader as the parent and enforces a parent first classloading strategy.
(!) TODO - how does it find the composite file to run?
h3. WebApp
Some of the samples that are shipped with the Tuscany SCA Java distribution run as web apps
(!) TODO
h4. Tomcat
Running a Tuscany SCA Java enabled webapp in Tomcat is as simple as copying the webapp to the Tomcat webapps directory.
h4. Geronimo
(!) TODO
h4. WebSphere
Please see this blog entry to learn how to do this: [http://jsdelfino.blogspot.com/2007/10/how-to-use-apache-tuscany-with.html]
h4. WebLogic
Please see this user's blog to learn how to do this: [http://davesowerby.blogspot.com/2008/02/using-tuscany-with-weblogic.html]
h3. Eclipse
There are two Getting Started documents that discuss this.
[Getting Started with Tuscany using a Tuscany Distribution In Eclipse|Getting Started with Tuscany]
[Getting Started with Tuscany using the Tuscany Eclipse Plugin|Getting Started with Tuscany (using Tuscany Eclipse Plugin)]
h2. {anchor:Tuscany SCA Domain }
{bgcolor:#C3CDA1}Tuscany SCA Domain
{bgcolor}
SCA has the concept of a domain. Section 10 of the SCA Assembly specification describes an SCA Domain as defining "the boundary of visibility for all SCA mechanisms". SCA wires can be used to connect components within a single SCA Domain.
From the calculator sample you can see that the wires between the component references and services, formed by adding a target component name to a reference, are resolved inside an SCA domain. For example, this section of the calculator composite file shows how the CalcuatorServiceComponent targets the AddServiceComponent.
{code}
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService" target="AddServiceComponent" />
<reference name="subtractService" target="SubtractServiceComponent" />
<reference name="multiplyService" target="MultiplyServiceComponent" />
<reference name="divideService" target="DivideServiceComponent" />
</component>
<component name="AddServiceComponent">
<implementation.java class="calculator.AddServiceImpl"/>
</component>
{code}
The target="AddServiceComponent" of the CalculatorServiceComponent's addService reference refers to the AddServiceComponent defined later on in this composite. A domain can consist of more than one composite and wires can run between components defined in the composites. The SCA Domain describes the boundary within which target component services can be located.
To connect to services outside of the SCA Domain (whether they be services provided by SCA or by other means) you configure an explicit binding, for example, lets assume that the AddServiceComponent is a non-sca web service out there on the network somewhere. As this is outside the SCA domain we can use an explicit remote binding to talk to it.
{code}
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService" >
<interface.java interface="calculator.AddService" />
<binding.ws uri="http://localhost:8080/sample-calculator-ws-webapp/AddServiceComponent"/>
</reference>
<reference name="subtractService" target="SubtractServiceComponent"></reference>
<reference name="multiplyService" target="MultiplyServiceComponent"></reference>
<reference name="divideService" target="DivideServiceComponent"></reference>
</component>
{code}
Tuscany SCA supports running an SCA Domain in a single Node or spread across multiple Nodes potentially on different machines. We have seen a domain with a single node before.
!calculator2.png|align=centre!
A domain with multiple nodes allows wires to run between components running in the separate nodes which may be running on different JVMs on different machines.
!calculator3.png|align=centre!
When reference and service are in different composites the domain manager is used to pre-process each composited prior to the composites being deployed to nodes for running. Contributions (containing the composites) are added to the domain manager. Configuration must be provided which tells the workspace where the nodes are that are going to run the composites and which composites they will run. Based on this information the domain manager makes an atom feed available for each composite that is deployed to a node. The node to which the composite is assigned must read the correct atom feed in order to configure itself by downloading the composite to run and the contributions required provide the artifacts required by the composite. There is a Node API that takes as input the URL of an atom feed exposed by the domain manager as follows.
{code}
SCANode2 node = SCANode2Factory.newInstance().createSCANodeFromURL("http://localhost:9990/node-config/NodeA");
{code}
The URL http://localhost:9990/node-config/NodeA is the URL of the atom feed that the domain manager provides.
The domain manager processes all the relationships between all composite components and provides a fully configured composite to each node, i.e. all of the binding URIs are filled out correctly so it's basically a pre-processing step. You can simulate the effect by manually adding the full uri to the reference binding.ws if you don't want to run with the domain manager
The calculator-distributed sample is a simple example of the use of the workspace. You can fire up the workspace and play with the gui or look at the 3 xml files in the top directory of that sample which the workspace relies on for configuration.
h3. Starting A Domain
There is a launcher that has a mainline for starting the domain. For example,
{code}
public static void main(String[] args) throws Exception {
DomainManagerLauncher.main(args);
}
{code}
(!) TODO - how is this run without having to create your own mainline.
h3. Configuring A Domain Through The Web Interface
One the domain manager is running you can get to the web interface of the default domain point you browser at http://localhost:9990/ui. This provides a number of different pages allowing you to
* Add contributions to the domain
* Add node configurations to the domain
* Configure composites to run on specific nodes
* Start local node instances to test the configuration
h3. Configuring a Domain Through The File System
Behind the domain manager web application there are three files where the configuration information is stored.
*workspace.xml* - stores the ID and location of each contribution that has been added to the domain.
*domain.composite* - the virtual domain composite. This is an SCA composite that represents the virtual domain which includes all of the composites that will run in the domain. A URI is provided which indicates which contribution each composite comes from. Ultimately an SCANode2 instance will be started for each composite included in the virtual domain. Each SCANode2 instance can be running on separate/distributed processors. So the virtual domain is a consolidated description of you distributed SCA application
*cloud.composite* - describes the compute cloud (the set of distributed SCANode2 instances) being used to run the SCA application. Each node is assigned a composite and also has details of the configuration of bindings when they run on that node, for example, the root URI is set. It's possibly slightly confusing that this file is in SCA composite format also but this is a convenience because firstly we didn't have to create a new file format and secondly there may be some benefit in the future of representing this network of nodes as a network of SCA services for management purposes although we don't do that yet.
These files are updated when you make changes to the domain through the domain manager interface but they have a fairly simple XML format and can be edited manually or new utilities could be constructed to edit them automatically.
{anchor:Tuscany Domain Manager}
h2. Tuscany Web-based Domain Manager Tool
This [article|http://www.ibm.com/developerworks/webservices/library/ws-sca-tuscany/index.html?S_TACT=105AGX04&S_CMP=EDU] that is hosted outside of Tuscany provides a step by step instruction for how to use the Tuscany web-based domain manager UI to administer an SCA domain and how to use the domain administrative UI to deploy an SOA solution comprised of SCA components.
h2. {anchor:Tuscany SCA Core Features}
{bgcolor:#C3CDA1}Tuscany SCA Core Features
{bgcolor}
h3. {anchor:Policy}
{bgcolor:#C3CDA1}Policy
{bgcolor}
(!) TODO
h2. {anchor:Tuscany SCA Extensions}
{bgcolor:#C3CDA1}Tuscany SCA Extensions
{bgcolor}
h3. {anchor:The Extensible Runtime}
{bgcolor:#C3CDA1}The Extensible Runtime
{bgcolor}
The Tuscany SCA runtime comprises a small set of core software which deals with:
* Managing extesions to the Tuscany SCA Runtime(_core_)
* Building and in memory assembly model of SCA applications (_assembly_)
* Processing SCA applcations that are contributed (_contribution_)
* Supporting databindings (_databinding_)
* Supporting Tuscany SCA when its embedded in other environments (_embedded_)
* Supporting Tuscany SCA when its running in a servlet container (_http_)
The collections of interfaces that describe these features are referred to as the System Programming Interface (SPI). The [developer guide|SCA Java Developer Guide] discusses them in more detail but from a user perspective the important thing to realize is that the majority of interesting functionality in Tuscany SCA is provided by extensions which build upon this core SPI. These extensions provide Tuscany SCA with its ability to support a wide variety features.
* Implementation types
* Binding types
* Databinding types
* Interface description styles
* Hosting environments
So to understand how to use the Tuscany SCA runtime is to understand how to use its extensions. The available extensions are described in the [User Reference|SCA Java User Reference]
h3. {anchor:Using Extensions}
{bgcolor:#C3CDA1}Using Extensions
{bgcolor}
Extensions are loaded into the Tuscany SCA runtime using the Java service loading mechanism. Each extension is packaged as a jar and provides a file;
{code}
META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
{code}
Using this information the Tuscany SCA runtime will load each extensions present on the the Java CLASSPATH. So if you want to use a particular feature make sure that it's available on your classpath. Conversely if you don't want a particular feature to be active remove it from the classpath.
Writing a new extension is a subject in its own right and is described in the [extension guide|SCA Java Extension Development Guide]
h2. {anchor:Tuscany SCA And IDEs}
{bgcolor:#C3CDA1}Tuscany SCA And IDEs
{bgcolor}
h3. {anchor:Using The Samples In An IDE Without Maven}
{bgcolor:#C3CDA1}Using The Samples In An IDE Without Maven
{bgcolor}
We don't provide any IDE project files with our disitributions so you will have to import the sample files into your IDE manually. Here's an example of how it can be done using Eclipse. Here the directory tuscany_sca_install_dir is the directory whch holds the Tuscany SCA Java binary installation after it's been extracted from its archive file, for example, for the 0.90 release this will be tuscany-sca-0.90-incubating.
In a new or existing workspace
* Create a new java project to represent the sample you want to work on, e.g.
{noformat}
my working dir/calculator
{noformat}
* Import all of the sample code and resources into this project, e.g.
{noformat}
Use the File,Import menu and then select tuscany_sca_install_dir/samples/calculator from the filesystem
{noformat}
* Configure the source path to include
{noformat}
tuscany_sca_install_dir/samples/calculator/src/main/java
tuscany_sca_install_dir/samples/calculator/src/main/resources
{noformat}
* Configure the output folder to be
{noformat}
tuscany_sca_install_dir/samples/calculator/target
{noformat}
* Configure the build path to include all of the jars provided in
{noformat}
tuscany_sca_install_dir/lib
{noformat}
* If you select calculator.CalculatorClient.java and run as "Java Application" you should see
{noformat}
3 + 2=5.0
3 - 2=1.0
3 * 2=6.0
3 / 2=1.5
{noformat}
The details of how to do this for other development environments will vary but the process will be similar.
h3. {anchor:Using The Samples In An IDE If You Have Maven}
{bgcolor:#C3CDA1}Using The Samples In An IDE If You Have Maven
{bgcolor}
If you are a Maven user you can use it to generate all of the IDE project files for you automatically. This works best if you generate IDE projects for all of the Apache Tuscany modules. You can then include the ones you are interested in working with in you IDE.
To build IDE project files for all of the modules in Apache Tuscany SCA;
{noformat}
cd sca
{noformat}
If you are an Eclipse user do the following
{noformat}
mvn -Peclipse eclipse:eclipse
{noformat}
If you are an IDEA user do the following
{noformat}
mvn idea:idea
{noformat}
These commands generate project files for each module in Apache Tuscany SCA. The modules you are interested in can now be included in your IDE, for example, in Eclipse, if you create a new Java project and use the option to "create a new project from existing source" you can specify an SCA module directory, which includes the generated project files, and Eclipse will treat it like any other Java project.
{HTMLcomment:hidden}{children:sort=creation}{HTMLcomment}
|