You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/02/13 19:49:36 UTC
svn commit: r507153 - in
/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src:
main/java/org/apache/tuscany/core/databinding/impl/
main/java/org/apache/tuscany/core/implementation/java/
main/java/org/apache/tuscany/core/implementation/p...
Author: svkrish
Date: Tue Feb 13 10:49:35 2007
New Revision: 507153
URL: http://svn.apache.org/viewvc?view=rev&rev=507153
Log:
Enhanced support for 'AllowsPassByReference' to be applied at component implementation method level
Modified:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java?view=diff&rev=507153&r1=507152&r2=507153
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java Tue Feb 13 10:49:35 2007
@@ -49,7 +49,6 @@
public PassByValueWirePostProcessor() {
super();
-
}
/**
@@ -67,21 +66,31 @@
Operation<?> sourceOperation;
DataBinding[] argsDataBindings;
DataBinding resultDataBinding;
+ AtomicComponentExtension targetComponent;
- boolean allowsPassByReference = false;
+ boolean implAllowsPassByReference = false;
+ boolean methodAllowsPassByReference = false;
if (target.getContainer() instanceof AtomicComponentExtension) {
- allowsPassByReference =
+ implAllowsPassByReference =
((AtomicComponentExtension) target.getContainer()).isAllowsPassByReference();
}
- if (target.getServiceContract().isRemotable()
- && !allowsPassByReference) {
- Map<Operation<?>, InboundInvocationChain> chains = target.getInvocationChains();
- for (Map.Entry<Operation<?>, InboundInvocationChain> entry : chains.entrySet()) {
- targetOperation = entry.getKey();
+
+ Map<Operation<?>, InboundInvocationChain> chains = target.getInvocationChains();
+ for (Map.Entry<Operation<?>, InboundInvocationChain> entry : chains.entrySet()) {
+ targetOperation = entry.getKey();
+ methodAllowsPassByReference = false;
+
+ if (target.getContainer() instanceof AtomicComponentExtension) {
+ methodAllowsPassByReference =
+ ((AtomicComponentExtension) target.getContainer()).
+ getPassByReferenceMethods().contains(targetOperation.getName());
+ }
+
+ if (target.getServiceContract().isRemotable()
+ && (!implAllowsPassByReference && !methodAllowsPassByReference)) {
sourceOperation =
getSourceOperation(source.getInvocationChains().keySet(), targetOperation.getName());
-
-
+
if (null != sourceOperation) {
argsDataBindings = resolveArgsDataBindings(targetOperation);
resultDataBinding = resolveResultDataBinding(targetOperation);
@@ -100,38 +109,47 @@
// Check if there's a callback
Map callbackOperations = source.getServiceContract().getCallbackOperations();
- allowsPassByReference = false;
- if (source.getContainer() instanceof AtomicComponentExtension) {
- allowsPassByReference =
- ((AtomicComponentExtension) source.getContainer()).isAllowsPassByReference();
- }
-
- if (source.getServiceContract().isRemotable()
- && !allowsPassByReference
- && callbackOperations != null
- && !callbackOperations.isEmpty()) {
+ implAllowsPassByReference = false;
+
+ if (callbackOperations != null && !callbackOperations.isEmpty()) {
+ if (source.getContainer() instanceof AtomicComponentExtension) {
+ implAllowsPassByReference =
+ ((AtomicComponentExtension) source.getContainer()).isAllowsPassByReference();
+ }
+
Object targetAddress = source.getContainer().getName();
Map<Operation<?>, InboundInvocationChain> callbackChains = source.getTargetCallbackInvocationChains();
for (Map.Entry<Operation<?>, InboundInvocationChain> entry : callbackChains.entrySet()) {
targetOperation = entry.getKey();
- sourceOperation =
- getSourceOperation(target.getSourceCallbackInvocationChains(targetAddress).keySet(),
- targetOperation.getName());
-
- argsDataBindings = resolveArgsDataBindings(targetOperation);
- resultDataBinding = resolveResultDataBinding(targetOperation);
-
- passByValueInterceptor = new PassByValueInterceptor();
- passByValueInterceptor.setDataBinding(getDataBinding(targetOperation));
- passByValueInterceptor.setArgsDataBindings(argsDataBindings);
- passByValueInterceptor.setResultDataBinding(resultDataBinding);
-
- entry.getValue().addInterceptor(0, passByValueInterceptor);
- tailInterceptor =
- target.getSourceCallbackInvocationChains(targetAddress).get(sourceOperation)
- .getTailInterceptor();
- if (tailInterceptor != null) {
- tailInterceptor.setNext(passByValueInterceptor);
+ methodAllowsPassByReference = false;
+
+ if (source.getContainer() instanceof AtomicComponentExtension) {
+ methodAllowsPassByReference =
+ ((AtomicComponentExtension) source.getContainer()).
+ getPassByReferenceMethods().contains(targetOperation.getName());
+ }
+
+ if (source.getServiceContract().isRemotable()
+ && (!implAllowsPassByReference && !methodAllowsPassByReference)) {
+ sourceOperation =
+ getSourceOperation(target.getSourceCallbackInvocationChains(targetAddress).keySet(),
+ targetOperation.getName());
+
+ argsDataBindings = resolveArgsDataBindings(targetOperation);
+ resultDataBinding = resolveResultDataBinding(targetOperation);
+
+ passByValueInterceptor = new PassByValueInterceptor();
+ passByValueInterceptor.setDataBinding(getDataBinding(targetOperation));
+ passByValueInterceptor.setArgsDataBindings(argsDataBindings);
+ passByValueInterceptor.setResultDataBinding(resultDataBinding);
+
+ entry.getValue().addInterceptor(0, passByValueInterceptor);
+ tailInterceptor =
+ target.getSourceCallbackInvocationChains(targetAddress).get(sourceOperation)
+ .getTailInterceptor();
+ if (tailInterceptor != null) {
+ tailInterceptor.setNext(passByValueInterceptor);
+ }
}
}
}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java?view=diff&rev=507153&r1=507152&r2=507153
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java Tue Feb 13 10:49:35 2007
@@ -135,7 +135,10 @@
handleCallbackSites(componentType, configuration);
// FIXME JFM this should be refactored to be by operation
+ // as per the Java C&I @AllowsPassByReference can be at the class level (applying to all methods in
+ //...the class or at the method level applying only to the specific method
component.setAllowsPassByReference(componentType.isAllowsPassByReference());
+ component.setPassByReferenceMethods(componentType.getPassByReferenceMethods());
if (componentType.getConversationIDMember() != null) {
component.addConversationIDFactory(componentType.getConversationIDMember());
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java?view=diff&rev=507153&r1=507152&r2=507153
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java Tue Feb 13 10:49:35 2007
@@ -18,6 +18,8 @@
*/
package org.apache.tuscany.core.implementation.processor;
+import java.lang.reflect.Method;
+
import org.osoa.sca.annotations.AllowsPassByReference;
import org.apache.tuscany.spi.component.CompositeComponent;
@@ -31,15 +33,15 @@
/**
* Processes {@link AllowsPassByReference} on an implementation
- *
+ *
* @version $Rev: 479093 $ $Date: 2006-11-25 12:34:41 +0530 (Sat, 25 Nov 2006) $
*/
public class AllowsPassByReferenceProcessor extends ImplementationProcessorExtension {
- public <T> void visitClass(CompositeComponent parent, Class<T> clazz,
+ public <T> void visitClass(CompositeComponent parent,
+ Class<T> clazz,
PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context)
- throws ProcessingException {
+ DeploymentContext context) throws ProcessingException {
AllowsPassByReference annotation = clazz.getAnnotation(AllowsPassByReference.class);
if (annotation != null) {
type.setAllowsPassByReference(true);
@@ -47,5 +49,15 @@
type.setAllowsPassByReference(false);
}
+ }
+
+ public void visitMethod(CompositeComponent parent, Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)throws ProcessingException {
+
+ AllowsPassByReference annotation = method.getAnnotation(AllowsPassByReference.class);
+ if (annotation != null) {
+ type.getPassByReferenceMethods().add(method.getName());
+ }
}
}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java?view=diff&rev=507153&r1=507152&r2=507153
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java Tue Feb 13 10:49:35 2007
@@ -20,6 +20,7 @@
package org.apache.tuscany.core.databinding.impl;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
@@ -80,14 +81,15 @@
inChainsMap.put(operation1, inChain);
AtomicComponentExtension componentExtn = new FooComponent();
+ componentExtn.setPassByReferenceMethods(new ArrayList<String>());
Map<Operation<?>, OutboundInvocationChain> outChainsMap =
new Hashtable<Operation<?>, OutboundInvocationChain>();
OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
outChainsMap.put(operation1, outChain);
- expect(inboundWire.getContainer()).andReturn(componentExtn).times(2);
- expect(outboundWire.getContainer()).andReturn(componentExtn).times(2);
+ expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
+ expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
expect(inboundWire.getServiceContract()).andReturn(serviceContract);
expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
expect(outboundWire.getServiceContract()).andReturn(serviceContract).times(2);
@@ -125,6 +127,7 @@
AtomicComponentExtension componentExtn = new FooComponent();
componentExtn.setAllowsPassByReference(true);
+ componentExtn.setPassByReferenceMethods(new ArrayList<String>());
Map<Operation<?>, OutboundInvocationChain> outChainsMap =
@@ -132,11 +135,57 @@
OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
outChainsMap.put(operation1, outChain);
- expect(inboundWire.getContainer()).andReturn(componentExtn).times(2);
- expect(outboundWire.getContainer()).andReturn(componentExtn).times(2);
+ expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
+ expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
expect(inboundWire.getServiceContract()).andReturn(serviceContract);
expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
- expect(outboundWire.getServiceContract()).andReturn(serviceContract).times(2);
+ expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes();
+ expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
+
+ Interceptor inInterceptor = createMock(Interceptor.class);
+ Interceptor outInterceptor = createMock(Interceptor.class);
+ inChain.addInterceptor(0, inInterceptor);
+ outChain.addInterceptor(0, outInterceptor);
+ outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
+
+ EasyMock.replay(inboundWire, outboundWire);
+ processor.process(outboundWire, inboundWire);
+
+ assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
+ assertEquals(false,
+ outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
+ assertEquals(true, outChain.getTailInterceptor().getNext().equals(
+ inChain.getHeadInterceptor()));
+ }
+
+ public void testProcessExclusionOfInterceptorWhenAllowsPassByReferenceAtMethod() {
+ InboundWire inboundWire = createMock(InboundWire.class);
+ OutboundWire outboundWire = createMock(OutboundWire.class);
+
+ ServiceContract<Type> serviceContract = new JavaServiceContract(null);
+ serviceContract.setRemotable(true);
+ Map<Operation<?>, InboundInvocationChain> inChainsMap =
+ new Hashtable<Operation<?>, InboundInvocationChain>();
+
+ Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
+ InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
+ inChainsMap.put(operation1, inChain);
+
+ AtomicComponentExtension componentExtn = new FooComponent();
+ componentExtn.setPassByReferenceMethods(new ArrayList<String>());
+ componentExtn.getPassByReferenceMethods().add("testMethod");
+
+
+ Map<Operation<?>, OutboundInvocationChain> outChainsMap =
+ new Hashtable<Operation<?>, OutboundInvocationChain>();
+ OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
+ outChainsMap.put(operation1, outChain);
+
+ expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
+ expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
+ expect(inboundWire.getServiceContract()).andReturn(serviceContract);
+ expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
+ expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes();
expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
Interceptor inInterceptor = createMock(Interceptor.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org