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/05/29 10:56:41 UTC
svn commit: r410059 [1/2] - in /incubator/tuscany/sandbox/jboynes/sca:
core2/src/main/java/org/apache/tuscany/core/builder/
core2/src/main/java/org/apache/tuscany/core/wire/
core2/src/main/java/org/apache/tuscany/core/wire/jdk/
core2/src/test/java/org/...
Author: jmarino
Date: Mon May 29 01:56:40 2006
New Revision: 410059
URL: http://svn.apache.org/viewvc?rev=410059&view=rev
Log:
first cut at invocation chain refactorings; cleanup still needed
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/TargetToTargetConnectTestCase.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKSourceInvocationHandlerTestCase.java
- copied, changed from r409975, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationHandler.java
- copied, changed from r409975, incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationHandler.java
Removed:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/Connector.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/RequestResponseInterceptor.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/SourceInvocationChainImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/TargetInvocationChainImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationChain.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationChain.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/Connector.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/Connector.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/Connector.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/Connector.java Mon May 29 01:56:40 2006
@@ -16,4 +16,5 @@
public <T> void connect(TargetWire<T> sourceWire, Context<?> targetContext) throws BuilderConfigException;
+
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java Mon May 29 01:56:40 2006
@@ -2,7 +2,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -135,40 +134,7 @@
}
}
TargetInvocationChain targetChain = targetWire.getInvocationChains().get(sourceChain.getMethod());
- if (sourceChain.getTailInterceptor() != null) {
- if (targetChain.getRequestHandlers() != null) {
- MessageChannel requestChannel = new MessageChannelImpl(targetChain.getRequestHandlers());
- MessageChannel responseChannel = new MessageChannelImpl(targetChain.getResponseHandlers());
- sourceChain.getTailInterceptor().setNext(new RequestResponseInterceptor(null, requestChannel, null, responseChannel));
- } else if (targetChain.getResponseHandlers() != null) {
- if (targetChain.getHeadInterceptor() == null) {
- BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
- e.setIdentifier(targetChain.getMethod().getName());
- throw e;
- }
- MessageChannel responseChannel = new MessageChannelImpl(targetChain.getResponseHandlers());
- sourceChain.getTailInterceptor().setNext(new BridgingResponseInterceptor(targetChain.getHeadInterceptor(), responseChannel));
- } else {
- if (targetChain.getHeadInterceptor() == null) {
- BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
- e.setIdentifier(targetChain.getMethod().getName());
- throw e;
- }
- sourceChain.getTailInterceptor().setNext(new BridgingInterceptor(targetChain.getHeadInterceptor()));
- }
- } else {
- // no target interceptor
- List<MessageHandler> sourceRequestHandlers = sourceChain.getRequestHandlers();
- List<MessageHandler> targetRequestHandlers = targetChain.getRequestHandlers();
- if (sourceRequestHandlers != null && !sourceRequestHandlers.isEmpty()) {
- sourceRequestHandlers.add(new BridgingHandler(targetRequestHandlers.get(0)));
- }
- List<MessageHandler> sourceResponseHandlers = sourceChain.getResponseHandlers();
- List<MessageHandler> targetResponseHandlers = targetChain.getResponseHandlers();
- if (sourceResponseHandlers != null && !sourceResponseHandlers.isEmpty()) {
- sourceResponseHandlers.add(new BridgingHandler(targetResponseHandlers.get(0)));
- }
- }
+ connect(sourceChain, targetChain);
}
}
@@ -192,13 +158,13 @@
throw e;
}
if (target instanceof ReferenceContext) {
- ReferenceContext referenceContext = (ReferenceContext)target;
+ ReferenceContext referenceContext = (ReferenceContext) target;
TargetInvoker invoker = referenceContext.createTargetInvoker(serviceName, sourceChain.getMethod());
- connect(sourceChain,targetChain, invoker);
+ connect(sourceChain, targetChain, invoker);
} else {
- ComponentContext componentContext = (ComponentContext)target;
+ ComponentContext componentContext = (ComponentContext) target;
TargetInvoker invoker = componentContext.createTargetInvoker(serviceName, sourceChain.getMethod());
- connect(sourceChain,targetChain,invoker);
+ connect(sourceChain, targetChain, invoker);
}
}
}
@@ -239,9 +205,70 @@
}
sourceChain.build();
sourceChain.setTargetInvoker(invoker);
-
}
+ public void connect(TargetInvocationChain sourceChain, TargetInvocationChain targetChain) {
+ if (sourceChain.getTailInterceptor() != null) {
+ if (targetChain.getRequestHandlers() != null) {
+ MessageChannel requestChannel = new MessageChannelImpl(targetChain.getRequestHandlers());
+ MessageChannel responseChannel = new MessageChannelImpl(targetChain.getResponseHandlers());
+ sourceChain.getTailInterceptor().setNext(new RequestResponseInterceptor(null, requestChannel,
+ null, responseChannel));
+ } else if (targetChain.getResponseHandlers() != null) {
+ if (targetChain.getHeadInterceptor() == null) {
+ BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
+ e.setIdentifier(targetChain.getMethod().getName());
+ throw e;
+ }
+ MessageChannel responseChannel = new MessageChannelImpl(targetChain.getResponseHandlers());
+ sourceChain.getTailInterceptor().setNext(new BridgingResponseInterceptor(targetChain.getHeadInterceptor(),
+ responseChannel));
+ } else {
+ // one interceptor, no handlers
+ if (targetChain.getHeadInterceptor() == null) {
+ BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
+ e.setIdentifier(targetChain.getMethod().getName());
+ throw e;
+ }
+ sourceChain.getTailInterceptor().setNext(new BridgingInterceptor(targetChain.getHeadInterceptor(),
+ sourceChain.getResponseChannel()));
+ }
+ } else {
+ // no interceptor
+ List<MessageHandler> sourceRequestHandlers = sourceChain.getRequestHandlers();
+ List<MessageHandler> targetRequestHandlers = targetChain.getRequestHandlers();
+ if (sourceRequestHandlers != null && !sourceRequestHandlers.isEmpty()) {
+ if (targetRequestHandlers != null && !targetRequestHandlers.isEmpty()) {
+ sourceRequestHandlers.add(new BridgingHandler(targetRequestHandlers.get(0)));
+ } else if (targetChain.getRequestHandlers() == null) {
+ sourceRequestHandlers.add(new MessageDispatcher(targetChain.getHeadInterceptor()));
+ }
+ } else {
+ MessageChannel requestChannel = targetChain.getRequestChannel();
+ MessageChannel responseChannel = targetChain.getResponseChannel();
+ if (requestChannel == null && responseChannel == null) {
+ sourceChain.setTargetInterceptor(targetChain.getHeadInterceptor());
+ } else {
+ if (requestChannel == null) {
+ sourceChain.setTargetInterceptor(new BridgingInterceptor(targetChain.getHeadInterceptor()));
+
+ } else {
+ sourceChain.setTargetRequestChannel(requestChannel);
+ sourceChain.addInterceptor(new RequestResponseInterceptor(null, requestChannel, null, responseChannel));
+ }
+ sourceChain.setTargetResponseChannel(responseChannel);
+ }
+ }
+
+ List<MessageHandler> sourceResponseHandlers = sourceChain.getResponseHandlers();
+ List<MessageHandler> targetResponseHandlers = targetChain.getResponseHandlers();
+ if (sourceResponseHandlers != null && !sourceResponseHandlers.isEmpty()) {
+ if (targetResponseHandlers != null && !targetResponseHandlers.isEmpty()) {
+ sourceResponseHandlers.add(new BridgingHandler(targetResponseHandlers.get(0)));
+ }
+ }
+ }
+ }
private boolean isOptimizable(Scope pReferrer, Scope pReferee) {
if (pReferrer == Scope.UNDEFINED || pReferee == Scope.UNDEFINED) {
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java Mon May 29 01:56:40 2006
@@ -2,6 +2,7 @@
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageChannel;
/**
* Bridges between interceptors in two {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s
@@ -10,13 +11,26 @@
*/
public class BridgingInterceptor implements Interceptor {
private Interceptor next;
+ private MessageChannel responseChannel;
+
+ public BridgingInterceptor() {
+ }
+
+ public BridgingInterceptor(Interceptor next, MessageChannel responseChannel) {
+ this.next = next;
+ this.responseChannel = responseChannel;
+ }
public BridgingInterceptor(Interceptor next) {
this.next = next;
}
public Message invoke(Message msg) {
- return next.invoke(msg);
+ Message response = next.invoke(msg);
+ if (responseChannel != null){
+ responseChannel.send(response);
+ }
+ return response;
}
public Interceptor getNext() {
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java Mon May 29 01:56:40 2006
@@ -17,34 +17,37 @@
package org.apache.tuscany.core.wire;
import java.lang.reflect.Method;
-import java.util.ArrayList;
import java.util.List;
+import java.util.ArrayList;
-import org.apache.tuscany.spi.wire.InvocationChain;
-import org.apache.tuscany.spi.wire.TargetInvoker;
import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.MessageChannel;
import org.apache.tuscany.spi.wire.MessageHandler;
+import org.apache.tuscany.spi.wire.TargetInvoker;
/**
* Contains functionality common to source- and target- side invocation chains
+ *
* @version $Rev$ $Date$
*/
public abstract class InvocationChainImpl implements InvocationChain {
-
- // the operation on the target that will utlimately be invoked
protected Method operation;
-
- // responsible for invoking a target instance
protected TargetInvoker targetInvoker;
-
protected Interceptor interceptorChainHead;
-
protected Interceptor interceptorChainTail;
-
protected List<MessageHandler> requestHandlers;
-
protected List<MessageHandler> responseHandlers;
+ protected MessageChannel requestChannel;
+ protected MessageChannel responseChannel;
+
+ // the pointer to a bridged target request channel, or null if the target has an interceptor
+ protected MessageChannel targetRequestChannel;
+ // the pointer to a bridged target response channel, or null if the target has an interceptor
+ protected MessageChannel targetResponseChannel;
+ // the pointer to a bridged target head interceptor or null if the target has no interceptors
+ protected Interceptor targetInterceptorChainHead;
public InvocationChainImpl(Method operation) {
assert (operation != null) : "No operation type specified";
@@ -55,20 +58,6 @@
return operation;
}
- public void addRequestHandler(MessageHandler handler) {
- if (requestHandlers == null) {
- requestHandlers = new ArrayList<MessageHandler>();
- }
- requestHandlers.add(handler);
- }
-
- public void addResponseHandler(MessageHandler handler) {
- if (responseHandlers == null) {
- responseHandlers = new ArrayList<MessageHandler>();
- }
- responseHandlers.add(handler);
- }
-
public List<MessageHandler> getRequestHandlers() {
return requestHandlers;
}
@@ -94,12 +83,61 @@
interceptorChainTail = interceptor;
}
+ public Interceptor getHeadInterceptor() {
+ return interceptorChainHead;
+ }
+
public Interceptor getTailInterceptor() {
return interceptorChainTail;
}
- public Interceptor getHeadInterceptor() {
- return interceptorChainHead;
+ public MessageChannel getRequestChannel() {
+ return requestChannel;
+ }
+
+ public MessageChannel getResponseChannel() {
+ return responseChannel;
+ }
+
+ public void addRequestHandler(MessageHandler handler) {
+ if (requestHandlers == null) {
+ requestHandlers = new ArrayList<MessageHandler>();
+ requestChannel = new MessageChannelImpl(requestHandlers);
+ }
+ requestHandlers.add(handler);
}
+
+ public void addResponseHandler(MessageHandler handler) {
+ if (responseHandlers == null) {
+ responseHandlers = new ArrayList<MessageHandler>();
+ responseChannel = new MessageChannelImpl(responseHandlers);
+ }
+ responseHandlers.add(handler);
+ }
+
+ public MessageChannel getTargetRequestChannel() {
+ return targetRequestChannel;
+ }
+
+ public void setTargetRequestChannel(MessageChannel channel) {
+ this.targetRequestChannel = channel;
+ }
+
+ public void setTargetResponseChannel(MessageChannel channel) {
+ this.targetResponseChannel = channel;
+ }
+
+ public MessageChannel getTargetResponseChannel() {
+ return targetResponseChannel;
+ }
+
+ public void setTargetInterceptor(Interceptor interceptor) {
+ targetInterceptorChainHead = interceptor;
+ }
+
+ public Interceptor getTargetInterceptor() {
+ return targetInterceptorChainHead;
+ }
+
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/RequestResponseInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/RequestResponseInterceptor.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/RequestResponseInterceptor.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/RequestResponseInterceptor.java Mon May 29 01:56:40 2006
@@ -54,10 +54,13 @@
if (sourceRequestChannel != null) {
sourceRequestChannel.send(requestMessage);
}
+ Message responseMessage;
if (targetRequestChannel != null) {
targetRequestChannel.send(requestMessage);
+ responseMessage = requestMessage.getRelatedCallbackMessage();
+ } else{
+ responseMessage = requestMessage;
}
- Message responseMessage = requestMessage.getRelatedCallbackMessage();
if (targetResponseChannel != null) {
targetResponseChannel.send(responseMessage);
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/SourceInvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/SourceInvocationChainImpl.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/SourceInvocationChainImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/SourceInvocationChainImpl.java Mon May 29 01:56:40 2006
@@ -16,10 +16,9 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
-import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.MessageChannel;
import org.apache.tuscany.spi.wire.MessageHandler;
+import org.apache.tuscany.spi.wire.SourceInvocationChain;
/**
* Contains a source-side invocation pipeline for a service operation.
@@ -28,56 +27,26 @@
*/
public class SourceInvocationChainImpl extends InvocationChainImpl implements SourceInvocationChain {
- // the pointer to the bridged target head interceptor or null if the target has no interceptors
- private Interceptor targetInterceptorChainHead;
-
- // the pointer to bridged target request channel, or null if the target has an interceptor
- private MessageChannel targetRequestChannel;
-
- // the pointer to bridged target response channel, or null if the target has an interceptor
- private MessageChannel targetResponseChannel;
-
/**
- * Creates an new wire configuration for the given service reference operation
- *
- * @param operation the method on the interface representing specified by the reference, where the method corresponds to the
- * service operation
+ * Creates an new source wire configuration
*/
public SourceInvocationChainImpl(Method operation) {
super(operation);
}
- public void setTargetInterceptor(Interceptor interceptor) {
- targetInterceptorChainHead = interceptor;
- }
-
- public Interceptor getTargetInterceptor() {
- return targetInterceptorChainHead;
- }
-
- public void setTargetRequestChannel(MessageChannel channel) {
- targetRequestChannel = channel;
- }
-
- public void setTargetResponseChannel(MessageChannel channel) {
- targetResponseChannel = channel;
- }
-
public void build() {
if ((requestHandlers != null || responseHandlers != null) && targetInterceptorChainHead != null) {
- // on target-side, connect existing handlers and interceptors
MessageHandler messageDispatcher = new MessageDispatcher(targetInterceptorChainHead);
if (requestHandlers == null) {
// case where there is only a response handler
requestHandlers = new ArrayList<MessageHandler>();
+ requestChannel = new MessageChannelImpl(requestHandlers);
}
requestHandlers.add(messageDispatcher);
}
if (requestHandlers != null || responseHandlers != null) {
- MessageChannel requestChannel = new MessageChannelImpl(requestHandlers);
- MessageChannel responseChannel = new MessageChannelImpl(responseHandlers);
Interceptor channelInterceptor = new RequestResponseInterceptor(requestChannel, targetRequestChannel,
responseChannel, targetResponseChannel);
@@ -88,7 +57,7 @@
}
} else {
- // no request handlers
+ // no handlers
if (interceptorChainHead != null) {
if (targetInterceptorChainHead != null) {
// Connect source interceptor chain directly to target interceptor chain
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/TargetInvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/TargetInvocationChainImpl.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/TargetInvocationChainImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/TargetInvocationChainImpl.java Mon May 29 01:56:40 2006
@@ -15,11 +15,11 @@
import java.lang.reflect.Method;
-import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.MessageHandler;
+import org.apache.tuscany.spi.wire.TargetInvocationChain;
/**
- * Contains a target-side invocation pipeline for a service operation.
+ * Contains a target-side invocation chain
*
* @version $Rev: 394379 $ $Date: 2006-04-15 15:01:36 -0700 (Sat, 15 Apr 2006) $
*/
@@ -27,20 +27,20 @@
/**
* Creates an new target-side chain for the given operation
- *
- * @param operation the method on the interface representing target service, where the method corresponds
- * to the service operation
*/
public TargetInvocationChainImpl(Method operation) {
super(operation);
}
public void build() {
- if (requestHandlers != null && interceptorChainHead != null) {
- // on target-side, connect existing handlers and interceptors
- MessageHandler messageDispatcher = new MessageDispatcher(interceptorChainHead);
- requestHandlers.add(messageDispatcher);
+ if (requestHandlers != null) {
+ if (interceptorChainHead != null) {
+ // on target-side, connect existing handlers and interceptors
+ MessageHandler messageDispatcher = new MessageDispatcher(interceptorChainHead);
+ requestHandlers.add(messageDispatcher);
+ }
}
}
+
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java Mon May 29 01:56:40 2006
@@ -25,7 +25,7 @@
import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.SourceWire;
import org.apache.tuscany.spi.wire.TargetWire;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.wire.SourceInvocationHandler;
/**
* Creates proxies that are injected on references using JDK dynamic proxy facilities and front a wire. The
@@ -47,8 +47,7 @@
// optimized, no interceptors or handlers on either end
return targetWire.getTargetService();
}
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(invocationChains);
+ SourceInvocationHandler handler = new SourceInvocationHandler(invocationChains);
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), businessInterfaces, handler);
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java Mon May 29 01:56:40 2006
@@ -11,6 +11,7 @@
import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.TargetWire;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.wire.TargetInvocationHandler;
/**
* Creates proxies that are returned to non-SCA clients using JDK dynamic proxy facilities and front a wire.
@@ -27,8 +28,7 @@
@SuppressWarnings("unchecked")
public T getTargetService() throws TargetException {
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(invocationChains);
+ WireInvocationHandler handler = new TargetInvocationHandler(invocationChains);
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), businessInterfaces, handler);
}
Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/TargetToTargetConnectTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/TargetToTargetConnectTestCase.java?rev=410059&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/TargetToTargetConnectTestCase.java (added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/TargetToTargetConnectTestCase.java Mon May 29 01:56:40 2006
@@ -0,0 +1,514 @@
+package org.apache.tuscany.core.builder;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.wire.MockHandler;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.TargetInvocationChainImpl;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageHandler;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s and
+ * {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class TargetToTargetConnectTestCase extends MockObjectTestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testNoInterceptorsNoHandlers() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ String[] val = new String[]{"foo"};
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invokeTarget").with(eq(val)).will(returnValue(val));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ sourceChain.setTargetInvoker(invoker);
+ connector.connect(sourceChain, targetChain);
+ targetChain.build();
+ assertEquals(val, sourceChain.getTargetInvoker().invokeTarget(val));
+ }
+
+
+ /**
+ * Verifies an invocation with a single source interceptor
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceInterceptor() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+
+ TargetInvocationChain sourceChain = setupChain(interceptors, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(1, interceptor.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a single target interceptor
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetInterceptor() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(interceptors, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ sourceChain.setTargetInvoker(invoker);
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getTargetInterceptor().invoke(msg));
+ assertEquals(1, interceptor.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a source and target interceptor
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceTargetInterceptor() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ List<Interceptor> sourceInterceptors = new ArrayList<Interceptor>();
+ sourceInterceptors.add(sourceInterceptor);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ List<Interceptor> targetInterceptors = new ArrayList<Interceptor>();
+ targetInterceptors.add(targetInterceptor);
+
+ TargetInvocationChain sourceChain = setupChain(sourceInterceptors, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(targetInterceptors, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, sourceInterceptor.getCount());
+ assertEquals(0, targetInterceptor.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(1, sourceInterceptor.getCount());
+ assertEquals(1, targetInterceptor.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a source interceptor and a request handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceInterceptorSourceRequestHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(interceptors, handlers, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ sourceChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ for (MessageHandler messageHandler : sourceChain.getRequestHandlers()) {
+ messageHandler.processMessage(msg);
+ }
+ assertEquals(1, interceptor.getCount());
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a target interceptor and a request handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetInterceptorTargetRequestHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(interceptors, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ sourceChain.getTargetRequestChannel().send(msg);
+ assertEquals(1, interceptor.getCount());
+ assertEquals(1, handler.getCount());
+ }
+
+
+ /**
+ * Verifies an invocation with a source interceptor and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceInterceptorSourceResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(interceptors, null, handlers);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(1, interceptor.getCount());
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a source interceptor and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetInterceptorTargetResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(interceptors, null, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getTargetInterceptor().invoke(msg));
+ sourceChain.getTargetResponseChannel().send(msg);
+ assertEquals(1, interceptor.getCount());
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a source interceptor, request handler, and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceInterceptorSourceRequestResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(interceptors, handlers, handlers);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ sourceChain.getRequestChannel().send(msg);
+ assertEquals(msg, msg.getRelatedCallbackMessage());
+ assertEquals(1, interceptor.getCount());
+ assertEquals(2, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a target interceptor, request handler, and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetInterceptorTargetRequestResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ interceptors.add(interceptor);
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, handlers);
+ TargetInvocationChain targetChain = setupTargetChain(interceptors, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, interceptor.getCount());
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ Message response = sourceChain.getHeadInterceptor().invoke(msg);
+ sourceChain.getResponseChannel().send(response);
+ assertEquals(msg, response);
+ assertEquals(1, interceptor.getCount());
+ assertEquals(2, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a source request handler and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceRequestResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, handlers, handlers);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ sourceChain.getRequestChannel().send(msg);
+ sourceChain.getResponseChannel().send(msg);
+ assertEquals(msg, msg.getRelatedCallbackMessage());
+ assertEquals(2, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a target request handler and response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetRequestResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, handlers, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(2, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a single source request handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceRequestHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, handlers, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ sourceChain.getRequestChannel().send(msg);
+ Message response = msg.getRelatedCallbackMessage();
+ assertEquals(msg, response);
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a single target request handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetRequestHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ sourceChain.build();
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a single source response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testSourceResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+
+ TargetInvocationChain sourceChain = setupChain(null, null, handlers);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getTargetInterceptor().invoke(msg));
+ sourceChain.getResponseChannel().send(msg);
+ assertEquals(1, handler.getCount());
+ }
+
+ /**
+ * Verifies an invocation with a single target response handler
+ */
+ @SuppressWarnings("unchecked")
+ public void testTargetResponseHandler() throws Exception {
+ ConnectorImpl connector = new ConnectorImpl();
+ MockHandler handler = new MockHandler();
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(handler);
+ TargetInvocationChain sourceChain = setupChain(null, null, null);
+ TargetInvocationChain targetChain = setupTargetChain(null, null, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain);
+ sourceChain.setTargetInvoker(invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getTargetInterceptor().invoke(msg));
+ targetChain.getResponseChannel().send(msg);
+ assertEquals(1, handler.getCount());
+ }
+
+
+ public TargetInvocationChain setupChain(List<Interceptor> interceptors,
+ List<MessageHandler> requestHandlers,
+ List<MessageHandler> responseHandlers) {
+
+ Method echo;
+ try {
+ echo = SimpleTarget.class.getMethod("echo", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError();
+ }
+ TargetInvocationChainImpl chain = new TargetInvocationChainImpl(echo);
+ if (interceptors != null) {
+ for (Interceptor interceptor : interceptors) {
+ chain.addInterceptor(interceptor);
+ }
+ }
+ if (requestHandlers != null) {
+ for (MessageHandler handler : requestHandlers) {
+ chain.addRequestHandler(handler);
+ }
+ }
+ if (responseHandlers != null) {
+ for (MessageHandler handler : responseHandlers) {
+ chain.addResponseHandler(handler);
+ }
+ }
+ return chain;
+ }
+
+ public TargetInvocationChain setupTargetChain(List<Interceptor> interceptors,
+ List<MessageHandler> requestHandlers,
+ List<MessageHandler> responseHandlers) {
+
+ TargetInvocationChain chain = setupChain(interceptors, requestHandlers, responseHandlers);
+ chain.addInterceptor(new InvokerInterceptor()); // add tail interceptor
+ return chain;
+ }
+
+}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java Mon May 29 01:56:40 2006
@@ -21,12 +21,11 @@
import java.util.Map;
import junit.framework.TestCase;
-import org.apache.tuscany.core.util.MethodHashMap;
-import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
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.spi.wire.InvocationChain;
+import org.apache.tuscany.core.util.MethodHashMap;
+import org.apache.tuscany.spi.wire.SourceInvocationHandler;
import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
@@ -56,10 +55,9 @@
}
public void testCheckedException() throws Exception {
- Map<Method, InvocationChain> config = new MethodHashMap<InvocationChain>();
+ Map<Method, SourceInvocationChain> config = new MethodHashMap<SourceInvocationChain>();
config.put(checkedMethod, getConfiguration(checkedMethod));
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(config);
+ WireInvocationHandler handler = new SourceInvocationHandler(config);
try {
TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
@@ -71,10 +69,9 @@
}
public void testRuntimeException() throws Exception {
- Map<Method, InvocationChain> config = new MethodHashMap<InvocationChain>();
+ Map<Method, SourceInvocationChain> config = new MethodHashMap<SourceInvocationChain>();
config.put(runtimeMethod, getConfiguration(runtimeMethod));
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(config);
+ WireInvocationHandler handler = new SourceInvocationHandler(config);
try {
TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
@@ -85,7 +82,7 @@
fail(TestException.class.getName() + " should have been thrown");
}
- private InvocationChain getConfiguration(Method m) {
+ private SourceInvocationChain getConfiguration(Method m) {
MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl());
SourceInvocationChain invocationConfiguration = new SourceInvocationChainImpl(m);
invocationConfiguration.addInterceptor(new MockSyncInterceptor());
Copied: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKSourceInvocationHandlerTestCase.java (from r409975, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKSourceInvocationHandlerTestCase.java?p2=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKSourceInvocationHandlerTestCase.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java&r1=409975&r2=410059&rev=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKSourceInvocationHandlerTestCase.java Mon May 29 01:56:40 2006
@@ -1,34 +1,33 @@
package org.apache.tuscany.core.wire.jdk;
+import java.lang.reflect.Method;
+import java.util.Map;
+
import junit.framework.TestCase;
-import org.apache.tuscany.core.wire.InvocationChainImpl;
-import org.apache.tuscany.core.util.MethodHashMap;
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.wire.SourceInvocationChainImpl;
+import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.core.wire.InvokerInterceptor;
import org.apache.tuscany.core.wire.MessageChannelImpl;
+import org.apache.tuscany.core.wire.SourceInvocationChainImpl;
import org.apache.tuscany.core.wire.TargetInvocationChainImpl;
import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.TargetInvocationChain;
-import org.apache.tuscany.spi.wire.InvocationChain;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.wire.SourceInvocationHandler;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-public class JDKInvocationHandlerTestCase extends TestCase {
+public class JDKSourceInvocationHandlerTestCase extends TestCase {
private Method hello;
- public JDKInvocationHandlerTestCase() {
+ public JDKSourceInvocationHandlerTestCase() {
super();
}
- public JDKInvocationHandlerTestCase(String arg0) {
+ public JDKSourceInvocationHandlerTestCase(String arg0) {
super(arg0);
}
@@ -37,20 +36,18 @@
}
public void testBasicInvoke() throws Throwable {
- Map<Method, InvocationChain> configs = new MethodHashMap<InvocationChain>();
- configs.put(hello, getInvocationHandler(hello));
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(configs);
- assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" }));
+ Map<Method, SourceInvocationChain> configs = new MethodHashMap<SourceInvocationChain>();
+ configs.put(hello, createChain(hello));
+ WireInvocationHandler handler = new SourceInvocationHandler(configs);
+ assertEquals("foo", handler.invoke(null, hello, new Object[]{"foo"}));
}
public void testErrorInvoke() throws Throwable {
- Map<Method, InvocationChain> configs = new MethodHashMap<InvocationChain>();
- configs.put(hello, getInvocationHandler(hello));
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(configs);
+ Map<Method, SourceInvocationChain> configs = new MethodHashMap<SourceInvocationChain>();
+ configs.put(hello, createChain(hello));
+ WireInvocationHandler handler = new SourceInvocationHandler(configs);
try {
- assertEquals("foo", handler.invoke(null, hello, new Object[] {}));
+ assertEquals("foo", handler.invoke(null, hello, new Object[]{}));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (IllegalArgumentException e) {
// should throw
@@ -62,12 +59,11 @@
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
- Map<Method, InvocationChain> configs = new MethodHashMap<InvocationChain>();
+ Map<Method, SourceInvocationChain> configs = new MethodHashMap<SourceInvocationChain>();
configs.put(hello, source);
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(configs);
+ WireInvocationHandler handler = new SourceInvocationHandler(configs);
try {
- assertEquals("foo", handler.invoke(null, hello, new Object[] {}));
+ assertEquals("foo", handler.invoke(null, hello, new Object[]{}));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (IllegalArgumentException e) {
// should throw
@@ -79,14 +75,13 @@
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
- Map<Method, InvocationChainImpl> configs = new MethodHashMap<InvocationChainImpl>();
+ Map<Method, SourceInvocationChain> configs = new MethodHashMap<SourceInvocationChain>();
configs.put(hello, source);
- WireInvocationHandler handler = new JDKInvocationHandler();
- handler.setChains(configs);
- assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" }));
+ WireInvocationHandler handler = new SourceInvocationHandler(configs);
+ assertEquals("foo", handler.invoke(null, hello, new Object[]{"foo"}));
}
- private InvocationChain getInvocationHandler(Method m) {
+ private SourceInvocationChain createChain(Method m) {
SourceInvocationChain source = new SourceInvocationChainImpl(m);
MockHandler sourceRequestHandler = new MockHandler();
MockHandler sourceResponseHandler = new MockHandler();
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java Mon May 29 01:56:40 2006
@@ -26,6 +26,7 @@
import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.TargetWire;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.wire.TargetInvocationHandler;
/**
* The default implementation of an external service context
@@ -36,7 +37,6 @@
protected TargetWire<T> targetWire;
protected Class<T> referenceInterface;
- protected ObjectFactory<WireInvocationHandler> handlerFactory;
protected ReferenceContextExtension(String name, CompositeContext<?> parent) {
super(name, parent);
@@ -62,10 +62,6 @@
this.referenceInterface = referenceInterface;
}
- public void setHandlerFactory(ObjectFactory<WireInvocationHandler> handlerFactory) {
- this.handlerFactory = handlerFactory;
- }
-
public T getService() throws TargetException {
return targetWire.getTargetService();
}
@@ -73,8 +69,7 @@
public InvocationHandler getHandler() throws TargetException {
Map<Method, TargetInvocationChain> configuration = targetWire.getInvocationChains();
assert(configuration != null);
- WireInvocationHandler handler = handlerFactory.getInstance();
- handler.setChains(configuration);
+ WireInvocationHandler handler = new TargetInvocationHandler(configuration);
return handler;
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java Mon May 29 01:56:40 2006
@@ -2,15 +2,15 @@
import java.lang.reflect.InvocationHandler;
-import org.apache.tuscany.spi.ObjectFactory;
-import org.apache.tuscany.spi.model.Scope;
import org.apache.tuscany.spi.CoreRuntimeException;
import org.apache.tuscany.spi.context.AbstractContext;
+import org.apache.tuscany.spi.context.CompositeContext;
import org.apache.tuscany.spi.context.ServiceContext;
import org.apache.tuscany.spi.context.TargetException;
-import org.apache.tuscany.spi.context.CompositeContext;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.TargetInvocationHandler;
import org.apache.tuscany.spi.wire.TargetWire;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* The default implementation of an service context
@@ -20,7 +20,6 @@
public class ServiceContextExtension<T> extends AbstractContext<T> implements ServiceContext<T> {
protected TargetWire<T> targetWire;
- protected ObjectFactory<WireInvocationHandler> handlerFactory;
private T target;
public ServiceContextExtension(String name, TargetWire<T> wire, CompositeContext parent) throws CoreRuntimeException {
@@ -41,11 +40,6 @@
targetWire = wire;
}
- public void setHandlerFactory(ObjectFactory<WireInvocationHandler> handlerFactory) {
- this.handlerFactory = handlerFactory;
- }
-
-
public T getService() throws TargetException {
if (target == null) {
target = targetWire.getTargetService();
@@ -54,8 +48,7 @@
}
public InvocationHandler getHandler() {
- WireInvocationHandler invocationHandler = handlerFactory.getInstance();
- invocationHandler.setChains(targetWire.getInvocationChains());
+ WireInvocationHandler invocationHandler = new TargetInvocationHandler(targetWire.getInvocationChains());
return invocationHandler;
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java Mon May 29 01:56:40 2006
@@ -4,51 +4,28 @@
import java.util.List;
/**
- * Contains a source- or target-side invocation pipeline for a service operation. The runtime framework
- * creates invocation chains on a per-operation, per-service basis. Moreover, invocation chains are further
- * distinguished by being part of the source or target sides of a wire. Chains are "bridged" together by the
- * runtime with the source-side holding references to the target.
+ * A source- or target-side invocation pipeline for a service operation. Invocation chains are associated with
+ * the source or target side of a wire and are bridged when an assembly is processed.
* <p/>
- * <code>InvocationChain</code>s are managed by {@link SourceWire}s and {@link TargetWire}s, which are used by
- * wire factories to buildSource wires and proxies.
+ * Invocation configurations contain at least one {@link Interceptor} and may have 0 to N {@link
+ * MessageHandler}s. <code>Interceptors>/code> process invocations in a synchronous, around style manner while
+ * <code>MessageHandler</code>s do so in a one-way manner.
* <p/>
- * Invocation configurations must contain at least one interceptor and may have 0 to N handlers. Handlers
- * process a wire request or response in a one-way fashion. A typical wire sequence where interceptors and
- * handlers are configured for both the source and target-side will proceed as follows:
- * <pre>
- * <ol>
- * <li>The first source interceptor will be called with a message, which will in
- * turn invoke the next interceptor in the chain
- * <li>If source handlers are present, they will be invoked by passing the message to a {@link
- * MessageChannel}
- * <li>The target-side request <code>MessageChannel</code> will be invoked next
- * <li>Following the last source-side handler, the first source-side interceptor will be invoked, which in
- * turn
- * will pass the message down the target-side interceptor chain.
- * <li>After invoking the last interceptor, the chain will retrieve the {@link TargetInvoker} from the
- * message and call it to invoke the operation on a target instance.
- * <li>The response is returned up the wire stack until it reaches the source-side wire, which invokes the
- * target and source-side response channels respectively.
- * <li>The response is then passed back up the rest of the wire stack. </ol>
- * </pre>
- * <p/>
- * The source-to-target bridge may be constructed in any of the following ways:
- * <pre>
- * <ul>
- * <li>Source handler-to-target handler
- * <li>Source handler-to-target interceptor
- * <li>Source interceptor-to-target handler
- * <li>Source interceptor-to-target interceptor
- * </ul>
- * </pre>
+ * Source-side chains may only connect to target-side chains. Target-side chains may connect to other
+ * target-side chains, for example, when invoking from a {@link org.apache.tuscany.spi.context.ServiceContext}
+ * to an {@link org.apache.tuscany.spi.context.AtomicContext}.
* <p/>
* In some scenarios, a service proxy may only contain target-side invocaton chains, for example, when a
* service is resolved through a locate operation by a non-component client. In this case, there will be no
* source-side wire chains and the target invoker will be held by the target-side and passed down the
* pipeline.
+ * <p/>
+ * A {@link Message} is used to pass data associated with an invocation through the chain.
+ * <code>Message</code>s contain a {@link TargetInvoker} responsible for dispatching to a target instance and
+ * may be cached on the client-side. Caching allows various optimizations such as avoiding target instance
+ * resolution when the client-side lifecycle scope is a shorter duration than the target.
*
* @version $Rev: 396284 $ $Date: 2006-04-23 08:27:42 -0700 (Sun, 23 Apr 2006) $
- * @see TargetInvoker
*/
public interface InvocationChain {
/**
@@ -57,12 +34,12 @@
Method getMethod();
/**
- * Adds an request handler to the invocation chain
+ * Adds a request handler to the invocation chain
*/
void addRequestHandler(MessageHandler handler);
/**
- * Adds an response handler to the invocation chain
+ * Adds a response handler to the invocation chain
*/
void addResponseHandler(MessageHandler handler);
@@ -77,6 +54,16 @@
List<MessageHandler> getResponseHandlers();
/**
+ * Returns the request channel for the chain
+ */
+ public MessageChannel getRequestChannel();
+
+ /**
+ * Returns the response channel for the chain
+ */
+ public MessageChannel getResponseChannel();
+
+ /**
* Sets the target invoker to pass down the chain
*/
void setTargetInvoker(TargetInvoker invoker);
@@ -92,14 +79,44 @@
void addInterceptor(Interceptor interceptor);
/**
+ * Returns the first interceptor in the chain
+ */
+ Interceptor getHeadInterceptor();
+
+ /**
* Returns the last interceptor in the chain
*/
Interceptor getTailInterceptor();
/**
- * Returns the first interceptor in the chain
+ * Sets the head interceptor of the bridged target-side chain
*/
- Interceptor getHeadInterceptor();
+ void setTargetInterceptor(Interceptor interceptor);
+
+ /**
+ * Returns the head interceptor of the birdged target-side chain
+ */
+ Interceptor getTargetInterceptor();
+
+ /**
+ * Sets the target-side request channel when two chains are bidged
+ */
+ void setTargetRequestChannel(MessageChannel channel);
+
+ /**
+ * Sets the target-side response channel when two chains are bridged
+ */
+ void setTargetResponseChannel(MessageChannel channel);
+
+ /**
+ * Returns the target-side request channel when two chains are bridged
+ */
+ public MessageChannel getTargetRequestChannel();
+
+ /**
+ * Returns the target-side response channel when two chains are bridged
+ */
+ public MessageChannel getTargetResponseChannel();
/**
* Signals to the chain that its configuration is complete. Implementations may use this callback to
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationChain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationChain.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationChain.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationChain.java Mon May 29 01:56:40 2006
@@ -2,33 +2,13 @@
/**
* A set of interceptors and handlers (contained in request and response message channels) associated with the
- * source side of a wire for a service operation. A service will have one chain per operation.
+ * source side of a wire for a service operation. Source invocation chains always start with an {@link
+ * Interceptor} and may contain 0..n {@link MessageHandler}s. <code>MessageHandlers</code> are part of a
+ * request or response chainnel, which are invoked prior to and after dispatching to a target instance
+ * respectively.
*
* @version $$Rev$$ $$Date$$
*/
public interface SourceInvocationChain extends InvocationChain {
- /**
- * Sets the head interceptor of the target-side configuration for the wire. Used when the runtime bridges
- * source and target chains.
- *
- * @param interceptor
- */
- void setTargetInterceptor(Interceptor interceptor);
-
- /**
- * Returns the head target-side interceptor. This will be the head interceptor of the "bridged" target
- * configuration.
- */
- Interceptor getTargetInterceptor();
-
- /**
- * Sets the target-side request channel. Used when the runtime bridges source and target chains.
- */
- void setTargetRequestChannel(MessageChannel channel);
-
- /**
- * Sets the target-side response channel. Used when the runtime bridges source and target chains.
- */
- void setTargetResponseChannel(MessageChannel channel);
}
Copied: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationHandler.java (from r409975, incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationHandler.java?p2=incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationHandler.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java&r1=409975&r2=410059&rev=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/SourceInvocationHandler.java Mon May 29 01:56:40 2006
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.tuscany.core.wire.jdk;
+package org.apache.tuscany.spi.wire;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -24,17 +24,17 @@
import org.apache.tuscany.spi.wire.MessageImpl;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.InvocationChain;
import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.TargetInvoker;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
+import org.apache.tuscany.spi.wire.SourceInvocationChain;
/**
* Receives a request from a proxy and dispatches it to a target invoker or source interceptor stack
*
* @version $Rev: 406016 $ $Date: 2006-05-12 22:45:22 -0700 (Fri, 12 May 2006) $
*/
-public class JDKInvocationHandler implements WireInvocationHandler {
+public class SourceInvocationHandler implements WireInvocationHandler {
/*
* an association of an operation to chain holder. The holder contains the master wire chain
@@ -45,7 +45,11 @@
*/
private Map<Method, ChainHolder> chains;
- public JDKInvocationHandler() {
+ public SourceInvocationHandler(Map<Method, SourceInvocationChain> invocationChains) {
+ this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
+ for (Map.Entry<Method, SourceInvocationChain> entry : invocationChains.entrySet()) {
+ this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
+ }
}
/**
@@ -59,7 +63,7 @@
e.setIdentifier(method.getName());
throw e;
}
- InvocationChain chain = holder.chain;
+ SourceInvocationChain chain = holder.chain;
if (chain != null) {
headInterceptor = chain.getHeadInterceptor();
}
@@ -109,23 +113,16 @@
}
}
- public void setChains(Map<Method, ? extends InvocationChain> invocationChains) {
- this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
- for (Map.Entry<Method, ? extends InvocationChain> entry : invocationChains.entrySet()) {
- this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
- }
- }
-
/**
* A holder used to associate an wire chain with a local copy of a target invoker that was
* previously cloned from the chain master
*/
private class ChainHolder {
- InvocationChain chain;
+ SourceInvocationChain chain;
TargetInvoker cachedInvoker;
- public ChainHolder(InvocationChain config) {
+ public ChainHolder(SourceInvocationChain config) {
this.chain = config;
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationChain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationChain.java?rev=410059&r1=410058&r2=410059&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationChain.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationChain.java Mon May 29 01:56:40 2006
@@ -2,10 +2,17 @@
/**
* A set of interceptors and handlers (contained in request and response message channels) associated with the
- * target side of a wire for a service operation. A service will have one chain per operation.
+ * target side of a wire for a service operation. Target invocation chains may start with request {@link
+ * MessageHandler}s and contain at least one {@link Interceptor} processed after the handlers prior to
+ * dipatching to the target instance. Target invocation chains may also contain a set of response
+ * <code>MessageHandler</code>s which are processed after dispatching to the target instance.
+ * <p/>
+ * Two target chains may be bridged together. The exact connection points (e.g. interceptors, request
+ * handlers, response handlers) will vary depending on the contains of each chain.
*
* @version $$Rev$$ $$Date$$
*/
public interface TargetInvocationChain extends InvocationChain {
+
}
Added: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationHandler.java?rev=410059&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationHandler.java (added)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvocationHandler.java Mon May 29 01:56:40 2006
@@ -0,0 +1,123 @@
+package org.apache.tuscany.spi.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.context.TargetException;
+
+/**
+ * Receives a request from a proxy and dispatches it to a target invoker or source interceptor stack
+ *
+ * @version $Rev: 406016 $ $Date: 2006-05-12 22:45:22 -0700 (Fri, 12 May 2006) $
+ */
+public class TargetInvocationHandler implements WireInvocationHandler {
+
+ /*
+ * an association of an operation to chain holder. The holder contains the master wire chain
+ * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
+ * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
+ * to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
+ * is not cacheable, the master associated with the wire chains will be used.
+ */
+ private Map<Method, ChainHolder> chains;
+
+ public TargetInvocationHandler(Map<Method, TargetInvocationChain> invocationChains) {
+ this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
+ for (Map.Entry<Method, TargetInvocationChain> entry : invocationChains.entrySet()) {
+ this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
+ }
+ }
+
+ /**
+ * Dispatches a client request made on a proxy
+ */
+ 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");
+ e.setIdentifier(method.getName());
+ throw e;
+ }
+ TargetInvocationChain chain = holder.chain;
+ if (chain != null) {
+ headInterceptor = chain.getHeadInterceptor();
+ }
+
+ TargetInvoker invoker;
+
+ if (holder.cachedInvoker == null) {
+ assert chain != null;
+ if (chain.getTargetInvoker() == null) {
+ TargetException e = new TargetException("No target invoker configured for operation");
+ e.setIdentifier(chain.getMethod().getName());
+ throw e;
+ }
+ if (chain.getTargetInvoker().isCacheable()) {
+ // clone and store the invoker locally
+ holder.cachedInvoker = (TargetInvoker) chain.getTargetInvoker().clone();
+ invoker = holder.cachedInvoker;
+ } else {
+ invoker = chain.getTargetInvoker();
+ }
+ } else {
+ 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);
+ return msg.getRelatedCallbackMessage();
+
+ } 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;
+ }
+ }
+ }
+
+ /**
+ * A holder used to associate an wire chain with a local copy of a target invoker that was previously
+ * cloned from the chain master
+ */
+ private class ChainHolder {
+
+ TargetInvocationChain chain;
+ TargetInvoker cachedInvoker;
+
+ public ChainHolder(TargetInvocationChain config) {
+ this.chain = config;
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org