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 2007/05/29 21:49:48 UTC

svn commit: r542637 - in /incubator/tuscany/sandbox/slaws/disitributed-changes: pom.xml src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java

Author: slaws
Date: Tue May 29 12:49:48 2007
New Revision: 542637

URL: http://svn.apache.org/viewvc?view=rev&rev=542637
Log:
disitributed runtime changes

Modified:
    incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java

Modified: incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml?view=diff&rev=542637&r1=542636&r2=542637
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml (original)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml Tue May 29 12:49:48 2007
@@ -50,6 +50,13 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-jms</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+        
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.2</version>

Modified: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java?view=diff&rev=542637&r1=542636&r2=542637
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java (original)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java Tue May 29 12:49:48 2007
@@ -79,7 +79,7 @@
     }
     
     public void setRuntimeId(String runtimeId) {
-        System.out.println(">>> RuntimeId set to: " + runtimeId);           
+//        System.out.println(">>> RuntimeId set to: " + runtimeId);           
         this.runtimeId = runtimeId;
     }    
     
@@ -88,7 +88,7 @@
     }
     
     public void setURI(String uri) {
-        System.out.println(">>> Component uri set to: " + uri);           
+        //System.out.println(">>> Component uri set to: " + uri);           
         this.uri = uri;
     }
 
@@ -125,7 +125,7 @@
     }
 
     public void setName(String name) {
-        System.out.println(">>> Component name set to: " + name);         
+        //System.out.println(">>> Component name set to: " + name);         
         this.name = name;
     }
 

Modified: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java?view=diff&rev=542637&r1=542636&r2=542637
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java (original)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java Tue May 29 12:49:48 2007
@@ -19,6 +19,9 @@
 
 package org.apache.tuscany.sca.core.runtime;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.Component;
@@ -34,6 +37,7 @@
 import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
 import org.apache.tuscany.sca.core.invocation.InvocationChainImpl;
 import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
@@ -56,6 +60,9 @@
 import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
 import org.apache.tuscany.sca.work.WorkScheduler;
 
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingImpl;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -369,7 +376,7 @@
             EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)target,
                                                                      (RuntimeComponentService)service, binding,
                                                                      targetContract);
-            
+     /*       
             String sourceRuntimeId = component.getRuntimeId();
             String targetRuntimeId = target.getRuntimeId();
             
@@ -384,7 +391,7 @@
                                    " and " +
                                    component.getName());
             }
-
+*/
             RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget);
 
             for (Operation operation : bindingContract.getInterface().getOperations()) {
@@ -587,10 +594,97 @@
         // the composite..."));
         // }
     }
+    /**
+     * Looks for components that either have no runtimeID set
+     * or have a runtimeId that matches the id of the runtime 
+     * we are currently in. These components will run in this
+     * runtime so are kept in the component list. These
+     * components have their services and references tested. 
+     * Any services or references that only have an SCA binding
+     * and are wired to components in other runtimes have new
+     * (JMS) bindings created that allow the wire to cross
+     * the VM boundary. 
+     * 
+     * @param composite
+     * @throws IncompatibleInterfaceContractException
+     */
+    protected void localizeComposite(Composite composite) throws ActivationException {
+        
+        // TODO a cheat to get the current domain URI which I'm using
+        // to identify the runtime. 
+        String domainURI = composite.getURI();
+        
+        List<Component> componentsToDelete = new ArrayList<Component>();
+        
+        for (Component component : composite.getComponents()) {
+            
+            String sourceRuntimeId = component.getRuntimeId();
+            
+            // Look at all the reference/service pairs looking for examples
+            // where the target and source are bound to different runtimes.
+            // If this is the case create a JMS binding so allow the otherwise
+            // local SCA binding to cross the VM boundary
+            for (ComponentReference reference : component.getReferences()) {
+                for (ComponentService service : reference.getTargets()) {
+                    
+                    Component target = null;
+                    SCABinding scaBinding = service.getBinding(SCABinding.class);
+                    if (scaBinding != null) {
+                        target = scaBinding.getComponent();
+                    } else {
+                        throw new ActivationException ("No SCABinding on service " +
+                                                       service.getName()); 
+                    }
+                    String targetRuntimeId = target.getRuntimeId();
+                                 
+                    // Detect whether this component will run in this runtime
+                    if ( (sourceRuntimeId != null ) &&
+                        (!domainURI.equals(component.getRuntimeId())) ){
+                       // component will not run in this runtime
+                       // so remove it from the component list. 
+                       componentsToDelete.add(component); 
+                       System.out.println(">>>>> Not Running component " + component.getName() );
+                    } else {
+                       System.out.println(">>>>> Running component " + component.getName() );
+                    }
+
+                    // Look at the references runtimeId and check that 
+                    // the service to which it refers is also in this 
+                    // runtime if it's not then create appropriate
+                    // JMS bindings.                
+                    if ( !sourceRuntimeId.equals(targetRuntimeId)) {
+                        System.out.println(">>>>> Swap SCA binding for distributed binding for wire between " +
+                                            component.getName() +
+                                            " and " +
+                                            target.getName());
+                        
+                        // for the purposes of this demo create a JMS 
+                        // binding on the reference and the service. This
+                        // looks very peculiar as I'm adding the same binding
+                        // to both reference and service. I know however that
+                        // one of these will not be used as the only reason
+                        // I am here is because one of these is outside
+                        // this VM. Which one gets discarded depends on
+                        // which runtime I'm in. 
+                        JMSBinding jmsBinding = new JMSBindingImpl();
+                        reference.getBindings().add(0, jmsBinding);
+                        service.getBindings().add(0, jmsBinding);
+                    }             
+                }                 
+            }
+        }
+        
+        // remove all the components from the composite that won't run
+        // in this runtime
+        for (Component component : componentsToDelete) {
+            composite.getComponents().remove(component);            
+        }
+    }
 
     public void activate(Composite composite) throws ActivationException {
         try {
             buildComposite(composite);
+            localizeComposite(composite);
             configureComposite(composite);
             createRuntimeWires(composite);
         } catch (Exception e) {



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