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/15 08:03:59 UTC
svn commit: r518500 - in /incubator/tuscany/java/sca/kernel:
core/src/main/java/org/apache/tuscany/core/implementation/java/
core/src/main/java/org/apache/tuscany/core/wire/
core/src/main/java/org/apache/tuscany/core/wire/jdk/
core/src/test/java/org/ap...
Author: jmarino
Date: Thu Mar 15 00:03:58 2007
New Revision: 518500
URL: http://svn.apache.org/viewvc?view=rev&rev=518500
Log:
get the invocation infrastructure working with the federated marshallers
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java (with props)
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java (with props)
Modified:
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/WireObjectFactory.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.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/idl/java/JavaIDLUtils.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.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/ProxyService.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java
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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -52,7 +52,7 @@
import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
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.wire.WireObjectFactory2;
/**
* The physical component builder for Java implementation types. Responsible for creating the Component runtime artifact
@@ -174,7 +174,7 @@
Component target,
Wire wire,
JavaPhysicalWireSourceDefinition definition) {
- URI sourceUri = wire.getSourceUri();
+ URI sourceUri = definition.getUri();
InjectionSource referenceSource = new InjectionSource(REFERENCE, sourceUri.getFragment());
Class<?> type = source.getMemberType(referenceSource);
if (definition.isOptimizable()) {
@@ -184,7 +184,7 @@
ObjectFactory<?> factory = new InstanceObjectFactory((AtomicComponent) target, container);
source.setObjectFactory(referenceSource, factory);
} else {
- ObjectFactory<?> factory = new WireObjectFactory(type, wire, proxyService);
+ ObjectFactory<?> factory = new WireObjectFactory2(type, definition.isConversational(), wire, proxyService);
source.setObjectFactory(referenceSource, factory);
if (!wire.getCallbackInvocationChains().isEmpty()) {
URI callbackUri = definition.getCallbackUri();
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java Thu Mar 15 00:03:58 2007
@@ -31,6 +31,7 @@
/**
* Uses a wire to return an object instance
+ * @Deprecated
*
* @version $Rev$ $Date$
*/
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java?view=auto&rev=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java Thu Mar 15 00:03:58 2007
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Uses a wire to return an object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactory2<T> implements ObjectFactory<T> {
+ private Class<T> interfaze;
+ private boolean conversational;
+ private Wire wire;
+ private ProxyService proxyService;
+ // the cache of proxy interface method to operation mappings
+ private Map<Method, InvocationChain> mappings;
+
+ /**
+ * Constructor.
+ *
+ * @param interfaze the interface to inject on the client
+ * @param conversational if the wire is conversational
+ * @param wire the backing wire
+ * @param proxyService the wire service to create the proxy
+ * @throws org.apache.tuscany.core.wire.NoMethodForOperationException
+ *
+ */
+ public WireObjectFactory2(Class<T> interfaze, boolean conversational, Wire wire, ProxyService proxyService)
+ throws NoMethodForOperationException {
+ this.interfaze = interfaze;
+ this.conversational= conversational;
+ this.wire = wire;
+ this.proxyService = proxyService;
+ this.mappings = WireUtils.createInterfaceToWireMapping2(interfaze, wire);
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ return interfaze.cast(proxyService.createProxy2(interfaze, conversational, wire));
+ }
+}
+
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java Thu Mar 15 00:03:58 2007
@@ -23,10 +23,13 @@
import java.util.Map;
import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod2;
import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
import org.apache.tuscany.spi.wire.ChainHolder;
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
import org.apache.tuscany.spi.wire.Wire;
/**
@@ -47,10 +50,12 @@
* @param wire the wire to map to
* @return a collection of method to operation mappings
* @throws NoMethodForOperationException
+ * @Deprecated
*/
public static Map<Method, ChainHolder> createInterfaceToWireMapping(Class<?> interfaze, Wire wire)
throws NoMethodForOperationException {
Map<Operation<?>, InvocationChain> invocationChains = wire.getInvocationChains();
+
Map<Method, ChainHolder> chains = new HashMap<Method, ChainHolder>(invocationChains.size());
for (Map.Entry<Operation<?>, InvocationChain> entry : invocationChains.entrySet()) {
Operation operation = entry.getKey();
@@ -59,6 +64,25 @@
chains.put(method, new ChainHolder(entry.getValue()));
} catch (NoSuchMethodException e) {
throw new NoMethodForOperationException(operation.getName());
+ }
+ }
+ return chains;
+ }
+
+ public static Map<Method, InvocationChain> createInterfaceToWireMapping2(Class<?> interfaze, Wire wire)
+ throws NoMethodForOperationException {
+ Map<PhysicalOperationDefinition, InvocationChain> invocationChains = wire.getPhysicalInvocationChains();
+
+ Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>(invocationChains.size());
+ for (Map.Entry<PhysicalOperationDefinition, InvocationChain> entry : invocationChains.entrySet()) {
+ PhysicalOperationDefinition operation = entry.getKey();
+ try {
+ Method method = findMethod2(interfaze, operation);
+ chains.put(method, entry.getValue());
+ } catch (NoSuchMethodException e) {
+ throw new NoMethodForOperationException(operation.getName());
+ } catch (ClassNotFoundException e) {
+ throw new ProxyCreationException(e);
}
}
return chains;
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java Thu Mar 15 00:03:58 2007
@@ -50,7 +50,7 @@
* Responsible for dispatching to a callback through a wire.
* <p/>
* TODO cache target invoker
- *
+ * @Deprecated
* @version $Rev$ $Date$
*/
public class JDKCallbackInvocationHandler extends AbstractInvocationHandler
Modified: 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=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java Thu Mar 15 00:03:58 2007
@@ -34,10 +34,9 @@
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.model.physical.PhysicalOperationDefinition;
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;
/**
@@ -77,14 +76,13 @@
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());
+ Map<PhysicalOperationDefinition, InvocationChain> chains = wire.getCallbackPhysicalInvocationChains();
+ PhysicalOperationDefinition operation = JavaIDLUtils.findOperation2(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);
+ return invokeTarget(chain, args, correlationId, wires);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof NoRegisteredCallbackException) {
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java Thu Mar 15 00:03:58 2007
@@ -51,6 +51,7 @@
* Dispatches to a target through a wire.
*
* @version $Rev$ $Date$
+ * @Deprecated
*/
public final class JDKInvocationHandler extends AbstractInvocationHandler
implements InvocationHandler, Externalizable, SCAExternalizable {
@@ -95,6 +96,7 @@
Map<Method, ChainHolder> mapping,
WorkContext workContext)
throws NoMethodForOperationException {
+ super(false);
this.workContext = workContext;
this.proxyInterface = interfaze;
init(interfaze, wire, mapping);
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java?view=auto&rev=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java Thu Mar 15 00:03:58 2007
@@ -0,0 +1,187 @@
+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.Method;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.TargetInvocationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.wire.NoMethodForOperationException;
+import org.apache.tuscany.core.wire.WireUtils;
+
+/**
+ * Dispatches to a target through a wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JDKInvocationHandler2 extends AbstractInvocationHandler
+ implements InvocationHandler, Externalizable, SCAExternalizable {
+ private static final long serialVersionUID = -6155278451964527325L;
+
+ // the wire this handler fronts
+ private transient Wire wire;
+ // the name of the source reference the wire is attached to, used during deserialization
+ private String referenceName;
+ // the interface the reference proxy implements
+ private Class<?> proxyInterface;
+ private transient WorkContext workContext;
+ // if the associated wire has a callback
+ private transient boolean callback;
+ // if the associated wire is conversational
+ private boolean conversational;
+ private transient Map<Method, InvocationChain> chains;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKInvocationHandler2() {
+ }
+
+ public JDKInvocationHandler2(Class<?> interfaze, boolean conversational, Wire wire, WorkContext workContext)
+ throws NoMethodForOperationException {
+ super(conversational);
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ this.wire = wire;
+ this.conversational = conversational;
+ init(interfaze, wire, null);
+ }
+
+ public JDKInvocationHandler2(Class<?> interfaze,
+ Wire wire,
+ Map<Method, InvocationChain> mapping,
+ WorkContext workContext)
+ throws NoMethodForOperationException {
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ init(interfaze, wire, mapping);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ InvocationChain chain = chains.get(method);
+ if (chain == null) {
+ 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
+ }
+ throw new TargetInvocationException("Operation not configured", method.getName());
+ }
+
+ if (conversational) {
+ Object id = workContext.getIdentifier(Scope.CONVERSATION);
+ if (id == null) {
+ String convIdFromThread = createConversationID();
+ workContext.setIdentifier(Scope.CONVERSATION, convIdFromThread);
+ }
+ }
+ LinkedList<Wire> list = null;
+ if (callback) {
+ // set up callback address
+ list = workContext.getCallbackWires();
+ if (list == null) {
+ list = new LinkedList<Wire>();
+ workContext.setCallbackWires(list);
+ }
+ list.add(wire);
+ }
+ // send the invocation down the wire
+ Object result = invokeTarget(chain, args, null, list);
+
+ if (callback) {
+ list = workContext.getCallbackWires();
+ if (list != null) {
+ // pop last address
+ list.removeLast();
+ }
+ }
+ return result;
+ }
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+
+ public void setWorkContext(WorkContext context) {
+ workContext = context;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(referenceName);
+ out.writeObject(proxyInterface);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ referenceName = (String) in.readObject();
+ proxyInterface = (Class<?>) in.readObject();
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = workContext.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ List<Wire> wires = owner.getWires(referenceName);
+ if (wires == null) {
+ throw new ReactivationException("Reference wire not found", referenceName, owner.getUri().toString());
+ }
+ // TODO handle multiplicity
+ Wire wire = wires.get(0);
+ try {
+ init(proxyInterface, wire, null);
+ } catch (NoMethodForOperationException e) {
+ throw new ReactivationException(e);
+ }
+ }
+
+ /**
+ * Reinitializes the proxy handler
+ *
+ * @param interfaze the interface the proxy implements
+ * @param wire the wire fronted by the proxy
+ * @param mapping a mapping from proxy interface methods to invocation chain holders
+ * @throws org.apache.tuscany.core.wire.NoMethodForOperationException
+ *
+ */
+ private void init(Class<?> interfaze, Wire wire, Map<Method, InvocationChain> mapping)
+ throws NoMethodForOperationException {
+ this.referenceName = wire.getSourceUri().getFragment();
+ this.callback = !wire.getPhysicalInvocationChains().isEmpty();
+ if (mapping == null) {
+ chains = WireUtils.createInterfaceToWireMapping2(interfaze, wire);
+ } else {
+ chains = mapping;
+ }
+ }
+
+ /**
+ * Creates a new conversational id
+ *
+ * @return the conversational id
+ */
+ private String createConversationID() {
+ return UUID.randomUUID().toString();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -33,6 +33,7 @@
import org.apache.tuscany.spi.wire.ChainHolder;
import org.apache.tuscany.spi.wire.ProxyCreationException;
import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.InvocationChain;
import org.apache.tuscany.core.wire.ProxyServiceExtension;
@@ -57,6 +58,14 @@
assert interfaze != null;
assert wire != null;
JDKInvocationHandler handler = new JDKInvocationHandler(interfaze, wire, context);
+ ClassLoader cl = interfaze.getClassLoader();
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException {
+ assert interfaze != null;
+ assert wire != null;
+ JDKInvocationHandler2 handler = new JDKInvocationHandler2(interfaze, conversational, wire, context);
ClassLoader cl = interfaze.getClassLoader();
return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
}
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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -36,6 +36,7 @@
import org.apache.tuscany.spi.wire.ProxyCreationException;
import org.apache.tuscany.spi.wire.Wire;
import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.InvocationChain;
import junit.framework.TestCase;
import org.osoa.sca.CallableReference;
@@ -350,17 +351,30 @@
throw new UnsupportedOperationException();
}
+ public <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
throws ProxyCreationException {
throw new UnsupportedOperationException();
}
+ public <T> T createProxy2(Class<T> interfaze, Wire wire, Map<Method, InvocationChain> mapping)
+ throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
- return null;
+ throw new UnsupportedOperationException();
}
public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
- return null;
+ throw new UnsupportedOperationException();
}
public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract,
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java Thu Mar 15 00:03:58 2007
@@ -25,6 +25,7 @@
import org.apache.tuscany.spi.model.DataType;
import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
/**
* Contains methods for mapping between an operation in a {@link org.apache.tuscany.spi.model.ServiceContract} and a
@@ -44,6 +45,7 @@
* @param operation the operation to match
* @return the method described by the operation
* @throws NoSuchMethodException if no such method exists
+ * @Deprecated
*/
public static <T> Method findMethod(Class<?> implClass, Operation<T> operation) throws NoSuchMethodException {
String name = operation.getName();
@@ -51,11 +53,29 @@
return implClass.getMethod(name, paramTypes);
}
+ /**
+ * TODO JFM testme
+ */
+ public static Method findMethod2(Class<?> implClass, PhysicalOperationDefinition operation)
+ throws NoSuchMethodException, ClassNotFoundException {
+ String name = operation.getName();
+ List<String> params = operation.getParameters();
+ Class<?>[] types = new Class<?>[params.size()];
+ for (int i = 0; i < params.size(); i++) {
+ types[i] = implClass.getClassLoader().loadClass(params.get(i));
+ }
+ return implClass.getMethod(name, types);
+ }
+
+
+ /**
+ * @Deprecated
+ */
private static <T> Class<?>[] getPhysicalTypes(Operation<T> operation) {
DataType<List<DataType<T>>> inputType = operation.getInputType();
List<DataType<T>> types = inputType.getLogical();
Class<?>[] javaTypes = new Class<?>[types.size()];
- for (int i = 0; i < javaTypes.length ; i++) {
+ for (int i = 0; i < javaTypes.length; i++) {
Type physical = types.get(i).getPhysical();
if (physical instanceof Class<?>) {
javaTypes[i] = (Class<?>) physical;
@@ -72,11 +92,32 @@
* @param method the method to match
* @param operations the operations to match against
* @return a matching operation or null
+ * @Deprecated
*/
public static Operation findOperation(Method method, Collection<Operation<?>> operations) {
for (Operation<?> operation : operations) {
if (match(operation, method)) {
return operation;
+ }
+ }
+ return null;
+ }
+
+ public static PhysicalOperationDefinition findOperation2(Method method,
+ Collection<PhysicalOperationDefinition> operations) {
+ for (PhysicalOperationDefinition operation : operations) {
+ Class<?>[] params = method.getParameterTypes();
+ List<String> types = operation.getParameters();
+ boolean found = true;
+ if (types.size() == params.length && method.getName().equals(operation.getName())) {
+ for (int i = 0; i < params.length; i++) {
+ if (params[i].getName().equals(types.get(0))) {
+ found = false;
+ }
+ }
+ if (found) {
+ return operation;
+ }
}
}
return null;
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java Thu Mar 15 00:03:58 2007
@@ -47,6 +47,8 @@
// Callback
private boolean callback;
+ private int conversationSequence;
+
// Interceptors defined against the operation
private Set<PhysicalInterceptorDefinition> interceptors = new HashSet<PhysicalInterceptorDefinition>();
@@ -141,4 +143,11 @@
}
+ public int getConversationSequence() {
+ return conversationSequence;
+ }
+
+ public void setConversationSequence(int conversationSequence) {
+ this.conversationSequence = conversationSequence;
+ }
}
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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -34,6 +34,7 @@
private URI uri;
private URI callbackUri;
private boolean optimizable;
+ private boolean conversational;
/**
* Gets the URI.
@@ -88,5 +89,13 @@
*/
public void setOptimizable(boolean optimizable) {
this.optimizable = optimizable;
+ }
+
+ public boolean isConversational() {
+ return conversational;
+ }
+
+ public void setConversational(boolean conversational) {
+ this.conversational = conversational;
}
}
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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -24,6 +24,7 @@
import org.apache.tuscany.spi.model.Operation;
import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
/**
* Base class for performing invocations on a wire. Subclasses are responsible for retrieving and supplying the
@@ -32,8 +33,16 @@
* @version $Rev$ $Date$
*/
public abstract class AbstractInvocationHandler {
+ protected boolean conversational;
private boolean conversationStarted;
+ protected AbstractInvocationHandler(boolean conversational) {
+ this.conversational = conversational;
+ }
+
+ public AbstractInvocationHandler() {
+ }
+
/**
* @Deprecated
*/
@@ -94,59 +103,42 @@
}
protected Object invokeTarget(InvocationChain chain,
- TargetInvoker invoker,
- Object[] args,
- Object correlationId,
- LinkedList<Wire> callbackWires)
+ 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();
- 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);
- }
+ assert headInterceptor != null;
+ Message msg = new MessageImpl();
+ if (correlationId != null) {
+ msg.setCorrelationId(correlationId);
+ }
+ if (callbackWires != null) {
+ msg.setCallbackWires(callbackWires);
+ }
+ PhysicalOperationDefinition operation = chain.getPhysicalOperation();
+ if (conversational) {
+ int sequence = operation.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;
}
+ 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;
}
}
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=518500&r1=518499&r2=518500
==============================================================================
--- 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 Thu Mar 15 00:03:58 2007
@@ -40,9 +40,13 @@
* @param interfaze the interface the proxy implements
* @param wire the wire to proxy @return the proxy
* @throws ProxyCreationException
+ * @Deprecated
*/
<T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException;
+ <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException;
+
+
/**
* Creates a Java proxy for the given wire
*
@@ -51,6 +55,7 @@
* @param mapping the method to chain holder mapping to use in creating the proxy. Clients may cache and resuse
* this mapping for performance.
* @throws ProxyCreationException
+ * @Deprecated
*/
<T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
throws ProxyCreationException;
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java?view=diff&rev=518500&r1=518499&r2=518500
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java Thu Mar 15 00:03:58 2007
@@ -75,6 +75,7 @@
* Returns the service contract associated with the the source side of the wire
*
* @return the service contract associated with the wire
+ * @Deprecated
*/
ServiceContract getSourceContract();
@@ -82,6 +83,7 @@
* Sets the contract associated with the source side of the wire
*
* @param contract the contract associated with the wire
+ * @Deprecated
*/
void setSourceContract(ServiceContract contract);
@@ -89,6 +91,7 @@
* Returns the service contract associated with the the target side of the wire
*
* @return the service contract associated with the wire
+ * @Deprecated
*/
ServiceContract getTargetContract();
@@ -96,6 +99,7 @@
* Sets the contract associated with the the target side of the wire
*
* @param contract the contract associated with the wire
+ * @Deprecated
*/
void setTargetContract(ServiceContract contract);
@@ -103,6 +107,7 @@
* Returns true if the wire is optimizable and its invocation chains may be bypassed
*
* @return true if the wire is optimizable and its invocation chains may be bypassed
+ * @Deprecated
*/
boolean isOptimizable();
@@ -117,6 +122,7 @@
* Returns the non-proxied target instance for this wire
*
* @return the non-proxied target instance for this wire
+ * @Deprecated
*/
Object getTargetInstance() throws TargetResolutionException;
@@ -124,6 +130,7 @@
* Sets the target for the wire for optimizations
*
* @param target the target for the wire
+ * @Deprecated
*/
void setTarget(AtomicComponent target);
@@ -139,6 +146,7 @@
*
* @param operation the service operation
* @param chain the invocation chain
+ * @Deprecated
*/
void addInvocationChain(Operation<?> operation, InvocationChain chain);
@@ -147,6 +155,7 @@
*
* @param operation the service operation
* @param chain the invocation chain
+ * @Deprecated
*/
void addInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain);
@@ -156,6 +165,7 @@
* Returns the invocation chains for callback service operations associated with the wire
*
* @return the invocation chains for callback service operations associated with the wire
+ * @Deprecated
*/
Map<Operation<?>, InvocationChain> getCallbackInvocationChains();
@@ -164,6 +174,7 @@
*
* @param operation the service operation
* @param chain the invocation chain
+ * @Deprecated
*/
void addCallbackInvocationChain(Operation<?> operation, InvocationChain chain);
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org