You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2007/03/14 05:34:42 UTC

svn commit: r518005 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/component/ core/src/main/java/org/apache/tuscany/core/implementation/java/ core/src/main/java/org/apache/tuscany/core/injection/ core/src/main/java/...

Author: jmarino
Date: Tue Mar 13 21:34:40 2007
New Revision: 518005

URL: http://svn.apache.org/viewvc?view=rev&rev=518005
Log:
start integration of callback handling with federated deployment process

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java Tue Mar 13 21:34:40 2007
@@ -28,6 +28,7 @@
 import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.spi.component.Component;
 import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Wire;
 
 /**
  * An implementation of an {@link org.apache.tuscany.spi.component.WorkContext} that handles event-to-thread
@@ -41,6 +42,7 @@
     private static final Object CALLBACK_URIS = new Object();
     private static final Object CURRENT_ATOMIC = new Object();
     private static final Object CURRENT_SERVICE_NAMES = new Object();
+    private static final Object CALLBACK_WIRES = new Object();
 
     // [rfeng] We cannot use InheritableThreadLocal for message ids here since it's shared by parent and children
     private ThreadLocal<Map<Object, Object>> workContext = new ThreadLocal<Map<Object, Object>>();
@@ -90,6 +92,21 @@
     public void setCallbackUris(LinkedList<URI> uris) {
         Map<Object, Object> map = getWorkContextMap();
         map.put(CALLBACK_URIS, uris);
+    }
+
+
+    @SuppressWarnings({"unchecked"})
+    public LinkedList<Wire> getCallbackWires() {
+        Map<Object, Object> map = workContext.get();
+        if (map == null) {
+            return null;
+        }
+        return (LinkedList<Wire>) map.get(CALLBACK_WIRES);
+    }
+
+    public void setCallbackWires(LinkedList<Wire> wires) {
+        Map<Object, Object> map = getWorkContextMap();
+        map.put(CALLBACK_WIRES, wires);
     }
 
     public Component getRemoteComponent() {

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java Tue Mar 13 21:34:40 2007
@@ -45,6 +45,7 @@
 import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
 import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
 import org.apache.tuscany.core.wire.WireObjectFactory;
+import org.apache.tuscany.core.injection.CallbackWireObjectFactory2;
 
 /**
  * The physical component builder for Java implementation types. Responsible for creating the Component runtime artifact

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java?view=auto&rev=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java Tue Mar 13 21:34:40 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory2<T> implements ObjectFactory {
+    private ProxyService proxyService;
+    private Class<T> interfaze;
+
+    public CallbackWireObjectFactory2(Class<T> interfaze, ProxyService proxyService) {
+        this.interfaze = interfaze;
+        this.proxyService = proxyService;
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public T getInstance() throws ObjectCreationException {
+        return (T) proxyService.createCallbackProxy(interfaze);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java?view=auto&rev=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java Tue Mar 13 21:34:40 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+
+/**
+ * Returns a component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class InstanceObjectFactory<T> implements ObjectFactory<T> {
+    private ScopeContainer scope;
+    private AtomicComponent component;
+
+    public InstanceObjectFactory(AtomicComponent component, ScopeContainer scope) {
+        this.component = component;
+        this.scope = scope;
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public T getInstance() throws ObjectCreationException {
+        try {
+            return (T) scope.getWrapper(component).getInstance();
+        } catch (TargetResolutionException e) {
+            throw new ObjectCreationException(e);
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/InstanceObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java Tue Mar 13 21:34:40 2007
@@ -29,6 +29,7 @@
 import org.apache.tuscany.spi.wire.Interceptor;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 
 /**
  * Adds non-blocking behavior to an invocation chain
@@ -133,6 +134,18 @@
 
         public void setCallbackUris(LinkedList<URI> uris) {
             throw new UnsupportedOperationException();
+        }
+
+        public void pushCallbackWire(Wire wire) {
+
+        }
+
+        public LinkedList<Wire> getCallbackWires() {
+            return null;
+        }
+
+        public void setCallbackWires(LinkedList<Wire> wires) {
+
         }
 
         public Object getMessageId() {

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java?view=auto&rev=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java Tue Mar 13 21:34:40 2007
@@ -0,0 +1,135 @@
+/*
+ * 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.wire.jdk;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Responsible for dispatching to a callback through a wire.
+ * <p/>
+ * TODO cache target invoker
+ *
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandler2 extends AbstractInvocationHandler
+    implements InvocationHandler, Externalizable, SCAExternalizable {
+    private transient WorkContext context;
+
+    /**
+     * Constructor used for deserialization only
+     */
+    public JDKCallbackInvocationHandler2() {
+    }
+
+    public JDKCallbackInvocationHandler2(WorkContext context) {
+        this.context = context;
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) {
+            return "[Proxy - " + Integer.toHexString(hashCode()) + "]";
+        } else if (method.getDeclaringClass().equals(Object.class)
+            && "equals".equals(method.getName())) {
+            // TODO implement
+            throw new UnsupportedOperationException();
+        } else if (Object.class.equals(method.getDeclaringClass())
+            && "hashCode".equals(method.getName())) {
+            return hashCode();
+            // TODO beter hash algorithm
+        }
+        LinkedList<Wire> wires = context.getCallbackWires();
+        Wire wire = wires.getLast();
+        assert wire != null;
+        Map<Operation<?>, InvocationChain> chains = wire.getCallbackInvocationChains();
+        Operation operation = JavaIDLUtils.findOperation(method, chains.keySet());
+        InvocationChain chain = chains.get(operation);
+        TargetInvoker invoker = chain.getTargetInvoker();
+        Object correlationId = context.getCorrelationId();
+        context.setCorrelationId(null);
+        try {
+            return invokeTarget(chain, invoker, args, correlationId, wires);
+        } catch (InvocationTargetException e) {
+            Throwable t = e.getCause();
+            if (t instanceof NoRegisteredCallbackException) {
+                throw t;
+            }
+            throw e;
+        }
+    }
+
+
+    public Object invoke(Method method, Object[] args) throws Throwable {
+        return invoke(null, method, args);
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        // TODO re-implement
+//        int i = sourceWireNames.size() - 1;
+//        out.writeInt(i);
+//        for (String name : sourceWireNames) {
+//            out.writeObject(name);
+//        }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+// TODO re-implement
+//        int num = in.readInt();
+//        for (int i = 0; i <= num; i++) {
+//            sourceWireNames.add((String) in.readObject());
+//        }
+    }
+
+    public void setWorkContext(WorkContext context) {
+        this.context = context;
+    }
+
+    public void reactivate() throws ReactivationException {
+//        AtomicComponent owner = context.getCurrentAtomicComponent();
+//        if (owner == null) {
+//            throw new ReactivationException("Current atomic component not set on work context");
+//        }
+//        for (String name : sourceWireNames) {
+//            // TODO JFM support multiplicity, remove get(0)
+//            Wire wire = owner.getWires(name).get(0);
+//            wires.put(wire.getSourceUri(), wire);
+//
+//        }
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java Tue Mar 13 21:34:40 2007
@@ -77,6 +77,12 @@
         return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
     }
 
+    public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
+        ClassLoader cl = interfaze.getClassLoader();
+        JDKCallbackInvocationHandler2 handler = new JDKCallbackInvocationHandler2(context);
+        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+    }
+
     public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
         InvocationHandler handler = Proxy.getInvocationHandler(target);
         if (handler instanceof JDKInvocationHandler) {

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java?view=auto&rev=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java Tue Mar 13 21:34:40 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.injection;
+
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory2TestCase extends TestCase {
+
+    @SuppressWarnings({"unchecked"})
+    public void testCreateInstance() throws Exception {
+        ProxyService service = EasyMock.createMock(ProxyService.class);
+        Foo foo = new Foo() {
+        };
+        EasyMock.expect(service.createCallbackProxy(EasyMock.eq(Foo.class))).andReturn(foo);
+        EasyMock.replay(service);
+        CallbackWireObjectFactory2 factory = new CallbackWireObjectFactory2(Foo.class, service);
+        assertEquals(foo, factory.getInstance());
+        EasyMock.verify(service);
+    }
+
+    private interface Foo {
+
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java Tue Mar 13 21:34:40 2007
@@ -359,6 +359,10 @@
             return null;
         }
 
+        public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
+            return null;
+        }
+
         public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract,
                                 QualifiedName targetName) {
             throw new UnsupportedOperationException();

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java Tue Mar 13 21:34:40 2007
@@ -21,6 +21,8 @@
 import java.net.URI;
 import java.util.LinkedList;
 
+import org.apache.tuscany.spi.wire.Wire;
+
 /**
  * Implementations track information associated with a request as it is processed by the runtime
  *
@@ -53,14 +55,31 @@
      * invocations for collocated components
      *
      * @return the current list of callback URIs
+     * @Deprecated
      */
     LinkedList<URI> getCallbackUris();
 
     /**
      * Sets an ordered list of callback URIs for the current context. Ordering is based on the sequence of service
      * invocations for collocated components
+     *
+     * @Deprecated
      */
     void setCallbackUris(LinkedList<URI> uris);
+
+    /**
+     * Returns an ordered list of callback wures for the current context. Ordering is based on the sequence of service
+     * invocations for collocated components
+     *
+     * @return the current list of callback wires
+     */
+    LinkedList<Wire> getCallbackWires();
+
+    /**
+     * Sets an ordered list of callback wires for the current context. Ordering is based on the sequence of service
+     * invocations for collocated components
+     */
+    void setCallbackWires(LinkedList<Wire> wires);
 
     /**
      * Returns the correlation id for the current invocation or null if not available. Transports may use correlation

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java Tue Mar 13 21:34:40 2007
@@ -25,16 +25,18 @@
 
 /**
  * Represents a physical wire source definition.
- * 
+ *
  * @version $Revision$ $Date$
  */
 public class PhysicalWireSourceDefinition extends ModelObject {
-    
+
     // URI
     private URI uri;
+    private boolean optimizable;
 
     /**
      * Gets the URI.
+     *
      * @return Gets the URI.
      */
     public URI getUri() {
@@ -43,10 +45,29 @@
 
     /**
      * Sets the URI.
+     *
      * @param uri Sets the URI.
      */
     public void setUri(URI uri) {
         this.uri = uri;
     }
 
+
+    /**
+     * Returns true if the wire may be optimized
+     *
+     * @return true if the wire may be optimized
+     */
+    public boolean isOptimizable() {
+        return optimizable;
+    }
+
+    /**
+     * Setting to true indicates the wire may be optimized
+     *
+     * @param optimizable if the wire can be optimized
+     */
+    public void setOptimizable(boolean optimizable) {
+        this.optimizable = optimizable;
+    }
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java Tue Mar 13 21:34:40 2007
@@ -34,6 +34,9 @@
 public abstract class AbstractInvocationHandler {
     private boolean conversationStarted;
 
+    /**
+     * @Deprecated
+     */
     protected Object invoke(InvocationChain chain,
                             TargetInvoker invoker,
                             Object[] args,
@@ -62,6 +65,62 @@
             }
             if (callbackUris != null) {
                 msg.setCallbackUris(callbackUris);
+            }
+            Operation operation = chain.getOperation();
+            ServiceContract contract = operation.getServiceContract();
+            if (contract.isConversational()) {
+                int sequence = chain.getOperation().getConversationSequence();
+                if (sequence == Operation.CONVERSATION_END) {
+                    msg.setConversationSequence(TargetInvoker.END);
+                    conversationStarted = false;
+                } else if (sequence == Operation.CONVERSATION_CONTINUE) {
+                    if (conversationStarted) {
+                        msg.setConversationSequence(TargetInvoker.CONTINUE);
+                    } else {
+                        conversationStarted = true;
+                        msg.setConversationSequence(TargetInvoker.START);
+                    }
+                }
+            }
+            msg.setBody(args);
+            // dispatch the wire down the chain and get the response
+            Message resp = headInterceptor.invoke(msg);
+            Object body = resp.getBody();
+            if (resp.isFault()) {
+                throw (Throwable) body;
+            }
+            return body;
+        }
+    }
+
+    protected Object invokeTarget(InvocationChain chain,
+                            TargetInvoker invoker,
+                            Object[] args,
+                            Object correlationId,
+                            LinkedList<Wire> callbackWires)
+        throws Throwable {
+        Interceptor headInterceptor = chain.getHeadInterceptor();
+        if (headInterceptor == null) {
+            try {
+                // short-circuit the dispatch and invoke the target directly
+                TargetInvoker targetInvoker = chain.getTargetInvoker();
+                if (targetInvoker == null) {
+                    String name = chain.getOperation().getName();
+                    throw new AssertionError("No target invoker [" + name + "]");
+                }
+                return targetInvoker.invokeTarget(args, TargetInvoker.NONE);
+            } catch (InvocationTargetException e) {
+                // the cause was thrown by the target so throw it
+                throw e.getCause();
+            }
+        } else {
+            Message msg = new MessageImpl();
+            msg.setTargetInvoker(invoker);
+            if (correlationId != null) {
+                msg.setCorrelationId(correlationId);
+            }
+            if (callbackWires != null) {
+                msg.setCallbackWires(callbackWires);
             }
             Operation operation = chain.getOperation();
             ServiceContract contract = operation.getServiceContract();

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java Tue Mar 13 21:34:40 2007
@@ -55,18 +55,45 @@
     /**
      * Adds a URI to the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a
      * callback.
+     *
+     * @Deprecated
      */
     void pushCallbackUri(URI uri);
 
     /**
      * Returns the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback.
+     *
+     * @Deprecated
      */
     LinkedList<URI> getCallbackUris();
 
     /**
      * Sets the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback.
+     *
+     * @Deprecated
      */
     void setCallbackUris(LinkedList<URI> uris);
+
+    /**
+     * Adds a callback wire to the ordered list of callbacks for the current invocation
+     *
+     * @param wire the callback wire
+     */
+    void pushCallbackWire(Wire wire);
+
+    /**
+     * Returns the ordered list of callback wires for the current invocation
+     *
+     * @return the ordered list of callback wires for the current invocation
+     */
+    LinkedList<Wire> getCallbackWires();
+
+    /**
+     * Sets the ordered list of callback wires for the current invocation
+     *
+     * @param wires the ordered list of callback wires for the current invocation
+     */
+    void setCallbackWires(LinkedList<Wire> wires);
 
     /**
      * Returns the id of the message

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java Tue Mar 13 21:34:40 2007
@@ -30,6 +30,7 @@
     private Object body;
     private TargetInvoker invoker;
     private LinkedList<URI> callbackUris;
+    private LinkedList<Wire> callbackWires;
     private Object messageId;
     private Object correlationId;
     private boolean isFault;
@@ -68,6 +69,21 @@
 
     public void setCallbackUris(LinkedList<URI> callbackRoutingChain) {
         this.callbackUris = callbackRoutingChain;
+    }
+
+    public void pushCallbackWire(Wire wire) {
+        if (callbackWires == null) {
+            callbackWires = new LinkedList<Wire>();
+        }
+        callbackWires.add(wire);
+    }
+
+    public LinkedList<Wire> getCallbackWires() {
+        return callbackWires;
+    }
+
+    public void setCallbackWires(LinkedList<Wire> wires) {
+        this.callbackWires = wires;
     }
 
     public Object getMessageId() {

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java?view=diff&rev=518005&r1=518004&r2=518005
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java Tue Mar 13 21:34:40 2007
@@ -61,10 +61,20 @@
      * @param interfaze the interface the proxy should implement
      * @return the proxy
      * @throws ProxyCreationException
+     * @Deprecated
      */
     Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException;
 
     /**
+     * Creates a Java proxy for the service contract callback
+     *
+     * @param interfaze the interface the proxy should implement
+     * @return the proxy
+     * @throws ProxyCreationException if an error is encountered during proxy generation
+     */
+    Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException;
+
+    /**
      * Cast a proxy to a CallableReference.
      *
      * @param target a proxy generated by this implementation
@@ -96,13 +106,12 @@
      * @return true if the service contracts are compatible
      * @throws IncompatibleServiceContractException
      *          If the source service contract is not compatible with the target one
-     * <p>
-     * TODO JFM this method should be moved from this interface to the allocator phase
+     *          <p/>
+     *          TODO JFM this method should be moved from this interface to the allocator phase
      */
     boolean checkCompatibility(ServiceContract<?> source,
                                ServiceContract<?> target,
                                boolean ignoreCallback,
-                               boolean silent)
-        throws IncompatibleServiceContractException;
+                               boolean silent) throws IncompatibleServiceContractException;
 
 }



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