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/07/01 19:43:42 UTC

svn commit: r552343 - in /incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed: assembly/ core/ host/ host/impl/ node/ node/impl/

Author: slaws
Date: Sun Jul  1 10:43:40 2007
New Revision: 552343

URL: http://svn.apache.org/viewvc?view=rev&rev=552343
Log:
Separate the node domain from the application domain 
Read the node configuration from file

Added:
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java   (with props)
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java   (with props)
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java   (with props)
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntime.java
      - copied, changed from r550023, incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntime.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntimeBuilder.java
      - copied, changed from r550023, incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java   (with props)
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java   (with props)
Removed:
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/SCADomainNode.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomain.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntime.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java
Modified:
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/assembly/DistributedSCABinding.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedCompositeActivatorImpl.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedRuntime.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java
    incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java

Modified: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/assembly/DistributedSCABinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/assembly/DistributedSCABinding.java?view=diff&rev=552343&r1=552342&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/assembly/DistributedSCABinding.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/assembly/DistributedSCABinding.java Sun Jul  1 10:43:40 2007
@@ -39,7 +39,7 @@
     public boolean getIsDistributed(); 
 
     /**
-     * Gets the flag which tells you if this SCABinding is distributed across nodes
+     * Sets the flag which tells you if this SCABinding is distributed across nodes
      * 
      * @param isDistributed true if this binding is distributed across nodes
      */

Modified: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedCompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedCompositeActivatorImpl.java?view=diff&rev=552343&r1=552342&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedCompositeActivatorImpl.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedCompositeActivatorImpl.java Sun Jul  1 10:43:40 2007
@@ -32,7 +32,7 @@
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
 import org.apache.tuscany.sca.core.runtime.CompositeActivatorImpl;
 import org.apache.tuscany.sca.distributed.assembly.DistributedSCABinding;
-import org.apache.tuscany.sca.distributed.host.SCADomainNode;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
 import org.apache.tuscany.sca.distributed.node.ComponentRegistry;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
@@ -48,24 +48,30 @@
  */
 public class DistributedCompositeActivatorImpl extends CompositeActivatorImpl {
 
-    private SCADomainNode domainNode;
-    private ComponentRegistry componentRegistry;    
-    
+    private DistributedSCADomain domain;
+    private ComponentRegistry componentRegistry; 
+        
     /**
+     * To extra information over and above that provided to the CompositeActivatirImpl
+     * is the domian. This is the domain for which this activiator was created. 
+     *
      * @param assemblyFactory
+     * @param scaBindingFactory
      * @param interfaceContractMapper
-     * @param workContext
+     * @param scopeRegistry
      * @param workScheduler
-     * @param wirePostProcessorRegistry
+     * @param wireProcessor
+     * @param providerFactories
+     * @param domain
      */
     public DistributedCompositeActivatorImpl(AssemblyFactory assemblyFactory,
-                                     SCABindingFactory scaBindingFactory,
-                                     InterfaceContractMapper interfaceContractMapper,
-                                     ScopeRegistry scopeRegistry,
-                                     WorkScheduler workScheduler,
-                                     RuntimeWireProcessor wireProcessor,
-                                     ProviderFactoryExtensionPoint providerFactories,
-                                     SCADomainNode domainNode) {
+                                             SCABindingFactory scaBindingFactory,
+                                             InterfaceContractMapper interfaceContractMapper,
+                                             ScopeRegistry scopeRegistry,
+                                             WorkScheduler workScheduler,
+                                             RuntimeWireProcessor wireProcessor,
+                                             ProviderFactoryExtensionPoint providerFactories,
+                                             DistributedSCADomain domain) {
         super(assemblyFactory,
               scaBindingFactory,
               interfaceContractMapper,
@@ -74,21 +80,28 @@
               wireProcessor,
               providerFactories);
         
-        this.domainNode = domainNode;
-        
+        this.domain = domain;
+                
         // if the domain node is available find the component registry 
-        if (domainNode != null) {
+        if ((domain != null) && (domain.getNodeDomain() != null)) {
             // get the ComponentRegistry
-            componentRegistry = domainNode.getNodeService(ComponentRegistry.class, "ComponentRegistry");
+            componentRegistry = domain.getNodeDomain().getService(ComponentRegistry.class, "ComponentRegistry");
         }      
         
     }
 
-
+    /**
+     * Take the composite and use the super class to build it. Once done 
+     * work out which components run in this node and create appropriate
+     * bindings to take account of references between nodes in the 
+     * distributed domain.
+     * 
+     * @param composite
+     */
     protected void buildComposite(Composite composite) throws CompositeBuilderException {
         super.buildComposite(composite);
         
-        // now we have a build composite look at which SCABindings
+        // now we have a built composite look at which SCABindings
         // need updating based on which components are present
         // in this node
         assignComponentsToNode(composite);
@@ -133,10 +146,10 @@
                         // get the information about the reference and associated services
                         
                         // reference
-                        String referenceNode = componentRegistry.getComponentNode(sourceComponent.getName());
+                        String referenceNode = componentRegistry.getComponentNode(domain.getURI(), sourceComponent.getName());
                         
                         // service 
-                        String serviceNode = componentRegistry.getComponentNode(targetComponent.getName());
+                        String serviceNode = componentRegistry.getComponentNode(domain.getURI(), targetComponent.getName());
                         
                         // check if reference and service are operating on 
                         // different nodes 
@@ -160,7 +173,7 @@
                            
                             // if the reference is operating on this node
                             // mark the binding as distributed
-                            if (referenceNode.equals(domainNode.getNodeName())) {
+                            if (referenceNode.equals(domain.getNodeDomain().getNodeName())) {
                                 DistributedSCABinding referenceSCABinding = 
                                     (DistributedSCABinding)reference.getBinding(SCABinding.class);
                                 
@@ -178,7 +191,7 @@
                                                    " SCABinding is set remote" );
                             }
                             
-                            if (serviceNode.equals(domainNode.getNodeName())) { 
+                            if (serviceNode.equals(domain.getNodeDomain().getNodeName())) { 
                                 // not used at the moment but maintain this 
                                 // flag in case the SCABinding becomes more 
                                 // functional                                

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java?view=auto&rev=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java Sun Jul  1 10:43:40 2007
@@ -0,0 +1,31 @@
+/*
+ * 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.distributed.core;
+
+/**
+ * An extension point for the distributed SCA domain. This allows the 
+ * DistributedSCADomain to be placed in the extension point registry
+ * which in turn allows all extension points to access it.  
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DistributedSCADomainExtensionPoint {
+    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/core/DistributedSCADomainExtensionPoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java?view=auto&rev=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java Sun Jul  1 10:43:40 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.distributed.host;
+
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.distributed.core.DistributedSCADomainExtensionPoint;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+/**
+ * An SCA Domain for the system components that allow a node
+ * in a distributed domain to be controlled. The distributed domain also
+ * holds information about the node that it is running in so that the 
+ * component activation process can make decisions about the appropriate
+ * bindings to create between components
+ * 
+ * @version $Rev$ $Date$
+ */
+public abstract class DistributedSCADomain extends SCADomain implements DistributedSCADomainExtensionPoint{
+    
+    /**
+     * Returns the name of the node that this part of the
+     * distributed domain is running on
+     * 
+     * @return the node name
+     */
+    public abstract String getNodeName();
+    
+    /**
+     * Returns the domain that is running the system
+     * components for this node
+     * 
+     * @return the node domain
+     */
+    public abstract DistributedSCADomain getNodeDomain();
+    
+    /** Starts the domain operation. Usually involves starting the
+     *  runtime and creating the top level composite ready for 
+     *  new contributions
+     *  
+     * @throws ActivationException
+     */
+    public abstract void start() throws ActivationException;
+    
+    /**
+     * Stops the runtime and all running components
+     * 
+     * @throws ActivationException
+     */
+    public abstract void stop() throws ActivationException;
+    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/DistributedSCADomain.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedRuntime.java?view=diff&rev=552343&r1=552342&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedRuntime.java Sun Jul  1 10:43:40 2007
@@ -19,24 +19,13 @@
 
 package org.apache.tuscany.sca.distributed.host.impl;
 
-import java.net.URL;
 import java.util.List;
 
-import javax.xml.stream.XMLInputFactory;
-
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
 import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
-import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl;
-import org.apache.tuscany.sca.contribution.service.ContributionReadException;
-import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
 import org.apache.tuscany.sca.contribution.service.ContributionService;
 import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
 import org.apache.tuscany.sca.core.DefaultModelFactoryExtensionPoint;
@@ -48,14 +37,12 @@
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.core.runtime.ActivationException;
 import org.apache.tuscany.sca.core.runtime.CompositeActivator;
-import org.apache.tuscany.sca.core.runtime.CompositeActivatorImpl;
 import org.apache.tuscany.sca.core.runtime.RuntimeAssemblyFactory;
 import org.apache.tuscany.sca.core.runtime.RuntimeSCABindingProviderFactory;
 import org.apache.tuscany.sca.core.work.Jsr237WorkScheduler;
 import org.apache.tuscany.sca.core.work.ThreadPoolWorkManager;
 import org.apache.tuscany.sca.distributed.core.DistributedCompositeActivatorImpl;
-import org.apache.tuscany.sca.distributed.host.SCADomainNode;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
 import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntimeBuilder;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
@@ -70,12 +57,10 @@
 import org.apache.tuscany.sca.scope.ScopeRegistry;
 import org.apache.tuscany.sca.work.WorkScheduler;
 
-import commonj.work.WorkManager;
-
 /**
  * This is almost exactly the same as the really small runtime
  * except that it defines it's members as protected and 
- * provides overideable methods for accessing some of the builder
+ * provides overrideable methods for accessing some of the builder
  * methods so that the builder can be changed
  */
 public class DistributedRuntime  {
@@ -89,19 +74,20 @@
     protected CompositeActivator compositeActivator;
     protected ThreadPoolWorkManager workManager;
     protected ScopeRegistry scopeRegistry;
-
+    
     public DistributedRuntime(ClassLoader classLoader) {
         this.classLoader = classLoader;
     }
 
-    public void start(SCADomain domainNode) throws ActivationException {
+    public void start(DistributedSCADomain domain) 
+      throws ActivationException {
 
         // Create our extension point registry
         registry = new DefaultExtensionPointRegistry();
         
-        // Add the current local domain to the extension point registry
-        if (domainNode != null) {
-            registry.addExtensionPoint(domainNode);
+        // Add the current domain to the extension point registry
+        if (domain != null ){
+            registry.addExtensionPoint(domain);
         }
 
         // Create a work manager
@@ -168,7 +154,7 @@
 
         // Create the composite activator
         compositeActivator = createCompositeActivator(registry,
-                                                      domainNode,
+                                                      domain,
                                                       assemblyFactory, 
                                                       scaBindingFactory,
                                                       mapper, 
@@ -191,15 +177,15 @@
                                                                    mapper);        
     }
     
-    public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
-                                                              SCADomain domainNode,
-                                                              AssemblyFactory assemblyFactory,
-                                                              SCABindingFactory scaBindingFactory,
-                                                              InterfaceContractMapper mapper,
-                                                              ScopeRegistry scopeRegistry,
-                                                              WorkScheduler workScheduler,
-                                                              RuntimeWireProcessor wireProcessor,
-                                                              ProviderFactoryExtensionPoint providerFactories) {
+    public CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
+                                                       DistributedSCADomain domain,
+                                                       AssemblyFactory assemblyFactory,
+                                                       SCABindingFactory scaBindingFactory,
+                                                       InterfaceContractMapper mapper,
+                                                       ScopeRegistry scopeRegistry,
+                                                       WorkScheduler workScheduler,
+                                                       RuntimeWireProcessor wireProcessor,
+                                                       ProviderFactoryExtensionPoint providerFactories) {
        return  new DistributedCompositeActivatorImpl(assemblyFactory, 
                                                      scaBindingFactory,
                                                      mapper, 
@@ -207,10 +193,8 @@
                                                      workScheduler, 
                                                      wireProcessor,
                                                      providerFactories,
-                                                     (SCADomainNode)domainNode);
+                                                     domain);
     }
-
-    
 
     public void stop() throws ActivationException {
 

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java?view=auto&rev=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java Sun Jul  1 10:43:40 2007
@@ -0,0 +1,407 @@
+/*
+ * 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.distributed.host.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.core.runtime.CompositeActivator;
+import org.apache.tuscany.sca.distributed.core.DistributedSCADomainExtensionPoint;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
+import org.apache.tuscany.sca.distributed.node.ComponentRegistry;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.Constants;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * An SCA domain implementation that allows the damain to be distributed
+ * across one or more processors. There is nothing particularly complicated
+ * about this domain implementation. It differs from the embedded domain implementation
+ * in that a different runtime is used to allow the domain to be stored in the 
+ * extension registry and for a new DistributedCompositeActivator to be use which, 
+ * in turn, uses the SCA binding to insert remote bindings at the right points 
+ * in the model. This domain also holds information about the node in which it 
+ * is running so that this information in available at various points in the runtime
+ * that need to make decisions based on node information. Namely the DistributedComposite
+ * Activator and the Distributed SCA binding. 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DistributedSCADomainImpl extends DistributedSCADomain implements DistributedSCADomainExtensionPoint  {
+    
+    private String uri;
+    private Composite domainComposite;
+    private DistributedRuntime runtime;
+    private Map<String, Component> components = new HashMap<String, Component>();
+    private DomainCompositeHelper domainCompositeHelper;
+    private ClassLoader runtimeClassLoader;
+    private DistributedSCADomain nodeDomain;
+       
+    public class DomainCompositeHelper {
+        
+        /**
+         * Add a composite to the domain
+         * @param composite
+         * @return
+         */
+        public Composite addComposite(Composite composite) throws ActivationException {
+            domainComposite.getIncludes().add(composite);
+            //CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            //compositeActivator.activate(composite);
+            //for (Component component : composite.getComponents()) {
+            //    components.put(component.getName(), component);
+            //}
+            return composite;
+        }
+
+        /**
+         * Remove a composite from the domain
+         * @param composite
+         * @throws ActivationException
+         */
+        public void removeComposite(Composite composite) throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.deactivate(composite);
+            domainComposite.getIncludes().remove(composite);
+            for (Component component : composite.getComponents()) {
+                components.remove(component.getName());
+            }
+        }
+        
+        /**
+         * Start a composite
+         * @deprecated
+         * @param composite
+         * @throws ActivationException
+         */
+        public void startComposite(Composite composite) throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.start(composite);
+        }
+        
+        /**
+         * Stop a composite
+         * @deprecated
+         * @param composite
+         * @throws ActivationException
+         */
+        public void stopComposite(Composite composite) throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.stop(composite);
+        }
+
+        /**
+         * Get a reference to a component by name
+         * @param componentName
+         * @return
+         */
+        public Component getComponent(String componentName){
+            return (Component) components.get(componentName);
+        }
+        
+        /**
+         * Start a component
+         * @param component
+         * @throws ActivationException
+         */
+        public void startComponent(Component component) throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.start(component);
+        }
+        
+        /**
+         * Stop a component
+         * @param component
+         * @throws ActivationException
+         */
+        public void stopComponent(Component component) throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.stop(component);
+        }    
+        
+        /**
+         * Start all components in the node
+         * @param component
+         * @throws ActivationException
+         */
+        public void startComponents() throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            
+            ComponentRegistry componentRegistry = 
+                ((SCADomain)nodeDomain).getService(ComponentRegistry.class, "ComponentRegistry");
+            
+            List<String> components = componentRegistry.getComponentsForNode(uri, nodeDomain.getNodeName());
+            
+            for (String componentName : components) {
+                compositeActivator.start(getComponent(componentName));
+            }
+        }
+        
+        /**
+         * Stop al components in the node
+         * @param component
+         * @throws ActivationException
+         */
+        public void stopComponents() throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            
+            ComponentRegistry componentRegistry = 
+                ((SCADomain)nodeDomain).getService(ComponentRegistry.class, "ComponentRegistry");
+            
+            List<String> components = componentRegistry.getComponentsForNode(uri, nodeDomain.getNodeName());
+            
+            for (String componentName : components) {
+                compositeActivator.stop(getComponent(componentName));
+            }
+        }          
+        
+        /**
+         * Activate SCA Domain
+         * @throws ActivationException
+         */
+        public void activateDomain() throws ActivationException {
+            CompositeActivator compositeActivator = runtime.getCompositeActivator();
+            compositeActivator.activate(domainComposite);
+            for (Component component : domainComposite.getComponents()) {
+                components.put(component.getName(), component);
+            }
+            
+            
+         /**
+          * Start the node components that should be running in this 
+          * runtime
+          */
+
+        }
+    }    
+    
+    /**
+     * Constructs a distributed domain for a node
+     *
+     * @param runtimeClassLoader
+     * @param domainURI
+     */
+    public DistributedSCADomainImpl(ClassLoader runtimeClassLoader,
+                                    String domainURI,
+                                    DistributedSCADomain nodeDomain) {
+        this.runtimeClassLoader = runtimeClassLoader;
+        this.uri = domainURI;
+        this.nodeDomain = nodeDomain;
+
+        // create a runtime to host the application services
+        this.runtime = new DistributedRuntime(this.runtimeClassLoader);
+    }
+    
+    /**
+     * Returns the name of the node that this part of the
+     * distributed domain is running on
+     * 
+     * @return the node name
+     */
+    public String getNodeName(){
+        return nodeDomain.getNodeName();
+    }
+    
+    /**
+     * Returns the domain that is running the system
+     * components for this node
+     * 
+     * @return the node name
+     */
+    public DistributedSCADomain getNodeDomain(){
+        return nodeDomain;
+    }
+    
+    /** Starts the domain operation. Usually involves starting the
+     *  runtime and creating the top level composite ready for 
+     *  new contributions
+     *  
+     * @throws ActivationException
+     */    
+    public void start()
+      throws ActivationException {
+
+        try {           
+            // Start the runtime
+            runtime.start(this);
+            
+            // Create an in-memory domain level composite
+            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+            domainComposite = assemblyFactory.createComposite();
+            domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
+            domainComposite.setURI(uri);
+    
+            // Create a domain composite helper
+            domainCompositeHelper = new DomainCompositeHelper();            
+            
+        } catch(Exception ex) {
+            throw new ActivationException(ex);
+        }
+    }
+    
+    /**
+     * Stops the runtime and all running components
+     * 
+     * @throws ActivationException
+     */    
+    public void stop() throws ActivationException {
+        
+        // close the domain 
+        close();
+        
+        // Stop the SCA domain components
+        getDomainCompositeHelper().stopComponents();    
+        
+        // Stop the runtime
+        try {
+            runtime.stop();
+        } catch (ActivationException e) {
+            throw new ServiceRuntimeException(e);
+        }
+        
+        // Cleanup
+        domainComposite = null;
+        domainCompositeHelper = null;
+    }
+
+    /** 
+     * Get the contribution service from the runtime. Nodes
+     * use this to add and remove contributions from the domain
+     * 
+     * @return
+     */
+    public ContributionService getContributionService() {
+        return runtime.getContributionService();
+    }
+    
+    /** 
+     * Get the composite helper for this domain. Nodes use this
+     * for fine grain controled over the operation of the domain
+     * 
+     * @return
+     */
+    public DomainCompositeHelper getDomainCompositeHelper() {
+        return domainCompositeHelper;
+    }
+    
+    @Override
+    public void close() {
+        super.close();
+                       
+    }
+
+    @Override
+    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public <B> B getService(Class<B> businessInterface, String serviceName) {
+        ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
+        if (serviceReference == null) {
+            throw new ServiceRuntimeException("Service not found: " + serviceName);
+        }
+        return serviceReference.getService();
+    }
+
+    @Override
+    public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
+
+        // Extract the component name
+        String componentName;
+        String serviceName;
+        int i = name.indexOf('/');
+        if (i != -1) {
+            componentName = name.substring(0, i);
+            serviceName = name.substring(i + 1);
+
+        } else {
+            componentName = name;
+            serviceName = null;
+        }
+
+        // Lookup the component in the domain
+        Component component = components.get(componentName);
+        if (component == null) {
+            throw new ServiceRuntimeException("Component not found: " + componentName);
+        }
+        ComponentContext componentContext = null;
+
+        // If the component is a composite, then we need to find the
+        // non-composite
+        // component that provides the requested service
+        if (component.getImplementation() instanceof Composite) {
+            ComponentService promotedService = null;
+            for (ComponentService componentService : component.getServices()) {
+                if (serviceName == null || serviceName.equals(componentService.getName())) {
+
+                    CompositeService compositeService = (CompositeService)componentService.getService();
+                    if (compositeService != null) {
+                        promotedService = compositeService.getPromotedService();
+                        SCABinding scaBinding = promotedService.getBinding(SCABinding.class);
+                        if (scaBinding != null) {
+                            Component promotedComponent = scaBinding.getComponent();
+                            if (serviceName != null) {
+                                serviceName = "$promoted$." + serviceName;
+                            }
+                            componentContext = (ComponentContext)promotedComponent;
+                        }
+                    }
+                    break;
+                }
+            }
+            if (componentContext == null) {
+                throw new ServiceRuntimeException("Composite service not found: " + name);
+            }
+        } else {
+            componentContext = (ComponentContext)component;
+        }
+
+        ServiceReference<B> serviceReference;
+        if (serviceName != null) {
+            serviceReference = componentContext.createSelfReference(businessInterface, serviceName);
+        } else {
+            serviceReference = componentContext.createSelfReference(businessInterface);
+        }
+        return serviceReference;
+
+    }
+
+    @Override
+    public String getURI() {
+        return uri;
+    }    
+    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/DistributedSCADomainImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntime.java (from r550023, incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntime.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntime.java?view=diff&rev=552343&p1=incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntime.java&r1=550023&p2=incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntime.java&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntime.java Sun Jul  1 10:43:40 2007
@@ -20,13 +20,9 @@
 package org.apache.tuscany.sca.distributed.host.impl;
 
 import java.net.URL;
-import java.util.List;
-
-import javax.xml.stream.XMLInputFactory;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
 import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
@@ -37,30 +33,18 @@
 import org.apache.tuscany.sca.contribution.service.ContributionReadException;
 import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
 import org.apache.tuscany.sca.contribution.service.ContributionService;
-import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.core.DefaultModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.core.ModuleActivator;
-import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl;
-import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.core.runtime.ActivationException;
 import org.apache.tuscany.sca.core.runtime.CompositeActivator;
 import org.apache.tuscany.sca.core.runtime.CompositeActivatorImpl;
-import org.apache.tuscany.sca.core.runtime.RuntimeAssemblyFactory;
-import org.apache.tuscany.sca.core.work.ThreadPoolWorkManager;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
-import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
-import org.apache.tuscany.sca.invocation.MessageFactory;
-import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
 import org.apache.tuscany.sca.scope.ScopeRegistry;
 import org.apache.tuscany.sca.work.WorkScheduler;
 
-import commonj.work.WorkManager;
 
 /**
  * This is almost exactly the same as the really small runtime
@@ -69,9 +53,9 @@
  * to run and manage the node
  *
  */
-public class NodeServiceRuntime extends DistributedRuntime  {
+public class NodeRuntime extends DistributedRuntime  {
 
-    public NodeServiceRuntime(ClassLoader classLoader) {
+    public NodeRuntime(ClassLoader classLoader) {
         super(classLoader);
     }
     
@@ -88,15 +72,16 @@
      * @param providerFactories
      * @return
      */
-    public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
-                                                              SCADomain domainNode,
-                                                              AssemblyFactory assemblyFactory,
-                                                              SCABindingFactory scaBindingFactory,
-                                                              InterfaceContractMapper mapper,
-                                                              ScopeRegistry scopeRegistry,
-                                                              WorkScheduler workScheduler,
-                                                              RuntimeWireProcessor wireProcessor,
-                                                              ProviderFactoryExtensionPoint providerFactories) {
+    @Override
+     public CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
+                                                        DistributedSCADomain domain,
+                                                        AssemblyFactory assemblyFactory,
+                                                        SCABindingFactory scaBindingFactory,
+                                                        InterfaceContractMapper mapper,
+                                                        ScopeRegistry scopeRegistry,
+                                                        WorkScheduler workScheduler,
+                                                        RuntimeWireProcessor wireProcessor,
+                                                        ProviderFactoryExtensionPoint providerFactories) {
         return  new CompositeActivatorImpl(assemblyFactory, 
                                            scaBindingFactory,
                                            mapper, 
@@ -118,11 +103,11 @@
                                                          PolicyFactory policyFactory,
                                                          InterfaceContractMapper mapper)
       throws ActivationException {        
-        return NodeServiceRuntimeBuilder.createContributionService(registry,
-                                                                   contributionFactory,
-                                                                   assemblyFactory,
-                                                                   policyFactory,
-                                                                   mapper);        
+        return NodeRuntimeBuilder.createContributionService(registry,
+                                                            contributionFactory,
+                                                            assemblyFactory,
+                                                            policyFactory,
+                                                            mapper);        
     }
     
     public Composite getNodeComposite(URL nodeFileURL)

Copied: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntimeBuilder.java (from r550023, incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntimeBuilder.java?view=diff&rev=552343&p1=incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java&r1=550023&p2=incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntimeBuilder.java&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeServiceRuntimeBuilder.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeRuntimeBuilder.java Sun Jul  1 10:43:40 2007
@@ -19,33 +19,24 @@
 
 package org.apache.tuscany.sca.distributed.host.impl;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;
 import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;
-import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
 import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
 import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;
 import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
+import org.apache.tuscany.sca.contribution.processor.ContributionPostProcessor;
+import org.apache.tuscany.sca.contribution.processor.DefaultContributionPostProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.DefaultPackageProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleContributionPostProcessor;
 import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
@@ -59,33 +50,10 @@
 import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl;
 import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
-import org.apache.tuscany.sca.core.invocation.JDKProxyService;
-import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.core.runtime.ActivationException;
-import org.apache.tuscany.sca.core.runtime.CompositeActivator;
-import org.apache.tuscany.sca.core.runtime.CompositeActivatorImpl;
-import org.apache.tuscany.sca.core.runtime.RuntimeSCABindingProviderFactory;
-import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory;
-import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory;
-import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl;
-import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
-import org.apache.tuscany.sca.core.work.Jsr237WorkScheduler;
 import org.apache.tuscany.sca.distributed.node.impl.NodeDocumentProcessor;
-import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntimeBuilder;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
-import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.provider.DefaultProviderFactoryExtensionPoint;
-import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
-import org.apache.tuscany.sca.runtime.DefaultWireProcessorExtensionPoint;
-import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
-import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
-import org.apache.tuscany.sca.scope.ScopeContainerFactory;
-import org.apache.tuscany.sca.scope.ScopeRegistry;
-import org.apache.tuscany.sca.work.WorkScheduler;
-
-import commonj.work.WorkManager;
 
 /**
  * This is almost exactly the same as the really small runtime builder
@@ -94,7 +62,7 @@
  * options are required to run and manage the node. 
  *
  */
-public class NodeServiceRuntimeBuilder {
+public class NodeRuntimeBuilder {
 
 
     /**
@@ -147,6 +115,11 @@
         packageProcessors.addPackageProcessor(new JarContributionProcessor());
         packageProcessors.addPackageProcessor(new FolderContributionProcessor());
 
+        //Create contribution postProcessor extension point
+        DefaultContributionPostProcessorExtensionPoint contributionPostProcessors = new DefaultContributionPostProcessorExtensionPoint();
+        ContributionPostProcessor postProcessor = new ExtensibleContributionPostProcessor(contributionPostProcessors);
+        registry.addExtensionPoint(contributionPostProcessors);        
+
         // Create a contribution repository
         ContributionRepository repository;
         try {
@@ -156,9 +129,13 @@
         }
 
         ExtensibleURLArtifactProcessor documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors);
-        ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessor,
-                                                                              documentProcessor, assemblyFactory,
-                                                                              contributionFactory, xmlFactory);
+        ContributionService contributionService = new ContributionServiceImpl(repository, 
+                                                                              packageProcessor,
+                                                                              documentProcessor, 
+                                                                              postProcessor,
+                                                                              assemblyFactory,
+                                                                              contributionFactory, 
+                                                                              xmlFactory);
         return contributionService;
     }
 }

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java?view=auto&rev=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java Sun Jul  1 10:43:40 2007
@@ -0,0 +1,268 @@
+/*
+ * 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.distributed.host.impl;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.core.runtime.CompositeActivator;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * An SCA domain that holds components used for managing a node. The components
+ * are read from a ".node" file to differentiate them from any other ".composite" 
+ * file that migh appear in a contribution. Other than that the ".node" file
+ * is like any other SCA assembly. 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeSCADomainImpl extends DistributedSCADomain {
+       
+    private String domainURI;
+    private String nodeName;
+    private NodeRuntime nodeRuntime;
+    private Composite nodeComposite;
+    private ClassLoader runtimeClassLoader;
+    private Map<String, Component> nodeComponents = new HashMap<String, Component>();
+    
+    
+    /**
+     * Constructs a new node in the distributed domain
+     *
+     * @param runtimeClassLoader
+     * @param domainURI
+     */
+    public NodeSCADomainImpl(ClassLoader runtimeClassLoader,
+                             String domainURI,
+                             String nodeName) {
+        this.runtimeClassLoader = runtimeClassLoader;
+        this.domainURI = domainURI;
+        this.nodeName = nodeName;
+        
+        // Create a runtime to host the node services
+        nodeRuntime = new NodeRuntime(runtimeClassLoader);
+        
+    }
+    
+    /**
+     * Returns the name of the node that this part of the
+     * distributed domain is running on
+     * 
+     * @return the node name
+     */
+    public String getNodeName(){
+        return nodeName;
+    }
+    
+    /**
+     * Returns the domain that is running the system
+     * components for this node. In this case it is this
+     * domain
+     * 
+     * @return the node domain
+     */
+    public  DistributedSCADomain getNodeDomain(){
+        return this;
+    }
+    
+    /** 
+     * Starts the domain operation. In this case it involves
+     * reading the components from the nodename.node file 
+     *  
+     * @throws ActivationException
+     */    
+    public void start()
+      throws ActivationException {
+
+        try {
+        
+            // start up the node services
+            
+            // Start the node service runtime. Null is passed in here
+            // to stop the SCAbinding in this runtime trying to look 
+            // back into the domain node model
+            nodeRuntime.start(null);
+            
+            // get the node service configuration model
+                   
+            // we expect the node file to be in the same package as the
+            // mainline for the node itself. At some point we may want to
+            // get smart about where we find this information. 
+            // For now we look if there is a file specifically for this
+            // node and if not we read the generic file. 
+            URL url = runtimeClassLoader.getResource(nodeName + ".node");
+            
+            if (url == null) {
+                url = runtimeClassLoader.getResource("default.node");
+            }
+            
+            if (url == null) {
+                throw new ServiceRuntimeException("Node file not found at either  " 
+                                                  + nodeName + 
+                                                  ".node or node.node");
+            }
+            
+            // load the node file
+            nodeComposite = nodeRuntime.getNodeComposite(url);
+                       
+            // activate the composite
+            CompositeActivator compositeActivator = nodeRuntime.getCompositeActivator();
+            compositeActivator.activate(nodeComposite);
+            
+            // start and record the components
+            for (Component component : nodeComposite.getComponents()) {
+                nodeComponents.put(component.getName(), component);
+                compositeActivator.start(component);
+            }           
+            
+        } catch(Exception ex) {
+            throw new ActivationException(ex);
+        }
+    }
+    
+    /**
+     * Stops the runtime and all running components
+     * 
+     * @throws ActivationException
+     */    
+    public void stop() throws ActivationException {
+                
+        // stop the nodes components
+        for (Component component : nodeComponents.values()) {
+            nodeRuntime.getCompositeActivator().stop(component);
+        }
+        
+        // Stop the runtimes
+        nodeRuntime.stop();
+    }
+    
+    @Override
+    public void close() {
+        super.close();
+    }
+
+    @Override
+    public String getURI() {
+        return domainURI;
+    }    
+    
+    @Override
+    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    /**
+     * Direct copy from getService but dealing in nodeCompinents
+     * 
+     * @param <B>
+     * @param businessInterface
+     * @param serviceName
+     * @return
+     */
+    public <B> B getService(Class<B> businessInterface, String serviceName) {       
+        ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
+        if (serviceReference == null) {
+            throw new ServiceRuntimeException("Service not found: " + serviceName);
+        }
+        return serviceReference.getService();
+    }  
+    
+    /**
+     * Direct copy from getServiceReference but dealing in nodeCompinents
+     * 
+     * @param <B>
+     * @param businessInterface
+     * @param name
+     * @return
+     */
+    public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
+
+        // Extract the component name
+        String componentName;
+        String serviceName;
+        int i = name.indexOf('/');
+        if (i != -1) {
+            componentName = name.substring(0, i);
+            serviceName = name.substring(i + 1);
+
+        } else {
+            componentName = name;
+            serviceName = null;
+        }
+
+        // Lookup the component in the domain
+        Component component = nodeComponents.get(componentName);
+        if (component == null) {
+            throw new ServiceRuntimeException("Component not found: " + componentName);
+        }
+        ComponentContext componentContext = null;
+
+        // If the component is a composite, then we need to find the
+        // non-composite
+        // component that provides the requested service
+        if (component.getImplementation() instanceof Composite) {
+            ComponentService promotedService = null;
+            for (ComponentService componentService : component.getServices()) {
+                if (serviceName == null || serviceName.equals(componentService.getName())) {
+
+                    CompositeService compositeService = (CompositeService)componentService.getService();
+                    if (compositeService != null) {
+                        promotedService = compositeService.getPromotedService();
+                        SCABinding scaBinding = promotedService.getBinding(SCABinding.class);
+                        if (scaBinding != null) {
+                            Component promotedComponent = scaBinding.getComponent();
+                            if (serviceName != null) {
+                                serviceName = "$promoted$." + serviceName;
+                            }
+                            componentContext = (ComponentContext)promotedComponent;
+                        }
+                    }
+                    break;
+                }
+            }
+            if (componentContext == null) {
+                throw new ServiceRuntimeException("Composite service not found: " + name);
+            }
+        } else {
+            componentContext = (ComponentContext)component;
+        }
+
+        ServiceReference<B> serviceReference;
+        if (serviceName != null) {
+            serviceReference = componentContext.createSelfReference(businessInterface, serviceName);
+        } else {
+            serviceReference = componentContext.createSelfReference(businessInterface);
+        }
+        return serviceReference;
+
+    }    
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/host/impl/NodeSCADomainImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java?view=diff&rev=552343&r1=552342&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/ComponentRegistry.java Sun Jul  1 10:43:40 2007
@@ -38,7 +38,7 @@
      * @param componentName the string name for the component of interest
      * @return node name
      */
-    public String getComponentNode(String componentName);
+    public String getComponentNode(String domainName, String componentName);
     
     
     /**
@@ -48,7 +48,7 @@
      * @param componentName the string name for the component of interest
      * @return node name
      */
-    public void setComponentNode(String componentName, String nodeName);
+    public void setComponentNode(String domainName, String componentName, String nodeName);
     
     /**
      * Loop through all the components in the model getting all the 
@@ -57,5 +57,5 @@
      * @param nodeName
      * @return
      */
-    public List<String> getComponentsForNode(String nodeName);    
+    public List<String> getComponentsForNode(String domainName, String nodeName);    
 }

Modified: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java?view=diff&rev=552343&r1=552342&r2=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java (original)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/DefaultComponentRegistry.java Sun Jul  1 10:43:40 2007
@@ -28,7 +28,8 @@
 /**
  * Represents the mapping between components and runtime nodes.
  * 
- * TBD - just a place holder at the moment
+ * TODO - just a place holder at the moment. For example, 
+ *        doesn;t take any notice of domains at present
  *
  * @version $Rev$ $Date$
  */
@@ -47,7 +48,7 @@
      * @param componentName the string name for the component of interest
      * @return node name
      */
-    public String getComponentNode(String componentName){
+    public String getComponentNode(String domainName, String componentName){
         return components.get(componentName);
     }
     
@@ -58,7 +59,7 @@
      * @param componentName the string name for the component of interest
      * @return node name
      */
-    public void setComponentNode(String componentName, String nodeName){
+    public void setComponentNode(String domainName, String componentName, String nodeName){
         components.put(componentName, nodeName);
     }
     
@@ -69,7 +70,7 @@
      * @param nodeName
      * @return
      */
-    public List<String> getComponentsForNode(String nodeName) {
+    public List<String> getComponentsForNode(String domainName, String nodeName) {
         List<String> componentList = new ArrayList<String>();
         
         for (String componentName : components.keySet()) {

Added: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java?view=auto&rev=552343
==============================================================================
--- incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java (added)
+++ incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java Sun Jul  1 10:43:40 2007
@@ -0,0 +1,196 @@
+/*
+ * 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.distributed.node.impl;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.core.runtime.ActivationException;
+import org.apache.tuscany.sca.distributed.host.DistributedSCADomain;
+import org.apache.tuscany.sca.distributed.host.impl.DistributedSCADomainImpl;
+import org.apache.tuscany.sca.distributed.host.impl.NodeSCADomainImpl;
+import org.apache.tuscany.sca.distributed.node.ComponentRegistry;
+import org.apache.tuscany.sca.topology.Component;
+import org.apache.tuscany.sca.topology.DefaultTopologyFactory;
+import org.apache.tuscany.sca.topology.Node;
+import org.apache.tuscany.sca.topology.Runtime;
+import org.apache.tuscany.sca.topology.TopologyFactory;
+import org.apache.tuscany.sca.topology.xml.TopologyDocumentProcessor;
+import org.apache.tuscany.sca.topology.xml.TopologyProcessor;
+
+/**
+ * A stand alone runtime node that holds a NodeSCADomain to run managment components and one 
+ * or more DistributedSCADomains for application components 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeImpl {
+  
+    private ClassLoader runtimeClassLoader;    
+    private String runtimeName;
+    private String nodeName;
+    private DistributedSCADomain nodeDomain;
+    private Map<String, DistributedSCADomain> appDomains = new HashMap<String, DistributedSCADomain>();
+    private ComponentRegistry componentRegistry;
+
+    public NodeImpl(String runtimeName,
+                              String nodeName,
+                              ClassLoader classLoader){
+        this.runtimeName = runtimeName;
+        this.nodeName = nodeName;
+        this.runtimeClassLoader = classLoader;
+        this.nodeDomain = new NodeSCADomainImpl(runtimeClassLoader,
+                                                runtimeName,
+                                                nodeName);     
+    }
+    
+    public void start() 
+      throws ActivationException, ContributionReadException {
+        //Start the node domain
+        nodeDomain.start();  
+        
+        // get the component registry 
+        componentRegistry = nodeDomain.getService(ComponentRegistry.class, "ComponentRegistry");        
+        
+        // load the topology from file
+        
+        // create the factories
+        AssemblyFactory factory = new DefaultAssemblyFactory();
+        TopologyFactory topologyFactory = new DefaultTopologyFactory();
+        
+        URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint();
+        ExtensibleURLArtifactProcessor documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); 
+        
+        // Create Stax processors
+        DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+        ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+        staxProcessors.addArtifactProcessor(new TopologyProcessor(topologyFactory, factory, staxProcessor));        
+        
+        // Create document processors
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance(); 
+        documentProcessors.addArtifactProcessor(new TopologyDocumentProcessor(staxProcessor, inputFactory));
+
+        URL url = runtimeClassLoader.getResource("runtime.topology");
+        
+        if ( url == null ){
+            throw new ActivationException("Unable to find file runtime.topology on classpath");            
+        }
+        
+        Runtime runtime = (Runtime)documentProcessor.read(null, null, url);
+        
+        // get the node model for this node
+        Node thisNode = runtime.getNode(nodeName);
+        
+        if ( thisNode == null ){
+            throw new ActivationException("Node " +
+                                          nodeName +
+                                          " not defined in runtime topology"); 
+        }
+        
+        // get all the domains that are in the node
+        for(String domainName : thisNode.getDomainNames()){
+            // create a domain. this will also add it to the
+            // appDomains property
+            DistributedSCADomain domain = createDistributedDomain(domainName);
+                      
+            // start the domain
+            startDomain(domainName);
+        }     
+        
+        // get all the node models and load the component registry
+        // we might expect this to be done across the network
+        for(Node node : runtime.getNodes()){
+            
+            // get all the domains that are in the node
+            for(String domainName : node.getDomainNames()){ 
+                
+                // set node mappings into the component registry  
+                for (Component component : node.getComponents(domainName)){
+                     componentRegistry.setComponentNode(domainName, component.getName(), node.getName());
+                }
+                
+                // set the scheme base urls into the URI registry
+                // TODO 
+            }
+        }
+    }
+    
+    public void stop()
+      throws ActivationException {
+        
+        for(DistributedSCADomain domain : appDomains.values()){
+            domain.close();            
+            domain.stop();
+        }
+        
+        nodeDomain.close();        
+        nodeDomain.stop();
+
+    }
+    
+    /**
+     * Returns the name of the node that this part of the
+     * distributed domain is running on
+     * 
+     * @return the node name
+     */
+    public String getNodeName(){
+        return nodeName;
+    }
+    
+    public DistributedSCADomain createDistributedDomain(String domainURI){
+        DistributedSCADomain domain = new DistributedSCADomainImpl(runtimeClassLoader,
+                                                                   domainURI,
+                                                                   nodeDomain);
+        addDomain(domain);
+        
+        return domain;
+    }
+    
+    public void addDomain(DistributedSCADomain distributedDomain) {
+        appDomains.put(distributedDomain.getURI(), distributedDomain);
+    }
+    
+    public DistributedSCADomain getDomain(String domainURI){
+        return appDomains.get(domainURI);
+    }
+    
+    public void startDomain(String domainURI) throws ActivationException {
+        DistributedSCADomain appDomain = appDomains.get(domainURI);
+        appDomain.start();
+    }
+    
+    public void stopDomain(String domainURI)throws ActivationException {
+        DistributedSCADomain appDomain = appDomains.get(domainURI);
+        appDomain.stop();
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/distributed/src/main/java/org/apache/tuscany/sca/distributed/node/impl/NodeImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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