tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r552346 - in /incubator/tuscany/java/sca/samples/calculator-distributed/src: main/java/calculator/CalculatorNode.java main/java/calculator/CalculatorNodeExe.java main/resources/runtime.topology test/java/calculator/CalculatorTestCase.java
Date Sun, 01 Jul 2007 17:46:03 GMT
Author: slaws
Date: Sun Jul  1 10:46:02 2007
New Revision: 552346

URL: http://svn.apache.org/viewvc?view=rev&rev=552346
Log:
Take account of reorganized distributed domain classes

Modified:
    incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNode.java
    incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNodeExe.java
    incubator/tuscany/java/sca/samples/calculator-distributed/src/main/resources/runtime.topology
    incubator/tuscany/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorTestCase.java

Modified: incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNode.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNode.java?view=diff&rev=552346&r1=552345&r2=552346
==============================================================================
--- incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNode.java
(original)
+++ incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNode.java
Sun Jul  1 10:46:02 2007
@@ -22,50 +22,30 @@
 import java.io.File;
 import java.net.URL;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
 
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
-import org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;
-import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;
-import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;
+
 import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl;
 import org.apache.tuscany.sca.contribution.service.ContributionService;
-import org.apache.tuscany.sca.distributed.host.impl.DistributedSCADomain;
-import org.apache.tuscany.sca.distributed.node.ComponentRegistry;
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.distributed.host.impl.DistributedSCADomainImpl;
+import org.apache.tuscany.sca.distributed.node.impl.NodeImpl;
 import org.apache.tuscany.sca.host.embedded.SCADomain;
-import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain;
-import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
-import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
-import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
-import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.topology.DefaultTopologyFactory;
-import org.apache.tuscany.sca.topology.Node;
-import org.apache.tuscany.sca.topology.TopologyFactory;
-import org.apache.tuscany.sca.topology.xml.TopologyDocumentProcessor;
-import org.apache.tuscany.sca.topology.xml.TopologyProcessor;
 
 /**
  * This is an example node implementation that uses the 
  * distributed runtime to run the calculator sample
  * We need to remove some of the function from here and 
- * put it in the runtime proper 
+ * put it in the runtime proper when we decide how nodes 
+ * will be configured remotely. For now the node is hardcoded
+ * to run the calculator sample. 
  */
 public class CalculatorNode {
     
-    private DistributedSCADomain domain;
+    private NodeImpl node;
+    private DistributedSCADomainImpl domain;
     private String domainName;
     private String nodeName;
     
@@ -75,25 +55,24 @@
     }
     
 
-    public SCADomain startDomain()
+    public SCADomain start()
       throws Exception {
-              
-        ClassLoader cl = CalculatorNode.class.getClassLoader();
-        domain = new DistributedSCADomain(cl,
-                                          domainName,
-                                          nodeName);
-        //Start the domain
-        domain.start();
-        
-        // configure the topology - should be done by file or remotely
-        ComponentRegistry componentRegistry = 
-            domain.getNodeService(ComponentRegistry.class, "ComponentRegistry");
-        
-        componentRegistry.setComponentNode("CalculatorServiceComponent", "nodeA");
-        componentRegistry.setComponentNode("AddServiceComponent", "nodeB");  
-        componentRegistry.setComponentNode("SubtractServiceComponent", "nodeC"); 
-        componentRegistry.setComponentNode("MultiplyServiceComponent", "nodeA");
-        componentRegistry.setComponentNode("DivideServiceComponent", "nodeA");
+        ClassLoader cl = CalculatorNodeExe.class.getClassLoader();        
+        
+        // create the node implementation. The node implementation
+        // will read the node configuration and then wait until you
+        // contribute assemblies
+        node = new NodeImpl("MyRuntime",
+                            nodeName,
+                            cl);
+        
+        // start the node to load the configuration
+        // and create the intial domains
+        node.start();          
+        
+        // load an application into a domain
+        // TODO - how are applications really going to be contributed?
+        domain = (DistributedSCADomainImpl)node.getDomain(domainName);
         
         // find the current directory as a URL. This is where our contribution 
         // will come from
@@ -117,14 +96,15 @@
         domain.getDomainCompositeHelper().activateDomain();
         
         // start the components, i.e. bring any exposed services on line
-        domain.getDomainCompositeHelper().startComponents();   
+        domain.getDomainCompositeHelper().startComponents(); 
         
-        return domain;        
+        return domain;
+    
     }
     
-    public void stopDomain() {
-        //Stop the domain
-        domain.close();        
+    public void stop() throws ActivationException {
+        //Stop the domains for this node
+        node.stop();
     }
 
 }

Modified: incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNodeExe.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNodeExe.java?view=diff&rev=552346&r1=552345&r2=552346
==============================================================================
--- incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNodeExe.java
(original)
+++ incubator/tuscany/java/sca/samples/calculator-distributed/src/main/java/calculator/CalculatorNodeExe.java
Sun Jul  1 10:46:02 2007
@@ -22,26 +22,33 @@
 import java.io.IOException;
 
 import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.topology.xml.Constants;
 
 /**
- * This client program shows how to create an SCA runtime, start it,
- * and locate and invoke an SCA component
+ * 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. 
  */
 public class CalculatorNodeExe {
-
+    
     public static void main(String[] args) throws Exception {
-              
+        
+        // Check that the correct arguments have been provided
         if (null == args || args.length != 1) {
              System.err.println("Useage: java CalculatorNodeExe nodename");   
              System.exit(1);
         }    
         
         String nodeName = args[0];
+                
+        // create and start the node. 
+        // this creates domains based on the runtime.topology file that
+        // must be present on the classpath
+        CalculatorNode node = new CalculatorNode(Constants.DEFAULT_DOMAIN,nodeName);
+        SCADomain domain = node.start(); 
         
-        // start the node and the domain at that node
-        CalculatorNode node = new CalculatorNode("domainA",nodeName);
-        SCADomain domain = node.startDomain();        
-        
+        // nodeA is the head node and runs some tests while all other nodes
+        // simply listen for incoming messages
         if ( nodeName.equals("nodeA") ) {            
             // do some application stuff
             CalculatorService calculatorService = 
@@ -62,7 +69,7 @@
             }  
         }
         
-        node.stopDomain();        
-             
+        // stop the node and all the domains in it 
+        node.stop(); 
     }
 }

Modified: incubator/tuscany/java/sca/samples/calculator-distributed/src/main/resources/runtime.topology
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/calculator-distributed/src/main/resources/runtime.topology?view=diff&rev=552346&r1=552345&r2=552346
==============================================================================
--- incubator/tuscany/java/sca/samples/calculator-distributed/src/main/resources/runtime.topology
(original)
+++ incubator/tuscany/java/sca/samples/calculator-distributed/src/main/resources/runtime.topology
Sun Jul  1 10:46:02 2007
@@ -18,11 +18,13 @@
  * under the License.    
 -->
 
-<runtime>
+<runtime xmlns="http://www.apache.org/tuscany/topology/1.0">
     <node name="nodeA">
         <schema name="http" baseURL="http://localhost:80" /> 
         <schema name="https" baseURL="https://localhost:443" />
         <component name="CalculatorServiceComponent" />
+        <component name="MultiplyServiceComponent" />   
+        <component name="DivideServiceComponent" />             
     </node>
     <node name="nodeB">
         <schema name="http" baseURL="http://localhost:81"/> 

Modified: incubator/tuscany/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorTestCase.java?view=diff&rev=552346&r1=552345&r2=552346
==============================================================================
--- incubator/tuscany/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorTestCase.java
(original)
+++ incubator/tuscany/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorTestCase.java
Sun Jul  1 10:46:02 2007
@@ -22,6 +22,7 @@
 
 import org.apache.activemq.broker.BrokerService;
 import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.topology.xml.Constants;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -52,28 +53,30 @@
         
         // start the node that runs the 
         // calculator component
-        nodeA = new CalculatorNode("domainA","nodeA");
-        domainA = nodeA.startDomain();
+        nodeA = new CalculatorNode(Constants.DEFAULT_DOMAIN,"nodeA");
+        domainA = nodeA.start();
         
         // start the node that runs the 
         // add component
-        nodeB = new CalculatorNode("domainA","nodeB");
-        domainB = nodeB.startDomain();
+        nodeB = new CalculatorNode(Constants.DEFAULT_DOMAIN,"nodeB");
+        domainB = nodeB.start();
         
         // start the node that runs the 
         // subtract component
-        nodeC = new CalculatorNode("domainA","nodeC");
-        domainC = nodeC.startDomain();        
+        nodeC = new CalculatorNode(Constants.DEFAULT_DOMAIN,"nodeC");
+        domainC = nodeC.start();        
         
+        // get a reference to the calculator service from domainA
+        // which will be running this component
         calculatorService = domainA.getService(CalculatorService.class, "CalculatorServiceComponent");
    }
 
     @AfterClass
     public static void destroy() throws Exception {
-        // stop the domains
-        nodeA.stopDomain();
-        nodeB.stopDomain();
-        nodeC.stopDomain();
+        // stop the nodes and hence the domains they contain
+        nodeA.stop();
+        nodeB.stop();
+        nodeC.stop();
         
         // stop the ActiveMQ broker
         broker.stop();
@@ -87,6 +90,5 @@
         Assert.assertEquals(calculatorService.subtract(3, 2), 1.0);
         Assert.assertEquals(calculatorService.multiply(3, 2), 6.0);
         Assert.assertEquals(calculatorService.divide(3, 2), 1.5);
-
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message