You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2011/04/14 12:02:32 UTC

svn commit: r1092086 - in /tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse: ./ src/ src/main/ src/main/java/ src/main/java/calculator/ src/main/java/launcher/ src/test/ src/test/java/ src/test/java/launcher/

Author: slaws
Date: Thu Apr 14 10:02:31 2011
New Revision: 1092086

URL: http://svn.apache.org/viewvc?rev=1092086&view=rev
Log:
Add a stripped down JSE sample. This has rolled it back to the simplest I think we can make it. 

Added:
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/   (with props)
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt   (with props)
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/
    tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java

Propchange: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Apr 14 10:02:31 2011
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.html Thu Apr 14 10:02:31 2011
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html
+  PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><!--This file was converted to xhtml by OpenOffice.org - see http://xml.openoffice.org/odf2xhtml for more info.--><head profile="http://dublincore.org/documents/dcmi-terms/"><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/><title xml:lang="en-US">- no title specified</title><meta name="DCTERMS.title" content="" xml:lang="en-US"/><meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646"/><meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml"/><meta name="DCTERMS.creator" content="ant "/><meta name="DCTERMS.issued" content="2011-03-15T09:48:55.71" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.modified" content="2011-04-14T10:51:43.28" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.provenance" content="" xml:lang="en-US"/><meta name="DCTERMS.subject" content="," xml:lang="en-US"/><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en"/><link rel="schema.DCT
 ERMS" href="http://purl.org/dc/terms/" hreflang="en"/><link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en"/><link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en"/><base href="."/><style type="text/css">
+	@page {  }
+	table { border-collapse:collapse; border-spacing:0; empty-cells:show }
+	td, th { vertical-align:top; font-size:12pt;}
+	h1, h2, h3, h4, h5, h6 { clear:both }
+	ol, ul { margin:0; padding:0;}
+	li { list-style: none; margin:0; padding:0;}
+	<!-- "li span.odfLiEnd" - IE 7 issue-->
+	li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; }
+	span.footnodeNumber { padding-right:1em; }
+	span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000;  margin:0; border:0; padding:0;  }
+	* { margin:0;}
+	.Heading_20_1 { font-size:115%; margin-bottom:0.212cm; margin-top:0.423cm; font-family:Arial; writing-mode:page; font-weight:bold; }
+	.Standard { font-size:12pt; font-family:Times New Roman; writing-mode:page; }
+	.T1 { color:#000000; font-family:Courier New; font-size:10pt; }
+	.T2 { font-family:Courier New; font-size:10pt; }
+	<!-- ODF styles with no properties representable as CSS -->
+	{ }
+	</style></head><body dir="ltr" style="max-width:21.001cm;margin-top:2cm; margin-bottom:2cm; margin-left:2cm; margin-right:2cm; "><h1 class="Heading_20_1"><a id="a__Running_the_Tuscany_runtime_from_a_Java_program"><span/></a>Running the Tuscany runtime from a Java program</h1><p class="Standard"> </p><p class="Standard">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. </p><p class="Standard"> </p><p class="Standard">The basic pattern is as follows:</p><p 
 class="Standard"> </p><p class="Standard">1/ Use the <span class="T1">org.apache.tuscany.sca.node.NodeFactory </span>API to create a <span class="T1">org.apache.tuscany.sca.node.Node</span> instance configured with enough contributions to run the required composite</p><p class="Standard">2/ Start the Node instance. This starts deployable composites contained in the provided contributions</p><p class="Standard">3/ Interact with the services that the Node instance has made available</p><p class="Standard">4/ Stop the Node instance </p><p class="Standard"> </p><p class="Standard">The pattern is demonstrated in this sample in the <span class="T2">launcher.</span><span class="T1">LaunchCalculatorContribution </span>class. It loads the <span class="T2">calculator-contribution.jar </span>contribution found in the parent directory, makes a simple call to add two numbers together using the Calculator service and then shuts down. </p><p class="Standard"> </p><p class="Standar
 d">To run the sample on Windows do:</p><p class="Standard"> </p><p class="Standard">cd jse</p><p class="Standard">run-sample.bat</p><p class="Standard"> </p><p class="Standard">To run the sample on *nix do:</p><p class="Standard"> </p><p class="Standard">cd jse</p><p class="Standard">run-sample.sh</p><p class="Standard"> </p><p class="Standard">To re-build the sample classes do </p><p class="Standard"> </p><p class="Standard">cd jse</p><p class="Standard">mvn</p><p class="Standard"> </p><p class="Standard">Note. The mvn build will automatically run a unit test that also runs the sample. </p><p class="Standard"> </p></body></html>
\ No newline at end of file

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt?rev=1092086&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/README.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/pom.xml Thu Apr 14 10:02:31 2011
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-samples-running-tuscany</artifactId>
+        <version>2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>jse</artifactId>
+    <name>Apache Tuscany SCA Sample JSE</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-base-runtime</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>        
+                
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.1</version>
+            <scope>test</scope>
+        </dependency>
+        
+    </dependencies>
+
+    <build>
+       <finalName>${project.artifactId}</finalName>
+    </build>
+</project>

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.bat Thu Apr 14 10:02:31 2011
@@ -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

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/run-sample.sh Thu Apr 14 10:02:31 2011
@@ -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

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/calculator/CalculatorService.java Thu Apr 14 10:02:31 2011
@@ -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);
+
+}

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/main/java/launcher/LaunchCalculatorContribution.java Thu Apr 14 10:02:31 2011
@@ -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();
+    }
+    
+}

Added: tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java?rev=1092086&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/running-tuscany/jse/src/test/java/launcher/LauncherTestCase.java Thu Apr 14 10:02:31 2011
@@ -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);
+    }
+       
+}