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 2006/08/04 21:16:22 UTC
svn commit: r428847 [2/3] - in /incubator/tuscany/java/sca:
commands/launcher/src/main/resources/META-INF/tuscany/
containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/
containers/container.javascript/src/main/java/org/apache/t...
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/system/wire/SystemOutboundWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/system/wire/SystemOutboundWireImpl.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/system/wire/SystemOutboundWireImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/system/wire/SystemOutboundWireImpl.java Fri Aug 4 12:16:20 2006
@@ -6,6 +6,7 @@
import org.apache.tuscany.spi.QualifiedName;
import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.InboundWire;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
@@ -61,6 +62,22 @@
return new Class[0];
}
+ @SuppressWarnings("unchecked")
+ public void setCallbackInterface(Class<T> interfaze) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class<T> getCallbackInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addCallbackInterface(Class<?> claz) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class[] getImplementedCallbackInterfaces() {
+ throw new UnsupportedOperationException();
+ }
public Map<Method, OutboundInvocationChain> getInvocationChains() {
return Collections.emptyMap();
@@ -71,6 +88,30 @@
}
public void addInvocationChains(Map chains) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Map<Method, InboundInvocationChain> getTargetCallbackInvocationChains() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addTargetCallbackInvocationChains(Map<Method, InboundInvocationChain> chains) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addTargetCallbackInvocationChain(Method method, InboundInvocationChain chain) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Map<Method, OutboundInvocationChain> getSourceCallbackInvocationChains() {
+ return null;
+ }
+
+ public void addSourceCallbackInvocationChains(Map<Method, OutboundInvocationChain> chains) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addSourceCallbackInvocationChain(Method method, OutboundInvocationChain chain) {
throw new UnsupportedOperationException();
}
Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,39 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.WireService;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory implements ObjectFactory {
+
+ private WireService wireService;
+ private Class<?> interfaze;
+
+ public CallbackWireObjectFactory(Class<?> interfaze, WireService wireService) {
+ this.interfaze = interfaze;
+ this.wireService = wireService;
+ }
+
+ public Object getInstance() throws ObjectCreationException {
+ return wireService.createCallbackProxy(interfaze);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/WireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/WireObjectFactory.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/WireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/WireObjectFactory.java Fri Aug 4 12:16:20 2006
@@ -15,7 +15,7 @@
import org.apache.tuscany.spi.ObjectCreationException;
import org.apache.tuscany.spi.ObjectFactory;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.RuntimeWire;
import org.apache.tuscany.spi.wire.WireService;
/**
@@ -25,11 +25,11 @@
*/
public class WireObjectFactory implements ObjectFactory {
- private OutboundWire<?> wire;
+ private RuntimeWire<?> wire;
private WireService wireService;
- public WireObjectFactory(OutboundWire<?> factory, WireService wireService) {
- this.wire = factory;
+ public WireObjectFactory(RuntimeWire<?> wire, WireService wireService) {
+ this.wire = wire;
this.wireService = wireService;
}
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java Fri Aug 4 12:16:20 2006
@@ -21,8 +21,9 @@
private String serviceName;
private Class[] businessInterfaces;
- private Map<Method, InboundInvocationChain> invocationChains = new MethodHashMap<InboundInvocationChain>();
private OutboundWire<T> targetWire;
+ private String callbackReferenceName;
+ private Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
@SuppressWarnings("unchecked")
public T getTargetService() throws TargetException {
@@ -59,23 +60,31 @@
}
public Map<Method, InboundInvocationChain> getInvocationChains() {
- return invocationChains;
+ return chains;
}
public void addInvocationChains(Map<Method, InboundInvocationChain> chains) {
- invocationChains.putAll(chains);
+ this.chains.putAll(chains);
}
public void addInvocationChain(Method method, InboundInvocationChain chain) {
- invocationChains.put(method, chain);
+ chains.put(method, chain);
}
public void setTargetWire(OutboundWire<T> wire) {
targetWire = wire;
}
+ public String getCallbackReferenceName() {
+ return callbackReferenceName;
+ }
+
+ public void setCallbackReferenceName(String callbackReferenceName) {
+ this.callbackReferenceName = callbackReferenceName;
+ }
+
public boolean isOptimizable() {
- for (InboundInvocationChain chain : invocationChains.values()) {
+ for (InboundInvocationChain chain : chains.values()) {
if (chain.getTargetInvoker() != null && !chain.getTargetInvoker().isOptimizable()) {
return false;
}
@@ -103,7 +112,6 @@
}
}
}
-
return true;
}
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java Fri Aug 4 12:16:20 2006
@@ -18,6 +18,7 @@
import org.apache.tuscany.spi.QualifiedName;
import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.InboundWire;
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.MessageHandler;
@@ -34,7 +35,10 @@
public class OutboundWireImpl<T> implements OutboundWire<T> {
private Class<T>[] businessInterfaces;
- private Map<Method, OutboundInvocationChain> invocationChains = new MethodHashMap<OutboundInvocationChain>();
+ private Class<T>[] callbackInterfaces;
+ private Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
+ private Map<Method, InboundInvocationChain> callbackTargetChains = new MethodHashMap<InboundInvocationChain>();
+ private Map<Method, OutboundInvocationChain> callbackSourceChains = new MethodHashMap<OutboundInvocationChain>();
private String referenceName;
private QualifiedName targetName;
private InboundWire<T> targetWire;
@@ -65,20 +69,61 @@
return businessInterfaces;
}
+ @SuppressWarnings("unchecked")
+ public void setCallbackInterface(Class<T> interfaze) {
+ callbackInterfaces = new Class[]{interfaze};
+ }
+
+ public Class<T> getCallbackInterface() {
+ return callbackInterfaces[0];
+ }
+
+ public void addCallbackInterface(Class<?> claz) {
+ throw new UnsupportedOperationException("Additional callback interfaces not yet supported");
+ }
+
+ public Class[] getImplementedCallbackInterfaces() {
+ return callbackInterfaces;
+ }
+
public void setTargetWire(InboundWire<T> wire) {
this.targetWire = wire;
}
public Map<Method, OutboundInvocationChain> getInvocationChains() {
- return invocationChains;
+ return chains;
}
public void addInvocationChains(Map<Method, OutboundInvocationChain> chains) {
- invocationChains.putAll(chains);
+ this.chains.putAll(chains);
}
public void addInvocationChain(Method method, OutboundInvocationChain chain) {
- invocationChains.put(method, chain);
+ chains.put(method, chain);
+ }
+
+ public Map<Method, InboundInvocationChain> getTargetCallbackInvocationChains() {
+ return callbackTargetChains;
+ }
+
+ public void addTargetCallbackInvocationChains(Map<Method, InboundInvocationChain> chains) {
+ callbackTargetChains.putAll(chains);
+ }
+
+ public void addTargetCallbackInvocationChain(Method method, InboundInvocationChain chain) {
+ callbackTargetChains.put(method, chain);
+ }
+
+ public Map<Method, OutboundInvocationChain> getSourceCallbackInvocationChains() {
+ return callbackSourceChains;
+ }
+
+ public void addSourceCallbackInvocationChains(Map<Method, OutboundInvocationChain> chains) {
+ callbackSourceChains.putAll(chains);
+ }
+
+ public void addSourceCallbackInvocationChain(Method method, OutboundInvocationChain chain) {
+ callbackSourceChains.put(method, chain);
}
public String getReferenceName() {
@@ -98,7 +143,7 @@
}
public boolean isOptimizable() {
- for (OutboundInvocationChain chain : invocationChains.values()) {
+ for (OutboundInvocationChain chain : chains.values()) {
if (chain.getHeadInterceptor() != null || !chain.getRequestHandlers().isEmpty()
|| !chain.getResponseHandlers().isEmpty()) {
Interceptor current = chain.getHeadInterceptor();
@@ -124,6 +169,36 @@
}
}
}
+
+ for (InboundInvocationChain chain : callbackTargetChains.values()) {
+ if (chain.getTargetInvoker() != null && !chain.getTargetInvoker().isOptimizable()) {
+ return false;
+ }
+ if (chain.getHeadInterceptor() != null) {
+ Interceptor current = chain.getHeadInterceptor();
+ while (current != null) {
+ if (!current.isOptimizable()) {
+ return false;
+ }
+ current = current.getNext();
+ }
+ }
+ if (chain.getRequestHandlers() != null && !chain.getRequestHandlers().isEmpty()) {
+ for (MessageHandler handler : chain.getRequestHandlers()) {
+ if (!handler.isOptimizable()) {
+ return false;
+ }
+ }
+ }
+ if (chain.getResponseHandlers() != null && !chain.getResponseHandlers().isEmpty()) {
+ for (MessageHandler handler : chain.getResponseHandlers()) {
+ if (!handler.isOptimizable()) {
+ return false;
+ }
+ }
+ }
+ }
+
return true;
}
}
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/PojoTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/PojoTargetInvoker.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/PojoTargetInvoker.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/PojoTargetInvoker.java Fri Aug 4 12:16:20 2006
@@ -5,16 +5,16 @@
import java.util.Set;
import org.apache.tuscany.spi.component.TargetException;
-import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.InvocationRuntimeException;
import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.findClosestMatchingMethod;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllUniquePublicProtectedMethods;
/**
* Base class for dispatching to a Java based component implementation. Subclasses implement a strategy for resolving
- * implementation instances.
+ * implementation instances.
*
* @version $Rev$ $Date$
*/
@@ -32,8 +32,8 @@
try {
Object instance = getInstance();
if (!operation.getDeclaringClass().isInstance(instance)) {
- Set<Method> methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(instance.getClass());
- Method newOperation = JavaIntrospectionHelper.findClosestMatchingMethod(operation.getName(),
+ Set<Method> methods = getAllUniquePublicProtectedMethods(instance.getClass());
+ Method newOperation = findClosestMatchingMethod(operation.getName(),
operation.getParameterTypes(), methods);
if (newOperation != null) {
operation = newOperation;
@@ -59,10 +59,6 @@
msg.setBody(e);
}
return msg;
- }
-
- public void setNext(Interceptor next) {
- throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain");
}
public boolean isCacheable() {
Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,76 @@
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
+
+/**
+ * Base class for performing invocations on an outbound chain. Subclasses are responsible for retrieving and supplying
+ * the appropriate chain, target invoker and invocation arguments.
+ *
+ * @version $Rev: 415032 $ $Date: 2006-06-17 10:28:07 -0700 (Sat, 17 Jun 2006) $
+ */
+public abstract class AbstractJDKOutboundInvocationHandler implements WireInvocationHandler, InvocationHandler {
+
+ public AbstractJDKOutboundInvocationHandler() {
+ }
+
+ protected Object invoke(OutboundInvocationChain chain, TargetInvoker invoker, Object[] args) throws Throwable {
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ Method method = chain.getMethod();
+ if (chain.getTargetRequestChannel() == null && chain.getTargetResponseChannel() == null
+ && headInterceptor == null) {
+ try {
+ // short-circuit the dispatch and invoke the target directly
+ if (chain.getTargetInvoker() == null) {
+ throw new AssertionError("No target invoker [" + method.getName() + "]");
+ }
+ return chain.getTargetInvoker().invokeTarget(args);
+ } catch (InvocationTargetException e) {
+ // the cause was thrown by the target so throw it
+ throw e.getCause();
+ }
+ } else {
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ msg.setBody(args);
+ // dispatch the wire down the chain and get the response
+ if (chain.getTargetRequestChannel() != null) {
+ chain.getTargetRequestChannel().send(msg);
+ Object body = msg.getRelatedCallbackMessage().getBody();
+ if (body instanceof Throwable) {
+ throw (Throwable) body;
+ }
+ return body;
+
+ } else if (headInterceptor == null) {
+ throw new AssertionError("No target interceptor configured [" + method.getName() + "]");
+
+ } else {
+ Message resp = headInterceptor.invoke(msg);
+ if (chain.getTargetResponseChannel() != null) {
+ chain.getTargetResponseChannel().send(resp);
+ resp = resp.getRelatedCallbackMessage();
+ }
+ Object body = resp.getBody();
+ if (body instanceof Throwable) {
+ throw (Throwable) body;
+ }
+ return body;
+ }
+ }
+ }
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,50 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Responsible for invoking on an outbound wire associated with a callback. The handler retrieves the correct outbound
+ * callback wire from the work context.
+ *
+ * TODO cache target invoker
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandler extends AbstractJDKOutboundInvocationHandler {
+
+ private WorkContext context;
+
+ public JDKCallbackInvocationHandler(WorkContext context) {
+ this.context = context;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ OutboundWire<?> wire = context.getCurrentInvocationWire();
+ context.setCurrentInvocationWire(null);
+ OutboundInvocationChain chain = wire.getSourceCallbackInvocationChains().get(method);
+ TargetInvoker invoker = chain.getTargetInvoker();
+ return invoke(chain, invoker, args);
+ }
+
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java Fri Aug 4 12:16:20 2006
@@ -16,19 +16,14 @@
*/
package org.apache.tuscany.core.wire.jdk;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.spi.component.TargetException;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.MessageImpl;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* Receives a request from a proxy and performs an invocation on an {@link org.apache.tuscany.spi.wire.OutboundWire} via
@@ -36,7 +31,7 @@
*
* @version $Rev$ $Date$
*/
-public class JDKOutboundInvocationHandler implements WireInvocationHandler, InvocationHandler {
+public class JDKOutboundInvocationHandler extends AbstractJDKOutboundInvocationHandler {
/*
* an association of an operation to chain holder. The holder contains an invocation chain
@@ -47,7 +42,8 @@
*/
private Map<Method, ChainHolder> chains;
- public JDKOutboundInvocationHandler(Map<Method, OutboundInvocationChain> invocationChains) {
+ public JDKOutboundInvocationHandler(OutboundWire<?> wire) {
+ Map<Method, OutboundInvocationChain> invocationChains = wire.getInvocationChains();
this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
for (Map.Entry<Method, OutboundInvocationChain> entry : invocationChains.entrySet()) {
this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
@@ -55,7 +51,6 @@
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- Interceptor headInterceptor = null;
ChainHolder holder = chains.get(method);
if (holder == null) {
TargetException e = new TargetException("Operation not configured");
@@ -63,10 +58,6 @@
throw e;
}
OutboundInvocationChain chain = holder.chain;
- if (chain != null) {
- headInterceptor = chain.getHeadInterceptor();
- }
-
TargetInvoker invoker;
if (holder.cachedInvoker == null) {
@@ -87,51 +78,7 @@
assert chain != null;
invoker = chain.getTargetInvoker();
}
- if (chain.getTargetRequestChannel() == null && chain.getTargetResponseChannel() == null
- && headInterceptor == null) {
- try {
- // short-circuit the dispatch and invoke the target directly
- if (chain.getTargetInvoker() == null) {
- throw new AssertionError("No target invoker [" + method.getName() + "]");
- }
- return chain.getTargetInvoker().invokeTarget(args);
- } catch (InvocationTargetException e) {
- // the cause was thrown by the target so throw it
- throw e.getCause();
- }
- } else {
- Message msg = new MessageImpl();
- msg.setTargetInvoker(invoker);
- msg.setBody(args);
- // dispatch the wire down the chain and get the response
- if (chain.getTargetRequestChannel() != null) {
- chain.getTargetRequestChannel().send(msg);
- Object body = msg.getRelatedCallbackMessage().getBody();
- if (body instanceof Throwable) {
- throw (Throwable) body;
- }
- return body;
-
- } else if (headInterceptor == null) {
- throw new AssertionError("No target interceptor configured [" + method.getName() + "]");
-
- } else {
- Message resp = headInterceptor.invoke(msg);
- if (chain.getTargetResponseChannel() != null) {
- chain.getTargetResponseChannel().send(resp);
- resp = resp.getRelatedCallbackMessage();
- }
- Object body = resp.getBody();
- if (body instanceof Throwable) {
- throw (Throwable) body;
- }
- return body;
- }
- }
- }
-
- public Object invoke(Method method, Object[] args) throws Throwable {
- return invoke(null, method, args);
+ return invoke(chain, invoker, args);
}
/**
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java Fri Aug 4 12:16:20 2006
@@ -2,10 +2,12 @@
import java.lang.reflect.Proxy;
+import org.osoa.sca.annotations.Constructor;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
import org.apache.tuscany.spi.wire.InboundWire;
import org.apache.tuscany.spi.wire.OutboundWire;
@@ -20,17 +22,15 @@
@Scope("MODULE")
public class JDKWireService implements WireService {
+ private WorkContext context;
//private PolicyBuilderRegistry policyRegistry;
public JDKWireService() {
}
- public JDKWireService(PolicyBuilderRegistry policyRegistry) {
- //this.policyRegistry = policyRegistry;
- }
-
- @Autowire
- public void setPolicyRegistry(PolicyBuilderRegistry policyRegistry) {
+ @Constructor({"workContext", "policyregisty"})
+ public JDKWireService(@Autowire WorkContext context, @Autowire PolicyBuilderRegistry policyRegistry) {
+ this.context = context;
//this.policyRegistry = policyRegistry;
}
@@ -48,9 +48,9 @@
ClassLoader cl = interfaze.getClassLoader();
return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
} else if (wire instanceof OutboundWire) {
- OutboundWire<T> inbound = (OutboundWire<T>) wire;
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(inbound.getInvocationChains());
- Class<T> interfaze = inbound.getBusinessInterface();
+ OutboundWire<T> outbound = (OutboundWire<T>) wire;
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(outbound);
+ Class<T> interfaze = outbound.getBusinessInterface();
ClassLoader cl = interfaze.getClassLoader();
return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
} else {
@@ -60,14 +60,20 @@
}
}
+ public <T> T createCallbackProxy(Class<T> interfaze) throws ProxyCreationException {
+ ClassLoader cl = interfaze.getClassLoader();
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(context);
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
public WireInvocationHandler createHandler(RuntimeWire<?> wire) {
assert wire != null : "WireDefinition was null";
if (wire instanceof InboundWire) {
InboundWire<?> inbound = (InboundWire) wire;
return new JDKInboundInvocationHandler(inbound.getInvocationChains());
} else if (wire instanceof OutboundWire) {
- OutboundWire<?> inbound = (OutboundWire) wire;
- return new JDKOutboundInvocationHandler(inbound.getInvocationChains());
+ OutboundWire<?> outbound = (OutboundWire) wire;
+ return new JDKOutboundInvocationHandler(outbound);
} else {
ProxyCreationException e = new ProxyCreationException("Invalid wire type");
e.setIdentifier(wire.getClass().getName());
@@ -75,43 +81,9 @@
}
}
- /*
- public OutboundWire createReferenceWire(ReferenceDefinition reference) throws BuilderConfigException {
- String name = reference.getName();
- Class interfaze = reference.getServiceContract().getInterfaceClass();
- OutboundWire<?> wire = new OutboundWireImpl();
- wire.setBusinessInterface(interfaze);
- wire.setReferenceName(name);
-
- Set<Method> javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(interfaze);
- for (Method method : javaMethods) {
- OutboundInvocationChain chain = new OutboundInvocationChainImpl(method);
- wire.addInvocationChain(method, chain);
- }
- if (policyRegistry != null) {
- // invoke policy builders
- policyRegistry.buildSource(reference, wire);
- }
- return wire;
+ public WireInvocationHandler createCallbackHandler() {
+ return new JDKCallbackInvocationHandler(context);
}
- public InboundWire createServiceWire(ServiceDefinition service) {
- String name = service.getName();
- Class interfaze = service.getServiceContract().getInterfaceClass();
- InboundWire<?> wire = new InboundWireImpl();
- wire.setBusinessInterface(interfaze);
- wire.setServiceName(name);
-
- Set<Method> javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(interfaze);
- for (Method method : javaMethods) {
- InboundInvocationChain chain = new InboundInvocationChainImpl(method);
- wire.addInvocationChain(method, chain);
- }
- if (policyRegistry != null) {
- // invoke policy builders
- policyRegistry.buildTarget(service, wire);
- }
- return wire;
- }
- */
+
}
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/AsyncJavaTargetInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/AsyncJavaTargetInvokerTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/AsyncJavaTargetInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/AsyncJavaTargetInvokerTestCase.java Fri Aug 4 12:16:20 2006
@@ -15,9 +15,11 @@
import java.lang.reflect.Method;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.services.work.WorkScheduler;
import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundWire;
import junit.framework.TestCase;
import static org.apache.tuscany.core.implementation.java.mock.MockFactory.createJavaComponent;
@@ -37,7 +39,7 @@
public class AsyncJavaTargetInvokerTestCase extends TestCase {
public void testInvoke() throws Exception {
- AsyncTarget target = createMock(AsyncTarget.class);
+ AsyncTarget target = createMock(AsyncTarget.class);
target.invoke();
expectLastCall().once();
replay(target);
@@ -55,9 +57,11 @@
}
});
replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
Method method = AsyncTarget.class.getMethod("invoke");
method.setAccessible(true);
- AsyncJavaTargetInvoker invoker = new AsyncJavaTargetInvoker(method, component, scheduler, monitor);
+ AsyncJavaTargetInvoker invoker =
+ new AsyncJavaTargetInvoker(method, null, component, scheduler, monitor, context);
Message msg = new MessageImpl();
invoker.invoke(msg);
verify(target);
@@ -81,9 +85,15 @@
}
});
replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
+ context.setCurrentInvocationWire(isA(OutboundWire.class));
+ expectLastCall().once();
+ replay(context);
+ OutboundWire wire = createMock(OutboundWire.class);
Method method = AsyncTarget.class.getMethod("invoke");
method.setAccessible(true);
- AsyncJavaTargetInvoker invoker = new AsyncJavaTargetInvoker(method, component, scheduler, monitor);
+ AsyncJavaTargetInvoker invoker =
+ new AsyncJavaTargetInvoker(method, wire, component, scheduler, monitor, context);
AsyncJavaTargetInvoker clone = invoker.clone();
Message msg = new MessageImpl();
clone.invoke(msg);
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java Fri Aug 4 12:16:20 2006
@@ -36,6 +36,7 @@
mock.stubs().method("getBusinessInterface").will(returnValue(Target.class));
mock.stubs().method("getServiceName").will(returnValue("Target"));
mock.expects(atLeastOnce()).method("getInvocationChains").will(returnValue(Collections.emptyMap()));
+ mock.stubs().method("getCallbackReferenceName").will(returnValue(null));
InboundWire<Target> wire = (InboundWire<Target>) mock.proxy();
component.addInboundWire(wire);
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderTestCase.java Fri Aug 4 12:16:20 2006
@@ -15,6 +15,7 @@
import org.apache.tuscany.core.deployer.RootDeploymentContext;
import org.apache.tuscany.core.implementation.ConstructorDefinition;
import org.apache.tuscany.core.implementation.JavaMappedReference;
+import org.apache.tuscany.core.implementation.JavaMappedService;
import org.apache.tuscany.core.implementation.JavaServiceContract;
import org.apache.tuscany.core.implementation.PojoComponentType;
import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
@@ -45,7 +46,7 @@
ServiceContract sourceContract = new JavaServiceContract();
sourceContract.setInterfaceClass(Source.class);
- ServiceDefinition sourceServiceDefinition = new ServiceDefinition();
+ ServiceDefinition sourceServiceDefinition = new JavaMappedService();
sourceServiceDefinition.setName("Source");
sourceServiceDefinition.setServiceContract(sourceContract);
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,234 @@
+package org.apache.tuscany.core.implementation.java.integration.component;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.osoa.sca.annotations.Callback;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.ModuleScopeContainer;
+import org.apache.tuscany.core.implementation.ConstructorDefinition;
+import org.apache.tuscany.core.implementation.JavaMappedCallback;
+import org.apache.tuscany.core.implementation.JavaMappedProperty;
+import org.apache.tuscany.core.implementation.JavaMappedReference;
+import org.apache.tuscany.core.implementation.JavaMappedService;
+import org.apache.tuscany.core.implementation.JavaServiceContract;
+import org.apache.tuscany.core.implementation.PojoComponentType;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.implementation.java.JavaComponentBuilder;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.wire.jdk.JDKWireService;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+/**
+ * Verifies callback integration scenarios.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackInvocationTestCase extends TestCase {
+
+ private ScopeContainer container;
+ private DeploymentContext context;
+ private JavaComponentBuilder builder;
+
+ /**
+ * Verifies callback wires are built and callback invocations are handled properly
+ */
+ public void testComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent<Foo> fooComponent =
+ (JavaAtomicComponent<Foo>) builder.build(null, targetDefinition, context);
+ container.register(fooComponent);
+
+ CompositeComponent parent = createMock(CompositeComponent.class);
+ parent.getChild(isA(String.class));
+ expectLastCall().andReturn(fooComponent).anyTimes();
+ replay(parent);
+
+ ComponentDefinition<JavaImplementation> sourceDefinition = createSource("fooClient");
+ JavaAtomicComponent<FooClient> clientComponent =
+ (JavaAtomicComponent<FooClient>) builder.build(parent, sourceDefinition, context);
+ container.register(clientComponent);
+
+ Connector connector = new ConnectorImpl();
+ connector.connect(clientComponent);
+ FooClient client = clientComponent.getServiceInstance();
+ client.invoke();
+ assertTrue(client.invoked);
+ }
+
+ /**
+ * Verifies a callback in response to an invocation from two different client components is routed back to the
+ * appropriate client.
+ */
+ public void testTwoSourceComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent<Foo> fooComponent =
+ (JavaAtomicComponent<Foo>) builder.build(null, targetDefinition, context);
+ container.register(fooComponent);
+
+ CompositeComponent parent = createMock(CompositeComponent.class);
+ parent.getChild(isA(String.class));
+ expectLastCall().andReturn(fooComponent).anyTimes();
+ replay(parent);
+
+ ComponentDefinition<JavaImplementation> sourceDefinition1 = createSource("fooCleint1");
+ ComponentDefinition<JavaImplementation> sourceDefinition2 = createSource("fooCleint2");
+ JavaAtomicComponent<FooClient> clientComponent1 =
+ (JavaAtomicComponent<FooClient>) builder.build(parent, sourceDefinition1, context);
+ container.register(clientComponent1);
+ JavaAtomicComponent<FooClient> clientComponent2 =
+ (JavaAtomicComponent<FooClient>) builder.build(parent, sourceDefinition2, context);
+ container.register(clientComponent2);
+
+ Connector connector = new ConnectorImpl();
+ connector.connect(clientComponent1);
+ connector.connect(clientComponent2);
+ FooClient client1 = clientComponent1.getServiceInstance();
+ client1.invoke();
+ assertTrue(client1.invoked);
+ FooClient client2 = clientComponent2.getServiceInstance();
+ client2.invoke();
+ assertTrue(client2.invoked);
+ }
+
+
+ private ComponentDefinition<JavaImplementation> createTarget() throws NoSuchMethodException {
+ ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.MODULE);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ JavaServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedService mappedService = new JavaMappedService("Foo", contract, false);
+ JavaMappedCallback mappedCallback = new JavaMappedCallback("callback", method, FooCallback.class);
+ mappedService.setCallbackReference(mappedCallback);
+ type.getServices().put("Foo", mappedService);
+
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooImpl.class);
+ return new ComponentDefinition<JavaImplementation>("foo", impl);
+ }
+
+ private ComponentDefinition<JavaImplementation> createSource(String name)
+ throws NoSuchMethodException, URISyntaxException {
+ ConstructorDefinition<FooClient> ctorDef =
+ new ConstructorDefinition<FooClient>(FooClient.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.MODULE);
+ Method method = FooClient.class.getMethod("setFoo", Foo.class);
+ JavaServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedReference mappedReference = new JavaMappedReference("foo", contract, method);
+ type.getReferences().put("foo", mappedReference);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName("foo");
+ refTarget.getTargets().add(new URI("foo"));
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooClient.class);
+ ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl);
+ def.getReferenceTargets().put("foo", refTarget);
+ return def;
+ }
+
+ @Callback(FooCallback.class)
+ public static interface Foo {
+ void call();
+ }
+
+ public static class FooImpl implements Foo {
+ private FooCallback callback;
+
+ public FooImpl() {
+ }
+
+ @Callback
+ public void setCallback(FooCallback callback) {
+ this.callback = callback;
+ }
+
+ public void call() {
+ callback.callback();
+ }
+ }
+
+ public static class FooClient implements FooCallback {
+
+ private Foo foo;
+ private boolean invoked;
+
+ public FooClient() {
+ }
+
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ public void callback() {
+ if (invoked) {
+ fail();
+ }
+ invoked = true;
+ }
+
+ public void invoke() {
+ foo.call();
+ }
+ }
+
+ public interface FooCallback {
+ void callback();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ container = new ModuleScopeContainer();
+ container.start();
+ context = createMock(DeploymentContext.class);
+ context.getModuleScope();
+ expectLastCall().andReturn(container).anyTimes();
+ replay(context);
+
+ WorkScheduler scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+
+ builder = new JavaComponentBuilder();
+ WorkContextImpl workContext = new WorkContextImpl();
+ builder.setWorkContext(workContext);
+ builder.setWireService(new JDKWireService(workContext, null));
+ builder.setWorkScheduler(scheduler);
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/CallbackInvocationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OneWayWireInvocationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OneWayWireInvocationTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OneWayWireInvocationTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OneWayWireInvocationTestCase.java Fri Aug 4 12:16:20 2006
@@ -15,6 +15,7 @@
import java.lang.reflect.Method;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.services.work.WorkScheduler;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.InboundWire;
@@ -46,7 +47,7 @@
WireService wireService = new JDKWireService();
public void testNoInterceptors() throws Exception {
- AsyncTarget target = createMock(AsyncTarget.class);
+ AsyncTarget target = createMock(AsyncTarget.class);
target.invoke();
expectLastCall().once();
replay(target);
@@ -61,9 +62,10 @@
}
});
replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
Method method = AsyncTarget.class.getMethod("invoke");
method.setAccessible(true);
- AsyncJavaTargetInvoker invoker = new AsyncJavaTargetInvoker(method, component, scheduler, null);
+ AsyncJavaTargetInvoker invoker = new AsyncJavaTargetInvoker(method, null, component, scheduler, null, context);
InboundWire<AsyncTarget> wire =
createServiceWire("foo", AsyncTarget.class, null, null, null);
InboundInvocationChain chain = wire.getInvocationChains().get(method);
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OutboundWireToJavaTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OutboundWireToJavaTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OutboundWireToJavaTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/component/OutboundWireToJavaTestCase.java Fri Aug 4 12:16:20 2006
@@ -162,7 +162,7 @@
JavaAtomicComponent<?> atomicComponent = new JavaAtomicComponent("target", configuration, null, null);
InboundWire targetWire = MockFactory.createTargetWire("Target", Target.class);
atomicComponent.addInboundWire(targetWire);
- connector.connect(wire, atomicComponent.getInboundWire("Target"), atomicComponent, false);
+ connector.connect(wire, atomicComponent.getInboundWire("Target"), atomicComponent, atomicComponent, false);
atomicComponent.start();
return wire;
}
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ProcessorUtilsServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ProcessorUtilsServiceTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ProcessorUtilsServiceTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ProcessorUtilsServiceTestCase.java Fri Aug 4 12:16:20 2006
@@ -28,7 +28,7 @@
*/
public class ProcessorUtilsServiceTestCase extends TestCase {
- public void testCreateConversationalService() {
+ public void testCreateConversationalService() throws Exception {
JavaMappedService service = ProcessorUtils.createService(Foo.class);
assertTrue(Foo.class.equals(service.getServiceContract().getInterfaceClass()));
assertTrue(service.isRemotable());
@@ -38,7 +38,7 @@
assertTrue("ProcessorUtilsServiceTestCase$Bar".equals(serviceContract.getCallbackName()));
}
- public void testCreateDefaultService() {
+ public void testCreateDefaultService() throws Exception {
JavaMappedService service = ProcessorUtils.createService(Baz.class);
assertTrue(Baz.class.equals(service.getServiceContract().getInterfaceClass()));
assertTrue(!service.isRemotable());
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,158 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.JavaMappedCallback;
+import org.apache.tuscany.core.implementation.JavaMappedProperty;
+import org.apache.tuscany.core.implementation.JavaMappedReference;
+import org.apache.tuscany.core.implementation.JavaMappedService;
+import org.apache.tuscany.core.implementation.PojoComponentType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+
+ ServiceProcessor processor = new ServiceProcessor();
+
+ public void testMethodCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(null, FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get("ServiceCallbackTestCase$Foo");
+ assertNotNull(service);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ processor.visitMethod(null, method, type, null);
+ JavaMappedCallback callback = service.getCallbackReference();
+ assertEquals(FooCallback.class, callback.getCallbackInterface());
+ }
+
+ public void testFieldCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(null, FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get("ServiceCallbackTestCase$Foo");
+ assertNotNull(service);
+ Field field = FooImpl.class.getDeclaredField("callback");
+ processor.visitField(null, field, type, null);
+ JavaMappedCallback callback = service.getCallbackReference();
+ assertEquals(FooCallback.class, callback.getCallbackInterface());
+ }
+
+ public void testMethodDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(null, BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class);
+ try {
+ processor.visitMethod(null, method, type, null);
+ fail();
+ } catch (IllegalCallbackException e) {
+ // expected
+ }
+ }
+
+ public void testNoParamCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(null, BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setNoParamCallback");
+ try {
+ processor.visitMethod(null, method, type, null);
+ fail();
+ } catch (IllegalCallbackException e) {
+ // expected
+ }
+ }
+
+ public void testFieldDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(null, BadBarImpl.class, type, null);
+ Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback");
+ try {
+ processor.visitField(null, field, type, null);
+ fail();
+ } catch (IllegalCallbackException e) {
+ // expected
+ }
+ }
+
+ public void testBadCallbackInterfaceAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(null, BadFooImpl.class, type, null);
+ fail();
+ } catch (IllegalCallbackException e) {
+ // expected
+ }
+ }
+
+ @Callback(FooCallback.class)
+ private interface Foo {
+
+ }
+
+ private interface FooCallback {
+
+ }
+
+ @Service(Foo.class)
+ private static class FooImpl implements Foo {
+
+ @Callback
+ protected FooCallback callback;
+
+ @Callback
+ public void setCallback(FooCallback cb) {
+
+ }
+ }
+
+ private static class BadBarImpl implements Foo {
+ @Callback
+ protected String wrongInterfaceCallback;
+
+ @Callback
+ public void setWrongInterfaceCallback(String cb) {
+
+ }
+
+ @Callback
+ public void setNoParamCallback() {
+
+ }
+
+ }
+
+ @Callback
+ private interface BadFoo {
+
+ }
+
+ @Service(BadFoo.class)
+ private static class BadFooImpl implements BadFoo {
+
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,42 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.WireService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactoryTestCase extends TestCase {
+
+ public void testCreateInstance() throws Exception {
+ WireService service = createMock(WireService.class);
+ service.createCallbackProxy(Foo.class);
+ expectLastCall().andReturn(null);
+ replay(service);
+ CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ }
+
+ private interface Foo {
+
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java?rev=428847&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java Fri Aug 4 12:16:20 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.RuntimeWire;
+import org.apache.tuscany.spi.wire.WireService;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactoryTestCase extends TestCase {
+
+ public void testCreateInstance() throws Exception {
+ RuntimeWire<?> wire = createMock(RuntimeWire.class);
+ WireService service = createMock(WireService.class);
+ service.createProxy(wire);
+ expectLastCall().andReturn(null);
+ replay(service);
+ WireObjectFactory factory = new WireObjectFactory(wire, service);
+ factory.getInstance();
+ verify(service);
+ }
+}
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/injection/WireObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderWireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderWireTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderWireTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderWireTestCase.java Fri Aug 4 12:16:20 2006
@@ -1,7 +1,17 @@
package org.apache.tuscany.core.integration.implementation.system.builder;
-import junit.framework.TestCase;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BoundReferenceDefinition;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import junit.framework.TestCase;
import org.apache.tuscany.core.builder.ConnectorImpl;
import org.apache.tuscany.core.component.WorkContextImpl;
import org.apache.tuscany.core.component.event.CompositeStart;
@@ -17,16 +27,6 @@
import org.apache.tuscany.core.mock.component.Source;
import org.apache.tuscany.core.mock.component.Target;
import org.apache.tuscany.core.mock.factories.MockComponentFactory;
-import org.apache.tuscany.spi.builder.Connector;
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.Reference;
-import org.apache.tuscany.spi.component.ScopeContainer;
-import org.apache.tuscany.spi.component.Service;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.model.BoundReferenceDefinition;
-import org.apache.tuscany.spi.model.BoundServiceDefinition;
-import org.apache.tuscany.spi.model.ComponentDefinition;
/**
* Validates that system builders and the default connector create properly wired contexts
@@ -146,7 +146,8 @@
connector.connect(sourceComponent);
String serviceName = service.getOutboundWire().getTargetName().getPortName();
- connector.connect(service.getOutboundWire(), sourceComponent.getInboundWire(serviceName), parent, true);
+ connector.connect(service.getOutboundWire(), sourceComponent.getInboundWire(serviceName), sourceComponent,
+ parent, true);
parent.start();
scope.onEvent(new CompositeStart(this, parent));
Target target = (Target) parent.getChild("serviceDefinition").getServiceInstance();
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockHandler.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockHandler.java Fri Aug 4 12:16:20 2006
@@ -14,7 +14,6 @@
private int count;
public boolean processMessage(Message message) {
- //System.out.println("Invoking handler");
count++;
return true;
}
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java Fri Aug 4 12:16:20 2006
@@ -30,7 +30,6 @@
public Message invoke(Message msg) {
++count;
- //System.out.println("Invoking interceptor");
return next.invoke(msg);
}
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java Fri Aug 4 12:16:20 2006
@@ -1,16 +1,15 @@
package org.apache.tuscany.core.wire;
import java.lang.reflect.Method;
-import java.util.Map;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
import org.apache.tuscany.core.mock.component.SimpleTarget;
import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
import org.apache.tuscany.core.mock.wire.MockHandler;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
-import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler;
import org.jmock.MockObjectTestCase;
@@ -22,7 +21,7 @@
private Method echo;
public void testHandlersInterceptorInvoke() throws Throwable {
- Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
+ //Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
OutboundInvocationChain chain = new OutboundInvocationChainImpl(echo);
MockSyncInterceptor interceptor = new MockSyncInterceptor();
@@ -34,8 +33,10 @@
chain.addResponseHandler(responseHandler);
chain.setTargetInvoker(invoker);
chain.prepare();
- chains.put(echo, chain);
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(chains);
+ //chains.put(echo, chain);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(echo, chain);
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
assertEquals(1, interceptor.getCount());
assertEquals(1, requestHandler.getCount());
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java Fri Aug 4 12:16:20 2006
@@ -18,15 +18,14 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.Map;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
import junit.framework.TestCase;
import org.apache.tuscany.core.mock.wire.MockHandler;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
-import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler;
/**
@@ -55,9 +54,9 @@
}
public void testCheckedException() throws Exception {
- Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
- chains.put(checkedMethod, createChain(checkedMethod));
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(chains);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(checkedMethod, createChain(checkedMethod));
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
try {
TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
@@ -69,9 +68,9 @@
}
public void testRuntimeException() throws Exception {
- Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
- chains.put(runtimeMethod, createChain(runtimeMethod));
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(chains);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(runtimeMethod, createChain(runtimeMethod));
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
try {
TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java Fri Aug 4 12:16:20 2006
@@ -1,10 +1,10 @@
package org.apache.tuscany.core.wire;
import java.lang.reflect.Method;
-import java.util.Map;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
import junit.framework.TestCase;
import org.apache.tuscany.core.mock.component.SimpleTarget;
@@ -12,7 +12,6 @@
import org.apache.tuscany.core.mock.wire.MockHandler;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
-import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler;
public class OutboundInvocationHandlerTestCase extends TestCase {
@@ -32,16 +31,16 @@
}
public void testBasicInvoke() throws Throwable {
- Map<Method, OutboundInvocationChain> configs = new MethodHashMap<OutboundInvocationChain>();
- configs.put(hello, createChain(hello));
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(configs);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(hello, createChain(hello));
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
}
public void testErrorInvoke() throws Throwable {
- Map<Method, OutboundInvocationChain> configs = new MethodHashMap<OutboundInvocationChain>();
- configs.put(hello, createChain(hello));
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(configs);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(hello, createChain(hello));
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
try {
handler.invoke(hello, new Object[]{});
fail("Expected " + IllegalArgumentException.class.getName());
@@ -55,9 +54,9 @@
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
- Map<Method, OutboundInvocationChain> configs = new MethodHashMap<OutboundInvocationChain>();
- configs.put(hello, source);
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(configs);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(hello, source);
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
try {
assertEquals("foo", handler.invoke(hello, new Object[]{}));
fail("Expected " + IllegalArgumentException.class.getName());
@@ -71,9 +70,9 @@
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
- Map<Method, OutboundInvocationChain> configs = new MethodHashMap<OutboundInvocationChain>();
- configs.put(hello, source);
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(configs);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.addInvocationChain(hello, source);
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire);
assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
}
Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java (original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java Fri Aug 4 12:16:20 2006
@@ -1,5 +1,6 @@
package org.apache.tuscany.spi.builder;
+import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.component.SCAObject;
import org.apache.tuscany.spi.model.Scope;
@@ -18,9 +19,16 @@
<T> void connect(InboundWire<T> inboundWire, OutboundWire<T> outboundWire, boolean optimizable)
throws BuilderConfigException;
- <T> void connect(OutboundWire<T> outboundWire, CompositeComponent<?> parent, Scope sourceScope)
+ <T> void connect(AtomicComponent<?> source,
+ OutboundWire<T> outboundWire,
+ CompositeComponent<?> parent,
+ Scope sourceScope)
throws BuilderConfigException;
- <T> void connect(OutboundWire<T> sourceWire, InboundWire<T> targetWire, SCAObject<?> context, boolean optimizable);
+ <T> void connect(OutboundWire<T> sourceWire,
+ InboundWire<T> targetWire,
+ AtomicComponent<?> source,
+ SCAObject<?> target,
+ boolean optimizable);
}
Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/Component.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/Component.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/Component.java (original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/Component.java Fri Aug 4 12:16:20 2006
@@ -64,4 +64,13 @@
*/
TargetInvoker createTargetInvoker(String serviceName, Method operation);
+ /**
+ * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service offered by
+ * the component
+ *
+ * @param serviceName the name of the service
+ * @param operation the operation to invoke
+ */
+ TargetInvoker createAsyncTargetInvoker(String serviceName, Method operation, OutboundWire wire);
+
}
Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java?rev=428847&r1=428846&r2=428847&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java (original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java Fri Aug 4 12:16:20 2006
@@ -1,5 +1,7 @@
package org.apache.tuscany.spi.component;
+import org.apache.tuscany.spi.wire.OutboundWire;
+
/**
* Implementations track information associated with a request as it is processed by the runtime
*
@@ -7,6 +9,10 @@
*/
public interface WorkContext {
+ OutboundWire getCurrentInvocationWire();
+
+ void setCurrentInvocationWire(OutboundWire wire);
+
/**
* Returns the composite where a remote request came in
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org