From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../1.1-RC3a/samples/calculator-distributed/README | 476 +++++++++++++++++++++ .../samples/calculator-distributed/build.xml | 109 +++++ .../calculator-distributed.png | Bin 0 -> 76839 bytes .../calculator-distributed.svg | 383 +++++++++++++++++ .../samples/calculator-distributed/pom.xml | 116 +++++ .../src/main/java/calculator/AddService.java | 31 ++ .../src/main/java/calculator/AddServiceImpl.java | 31 ++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 74 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 30 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 30 ++ .../src/main/java/calculator/SubtractService.java | 31 ++ .../main/java/calculator/SubtractServiceImpl.java | 31 ++ .../src/main/java/node/CalculatorNode.java | 108 +++++ .../src/main/java/node/DomainNode.java | 51 +++ .../src/main/resources/nodeA/Calculator.composite | 41 ++ .../resources/nodeA/META-INF/sca-contribution.xml | 24 ++ .../src/main/resources/nodeB/Calculator.composite | 29 ++ .../resources/nodeB/META-INF/sca-contribution.xml | 24 ++ .../src/main/resources/nodeC/Calculator.composite | 29 ++ .../resources/nodeC/META-INF/sca-contribution.xml | 24 ++ .../java/calculator/DomainInMemoryTestCase.java | 123 ++++++ 24 files changed, 1886 insertions(+) create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/README create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/build.xml create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.png create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.svg create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/pom.xml create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/CalculatorNode.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/DomainNode.java create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/Calculator.composite create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/Calculator.composite create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/Calculator.composite create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/test/java/calculator/DomainInMemoryTestCase.java (limited to 'tags/java/sca/1.1-RC3a/samples/calculator-distributed') diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/README b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/README new file mode 100644 index 0000000000..d0629903de --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/README @@ -0,0 +1,476 @@ +Calculator Distributed Sample +============================= +This sample implements a simple calculator using SCA components. It uses +exactly the same calculator application classes as the calculator sample but +runs the application distributed across three nodes. + +A node in this sample means an instance of the Tuscany SCA java runtime running +in a Java virtual machine. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open four command prompts and +navigate to this sample directory in each one. There is one command to be run +in each command prompt: + +ant runDomain +ant runNodeB +ant runNodeC +ant runNodeA + +Please run the commands in this order. + +OR if you don't have ant, on Windows use + +java -cp src\main\resources;..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-distributed.jar node.DomainNode +java -cp src\main\resources;..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-distributed.jar node.CalculatorNode mydomain nodeB +java -cp src\main\resources;..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-distributed.jar node.CalculatorNode mydomain nodeC +java -cp src\main\resources;..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-distributed.jar node.CalculatorNode mydomain nodeA + +and on *nix do + +java -cp src/main/resources:../../lib/tuscany-sca-manifest.jar:target/sample-calculator-distributed.jar node.DomainNode +java -cp src/main/resources:../../lib/tuscany-sca-manifest.jar:target/sample-calculator-distributed.jar node.CalculatorNode mydomain nodeB +java -cp src/main/resources:../../lib/tuscany-sca-manifest.jar:target/sample-calculator-distributed.jar node.CalculatorNode mydomain nodeC +java -cp src/main/resources:../../lib/tuscany-sca-manifest.jar:target/sample-calculator-distributed.jar node.CalculatorNode mydomain nodeA + + +The processes started on each of these command prompts can be ended by pressing +the key. + + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. NodeA exercises this interface by calling add, subtract, multiply and +divide operations. + +In the case of add and subtract the runtime recognises that +it can't find these services locally and, using the remote (web services) +version of the default SCA binding contacts the add service running in NodeB +and the subtract service running in NodeC. + +On the command prompt where you started NodeA, you would see output of invoking the +calculator functions distributed over NodeB and and NodeC. On the command prompts +where you have started NodeB and NodeC, you would see log messages that indicate that +the add and substract services where called on these nodes respectively. + +The sample demonstrates that the calculator application can be distributed +across multiple nodes with no change to the application or to the SCA description +files. + + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + node/ + CalculatorNode.java - runs up an sca application based on + configuration given on the command + line in the form + + CalculatorNode + + it looks for a directory name the same + as and loads the composites + there + + if = nodeA it calls the + +-/* operations otherwise it behaves + like a server and waits for service + requests + DomainNode.java - the node that provides the service + discovery mechanism to the distributed + domain + resources/ + nodeA - the SCA assembly for nodeA's part of the + calculator application + nodeB - the SCA assembly for nodeB's part of the + calculator application + nodeC - the SCA assembly for nodeB's part of the + calculator application + test/ + java/ + calculator/ + DomainInMemoryTestCase.java - JUnit test case which runs all of the + separate ndes in a single VM for test + purposes + calculator-distributed.png - a pictorial representation of the sample + .composite files + build.xml - the Ant build file + pom.xml - the Maven build file + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator-distributed +ant compile +ant runDomain +ant runNodeB +ant runNodeC +ant runNodeA + +You should see the following output from the four separate command prompt: + +runDomain: + [java] 14-Jan-2008 10:49:34 org.apache.tuscany.sca.domain.impl.SCADomainImp +l init + [java] INFO: Domain management configured from file:/C:/simon/tuscany/relea +se/sca-r1.1-rc2/tuscany-sca-1.1-incubating-SNAPSHOT/lib/tuscany-sca-all-1.1-incu +bating-SNAPSHOT.jar + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/domain/* + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/SCADomainManagerCom +ponent/SCADomainManagerService/* + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/SCADomainManagerCom +ponent/SCADomainManagerService + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/SCADomain/scaDomain +.js + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/SCADomainManagerCom +ponent/SCADomainEventService + [java] 14-Jan-2008 10:49:43 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8877/SCADomainManagerCom +ponent/SCADomainAPIService + [java] Domain started (press enter to shutdown) + + + +runNodeB: + [java] 14-Jan-2008 10:50:41 org.apache.tuscany.sca.domain.impl.SCADomainImp +l registerNode + [java] INFO: Registered node: http://L3AW203:2047 at endpoint http://L3AW20 +3:2047 + [java] 14-Jan-2008 10:50:41 org.apache.tuscany.sca.node.impl.SCADomainProxy +Impl createRuntime + [java] INFO: Domain management configured from file:/C:/simon/tuscany/relea +se/sca-r1.1-rc2/tuscany-sca-1.1-incubating-SNAPSHOT/lib/tuscany-sca-all-1.1-incu +bating-SNAPSHOT.jar + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCADomainEventServi +ceProxyComponent + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCADomainAPIService +ProxyComponent + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCANodeManagerCompo +nent/SCANodeManagerService + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCANodeManagerCompo +nent/ComponentManagerService/* + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCANodeManagerCompo +nent/ComponentManagerService + [java] 14-Jan-2008 10:50:51 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/SCADomain/scaDomain +.js + [java] 14-Jan-2008 10:50:53 org.apache.tuscany.sca.node.impl.SCANodeImpl ac +tivateComposite + [java] INFO: Building composite: {http://sample}CalculatorB + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Node started (press enter to shutdown) + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl st +artComposite + [java] INFO: Starting composite: {http://sample}CalculatorB + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2047/AddServiceComponent +B + [java] AddService - add 3.0 and 2.0 + [java] 14-Jan-2008 10:51:39 org.apache.tuscany.sca.node.impl.SCANodeImpl st +opComposite + [java] INFO: Stopping composite: {http://sample}CalculatorB + +runNodeC: + [java] 14-Jan-2008 10:51:06 org.apache.tuscany.sca.domain.impl.SCADomainImp +l registerNode + [java] INFO: Registered node: http://L3AW203:2053 at endpoint http://L3AW20 +3:2053 + [java] 14-Jan-2008 10:51:07 org.apache.tuscany.sca.node.impl.SCADomainProxy +Impl createRuntime + [java] INFO: Domain management configured from file:/C:/simon/tuscany/relea +se/sca-r1.1-rc2/tuscany-sca-1.1-incubating-SNAPSHOT/lib/tuscany-sca-all-1.1-incu +bating-SNAPSHOT.jar + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCADomainEventServi +ceProxyComponent + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCADomainAPIService +ProxyComponent + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCANodeManagerCompo +nent/SCANodeManagerService + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCANodeManagerCompo +nent/ComponentManagerService/* + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCANodeManagerCompo +nent/ComponentManagerService + [java] 14-Jan-2008 10:51:16 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SCADomain/scaDomain +.js + [java] 14-Jan-2008 10:51:18 org.apache.tuscany.sca.node.impl.SCANodeImpl ac +tivateComposite + [java] INFO: Building composite: {http://sample}CalculatorC + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Node started (press enter to shutdown) + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl st +artComposite + [java] INFO: Starting composite: {http://sample}CalculatorC + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2053/SubtractServiceComp +onentC + [java] SubtractService - subtract 3.0 and 2.0 + [java] 14-Jan-2008 10:51:39 org.apache.tuscany.sca.node.impl.SCANodeImpl st +opComposite + [java] INFO: Stopping composite: {http://sample}CalculatorC + + +runNodeA: + [java] 14-Jan-2008 10:51:26 org.apache.tuscany.sca.domain.impl.SCADomainImp +l registerNode + [java] INFO: Registered node: http://L3AW203:2057 at endpoint http://L3AW20 +3:2057 + [java] 14-Jan-2008 10:51:26 org.apache.tuscany.sca.node.impl.SCADomainProxy +Impl createRuntime + [java] INFO: Domain management configured from file:/C:/simon/tuscany/relea +se/sca-r1.1-rc2/tuscany-sca-1.1-incubating-SNAPSHOT/lib/tuscany-sca-all-1.1-incu +bating-SNAPSHOT.jar + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCADomainEventServi +ceProxyComponent + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCADomainAPIService +ProxyComponent + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCANodeManagerCompo +nent/SCANodeManagerService + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCANodeManagerCompo +nent/ComponentManagerService/* + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCANodeManagerCompo +nent/ComponentManagerService + [java] 14-Jan-2008 10:51:36 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:2057/SCADomain/scaDomain +.js + [java] 14-Jan-2008 10:51:37 org.apache.tuscany.sca.node.impl.SCANodeImpl ac +tivateComposite + [java] INFO: Building composite: {http://sample}CalculatorA + [java] 14-Jan-2008 10:51:37 org.apache.tuscany.sca.assembly.builder.impl.Co +mpositeBuilderImpl$1 problem + [java] WARNING: Component reference target not found, it might be a remote +service: SubtractServiceComponentC + [java] 14-Jan-2008 10:51:37 org.apache.tuscany.sca.assembly.builder.impl.Co +mpositeBuilderImpl$1 problem + [java] WARNING: Component reference target not found, it might be a remote +service: AddServiceComponentB + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl up +dateComposite + [java] INFO: Updating composite {http://sample}CalculatorA at node http://L +3AW203:2057 + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl up +dateComposite + [java] INFO: Adding binding CalculatorServiceComponentA reference addServic +e binding org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl URI AddServiceC +omponentB + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl up +dateComposite + [java] INFO: Adding binding CalculatorServiceComponentA reference subtractS +ervice binding org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl URI Subtra +ctServiceComponentC + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.node.impl.SCANodeImpl st +artComposite + [java] INFO: Starting composite: {http://sample}CalculatorA + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] CalculatorService - add 3.0 and 2.0 + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 AddServiceComponentB o +rg.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 3 + 2=5.0 + [java] CalculatorService - subtract 3.0 and 2.0 + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 14-Jan-2008 10:51:38 org.apache.tuscany.sca.domain.impl.SCADomainImp +l findServiceEndpoint + [java] INFO: Finding service: [http://localhost:8877 SubtractServiceCompone +ntC org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl] + [java] 3 - 2=1.0 + [java] CalculatorService - multiply 3.0 and 2.0 + [java] 3 * 2=6.0 + [java] CalculatorService - divide 3.0 and 2.0 + [java] 3 / 2=1.5 + [java] 14-Jan-2008 10:51:39 org.apache.tuscany.sca.node.impl.SCANodeImpl st +opComposite + [java] INFO: Stopping composite: {http://sample}CalculatorA + + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. When running from Maven the four nodes all run within +Java virtual machine. + +cd calculator-distributed +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.DomainInMemoryTestCase +Setting up distributed nodes +file:/C:/simon/tuscany/java-head/sca/samples/calculator-distributed/target/class +es/management/ +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +23-Aug-2007 18:18:41 org.apache.tuscany.sca.assembly.builder.impl.CompositeBuild +erImpl$1 problem +WARNING: [WARNING] Component reference target not found, it might be a remote se +rvice: AddServiceComponent null + +23-Aug-2007 18:18:41 org.apache.tuscany.sca.assembly.builder.impl.CompositeBuild +erImpl$1 problem +WARNING: [WARNING] Component reference target not found, it might be a remote se +rvice: SubtractServiceComponent null + +file:/C:/simon/tuscany/java-head/sca/samples/calculator-distributed/target/class +es/management/ +Registering service: [mydomain nodeB AddServiceComponent org.apache.tuscany.sca. +assembly.SCABinding http://localhost:8085/AddServiceComponent] +file:/C:/simon/tuscany/java-head/sca/samples/calculator-distributed/target/class +es/management/ +Registering service: [mydomain nodeC SubtractServiceComponent org.apache.tuscany +.sca.assembly.SCABinding http://localhost:8086/SubtractServiceComponent] +Finding service: [mydomain SubtractServiceComponent org.apache.tuscany.sca.assem +bly.SCABinding] +Matching service url: http://localhost:8086/SubtractServiceComponent +Finding service: [mydomain AddServiceComponent org.apache.tuscany.sca.assembly.S +CABinding] +Matching service url: http://localhost:8085/AddServiceComponent +23-Aug-2007 18:18:45 org.apache.tuscany.sca.http.jetty.JettyServer addServletMap +ping +INFO: Added Servlet mapping: http://localhost:8085/AddServiceComponent +23-Aug-2007 18:18:47 org.apache.tuscany.sca.http.jetty.JettyServer addServletMap +ping +INFO: Added Servlet mapping: http://localhost:8086/SubtractServiceComponent +CalculatorService - add 3.0 and 2.0 +AddService - add 3.0 and 2.0 +CalculatorService - subtract 3.0 and 2.0 +SubtractService - subtract 3.0 and 2.0 +CalculatorService - multiply 3.0 and 2.0 +CalculatorService - divide 3.0 and 2.0 +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.14 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + + +This shows that the Junit test cases have run successfully. + + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/build.xml b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/build.xml new file mode 100644 index 0000000000..59f704f4a2 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/build.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.png b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.png new file mode 100644 index 0000000000..7c0e175664 Binary files /dev/null and b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.png differ diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.svg b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.svg new file mode 100644 index 0000000000..be5a4b8185 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/calculator-distributed.svg @@ -0,0 +1,383 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + + nodeB nodeC + nodeA + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/pom.xml b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/pom.xml new file mode 100644 index 0000000000..bbecb6d9b2 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/pom.xml @@ -0,0 +1,116 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.1-incubating + ../../pom.xml + + sample-calculator-distributed + Apache Tuscany SCA Distributed Calculator Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.1-incubating + + + + org.apache.tuscany.sca + tuscany-node-api + 1.1-incubating + + + + org.apache.tuscany.sca + tuscany-domain-api + 1.1-incubating + + + + org.apache.tuscany.sca + tuscany-binding-sca-axis2 + 1.1-incubating + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 1.1-incubating + + + + org.apache.tuscany.sca + tuscany-binding-http + 1.1-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-resource + 1.1-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.1-incubating + test + + + + org.apache.tuscany.sca + tuscany-domain-impl + 1.1-incubating + test + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.1-incubating + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddService.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..d7dc4473ad --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddService.java @@ -0,0 +1,31 @@ +/* + * 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.osoa.sca.annotations.Remotable; + +/** + * The Add service interface + */ +@Remotable +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e9b7e254e5 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + System.out.println("AddService - add " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorService.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * 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; + + +/** + * The Calculator service interface. + */ +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/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..da869e00fd --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,74 @@ +/* + * 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.osoa.sca.annotations.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + public double add(double n1, double n2) { + System.out.println("CalculatorService - add " + n1 + " and " + n2); + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + System.out.println("CalculatorService - subtract " + n1 + " and " + n2); + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + System.out.println("CalculatorService - multiply " + n1 + " and " + n2); + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + System.out.println("CalculatorService - divide " + n1 + " and " + n2); + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideService.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..f7ac0b7287 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyService.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..b7dca792b2 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractService.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..78ab9c6ee0 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractService.java @@ -0,0 +1,31 @@ +/* + * 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.osoa.sca.annotations.Remotable; + +/** + * The interface for the multiply service + */ +@Remotable +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..1010207154 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + System.out.println("SubtractService - subtract " + n1 + " and " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/CalculatorNode.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/CalculatorNode.java new file mode 100644 index 0000000000..5dd64fc920 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/CalculatorNode.java @@ -0,0 +1,108 @@ +/* + * 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 node; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.domain.SCADomain; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to run a distributed SCA node. In this case a + * calculator node has been constructed specifically for running the calculator + * composite. Internally it creates a representation of a node and associates a + * distributed domain with the node. This separation is made different implementations + * of the distributed domain can be provided. + */ +public class CalculatorNode { + + + public static void main(String[] args) throws Exception { + + // Check that the correct arguments have been provided + if (null == args || args.length < 2) { + System.err.println("Useage: java CalculatorNode domainname nodename"); + System.exit(1); + } + + try { + String domainName = args[0]; + String nodeName = args[1]; + + ClassLoader cl = CalculatorNode.class.getClassLoader(); + + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); + SCANode node = nodeFactory.createSCANode(null, domainName); + node.addContribution(nodeName, cl.getResource(nodeName + "/")); + node.addToDomainLevelComposite((QName)null); + + // nodeA is the head node and runs some tests while all other nodes + // simply listen for incoming messages + if ( nodeName.equals("nodeA") ) { + + // start the domain + node.getDomain().start(); + + // do some application stuff + CalculatorService calculatorService = + node.getDomain().getService(CalculatorService.class, "CalculatorServiceComponentA"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + // a little hidden loop test to put some load on the nodes + if (args.length > 2){ + for (int i=0; i < 1000; i++){ + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + } + } + + // stop all the nodes + node.getDomain().stop(); + } else { + // start up and wait for messages + try { + System.out.println("Node started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + node.destroy(); + + } catch(Exception ex) { + System.err.println("Exception in node - " + ex.getMessage()); + ex.printStackTrace(System.err); + } + } +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/DomainNode.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/DomainNode.java new file mode 100644 index 0000000000..a900cb72f8 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/java/node/DomainNode.java @@ -0,0 +1,51 @@ +/* + * 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 node; + +import org.apache.tuscany.sca.domain.SCADomain; +import org.apache.tuscany.sca.domain.SCADomainFactory; + + +/** + * This server program that loads a composite to provide simple registry function. + * This server can be replaced with any registry that is appropriate but the components + * in each node that talk to the registry should be replaced also. + */ +public class DomainNode { + + private static String DEFAULT_DOMAIN_URI = "http://localhost:8877"; + + public static void main(String[] args) { + + try { + SCADomainFactory domainFactory = SCADomainFactory.newInstance(); + SCADomain domain = domainFactory.createSCADomain(DEFAULT_DOMAIN_URI); + + System.out.println("Domain started (press enter to shutdown)"); + System.in.read(); + + domain.destroy(); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Domain stopped"); + } + +} diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/Calculator.composite b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/Calculator.composite new file mode 100644 index 0000000000..172676a3c7 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/Calculator.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..1b1c0291e2 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/Calculator.composite b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/Calculator.composite new file mode 100644 index 0000000000..b770dbe8d4 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/Calculator.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..6c0ffe4ac0 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/Calculator.composite b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/Calculator.composite new file mode 100644 index 0000000000..66caf0d17b --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/Calculator.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..8c311553c3 --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/test/java/calculator/DomainInMemoryTestCase.java b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/test/java/calculator/DomainInMemoryTestCase.java new file mode 100644 index 0000000000..8dc6ffb2bd --- /dev/null +++ b/tags/java/sca/1.1-RC3a/samples/calculator-distributed/src/test/java/calculator/DomainInMemoryTestCase.java @@ -0,0 +1,123 @@ +/* + * 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 javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.domain.SCADomain; +import org.apache.tuscany.sca.domain.SCADomainFactory; +import org.apache.tuscany.sca.node.SCADomainFinder; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import calculator.CalculatorService; + +/** + * Runs a distributed domain in a single VM by using and in memory + * implementation of the distributed domain + */ +public class DomainInMemoryTestCase { + + private static SCADomain domainManager; + private static SCANode nodeA; + private static SCANode nodeB; + private static SCANode nodeC; + private static SCADomain domain; + private static CalculatorService calculatorServiceA; + private static CalculatorService calculatorServiceB; + private static AddService addServiceB; + + @BeforeClass + public static void init() throws Exception { + + try { + System.out.println("Setting up domain manager"); + + SCADomainFactory domainFactory = SCADomainFactory.newInstance(); + domainManager = domainFactory.createSCADomain("http://localhost:9999"); + + System.out.println("Setting up calculator nodes"); + + ClassLoader cl = DomainInMemoryTestCase.class.getClassLoader(); + + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); + + nodeA = nodeFactory.createSCANode("http://localhost:8085/nodeA", "http://localhost:9999"); + nodeA.addContribution("nodeA", cl.getResource("nodeA/")); + nodeA.addToDomainLevelComposite(new QName("http://sample", "CalculatorA")); + + + nodeB = nodeFactory.createSCANode("http://localhost:8086/nodeB", "http://localhost:9999"); + nodeB.addContribution("nodeB", cl.getResource("nodeB/")); + nodeB.addToDomainLevelComposite(new QName("http://sample", "CalculatorB")); + + + nodeC = nodeFactory.createSCANode("http://localhost:8087/nodeC", "http://localhost:9999"); + nodeC.addContribution("nodeC", cl.getResource("nodeC/")); + nodeC.addToDomainLevelComposite(new QName("http://sample", "CalculatorC")); + + + SCADomainFinder domainFinder = SCADomainFinder.newInstance(); + domain = domainFinder.getSCADomain("http://localhost:9999"); + + domain.start(); + + // get a reference to various services in the domain + calculatorServiceA = nodeA.getDomain().getService(CalculatorService.class, "CalculatorServiceComponentA"); + //calculatorServiceB = nodeB.getDomain().getService(CalculatorService.class, "CalculatorServiceComponentB"); + + //addServiceB = domain.getService(AddService.class, "AddServiceComponentB"); + //addServiceB = nodeA.getDomain().getService(AddService.class, "AddServiceComponentB"); + + } catch(Exception ex){ + System.err.println(ex.toString()); + } + + } + + @AfterClass + public static void destroy() throws Exception { + // stop the domain + domain.stop(); + + // destory the nodes + nodeA.destroy(); + nodeB.destroy(); + nodeC.destroy(); + + // destroy the domain + domain.destroy(); + } + + @Test + public void testCalculator() throws Exception { + + // Calculate + Assert.assertEquals(calculatorServiceA.add(3, 2), 5.0); + Assert.assertEquals(calculatorServiceA.subtract(3, 2), 1.0); + Assert.assertEquals(calculatorServiceA.multiply(3, 2), 6.0); + Assert.assertEquals(calculatorServiceA.divide(3, 2), 1.5); + } +} -- cgit v1.2.3