You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2006/09/14 17:06:54 UTC
svn commit: r443379 - in /incubator/tuscany/java/sca/kernel/core/src:
main/java/org/apache/tuscany/core/builder/
main/java/org/apache/tuscany/core/wire/
main/java/org/apache/tuscany/core/wire/jdk/
test/java/org/apache/tuscany/core/wire/ test/java/org/a...
Author: antelder
Date: Thu Sep 14 08:06:53 2006
New Revision: 443379
URL: http://svn.apache.org/viewvc?view=rev&rev=443379
Log:
TUSCANY-721, Apply patch from Ignacio for binding async support
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java Thu Sep 14 08:06:53 2006
@@ -184,13 +184,14 @@
throw e;
}
TargetInvoker invoker = null;
+ boolean isOneWayOperation = operation.isNonBlocking();
+ boolean operationHasCallback = contract.getCallbackName() != null;
+ if (isOneWayOperation && operationHasCallback) {
+ throw new ComponentRuntimeException("Operation cannot be marked one-way and have a callback");
+ }
+
if (target instanceof Component) {
Component component = (Component) target;
- boolean isOneWayOperation = operation.isNonBlocking();
- boolean operationHasCallback = contract.getCallbackName() != null;
- if (isOneWayOperation && operationHasCallback) {
- throw new ComponentRuntimeException("Operation cannot be marked one-way and have a callback");
- }
if (isOneWayOperation || operationHasCallback) {
invoker = component.createAsyncTargetInvoker(targetWire, operation);
} else {
@@ -199,7 +200,12 @@
}
} else if (target instanceof Reference) {
Reference reference = (Reference) target;
- invoker = reference.createTargetInvoker(targetWire.getServiceContract(), inboundChain.getOperation());
+ if (!(reference instanceof CompositeReference) && operationHasCallback) {
+ // Notice that for bound references we only use async target invokers for callback operations
+ invoker = reference.createAsyncTargetInvoker(sourceWire, operation);
+ } else {
+ invoker = reference.createTargetInvoker(targetWire.getServiceContract(), inboundChain.getOperation());
+ }
} else if (target instanceof CompositeService) {
CompositeService compServ = (CompositeService) target;
invoker = compServ.createTargetInvoker(targetWire.getServiceContract(), inboundChain.getOperation());
@@ -238,10 +244,10 @@
CompositeReference compRef = (CompositeReference) source;
TargetInvoker invoker = compRef.createCallbackTargetInvoker(sourceWire.getServiceContract(), operation);
connect(outboundChain, inboundChain, invoker);
- } else if (source instanceof CompositeService) {
- CompositeService compServ = (CompositeService) source;
+ } else if (source instanceof Service) {
+ Service service = (Service) source;
ServiceContract sourceContract = sourceWire.getServiceContract();
- TargetInvoker invoker = compServ.createCallbackTargetInvoker(sourceContract, operation);
+ TargetInvoker invoker = service.createCallbackTargetInvoker(sourceContract, operation);
connect(outboundChain, inboundChain, invoker);
} else if (target instanceof Service) {
throw new UnsupportedOperationException();
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java Thu Sep 14 08:06:53 2006
@@ -23,6 +23,7 @@
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageId;
import org.apache.tuscany.spi.wire.MessageImpl;
import org.apache.tuscany.spi.wire.TargetInvoker;
@@ -52,6 +53,13 @@
} else {
Message msg = new MessageImpl();
msg.setTargetInvoker(invoker);
+ Object messageId = getMessageId();
+ if (messageId == null) {
+ messageId = new MessageId();
+ }
+ msg.setMessageId(messageId);
+ Object corrId = getCorrelationId();
+ msg.setCorrelationId(corrId);
msg.setBody(args);
Message resp;
// dispatch the wire down the chain and get the response
@@ -64,5 +72,7 @@
}
}
+ protected abstract Object getMessageId();
+ protected abstract Object getCorrelationId();
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java Thu Sep 14 08:06:53 2006
@@ -24,6 +24,7 @@
import java.util.Map;
import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.TargetInvoker;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
@@ -47,12 +48,16 @@
* is not cacheable, the master associated with the wire chains will be used.
*/
private Map<Method, ChainHolder> chains;
+ private WorkContext context;
+ private Object messageId;
+ private Object correlationId;
- public JDKInboundInvocationHandler(Map<Method, InboundInvocationChain> invocationChains) {
+ public JDKInboundInvocationHandler(Map<Method, InboundInvocationChain> invocationChains, WorkContext context) {
this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
for (Map.Entry<Method, InboundInvocationChain> entry : invocationChains.entrySet()) {
this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
}
+ this.context = context;
}
/**
@@ -96,6 +101,10 @@
assert chain != null;
invoker = chain.getTargetInvoker();
}
+ messageId = context.getCurrentMessageId();
+ context.setCurrentMessageId(null);
+ correlationId = context.getCurrentCorrelationId();
+ context.setCurrentCorrelationId(null);
return invoke(chain, invoker, args);
}
@@ -117,6 +126,14 @@
this.chain = config;
}
+ }
+
+ protected Object getMessageId() {
+ return messageId;
+ }
+
+ protected Object getCorrelationId() {
+ return correlationId;
}
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java Thu Sep 14 08:06:53 2006
@@ -109,7 +109,7 @@
Class<?> interfaze = wire.getServiceContract().getInterfaceClass();
Method[] methods = interfaze.getMethods();
Map<Method, InboundInvocationChain> chains = createInboundMapping(inbound, methods);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, context);
ClassLoader cl = interfaze.getClassLoader();
//FIXME
return Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler);
@@ -139,7 +139,7 @@
InboundWire inbound = (InboundWire) wire;
Method[] methods = inbound.getServiceContract().getInterfaceClass().getMethods();
Map<Method, InboundInvocationChain> chains = createInboundMapping(inbound, methods);
- return new JDKInboundInvocationHandler(chains);
+ return new JDKInboundInvocationHandler(chains, context);
} else if (wire instanceof OutboundWire) {
OutboundWire outbound = (OutboundWire) wire;
return new JDKOutboundInvocationHandler(outbound, context);
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java Thu Sep 14 08:06:53 2006
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
import org.apache.tuscany.spi.model.Operation;
@@ -30,10 +31,12 @@
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import junit.framework.TestCase;
+
import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
import org.apache.tuscany.core.wire.jdk.JDKInboundInvocationHandler;
+import org.easymock.classextension.EasyMock;
/**
* Tests handling of exceptions thrown during an inbound wire invocation
@@ -78,7 +81,9 @@
public void testCheckedException() throws Exception {
Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
chains.put(checkedMethod, createChain(checkedMethod, checkedOperation));
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
try {
InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy
.newProxyInstance(Thread.currentThread().getContextClassLoader(),
@@ -93,7 +98,9 @@
public void testRuntimeException() throws Exception {
Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
chains.put(runtimeMethod, createChain(runtimeMethod, runtimeOperation));
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
try {
InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy
.newProxyInstance(Thread.currentThread().getContextClassLoader(),
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java?view=diff&rev=443379&r1=443378&r2=443379
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java Thu Sep 14 08:06:53 2006
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
import org.apache.tuscany.spi.model.Operation;
@@ -30,6 +31,7 @@
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import junit.framework.TestCase;
+
import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.core.mock.component.SimpleTarget;
import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
@@ -37,6 +39,7 @@
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.easymock.classextension.EasyMock;
/**
* Verifies invocations on inbound wires
@@ -58,7 +61,9 @@
chain.setTargetInvoker(invoker);
chain.prepare();
chains.put(echo, chain);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
assertEquals("foo", handler.invoke(echo, new String[]{"foo"}));
assertEquals(1, interceptor.getCount());
}
@@ -71,7 +76,9 @@
Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
chains.put(echo, source);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
try {
assertEquals("foo", handler.invoke(echo, new Object[]{}));
fail("Expected " + IllegalArgumentException.class.getName());
@@ -87,20 +94,26 @@
Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
chains.put(echo, source);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains);
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
assertEquals("foo", handler.invoke(echo, new Object[]{"foo"}));
}
public void testToString() {
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
JDKInboundInvocationHandler handler =
- new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>());
+ new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>(), workContext);
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.toString());
}
public void testHashCode() {
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ EasyMock.replay(workContext);
JDKInboundInvocationHandler handler =
- new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>());
+ new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>(), workContext);
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.hashCode());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org