From 0c25c1f440cf92887597ca85d622c8e65343fb30 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 14 Apr 2011 10:02:31 +0000 Subject: Add a stripped down JSE sample. This has rolled it back to the simplest I think we can make it. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1092086 13f79535-47bb-0310-9956-ffa450edef68 --- .../trunk/samples/running-tuscany/jse/README.html | 22 ++++++++ .../trunk/samples/running-tuscany/jse/README.odt | Bin 0 -> 17416 bytes .../trunk/samples/running-tuscany/jse/pom.xml | 50 +++++++++++++++++ .../samples/running-tuscany/jse/run-sample.bat | 18 +++++++ .../samples/running-tuscany/jse/run-sample.sh | 19 +++++++ .../main/java/calculator/CalculatorService.java | 38 +++++++++++++ .../launcher/LaunchCalculatorContribution.java | 60 +++++++++++++++++++++ .../src/test/java/launcher/LauncherTestCase.java | 33 ++++++++++++ 8 files changed, 240 insertions(+) create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/README.html create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java create mode 100644 sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java (limited to 'sca-java-2.x') diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html b/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html new file mode 100644 index 0000000000..8bf943b454 --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html @@ -0,0 +1,22 @@ + + +- no title specified

Running the Tuscany runtime from a Java program

 

The Tuscany SCA Runtime provides a Node API that allows the runtime to be started from within a Java program. A Node in Tuscany represents a set of activated composites and a Node is configured  with all of the contributions required for those composites to run. The idea is to allow you to partition the domain up into it's constituent deployable composites and run each one in its own node on an appropriate machine. In that way the domain can easily be distributed while SCA takes care of making sure that wired services can communicate regardless of where they are.

 

The basic pattern is as follows:

 

1/ Use the org.apache.tuscany.sca.node.NodeFactory API to create a org.apache.tuscany.sca.node.Node instance configured with enough contributions to run the required composite

2/ Start the Node instance. This starts deployable composites contained in the provided contributions

3/ Interact with the services that the Node instance has made available

4/ Stop the Node instance

 

The pattern is demonstrated in this sample in the launcher.LaunchCalculatorContribution class. It loads the calculator-contribution.jar contribution found in the parent directory, makes a simple call to add two numbers together using the Calculator service and then shuts down.

 

To run the sample on Windows do:

 

cd jse

run-sample.bat

 

To run the sample on *nix do:

 

cd jse

run-sample.sh

 

To re-build the sample classes do

 

cd jse

mvn

 

Note. The mvn build will automatically run a unit test that also runs the sample.

 

\ No newline at end of file diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt b/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt new file mode 100644 index 0000000000..50548b82e0 Binary files /dev/null and b/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt differ diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml b/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml new file mode 100644 index 0000000000..7e2077d601 --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples-running-tuscany + 2.0-SNAPSHOT + ../pom.xml + + jse + Apache Tuscany SCA Sample JSE + + + + org.apache.tuscany.sca + tuscany-base-runtime + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${project.artifactId} + + diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat b/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat new file mode 100644 index 0000000000..a7965ff45c --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat @@ -0,0 +1,18 @@ +REM # Licensed to the Apache Software Foundation (ASF) under one +REM # or more contributor license agreements. See the NOTICE file +REM # distributed with this work for additional information +REM # regarding copyright ownership. The ASF licenses this file +REM # to you under the Apache License, Version 2.0 (the +REM # "License"); you may not use this file except in compliance +REM # with the License. You may obtain a copy of the License at +REM # +REM # http://www.apache.org/licenses/LICENSE-2.0 +REM # +REM # Unless required by applicable law or agreed to in writing, +REM # software distributed under the License is distributed on an +REM # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +REM # KIND, either express or implied. See the License for the +REM # specific language governing permissions and limitations +REM # under the License. + +java -cp ..\..\..\features\tuscany-base-runtime-pom\tuscany-base-runtime-pom-manifest.jar;target\jse.jar launcher.LaunchCalculatorContribution diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh b/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh new file mode 100644 index 0000000000..ecc78c2e46 --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations + +#!/bin/bash + +java -cp ../../../features/tuscany-base-runtime-pom/tuscany-base-runtime-pom-manifest.jar;target/jse.jar launcher.LaunchCalculatorContribution diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java new file mode 100644 index 0000000000..2b787fb6b8 --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component from Java. + */ +public class LaunchCalculatorContribution { + + /* + * Use the Tuscany Node API to: + * - create a Node instance and load a contribution from the parent directory + * - start the node (which starts deployable composites) + * - get a local service proxy + * - make a service call using the proxy + * - stop the node + */ + public static void main(String[] args) throws Exception { + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../calculator-contribution.jar")); + + node.start(); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + double result = calculator.add(3, 2); + + System.out.println("3 + 2 = " + result); + + if (result != 5.0){ + throw new RuntimeException("Expected 5.0 but result was " + result); + } + + node.stop(); + } + +} diff --git a/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java new file mode 100644 index 0000000000..8adabd8137 --- /dev/null +++ b/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package launcher; + +import org.junit.Test; + +/** + * Test the sample launcher + */ +public class LauncherTestCase { + + @Test + public void testCalculatorContribution() throws Exception { + LaunchCalculatorContribution.main(null); + } + +} -- cgit v1.2.3