You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/01/15 16:28:25 UTC

svn commit: r899664 - /tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java

Author: slaws
Date: Fri Jan 15 15:28:24 2010
New Revision: 899664

URL: http://svn.apache.org/viewvc?rev=899664&view=rev
Log:
The code for build time matching. To actually use this we need to create a build time registry. As it stands you get duplicate endpoint regsitration notifications. 

Modified:
    tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java?rev=899664&r1=899663&r2=899664&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java Fri Jan 15 15:28:24 2010
@@ -44,7 +44,13 @@
 import javax.xml.stream.XMLStreamException;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.common.java.io.IOHelper;
 import org.apache.tuscany.sca.contribution.Artifact;
 import org.apache.tuscany.sca.contribution.Contribution;
@@ -71,6 +77,9 @@
 import org.apache.tuscany.sca.node.configuration.ContributionConfiguration;
 import org.apache.tuscany.sca.node.configuration.DeploymentComposite;
 import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
+import org.apache.tuscany.sca.runtime.EndpointReferenceBinder;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
 import org.apache.tuscany.sca.work.WorkScheduler;
 import org.oasisopen.sca.ServiceRuntimeException;
 
@@ -273,9 +282,63 @@
         }
         Composite domainComposite = deployer.build(contributions, bindingBaseURIs, monitor);
         analyzeProblems(monitor);
-
+        
+        // postBuildEndpointReferenceMatching(domainComposite);
+        
         return domainComposite;
     }
+    
+    // =============================================
+    // TODO - TUSCANY-3425
+    // post build endpoint reference matching. Give the matching algorithm
+    // a chance to run and report any errors for local references prior to 
+    // runtime start. Not in use at the moment as we are getting away with
+    // runtime matching. Leaving here for when we come to sorting out 
+    // autowire which still relies on matching in the builder
+    private void postBuildEndpointReferenceMatching(Composite composite){
+        EndpointReferenceBinder endpointReferenceBinder = registry.getExtensionPoint(EndpointReferenceBinder.class);
+        DomainRegistryFactory domainRegistryFactory = registry.getExtensionPoint(DomainRegistryFactory.class);
+        
+        // create temporary local registry for all available local endpoints
+        // TODO - need a better way of getting a local registry
+        EndpointRegistry registry = domainRegistryFactory.getEndpointRegistry("vm://tmp", "local");
+        
+        // populate the registry with all the endpoints that are currently present in the model
+        populateLocalRegistry(composite, registry);
+        
+        // look at all the endpoint references and try to match them to 
+        // any local endpoints
+        for (EndpointReference endpointReference : registry.getEndpointReferences()){
+            endpointReferenceBinder.bindBuildTime(registry, endpointReference);
+        }
+        
+        // remove the local registry
+        domainRegistryFactory.getEndpointRegistries().remove(registry);
+    }
+    
+    private void populateLocalRegistry(Composite composite, EndpointRegistry registry){
+        for (Component component : composite.getComponents()) {
+            // recurse for composite implementations
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                populateLocalRegistry((Composite)implementation, registry);
+            }
+            
+            for (ComponentService service : component.getServices()) {
+                for (Endpoint endpoint : service.getEndpoints()){
+                    registry.addEndpoint(endpoint);
+                }
+            }
+            
+            for (ComponentReference reference : component.getReferences()) {
+                for (EndpointReference endpointReference : reference.getEndpointReferences()){
+                    registry.addEndpointReference(endpointReference);
+                }
+            }            
+        }
+    }    
+    
+    // =============================================
 
     protected List<Contribution> loadContributions(NodeConfiguration configuration, ProcessorContext context) throws Throwable {
         List<Contribution> contributions = new ArrayList<Contribution>();