Author: slaws
Date: Tue Oct 30 06:06:01 2007
New Revision: 590057
URL: http://svn.apache.org/viewvc?rev=590057&view=rev
Log:
Add a new create operation to the node factory for stand alone operation
Allow the node to stopped and started repeatedly
Add a test case for stand alone operation
Added:
incubator/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/StandaloneNodeTestCase.java
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/Calculator.composite
Modified:
incubator/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeFactoryImpl.java
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
Modified:
incubator/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java?rev=590057&r1=590056&r2=590057&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
(original)
+++
incubator/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
Tue Oct 30 06:06:01 2007
@@ -66,6 +66,16 @@
}
/**
+ * Creates a new standalone SCA node. i.e. a node that is not connected to
a
+ * wider distributed domain
+ *
+ * @param nodeURI the URI of the node, this is the endpoint URI of the
+ * node administration service
+ * @return a new SCA node.
+ */
+ public abstract SCANode createSCANode(String nodeURI) throws NodeException;
+
+ /**
* Creates a new SCA node.
*
* @param nodeURI the URI of the node, this is the endpoint URI of the
Modified:
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeFactoryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeFactoryImpl.java?rev=590057&r1=590056&r2=590057&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeFactoryImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeFactoryImpl.java
Tue Oct 30 06:06:01 2007
@@ -33,12 +33,24 @@
/**
- * Returns a new SCA domain finder instance.
+ * Create a new SCA node factory instance.
*
- * @return a new SCA domain finder
+ * @return a new SCA node factory
*/
public SCANodeFactoryImpl() {
+ }
+
+ /**
+ * Creates a new standalone SCA node. i.e. a node that is not connected to
a
+ * wider distributed domain
+ *
+ * @param nodeURI the URI of the node, this is the endpoint URI of the
+ * node administration service
+ * @return a new SCA node.
+ */
+ public SCANode createSCANode(String nodeURI) throws NodeException {
+ return new SCANodeImpl(nodeURI, null, null);
}
/**
Modified:
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java?rev=590057&r1=590056&r2=590057&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
Tue Oct 30 06:06:01 2007
@@ -316,12 +316,28 @@
}
public void removeContribution(String contributionURI) throws
NodeException {
- try {
+ try {
+ Contribution contribution = contributions.get(contributionURI);
+
+ // remove the local record of composites associated with this
contribution
+ for (DeployedArtifact artifact : contribution.getArtifacts()) {
+ if (artifact.getModel() instanceof Composite) {
+ Composite composite = (Composite)artifact.getModel();
+ composites.remove(composite.getName());
+ compositeFiles.remove(composite.getURI());
+ compositesToStart.remove(composite.getName());
+ }
+ }
+
+ // remove the contribution from the runtime
nodeRuntime.getContributionService().remove(contributionURI);
+
+ // remove the local record of the contribution
+ contributions.remove(contributionURI);
} catch (Exception ex) {
throw new NodeException(ex);
}
- contributions.remove(contributionURI);
+
}
private void removeAllContributions() throws NodeException {
@@ -329,8 +345,14 @@
// Remove all contributions
for (String contributionURI : contributions.keySet()){
nodeRuntime.getContributionService().remove(contributionURI);
- contributions.remove(contributionURI);
}
+
+ // remove local records
+ contributions.clear();
+ composites.clear();
+ compositeFiles.clear();
+ compositesToStart.clear();
+
} catch (Exception ex) {
throw new NodeException(ex);
}
@@ -467,15 +489,10 @@
nodeRuntime.getCompositeActivator().stop(composite);
nodeRuntime.getCompositeActivator().deactivate(composite);
-
- composites.remove(compositeName);
- compositeFiles.remove(composite.getURI());
}
- compositesToStart.clear();
} catch (NodeException ex) {
- throw ex;
-
+ throw ex;
} catch (Exception ex) {
throw new NodeException(ex);
}
Added:
incubator/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/StandaloneNodeTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/StandaloneNodeTestCase.java?rev=590057&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/StandaloneNodeTestCase.java
(added)
+++
incubator/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/StandaloneNodeTestCase.java
Tue Oct 30 06:06:01 2007
@@ -0,0 +1,118 @@
+/*
+ * 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 org.apache.tuscany.sca.node.impl;
+
+
+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.AddService;
+import calculator.CalculatorService;
+import calculator.SubtractService;
+
+/**
+ * Runs a distributed domain in a single VM by using and in memory
+ * implementation of the distributed domain
+ */
+public class StandaloneNodeTestCase {
+
+ private static SCANode node;
+ private static CalculatorService calculatorServiceD;
+ private static AddService addServiceD;
+ private static SubtractService subtractServiceC;
+ private static ClassLoader cl;
+
+
+ @BeforeClass
+ public static void init() throws Exception {
+
+ try {
+ System.out.println("Setting up add node");
+
+ cl = StandaloneNodeTestCase.class.getClassLoader();
+
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+
+ // rely on meta data to start composite
+ node = nodeFactory.createSCANode("http://localhost:8200/node");
+ node.addContribution("nodeC", cl.getResource("nodeC/"));
+ node.addToDomainLevelComposite(new QName("http://sample",
"Calculator"));
+ node.start();
+
+ // get a reference to various services in the node
+ subtractServiceC =
node.getDomain().getService(SubtractService.class,
"SubtractServiceComponentC");
+
+ } catch(Exception ex){
+ System.err.println(ex.toString());
+ }
+
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ // stop the node
+ node.destroy();
+ }
+
+ @Test
+ public void testSubtract() throws Exception {
+ Assert.assertEquals(subtractServiceC.subtract(3, 2), 1.0);
+ }
+
+ @Test
+ public void testAddSecondContribution() throws Exception {
+ node.stop();
+ try {
+ subtractServiceC.subtract(3, 2);
+ } catch (Exception ex) {
+ // System.out.println(ex.toString());
+ }
+
+ node.addContribution("nodeD", cl.getResource("nodeD/"));
+ node.start();
+ subtractServiceC = node.getDomain().getService(SubtractService.class,
"SubtractServiceComponentC");
+ calculatorServiceD =
node.getDomain().getService(CalculatorService.class,
"CalculatorServiceComponentD");
+ addServiceD = node.getDomain().getService(AddService.class,
"AddServiceComponentD");
+
+ }
+
+ @Test
+ public void testCalculate() throws Exception {
+
+ // Calculate
+ Assert.assertEquals(calculatorServiceD.add(3, 2), 5.0);
+ Assert.assertEquals(calculatorServiceD.subtract(3, 2), 1.0);
+ Assert.assertEquals(calculatorServiceD.multiply(3, 2), 6.0);
+ Assert.assertEquals(calculatorServiceD.divide(3, 2), 1.5);
+ Assert.assertEquals(addServiceD.add(3, 2), 5.0);
+ Assert.assertEquals(subtractServiceC.subtract(3, 2), 1.0);
+
+ }
+}
Added:
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/Calculator.composite
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/Calculator.composite?rev=590057&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/Calculator.composite
(added)
+++
incubator/tuscany/java/sca/modules/node-impl/src/test/resources/nodeD/META-INF/sca-deployables/Calculator.composite
Tue Oct 30 06:06:01 2007
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="CalculatorFull">
+
+ <component name="CalculatorServiceComponentD">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponentD" />
+ <reference name="subtractService" target="SubtractServiceComponentD" />
+ <reference name="multiplyService" target="MultiplyServiceComponentD"/>
+ <reference name="divideService" target="DivideServiceComponentD" />
+ </component>
+
+ <component name="MultiplyServiceComponentD">
+ <implementation.java class="calculator.MultiplyServiceImpl" />
+ </component>
+
+ <component name="DivideServiceComponentD">
+ <implementation.java class="calculator.DivideServiceImpl" />
+ </component>
+
+ <component name="AddServiceComponentD">
+ <implementation.java class="calculator.AddServiceImpl" />
+ </component>
+
+ <component name="SubtractServiceComponentD">
+ <implementation.java class="calculator.SubtractServiceImpl" />
+ </component>
+
+</composite>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]