tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r534955 - in /incubator/tuscany/java/sca: modules/core-spi/src/main/java/org/apache/tuscany/core/ modules/core/src/main/java/org/apache/tuscany/core/runtime/ samples/binding-echo/src/main/java/echo/
Date Thu, 03 May 2007 18:42:21 GMT
Author: rfeng
Date: Thu May  3 11:42:20 2007
New Revision: 534955

URL: http://svn.apache.org/viewvc?view=rev&rev=534955
Log:
Add runtime wires for component services and use them to dispatch the inbound invocations
from a service to the promoted component

Added:
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/core/RuntimeComponentService.java
  (with props)
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentServiceImpl.java
  (with props)
Modified:
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/DefaultCompositeActivator.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
    incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java

Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/core/RuntimeComponentService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/core/RuntimeComponentService.java?view=auto&rev=534955
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/core/RuntimeComponentService.java
(added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/core/RuntimeComponentService.java
Thu May  3 11:42:20 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.core;
+
+import java.util.List;
+
+import org.apache.tuscany.assembly.ComponentService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeComponentService extends ComponentService {
+    /**
+     * @param wire
+     */
+    void addRuntimeWire(RuntimeWire wire);
+    /**
+     * @return
+     */
+    List<RuntimeWire> getRuntimeWires();    
+}

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

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

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/DefaultCompositeActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/DefaultCompositeActivator.java?view=diff&rev=534955&r1=534954&r2=534955
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/DefaultCompositeActivator.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/DefaultCompositeActivator.java
Thu May  3 11:42:20 2007
@@ -19,7 +19,6 @@
 
 package org.apache.tuscany.core.runtime;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -40,11 +39,12 @@
 import org.apache.tuscany.core.ReferenceBindingProvider;
 import org.apache.tuscany.core.RuntimeComponent;
 import org.apache.tuscany.core.RuntimeComponentReference;
+import org.apache.tuscany.core.RuntimeComponentService;
 import org.apache.tuscany.core.RuntimeWire;
 import org.apache.tuscany.core.ScopedImplementationProvider;
 import org.apache.tuscany.core.ServiceBindingActivator;
+import org.apache.tuscany.core.ServiceBindingProvider;
 import org.apache.tuscany.core.component.WorkContextImpl;
-import org.apache.tuscany.core.util.JavaIntrospectionHelper;
 import org.apache.tuscany.core.wire.InvocationChainImpl;
 import org.apache.tuscany.core.wire.NonBlockingInterceptor;
 import org.apache.tuscany.core.work.Jsr237WorkScheduler;
@@ -91,20 +91,9 @@
         this.wirePostProcessorRegistry = wirePostProcessorRegistry;
     }
 
-    public static <T> T getContract(Object target, Class<T> interfaceClass) {
-        if (interfaceClass.isInstance(target)) {
-            return interfaceClass.cast(target);
-        } else {
-            try {
-                String methodName = JavaIntrospectionHelper.toGetter(interfaceClass.getSimpleName());
-                Method method = target.getClass().getMethod(methodName, new Class[] {});
-                return interfaceClass.cast(method.invoke(target, new Object[] {}));
-            } catch (Exception e) {
-                return null;
-            }
-        }
-    }
-
+    /**
+     * Start a composite
+     */
     public void start(Composite composite) {
         for (Component component : composite.getComponents()) {
 
@@ -134,6 +123,11 @@
 
     }
 
+    /**
+     * Configure a composite
+     * 
+     * @param composite
+     */
     public void configure(Composite composite) {
         for (Component component : composite.getComponents()) {
 
@@ -147,6 +141,9 @@
 
     }
 
+    /**
+     * Stop a composite
+     */
     public void stop(Composite composite) {
         for (Component component : composite.getComponents()) {
 
@@ -176,52 +173,83 @@
 
     }
 
-    public void createRuntimeWires(Composite composite) throws IncompatibleInterfaceContractException
{
+    /**
+     * Create runtime wires for the composite
+     * 
+     * @param composite
+     * @throws IncompatibleInterfaceContractException
+     */
+    protected void createRuntimeWires(Composite composite) throws IncompatibleInterfaceContractException
{
         for (Component component : composite.getComponents()) {
-
             Implementation implementation = component.getImplementation();
             if (implementation instanceof Composite) {
+                // Recursively create runtime wires
                 createRuntimeWires((Composite)implementation);
             } else {
-                // createSelfReferences(component);
+                // Create outbound wires for the component references
                 for (ComponentReference reference : component.getReferences()) {
                     for (Binding binding : reference.getBindings()) {
                         createWires(component, reference, binding);
                     }
                 }
+                // Create inbound wires for the component services
+                for (ComponentService service : component.getServices()) {
+                    for (Binding binding : service.getBindings()) {
+                        createWires(component, service, binding);
+                    }
+                }
             }
         }
     }
 
+    /**
+     * Get the effective interface contract for a reference binding
+     * 
+     * @param reference
+     * @param binding
+     * @return
+     */
+    private InterfaceContract getInterfaceContract(ComponentReference reference, Binding
binding) {
+        InterfaceContract sourceContract = reference.getInterfaceContract();
+        if (binding instanceof ReferenceBindingProvider) {
+            ReferenceBindingProvider provider = (ReferenceBindingProvider)binding;
+            InterfaceContract bindingContract = provider.getBindingInterfaceContract(reference);
+            if (bindingContract != null) {
+                sourceContract = bindingContract;
+            }
+        }
+        return sourceContract;
+    }
+
+    /**
+     * Create the runtime wires for a reference binding
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     */
     private void createWires(Component component, ComponentReference reference, Binding binding)
{
-        if (!(binding instanceof ReferenceBindingProvider)) {
+        if (!(reference instanceof RuntimeComponentReference)) {
             return;
         }
-
         RuntimeComponentReference wireSource = (RuntimeComponentReference)reference;
-        ReferenceBindingProvider provider = (ReferenceBindingProvider)binding;
+        InterfaceContract sourceContract = getInterfaceContract(reference, binding);
 
         if (!(binding instanceof SCABinding)) {
             RuntimeWire wire = new RuntimeWireImpl(reference, binding);
-
-            InterfaceContract sourceContract = provider.getBindingInterfaceContract(reference);
             for (Operation operation : sourceContract.getInterface().getOperations()) {
                 Operation targetOperation = operation;
                 InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
-                /* lresende */
                 if (operation.isNonBlocking()) {
                     chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
                 }
-
                 addBindingIntercepor(component, reference, binding, chain, operation, false);
-
                 wire.getInvocationChains().add(chain);
             }
             if (sourceContract.getCallbackInterface() != null) {
                 for (Operation operation : sourceContract.getCallbackInterface().getOperations())
{
                     Operation targetOperation = operation;
                     InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
-                    /* lresende */
                     if (operation.isNonBlocking()) {
                         chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
                     }
@@ -229,12 +257,9 @@
                     wire.getCallbackInvocationChains().add(chain);
                 }
             }
-
             wireSource.addRuntimeWire(wire);
         }
         for (ComponentService service : reference.getTargets()) {
-            // FIXME: Need a way to find the owning component of a component
-            // service
             Component target = null;
             SCABinding scaBinding = service.getBinding(SCABinding.class);
             if (scaBinding != null) {
@@ -242,19 +267,14 @@
             }
 
             RuntimeWire wire = new RuntimeWireImpl(reference, service);
-
-            InterfaceContract sourceContract = provider.getBindingInterfaceContract(reference);
             InterfaceContract targetContract = service.getInterfaceContract();
             for (Operation operation : sourceContract.getInterface().getOperations()) {
                 Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(),
operation);
                 InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
-                /* lresende */
                 if (operation.isNonBlocking()) {
                     chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
                 }
-
                 addBindingIntercepor(component, reference, binding, chain, operation, false);
-
                 if (target != null) {
                     addImplementationInterceptor(target, service, chain, operation, false);
                 }
@@ -265,7 +285,6 @@
                     Operation targetOperation = interfaceContractMapper.map(targetContract.getCallbackInterface(),
                                                                             operation);
                     InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
-                    /* lresende */
                     if (operation.isNonBlocking()) {
                         chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
                     }
@@ -279,21 +298,106 @@
         }
     }
 
+    /**
+     * Get the effective interface contract for the service binding
+     * 
+     * @param service
+     * @param binding
+     * @return
+     */
+    private InterfaceContract getInterfaceContract(ComponentService service, Binding binding)
{
+        InterfaceContract sourceContract = service.getInterfaceContract();
+
+        if (binding instanceof ServiceBindingProvider) {
+            ServiceBindingProvider provider = (ServiceBindingProvider)binding;
+            InterfaceContract bindingContract = provider.getBindingInterfaceContract(service);
+            if (bindingContract != null) {
+                sourceContract = bindingContract;
+            }
+        }
+        return sourceContract;
+    }
+
+    /**
+     * Create runtime wires for a service binding
+     * 
+     * @param component
+     * @param service
+     * @param binding
+     */
+    private void createWires(Component component, ComponentService service, Binding binding)
{
+        if (!(service instanceof RuntimeComponentService)) {
+            return;
+        }
+        RuntimeComponentService wireSource = (RuntimeComponentService)service;
+
+        InterfaceContract targetContract = service.getInterfaceContract();
+        InterfaceContract sourceContract = getInterfaceContract(service, binding);
+
+        RuntimeWire wire = new RuntimeWireImpl(null, service);
+
+        for (Operation operation : sourceContract.getInterface().getOperations()) {
+            Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(),
operation);
+            InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+            /* lresende */
+            if (operation.isNonBlocking()) {
+                chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
+            }
+
+            addImplementationInterceptor(component, service, chain, operation, false);
+            wire.getInvocationChains().add(chain);
+        }
+        if (sourceContract.getCallbackInterface() != null) {
+            for (Operation operation : sourceContract.getCallbackInterface().getOperations())
{
+                Operation targetOperation = interfaceContractMapper.map(targetContract.getCallbackInterface(),
+                                                                        operation);
+                InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                /* lresende */
+                if (operation.isNonBlocking()) {
+                    chain.addInterceptor(new NonBlockingInterceptor(workScheduler, workContext));
+                }
+                addImplementationInterceptor(component, service, chain, operation, false);
+                wire.getCallbackInvocationChains().add(chain);
+            }
+        }
+
+        wireSource.addRuntimeWire(wire);
+    }
+
+    /**
+     * Add the interceptor for a component implementation
+     * 
+     * @param component
+     * @param service
+     * @param chain
+     * @param operation
+     * @param isCallback
+     */
     private void addImplementationInterceptor(Component component,
                                               ComponentService service,
                                               InvocationChain chain,
                                               Operation operation,
                                               boolean isCallback) {
         if (component.getImplementation() instanceof ImplementationProvider) {
-            ImplementationProvider factory = (ImplementationProvider)component.getImplementation();
-            Interceptor interceptor = factory.createInterceptor((RuntimeComponent)component,
-                                                                service,
-                                                                operation,
-                                                                isCallback);
+            ImplementationProvider provider = (ImplementationProvider)component.getImplementation();
+            Interceptor interceptor = provider.createInterceptor((RuntimeComponent)component,
+                                                                 service,
+                                                                 operation,
+                                                                 isCallback);
             chain.addInterceptor(interceptor);
         }
     }
 
+    /**
+     * Add the interceptor for a binding
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     * @param chain
+     * @param operation
+     * @param isCallback
+     */
     private void addBindingIntercepor(Component component,
                                       ComponentReference reference,
                                       Binding binding,
@@ -301,14 +405,20 @@
                                       Operation operation,
                                       boolean isCallback) {
         if (binding instanceof ReferenceBindingProvider) {
-            ReferenceBindingProvider factory = (ReferenceBindingProvider)binding;
-            Interceptor interceptor = factory.createInterceptor(component, reference, operation,
isCallback);
+            ReferenceBindingProvider provider = (ReferenceBindingProvider)binding;
+            Interceptor interceptor = provider.createInterceptor(component, reference, operation,
isCallback);
             if (interceptor != null) {
                 chain.addInterceptor(interceptor);
             }
         }
     }
 
+    /**
+     * Get the scope for a component
+     * 
+     * @param component
+     * @return
+     */
     private Scope getScope(Component component) {
         Implementation impl = component.getImplementation();
         if (impl instanceof ScopedImplementationProvider) {
@@ -411,7 +521,7 @@
                 return super.add(o);
             }
         };
-        
+
         compositeUtil.configureAndWire(composite, problems);
 
         // if (!problems.isEmpty()) {
@@ -420,6 +530,12 @@
         // }
     }
 
+    /**
+     * Activate a composite
+     * 
+     * @param composite
+     * @throws IncompatibleInterfaceContractException
+     */
     public void activate(Composite composite) throws IncompatibleInterfaceContractException
{
         wire(composite, assemblyFactory, interfaceContractMapper);
         configure(composite);

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java?view=diff&rev=534955&r1=534954&r2=534955
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
Thu May  3 11:42:20 2007
@@ -21,6 +21,7 @@
 
 import org.apache.tuscany.assembly.Component;
 import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.ComponentService;
 import org.apache.tuscany.assembly.SCABinding;
 import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
 
@@ -42,6 +43,11 @@
     @Override
     public SCABinding createSCABinding() {
         return new RuntimeSCABindingImpl();
+    }
+
+    @Override
+    public ComponentService createComponentService() {
+        return new RuntimeComponentServiceImpl();
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java?view=diff&rev=534955&r1=534954&r2=534955
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
Thu May  3 11:42:20 2007
@@ -17,5 +17,4 @@
         return wires;
     }
 
-
 }

Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentServiceImpl.java?view=auto&rev=534955
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentServiceImpl.java
(added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentServiceImpl.java
Thu May  3 11:42:20 2007
@@ -0,0 +1,23 @@
+package org.apache.tuscany.core.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.assembly.impl.ComponentReferenceImpl;
+import org.apache.tuscany.assembly.impl.ComponentServiceImpl;
+import org.apache.tuscany.core.RuntimeComponentReference;
+import org.apache.tuscany.core.RuntimeComponentService;
+import org.apache.tuscany.core.RuntimeWire;
+
+public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService
{
+    private List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+
+    public void addRuntimeWire(RuntimeWire wire) {
+        wires.add(wire);
+    }
+
+    public List<RuntimeWire> getRuntimeWires() {
+        return wires;
+    }
+
+}

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

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

Modified: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java?view=diff&rev=534955&r1=534954&r2=534955
==============================================================================
--- incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
(original)
+++ incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
Thu May  3 11:42:20 2007
@@ -24,15 +24,16 @@
 import org.apache.tuscany.assembly.Component;
 import org.apache.tuscany.assembly.ComponentReference;
 import org.apache.tuscany.assembly.ComponentService;
-import org.apache.tuscany.core.ImplementationProvider;
 import org.apache.tuscany.core.ReferenceBindingActivator;
 import org.apache.tuscany.core.ReferenceBindingProvider;
-import org.apache.tuscany.core.RuntimeComponent;
+import org.apache.tuscany.core.RuntimeComponentService;
+import org.apache.tuscany.core.RuntimeWire;
 import org.apache.tuscany.core.ServiceBindingActivator;
 import org.apache.tuscany.core.ServiceBindingProvider;
 import org.apache.tuscany.interfacedef.InterfaceContract;
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 
 /**
  * Implementation of the Echo binding provider.
@@ -70,11 +71,11 @@
     public void start(Component component, ComponentService service) {
         URI uri = URI.create(component.getURI() + "/" + getName());
         setURI(uri.toString());
-        ImplementationProvider impl = (ImplementationProvider)component.getImplementation();
-        Interceptor interceptor = impl.createInterceptor((RuntimeComponent)component, service,
service
-            .getInterfaceContract().getInterface().getOperations().get(0), false);
+        RuntimeComponentService componentService = (RuntimeComponentService) service;
+        RuntimeWire wire = componentService.getRuntimeWires().get(0);
+        InvocationChain chain = wire.getInvocationChains().get(0);
         // Register with the hosting server
-        EchoServer.getServer().register(new EchoService(interceptor), uri);
+        EchoServer.getServer().register(new EchoService(chain.getHeadInterceptor()), uri);
     }
 
     public void stop(Component component, ComponentService service) {



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


Mime
View raw message