tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1101408 - in /tuscany/sca-java-2.x/trunk/modules: domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
Date Tue, 10 May 2011 11:21:09 GMT
Author: antelder
Date: Tue May 10 11:21:09 2011
New Revision: 1101408

URL: http://svn.apache.org/viewvc?rev=1101408&view=rev
Log:
Finish the hazelcast registry composite serialization to share the composites amoungst nodes

Modified:
    tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java?rev=1101408&r1=1101407&r2=1101408&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java
Tue May 10 11:21:09 2011
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.endpoint.
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.StringReader;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -37,10 +38,18 @@ import javax.wsdl.WSDLException;
 import javax.wsdl.xml.WSDLReader;
 import javax.wsdl.xml.WSDLWriter;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.LifeCycleListener;
@@ -479,7 +488,7 @@ public class HazelcastEndpointRegistry e
     @Override
     public void addRunningComposite(Composite composite) {
         String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
-        String compositeXML = ""; // TODO: serialize composite
+        String compositeXML = writeComposite(composite);
         Transaction txn = hazelcastInstance.getTransaction();
         txn.begin();
         try {
@@ -510,11 +519,42 @@ public class HazelcastEndpointRegistry e
     @Override
     public Composite getRunningComposite(QName name) {
         String compositeXML = runningComposites.get(name);
-        return null; // TODO: unserialize composite xml
+        return readComposite(compositeXML);
     }
 
     @Override
     public List<QName> getRunningCompositeNames() {
         return new ArrayList<QName>(runningCompositeOwners.values());
     }
+
+    protected Composite readComposite(String compositeXML) {
+        try {
+            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
+            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors,
stAXHelper.getInputFactory(), null);
+            XMLStreamReader reader = stAXHelper.createXMLStreamReader(compositeXML);
+            Composite composite = (Composite)staxProcessor.read(reader, new ProcessorContext(registry));
+            return composite;
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        } catch (ContributionReadException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected String writeComposite(Composite composite) {
+        try {
+            StAXHelper stAXHelper = StAXHelper.getInstance(registry);
+            StAXArtifactProcessorExtensionPoint staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+            ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors,
null, stAXHelper.getOutputFactory());
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            staxProcessor.write(composite, bos, new ProcessorContext(registry));
+            bos.close();
+            return bos.toString();
+        } catch (ContributionWriteException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java?rev=1101408&r1=1101407&r2=1101408&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
Tue May 10 11:21:09 2011
@@ -32,8 +32,17 @@ import org.oasisopen.sca.NoSuchServiceEx
 public class DomainCompositeTestCase {
 
     @Test
-    public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException,
ContributionReadException, ActivationException, ValidationException {
-        Node node = TuscanyRuntime.newInstance().createNode("default");
+    public void localOnlyDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException,
ActivationException, ValidationException {
+        Node node = TuscanyRuntime.newInstance().createNode("DomainCompositeTestCase.localOnlyDomain");
+        testIt(node);
+    }
+    @Test
+    public void distributedDomain() throws NoSuchServiceException, NoSuchDomainException,
ContributionReadException, ActivationException, ValidationException {
+        Node node = TuscanyRuntime.newInstance().createNode("uri:DomainCompositeTestCase.distributedDomain");
+        testIt(node);
+    }
+
+    private void testIt(Node node) throws ContributionReadException, ActivationException,
ValidationException {
         node.installContribution("helloworld", "src/test/resources/sample-helloworld.jar",
null, null, true);
         
         Composite dc = node.getDomainLevelComposite();



Mime
View raw message