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/02/16 20:24:23 UTC
svn commit: r378344 - in /incubator/tuscany/java/sca/core/src:
main/java/org/apache/tuscany/core/builder/impl/
main/java/org/apache/tuscany/core/invocation/
test/java/org/apache/tuscany/core/builder/impl/
test/java/org/apache/tuscany/core/invocation/ t...
Author: jmarino
Date: Thu Feb 16 11:24:19 2006
New Revision: 378344
URL: http://svn.apache.org/viewcvs?rev=378344&view=rev
Log:
more unit tests; remove assertion bug on ProxyConfig
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/InvocationConfiguration.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java Thu Feb 16 11:24:19 2006
@@ -64,9 +64,9 @@
.getOperationType());
// if handler is configured, add that
if (targetInvocationConfig.getRequestHandlers() != null) {
- sourceInvocationConfig.addTargetRequestChannel(new MessageChannelImpl(targetInvocationConfig
+ sourceInvocationConfig.setTargetRequestChannel(new MessageChannelImpl(targetInvocationConfig
.getRequestHandlers()));
- sourceInvocationConfig.addTargetResponseChannel(new MessageChannelImpl(targetInvocationConfig
+ sourceInvocationConfig.setTargetResponseChannel(new MessageChannelImpl(targetInvocationConfig
.getResponseHandlers()));
} else {
// no handlers, just connect interceptors
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/InvocationConfiguration.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/InvocationConfiguration.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/InvocationConfiguration.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/InvocationConfiguration.java Thu Feb 16 11:24:19 2006
@@ -27,14 +27,58 @@
import org.apache.tuscany.model.types.OperationType;
/**
- * Represents the proxy configuration information for an operation on a service reference
+ * Represents the source or target-side of a wire, including proxy configuration information and invocation pipeline
+ * (interceptors and handlers) for an operation. Source and target invocation configurations are "bridged" together by a
+ * set of wire builders with the source-side holding references to the target.
+ * <p>
+ * A set of invocation configurations are used by a {@link org.apache.tuscany.core.invocation.spi.ProxyFactory} to
+ * create proxies representing the business interface of the target that are injected onto source references.
+ * <p>
+ * Invocation configurations must contain at least one interceptor and may have 0 to N handlers. Handlers process an
+ * invocation request or response in a one-way fashion. A typical invocation sequence where interceptors and handlers
+ * are configured for both the source and target-side will proceed as follows:
+ * <ol>
+ * <li>The first source interceptor will be called with a message, which will in turn invoke the next interceptor in
+ * the chain
+ * <li>The last source interceptor, which must be of type
+ * {@link org.apache.tuscany.core.invocation.impl.RequestResponseInterceptor} if there are handlers present, will be
+ * invoked. The RR interceptor will in turn pass the message to a
+ * {@link org.apache.tuscany.core.message.channel.MessageChannel} which will invoke all source-side request handlers.
+ * <li> The RR interceptor will then invoke the target-side request <tt>MessageChannel</tt>.
+ * <li> The last source-side handler, an instance of
+ * {@link org.apache.tuscany.core.message.channel.impl.MessageDispatcher}, will invoke the first source-side
+ * interceptor, which in turn will pass the message down the target-side interceptor chain.
+ * <li> If the target is a component instance the last target-side interceptor, an instance of
+ * {@link org.apache.tuscany.core.invocation.impl.InvokerInterceptor} will retrieve the
+ * {@link org.apache.tuscany.core.invocation.TargetInvoker} from the message and call it to invoke the operation on a
+ * target instance. <tt>TargetInvoker</tt>s are help by the source proxy to enable optimizations such as caching of
+ * target instances.
+ * <li> The response is returned up the invocation stack until it reaches the source-side
+ * <tt>RequestResponseInterceptor</tt>, which invokes the target and source-side response channels respectively.
+ * <li> The response is then passed back up the rest of the invocation stack.
+ * </ol>
+ * <p>
+ * The source-to-target bridge may be constructed in any of the following ways:
+ * <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>
+ *
+ * @see org.apache.tuscany.core.builder.WireBuilder
+ * @see org.apache.tuscany.core.invocation.spi.ProxyFactory
+ * @see org.apache.tuscany.core.invocation.TargetInvoker
+ * @see org.apache.tuscany.core.message.channel.impl.MessageDispatcher
*
* @version $Rev$ $Date$
*/
public class InvocationConfiguration {
+ // the operation on the target that will utlimately be invoked
private OperationType operation;
+ // responsible for invoking a target instance, this is held by source-side invocation configurations
private TargetInvoker targetInvoker;
private Interceptor sourceInterceptorChainHead;
@@ -49,27 +93,46 @@
private List<MessageHandler> responseHandlers;
+ // a source-side pointer to target request handlers, if the exist
private MessageChannel targetRequestChannel;
+ // a source-side pointer to target response handlers, if the exist
private MessageChannel targetResponseChannel;
+ /**
+ * Creates an new invocation configuration for the given target operation
+ */
public InvocationConfiguration(OperationType operation) {
assert (operation != null) : "No operation type specified";
this.operation = operation;
}
+ /**
+ * Returns the target operation for the invocation configuration
+ */
public OperationType getOperationType() {
return operation;
}
- public void addTargetRequestChannel(MessageChannel channel) {
+ /**
+ * Used by source-side configurations, sets a pointer to the target-side request channel. This may be null when no
+ * target request handlers exist.
+ */
+ public void setTargetRequestChannel(MessageChannel channel) {
targetRequestChannel = channel;
}
- public void addTargetResponseChannel(MessageChannel channel) {
+ /**
+ * Used by source-side configurations, sets a pointer to the target-side response channel. This may be null when no
+ * target response handlers exist.
+ */
+ public void setTargetResponseChannel(MessageChannel channel) {
targetResponseChannel = channel;
}
+ /**
+ * Adds an interceptor to the invocation chain for source-side configurations
+ */
public void addSourceInterceptor(Interceptor interceptor) {
if (sourceInterceptorChainHead == null) {
sourceInterceptorChainHead = interceptor;
@@ -79,6 +142,9 @@
sourceInterceptorChainTail = interceptor;
}
+ /**
+ * Adds an interceptor to the invocation chain for target-side configurations
+ */
public void addTargetInterceptor(Interceptor interceptor) {
if (targetInterceptorChainHead == null) {
targetInterceptorChainHead = interceptor;
@@ -88,6 +154,9 @@
targetInterceptorChainTail = interceptor;
}
+ /**
+ * Adds an request handler to the invocation chain for either a source- or target-side configuration
+ */
public void addRequestHandler(MessageHandler handler) {
if (requestHandlers == null) {
requestHandlers = new ArrayList<MessageHandler>();
@@ -95,6 +164,9 @@
requestHandlers.add(handler);
}
+ /**
+ * Adds an response handler to the invocation chain for either a source- or target-side configuration
+ */
public void addResponseHandler(MessageHandler handler) {
if (responseHandlers == null) {
responseHandlers = new ArrayList<MessageHandler>();
@@ -102,37 +174,56 @@
responseHandlers.add(handler);
}
- public void setTargetInvoker(TargetInvoker invoker) {
- this.targetInvoker = invoker;
+ /**
+ * Returns the request handler chain for either a source- or target-side configuration
+ */
+ public List<MessageHandler> getRequestHandlers() {
+ return requestHandlers;
}
- public TargetInvoker getTargetInvoker() {
- return targetInvoker;
+ /**
+ * Returns the response handler chain for either a source- or target-side configuration
+ */
+ public List<MessageHandler> getResponseHandlers() {
+ return responseHandlers;
}
+ /**
+ * Returns the head source-side interceptor. This will be null for target-side configurations
+ */
public Interceptor getSourceInterceptor() {
return sourceInterceptorChainHead;
}
+ /**
+ * Returns the head target-side interceptor. On source-side configurations, this will be the head interceptor of the
+ * "bridged" target configuration.
+ */
public Interceptor getTargetInterceptor() {
return targetInterceptorChainHead;
}
- public List<MessageHandler> getRequestHandlers() {
- return requestHandlers;
+ /**
+ * Sets the target invoker to pass down the invocation pipeline on the source-side
+ */
+ public void setTargetInvoker(TargetInvoker invoker) {
+ this.targetInvoker = invoker;
}
- public List<MessageHandler> getResponseHandlers() {
- return responseHandlers;
+ /**
+ * Returns the target invoker that is passed down the invocation pipeline on the source-side
+ */
+ public TargetInvoker getTargetInvoker() {
+ return targetInvoker;
}
/**
- * Build the configuration, link the interceptors and handlers together
+ * Prepares the configuration by linking interceptors and handlers
*/
public void build() {
if (requestHandlers != null && targetInterceptorChainHead != null) {
- // on target side, connect existing handlers and interceptors
+ // on target-side, connect existing handlers and interceptors
MessageHandler messageDispatcher = new MessageDispatcher(targetInterceptorChainHead);
requestHandlers.add(messageDispatcher);
}
@@ -155,7 +246,7 @@
if (targetInterceptorChainHead != null) {
// Connect source interceptor chain directly to target interceptor chain
sourceInterceptorChainTail.setNext(targetInterceptorChainHead);
- //sourceInterceptorChainTail = targetInterceptorChainHead;
+ // sourceInterceptorChainTail = targetInterceptorChainHead;
} else {
// Connect source interceptor chain to the target request channel
Interceptor channelInterceptor = new RequestResponseInterceptor(null, targetRequestChannel, null,
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java Thu Feb 16 11:24:19 2006
@@ -49,7 +49,6 @@
public ProxyConfiguration(QualifiedName targetName, Map<OperationType, InvocationConfiguration> invocationConfigs,
ClassLoader proxyClassLoader, Map<Integer, ScopeContext> scopeContainers, MessageFactory messageFactory) {
assert (invocationConfigs != null) : "No invocation configuration map specified";
- assert (targetName != null) : "No target name specified";
this.targetName = targetName;
configurations = invocationConfigs;
this.scopeContainers = scopeContainers;
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java Thu Feb 16 11:24:19 2006
@@ -213,7 +213,7 @@
Assert.assertEquals(1, targetInterceptor.getCount());
}
- public void testWireWithInterceptorsOnly() throws Exception {
+ public void testWireWithSourceAndTargetInterceptors() throws Exception {
MessageFactory msgFactory = new PojoMessageFactory();
OperationType operation = new MockJavaOperationType(hello);
@@ -365,6 +365,50 @@
Assert.assertEquals("foo", response.getPayload());
Assert.assertEquals(1, targetRequestHandler.getCount());
Assert.assertEquals(1, targetResponseHandler.getCount());
+ Assert.assertEquals(1, targetInterceptor.getCount());
+ }
+
+ public void testWireWithTargetInterceptor() throws Exception {
+ MessageFactory msgFactory = new PojoMessageFactory();
+ OperationType operation = new MockJavaOperationType(hello);
+
+ InvocationConfiguration source = new InvocationConfiguration(operation);
+
+ ProxyFactory sourceFactory = new JDKProxyFactory();
+ Map<OperationType, InvocationConfiguration> sourceInvocationConfigs = new HashMap();
+ sourceInvocationConfigs.put(operation, source);
+ ProxyConfiguration sourceConfig = new ProxyConfiguration(new QualifiedName("target/SimpleTarget"),
+ sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), null, msgFactory);
+ sourceFactory.setProxyConfiguration(sourceConfig);
+ sourceFactory.setBusinessInterface(SimpleTarget.class);
+
+ InvocationConfiguration target = new InvocationConfiguration(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ target.addTargetInterceptor(targetInterceptor);
+ target.addTargetInterceptor(new InvokerInterceptor());
+
+ ProxyFactory targetFactory = new JDKProxyFactory();
+ Map<OperationType, InvocationConfiguration> targetInvocationConfigs = new HashMap();
+ targetInvocationConfigs.put(operation, target);
+ ProxyConfiguration targetConfig = new ProxyConfiguration(new QualifiedName("target/SimpleTarget"),
+ targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), null, msgFactory);
+ targetFactory.setProxyConfiguration(targetConfig);
+ targetFactory.setBusinessInterface(SimpleTarget.class);
+
+ // connect the source to the target
+ DefaultWireBuilder builder = new DefaultWireBuilder();
+ // no need for scopes since we use a static invoker
+ builder.wire(sourceFactory, targetFactory, null, true, null);
+ target.build();
+ // set a static invoker
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Message msg = new PojoMessageImpl();
+ msg.setPayload("foo");
+ msg.setTargetInvoker(invoker);
+ Message response = (Message) source.getSourceInterceptor().invoke(msg);
+ Assert.assertEquals("foo", response.getPayload());
Assert.assertEquals(1, targetInterceptor.getCount());
}
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java Thu Feb 16 11:24:19 2006
@@ -74,8 +74,8 @@
target.addTargetInterceptor(new InvokerInterceptor());
// connect the source to the target
- source.addTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
- source.addTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
+ source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
+ source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
@@ -109,8 +109,8 @@
target.addTargetInterceptor(new InvokerInterceptor());
// connect the source to the target
- source.addTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
- source.addTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
+ source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
+ source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java Thu Feb 16 11:24:19 2006
@@ -72,8 +72,8 @@
target.addTargetInterceptor(new InvokerInterceptor());
// connect the source to the target
- source.addTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
- source.addTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
+ source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
+ source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
@@ -108,8 +108,8 @@
target.addTargetInterceptor(new InvokerInterceptor());
// connect the source to the target
- source.addTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
- source.addTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
+ source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
+ source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java?rev=378344&r1=378343&r2=378344&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java Thu Feb 16 11:24:19 2006
@@ -106,8 +106,8 @@
target.addTargetInterceptor(new InvokerInterceptor());
// connect the source to the target
- source.addTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
- source.addTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
+ source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
+ source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
MockStaticInvoker invoker = new MockStaticInvoker(m, new SimpleTargetImpl());