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 2008/05/16 10:03:28 UTC

svn commit: r656959 [2/2] - in /incubator/tuscany/java/sca: itest/validation/ itest/validation/src/main/resources/NoMatchingBinding/ itest/validation/src/test/java/calculator/ modules/ modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ mod...

Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java Fri May 16 01:03:27 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.core.assembly;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.core.context.ComponentContextImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceUnavailableException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EndpointWireImpl implements RuntimeWire {
+
+    private Endpoint endpoint;
+    private CompositeActivatorImpl compositeActivator;
+    
+    private EndpointProvider endpointProvider;
+    private EndpointReference source;
+    private RuntimeWire wire;
+
+    /**
+     * @param endpoint
+     */
+    public EndpointWireImpl(Endpoint endpoint, CompositeActivator compositeActivator) {
+        super();
+        this.endpoint = endpoint;
+        // TODO - improve the SPI to get rid of this cast
+        this.compositeActivator = (CompositeActivatorImpl)compositeActivator;
+        
+        // store source configuration as we have most of this now. We don't though know what the 
+        // target is yet. 
+        Reference componentTypeRef = endpoint.getSourceComponentReference().getReference();
+        InterfaceContract sourceContract =
+            componentTypeRef == null ? endpoint.getSourceComponentReference().getInterfaceContract() : componentTypeRef.getInterfaceContract();
+        sourceContract = sourceContract.makeUnidirectional(false);
+
+        source = new EndpointReferenceImpl((RuntimeComponent)endpoint.getSourceComponent(), 
+                                            endpoint.getSourceComponentReference(), 
+                                            null, 
+                                            sourceContract);
+        
+        RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference());
+        endpointProvider = runtimeRef.getEndpointProvider(endpoint);
+        
+    }
+
+    public synchronized List<InvocationChain> getInvocationChains() {
+        // where late binding happens. Find the endpoint provider and
+        // ask it to do the endpoint resolution.
+        if (endpoint.isUnresolved()){
+            
+            // this method should locate a viable target service and complete the 
+            // endpoint configuration
+            endpointProvider.start();
+            
+            if (endpoint.isUnresolved()){
+                throw new ServiceUnavailableException("Unable to resolve service for component: " +
+                        endpoint.getSourceComponent().getName() +
+                        " reference: " + 
+                        endpoint.getSourceComponentReference().getName() +
+                        " target: " + 
+                        endpoint.getTargetName());
+            } 
+        }
+        
+        if (wire == null){           
+            RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference());
+            
+            // add the resolved binding into the reference
+            runtimeRef.getBindings().add(endpoint.getSourceBinding());
+            
+            // add a binding provider into the reference for the resolved binding 
+            compositeActivator.addReferenceBindingProviderForEndpoint(endpoint);
+            
+            // extract the binding provider that has been created
+            ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpoint.getSourceBinding());
+            
+            // start the binding provider  
+            bindingProvider.start();
+            
+            // create the wire
+            compositeActivator.addReferenceWireForEndpoint(endpoint);
+            
+            // extract the wire that has been created
+            wire = runtimeRef.getRuntimeWire(endpoint.getSourceBinding());
+        }            
+
+        return wire.getInvocationChains();
+    }
+
+    public InvocationChain getInvocationChain(Operation operation) {
+        if (wire ==null){
+            return null;
+        } else {
+            return wire.getInvocationChain(operation);
+        }
+    }
+
+    public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
+        // not called as the endpoint wire only appears on the reference side
+        return null;
+    }
+
+    public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+        // not called as the endpoint wire only appears on the reference side
+        return null;
+    }
+
+
+    public EndpointReference getSource() {
+        return source;
+    }
+
+    public EndpointReference getTarget() {
+        return null;
+    }
+
+    public void setTarget(EndpointReference target) {
+    }
+
+    public void rebuild() {
+    }
+
+    /**
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        EndpointWireImpl copy = (EndpointWireImpl)super.clone();
+        return copy;
+    }
+}

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

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

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java Fri May 16 01:03:27 2008
@@ -24,10 +24,12 @@
 import java.util.List;
 
 import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.InvocationChain;
 import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.EndpointProvider;
 import org.apache.tuscany.sca.provider.PolicyProvider;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -43,6 +45,8 @@
     private ArrayList<RuntimeWire> wires;
     private HashMap<Binding, ReferenceBindingProvider> bindingProviders =
         new HashMap<Binding, ReferenceBindingProvider>();
+    private HashMap<Endpoint, EndpointProvider> endpointProviders =
+        new HashMap<Endpoint, EndpointProvider>();    
     private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
 
     private RuntimeComponent component;
@@ -75,6 +79,14 @@
     public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) {
         bindingProviders.put(binding, bindingProvider);
     }
+    
+    public EndpointProvider getEndpointProvider(Endpoint endpoint){
+        return endpointProviders.get(endpoint);
+    }
+    
+    public void setEndpointProvider(Endpoint endpoint, EndpointProvider endpointProvider){
+        endpointProviders.put(endpoint, endpointProvider);
+    }
 
     public Invoker getInvoker(Binding binding, Operation operation) {
         RuntimeWire wire = getRuntimeWire(binding);

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java Fri May 16 01:03:27 2008
@@ -37,6 +37,7 @@
 import org.apache.tuscany.sca.core.assembly.CompositeActivator;
 import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
 import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.EndpointWireImpl;
 import org.apache.tuscany.sca.core.assembly.ReferenceParametersImpl;
 import org.apache.tuscany.sca.core.conversation.ConversationManager;
 import org.apache.tuscany.sca.core.conversation.ConversationState;
@@ -83,6 +84,8 @@
     private transient RuntimeComponentReference clonedRef;
     private transient ReferenceParameters refParams;
     private transient XMLStreamReader xmlReader;
+    
+    private transient RuntimeWire endpointWire;
 
     /*
      * Public constructor for Externalizable serialization/deserialization
@@ -123,7 +126,7 @@
         // sca:component1/component11/component112/service1?
         this.compositeActivator = compositeActivator;
         this.conversationManager = this.compositeActivator.getConversationManager();
-        RuntimeWire wire = this.reference.getRuntimeWire(this.binding);
+        //RuntimeWire wire = this.reference.getRuntimeWire(this.binding);
         // init(wire);
         initCallbackID();
     }
@@ -137,7 +140,9 @@
     public RuntimeWire getRuntimeWire() {
         try {
             resolve();
-            if (reference != null) {
+            if (endpointWire != null){
+                return endpointWire;
+            } else if (reference != null) {
                 return reference.getRuntimeWire(binding);
             } else {
                 return null;
@@ -149,6 +154,10 @@
 
     protected void bind(RuntimeWire wire) {
         if (wire != null) {
+            
+            if (wire instanceof EndpointWireImpl){
+                endpointWire = wire;
+            }
             this.component = wire.getSource().getComponent();
             this.reference = (RuntimeComponentReference)wire.getSource().getContract();
             this.binding = wire.getSource().getBinding();

Modified: incubator/tuscany/java/sca/modules/host-embedded/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/pom.xml?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/pom.xml Fri May 16 01:03:27 2008
@@ -101,6 +101,13 @@
             <version>2.0-incubating-SNAPSHOT</version>
             <scope>runtime</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-endpoint</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>        
      
 
     </dependencies>

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java Fri May 16 01:03:27 2008
@@ -235,7 +235,7 @@
         for (Composite composite : domainComposite.getIncludes()) {
             try {
                 compositeActivator.activate(composite);
-            } catch (ActivationException e) {
+            } catch (Exception e) {
                 throw new ServiceRuntimeException(e);
             }
         }
@@ -244,7 +244,7 @@
                 for (Component component : composite.getComponents()) {
                     compositeActivator.start(component);
                 }
-            } catch (ActivationException e) {
+            } catch (Exception e) {
                 throw new ServiceRuntimeException(e);
             }
         }

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java Fri May 16 01:03:27 2008
@@ -29,6 +29,8 @@
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultEndpointFactory;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
@@ -217,9 +219,9 @@
         ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
         SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
         IntentAttachPointTypeFactory intentAttachPointTypeFactory = factories.getFactory(IntentAttachPointTypeFactory.class);
+        EndpointFactory endpointFactory = factories.getFactory(EndpointFactory.class);        
         InterfaceContractMapper mapper = new InterfaceContractMapperImpl();
         
-        
         //Create a composite builder
         SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl();
         for ( SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions) ) {
@@ -228,6 +230,7 @@
         compositeBuilder = ReallySmallRuntimeBuilder.createCompositeBuilder(monitor,
                                                                             assemblyFactory,
                                                                             scaBindingFactory,
+                                                                            endpointFactory,
                                                                             intentAttachPointTypeFactory,
                                                                             mapper, 
                                                                             aggregatedDefinitions);

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java Fri May 16 01:03:27 2008
@@ -31,6 +31,7 @@
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.DomainBuilder;
@@ -151,12 +152,14 @@
     public static CompositeBuilder createCompositeBuilder(Monitor monitor,
                                                           AssemblyFactory assemblyFactory,
                                                           SCABindingFactory scaBindingFactory,
+                                                          EndpointFactory endpointFactory,
                                                           IntentAttachPointTypeFactory intentAttachPointTypeFactory,
                                                           InterfaceContractMapper interfaceContractMapper,
                                                           SCADefinitions policyDefinitions) {
       
         
         return new CompositeBuilderImpl(assemblyFactory, 
+                                        endpointFactory,
                                         scaBindingFactory, 
                                         intentAttachPointTypeFactory, 
                                         interfaceContractMapper,

Modified: incubator/tuscany/java/sca/modules/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/pom.xml?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/pom.xml Fri May 16 01:03:27 2008
@@ -95,6 +95,7 @@
                 <module>domain-api</module>
                 <module>domain-impl</module>
                 <module>domain-manager</module>
+                <module>endpoint</module>
                 <module>extensibility</module>
                 <module>extension-helper</module>
                 <module>host-embedded</module>