Tuscany Calculator Sample

Overview

The Tuscany calculator sample shows using the Tuscany SCA runtime in a J2SE environment  loading several components. Each component provides a basic operation (add, subtract, etc).
The main component uses each of these to perrform a simple calculation.

Location

This sample is located  in the samples\sca\calculator directory.

Setup

This sample depends on the Tuscany runtime and the sample jar, sample-calculator-incubating-M1.jar , both of these must be available on the classpath to run the sample.

Running

In the directory samples/sca/calculator use the JDK 1.5 java command to run the class calculator.CalculatorClient
Linux: java -cp ../../../lib/tuscany-runtime-incubating-M1.jar:target/sample-calculator-incubating-M1.jar calculator.CalculatorClient
Windows: java -cp ../../../lib/tuscany-runtime-incubating-M1.jar;target/sample-calculator-incubating-M1.jar calculator.CalculatorClient

Results

The sample when run should simply display to the standard output:
Hello World

Code Overview

The source files are physically organized as shown below:
src
+---main
    +---java
    ¦   +---calculator
    ¦           AddService.java
    ¦           AddServiceImpl.java
    ¦           CalculatorClient.java
    ¦           CalculatorService.java
    ¦           CalculatorServiceImpl.java
    ¦           DivideService.java
    ¦           DivideServiceImpl.java
    ¦           MultiplyService.java
    ¦           MultiplyServiceImpl.java
    ¦           SubtractService.java
    ¦           SubtractServiceImpl.java
    ¦
    +---resources
            logging.properties
            sca.module

sca.module Defines the SCA module and component. Defines for the CalculatorServiceComponent component  the Java class that implements that component.  Wires each of the operation components to the CalculatorServiceComponent
CalculatorService.java Defines the Java interface implemented by the cacomponent.
CalculatorServiceImpl.java Implements the SCA component. Uses the SCA service annotation tag on the class to show what SCA interface is being implemented.
CalculatorClient.java Creates a Tuscany runtime and starts it.  Obtains the module context which was defined by the sca.module file. From the module context locates the CalculatorServiceComponent and then calls operations on that component to demonstrating it using the multiple components implementing the operations..