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.