tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1101207 - in /tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src: main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java
Date Mon, 09 May 2011 20:27:03 GMT
Author: antelder
Date: Mon May  9 20:27:03 2011
New Revision: 1101207

URL: http://svn.apache.org/viewvc?rev=1101207&view=rev
Log:
Update hazelcast registry to store and use the wsdl interface contract for endpoints in the
domain so that remote endpoints include the interface information

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-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.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=1101207&r1=1101206&r2=1101207&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
Mon May  9 20:27:03 2011
@@ -19,7 +19,9 @@
 
 package org.apache.tuscany.sca.endpoint.hazelcast;
 
+import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
+import java.io.StringReader;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,6 +33,10 @@ import java.util.concurrent.ConcurrentHa
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLWriter;
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -40,11 +46,17 @@ import org.apache.tuscany.sca.core.Exten
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.LifeCycleListener;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
 import org.apache.tuscany.sca.runtime.BaseEndpointRegistry;
 import org.apache.tuscany.sca.runtime.EndpointRegistry;
 import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
 import org.apache.tuscany.sca.runtime.RuntimeProperties;
 import org.oasisopen.sca.ServiceRuntimeException;
+import org.xml.sax.InputSource;
 
 import com.hazelcast.config.Config;
 import com.hazelcast.config.NearCacheConfig;
@@ -71,15 +83,15 @@ public class HazelcastEndpointRegistry e
 
     private HazelcastInstance hazelcastInstance;
     protected Map<Object, Object> endpointMap;
+    protected Map<Object, Object> endpointWsdls;
+    protected Map<QName, Composite> runningComposites;
     protected Map<String, Endpoint> localEndpoints = new ConcurrentHashMap<String,
Endpoint>();
     protected MultiMap<String, String> endpointOwners;
-    protected Map<QName, Composite> runningComposites;
 
     protected AssemblyFactory assemblyFactory;
     protected Object shutdownMutex = new Object();
     protected Properties properties;
 
-
     public HazelcastEndpointRegistry(ExtensionPointRegistry registry, Properties properties,
String endpointRegistryURI, String domainURI) {
         super(registry, null, endpointRegistryURI, domainURI);
         this.assemblyFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(AssemblyFactory.class);
@@ -112,6 +124,7 @@ public class HazelcastEndpointRegistry e
             endpointMap = imap;
             
             endpointOwners = hazelcastInstance.getMultiMap(domainURI + "/EndpointOwners");
+            endpointWsdls = hazelcastInstance.getMap(domainURI + "/EndpointWsdls");
 
             // TODO: get going in-JVM first then fix this which needs to serialize/deserialize
the composite
             // runningComposites = hazelcastInstance.getMap(domainURI + "/composites");
@@ -128,6 +141,7 @@ public class HazelcastEndpointRegistry e
                 hazelcastInstance = null;
                 endpointMap = null;
                 endpointOwners = null;
+                endpointWsdls = null;
             }
         }
     }
@@ -233,10 +247,12 @@ public class HazelcastEndpointRegistry e
             
         String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
         String endpointURI = endpoint.getURI();
+        String wsdl = getWsdl(endpoint);
         Transaction txn = hazelcastInstance.getTransaction();
         txn.begin();
         try {
             endpointMap.put(endpointURI, endpoint);
+            endpointWsdls.put(endpointURI, wsdl);
             endpointOwners.put(localMemberAddr, endpointURI);
             txn.commit();
         } catch (Throwable e) {
@@ -247,6 +263,23 @@ public class HazelcastEndpointRegistry e
         logger.info("Add endpoint - " + endpoint);
     }
 
+    private String getWsdl(Endpoint endpoint) {
+        WSDLInterfaceContract wsdlIC = (WSDLInterfaceContract)((RuntimeEndpoint)endpoint).getGeneratedWSDLContract(endpoint.getComponentServiceInterfaceContract());
+        if (wsdlIC == null) {
+            return "";
+        }
+        WSDLInterface wsdl = (WSDLInterface)wsdlIC.getInterface();
+        WSDLDefinition d = wsdl.getWsdlDefinition();
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+        try {
+            WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
+            writer.writeWSDL(d.getDefinition(), outStream);
+        } catch (Exception e){
+            throw new RuntimeException(e);
+        }
+        return outStream.toString();
+    }
+
     public List<Endpoint> findEndpoint(String uri) {
         List<Endpoint> foundEndpoints = new ArrayList<Endpoint>();
         for (Object v : endpointMap.values()) {
@@ -266,6 +299,11 @@ public class HazelcastEndpointRegistry e
         if (!isLocal(endpoint)) {
             endpoint.setRemote(true);
             ((RuntimeEndpoint)endpoint).bind(registry, this);
+            try {
+                setNormailizedWSDLContract(endpoint);
+            } catch (WSDLException e) {
+                throw new RuntimeException(e);
+            }
         } else {
             // get the local version of the endpoint
             // this local version won't have been serialized
@@ -277,6 +315,25 @@ public class HazelcastEndpointRegistry e
     }
     
 
+    private void setNormailizedWSDLContract(Endpoint endpoint) throws WSDLException {
+        String wsdl = endpointWsdls == null ? null : (String)endpointWsdls.get(endpoint.getURI());
+        if (wsdl == null || wsdl.length() < 1) {
+            return;
+        }
+        InterfaceContract ic = endpoint.getComponentServiceInterfaceContract();
+        WSDLFactory wsdlFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(WSDLFactory.class);
+        WSDLInterfaceContract wsdlIC = wsdlFactory.createWSDLInterfaceContract();
+        WSDLInterface wsdlIface = wsdlFactory.createWSDLInterface();
+        WSDLDefinition wsdlDef = wsdlFactory.createWSDLDefinition();
+        WSDLReader reader = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader();
+        InputSource inputSource = new InputSource(new StringReader(wsdl));
+        Definition def = reader.readWSDL("", inputSource);
+        wsdlDef.setDefinition(def);
+        wsdlIface.setWsdlDefinition(wsdlDef);
+        wsdlIC.setInterface(wsdlIface);
+        ic.setNormailizedWSDLContract(wsdlIC);
+    }
+
     private boolean isLocal(Endpoint endpoint) {
         return localEndpoints.containsKey(endpoint.getURI());
     }
@@ -306,6 +363,7 @@ public class HazelcastEndpointRegistry e
             try {
                 endpointOwners.remove(localMemberAddr, endpointURI);
                 endpointMap.remove(endpointURI);
+                endpointWsdls.remove(endpointURI);
                 txn.commit();
             } catch (Throwable e) {
                 txn.rollback();
@@ -373,6 +431,7 @@ public class HazelcastEndpointRegistry e
                             Collection<String> keys = endpointOwners.remove(memberAddr);
                             for (Object k : keys) {
                                 endpointMap.remove(k);
+                                endpointWsdls.remove(k);
                             }
                         }
                     } finally {
@@ -406,7 +465,6 @@ public class HazelcastEndpointRegistry e
         }
         return null;
     }
-
     @Override
     public void addRunningComposite(Composite composite) {
         runningComposites.put(composite.getName(), composite);

Modified: tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java?rev=1101207&r1=1101206&r2=1101207&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java
Mon May  9 20:27:03 2011
@@ -30,6 +30,9 @@ import org.apache.tuscany.sca.core.Defau
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
 import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
 import org.apache.tuscany.sca.runtime.RuntimeProperties;
 import org.junit.Assert;
@@ -154,10 +157,61 @@ public class MultiRegTestCase {
         Component comp = assemblyFactory.createComponent();
         ep.setComponent(comp);
         ep.setService(assemblyFactory.createComponentService());
+        ep.getService().setInterfaceContract(getIC());
         Binding b = scaBindingFactory.createSCABinding();
         ep.setBinding(b);
         ep.setURI(uri);
         return ep;
     }
+
+    private InterfaceContract getIC() {
+        InterfaceContract ic = new JavaInterfaceContract(){
+
+            public Object clone() throws CloneNotSupportedException {
+                return null;
+            }
+            @Override
+            public Interface getInterface() {
+                // TODO Auto-generated method stub
+                return null;
+            }
+
+            @Override
+            public void setInterface(Interface callInterface) {
+                // TODO Auto-generated method stub
+                
+            }
+
+            @Override
+            public Interface getCallbackInterface() {
+                // TODO Auto-generated method stub
+                return null;
+            }
+
+            @Override
+            public void setCallbackInterface(Interface callbackInterface) {
+                // TODO Auto-generated method stub
+                
+            }
+
+            @Override
+            public InterfaceContract makeUnidirectional(boolean isCallback) {
+                // TODO Auto-generated method stub
+                return null;
+            }
+
+            @Override
+            public InterfaceContract getNormalizedWSDLContract() {
+                // TODO Auto-generated method stub
+                return null;
+            }
+
+            @Override
+            public void setNormailizedWSDLContract(InterfaceContract wsdlInterfaceContract)
{
+                // TODO Auto-generated method stub
+                
+            }};
+        return ic;
+    }
     
 }



Mime
View raw message