summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-sca-runtime
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-02-25 23:00:57 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-02-25 23:00:57 +0000
commitd7c15da034109074d717d3f9f0c3325a54b597dd (patch)
tree553365305a3bad892346fb83cf92187b24ca0288 /sca-java-2.x/trunk/modules/binding-sca-runtime
parentf026711cd4af3326d8e40a428954f822f65e4c80 (diff)
Add the check for local-by-reference, local-by-value and remote invocations for binding.sca
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@916483 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-sca-runtime')
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java56
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java52
2 files changed, 54 insertions, 54 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java
index ec4e893b5f..3ace5a7d01 100644
--- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java
@@ -29,11 +29,14 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.interfacedef.Compatibility;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.InvocationChain;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.EndpointReferenceProvider;
import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -41,6 +44,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.oasisopen.sca.ServiceRuntimeException;
import org.oasisopen.sca.ServiceUnavailableException;
/**
@@ -52,7 +56,7 @@ import org.oasisopen.sca.ServiceUnavailableException;
*
* @version $Rev$ $Date$
*/
-public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvider {
+public class RuntimeSCAReferenceBindingProvider implements EndpointReferenceProvider {
private static final Logger logger = Logger.getLogger(RuntimeSCAReferenceBindingProvider.class.getName());
@@ -66,6 +70,7 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
private ReferenceBindingProvider distributedProvider = null;
private SCABindingFactory scaBindingFactory;
private Mediator mediator;
+ private InterfaceContractMapper interfaceContractMapper;
public RuntimeSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints,
RuntimeEndpointReference endpointReference) {
@@ -85,10 +90,14 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
(BindingProviderFactory<DistributedSCABinding>)factoryExtensionPoint
.getProviderFactory(DistributedSCABinding.class);
- this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ this.mediator = utilities.getUtility(Mediator.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
}
public boolean isTargetRemote() {
+ return endpointReference.getTargetEndpoint().isRemote();
+ /*
boolean targetIsRemote = false;
// The decision is based on the results of the wiring process in the assembly model
@@ -119,6 +128,7 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
targetIsRemote = false;
}
return targetIsRemote;
+ */
}
private ReferenceBindingProvider getDistributedProvider() {
@@ -127,14 +137,14 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
// initialize the remote provider if it hasn't been done already
if (distributedProvider == null) {
if (reference.getInterfaceContract() != null && !reference.getInterfaceContract().getInterface().isRemotable()) {
- throw new IllegalStateException("Reference interface not remotable for component: " + component
+ throw new ServiceRuntimeException("Reference interface not remotable for component: " + component
.getName()
+ " and reference: "
+ reference.getName());
}
if (distributedProviderFactory == null) {
- throw new IllegalStateException("No distributed SCA binding available for component: " + component
+ throw new ServiceRuntimeException("No distributed SCA binding available for component: " + component
.getName()
+ " and reference: "
+ reference.getName());
@@ -182,6 +192,7 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
return false;
}
}
+
private Invoker getInvoker(RuntimeEndpointReference epr, Operation operation) {
Endpoint target = epr.getTargetEndpoint();
@@ -190,10 +201,24 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
if (service != null) { // not a callback wire
InvocationChain chain = ((RuntimeEndpoint) target).getInvocationChain(operation);
+ boolean passByValue = false;
+ Operation targetOp = chain.getTargetOperation();
+ if (!operation.getInterface().isRemotable()) {
+ if (interfaceContractMapper.isCompatibleByReference(operation, targetOp, Compatibility.SUBSET)) {
+ passByValue = false;
+ }
+ } else {
+ boolean allowsPBR = chain.allowsPassByReference();
+ if (allowsPBR && interfaceContractMapper.isCompatibleByReference(operation, targetOp, Compatibility.SUBSET)) {
+ passByValue = false;
+ } else if (interfaceContractMapper.isCompatibleByValue(operation, targetOp, Compatibility.SUBSET)) {
+ passByValue = true;
+ }
+ }
// it turns out that the chain source and target operations are the same, and are the operation
// from the target, not sure if thats by design or a bug. The SCA binding invoker needs to know
// the source and target class loaders so pass in the real source operation in the constructor
- return chain == null ? null : new SCABindingInvoker(chain, operation, mediator);
+ return chain == null ? null : new SCABindingInvoker(chain, operation, mediator, passByValue);
}
}
return null;
@@ -221,25 +246,32 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
public void start() {
if (started) {
return;
- } else {
- started = true;
- }
-
+ }
if (getDistributedProvider() != null) {
distributedProvider.start();
}
+ started = true;
}
public void stop() {
if (!started) {
return;
- } else {
+ }
+
+ try {
+ if (getDistributedProvider() != null) {
+ distributedProvider.stop();
+ }
+ } finally {
started = false;
}
+ }
- if (getDistributedProvider() != null) {
- distributedProvider.stop();
+ public void configure() {
+ if (distributedProvider instanceof EndpointReferenceProvider) {
+ ((EndpointReferenceProvider)distributedProvider).configure();
}
+
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java
index 0f46e9390f..cbe836954d 100644
--- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java
@@ -26,6 +26,7 @@ import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.InvocationChain;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.Phase;
/**
* @version $Rev$ $Date$
@@ -35,25 +36,25 @@ public class SCABindingInvoker implements Interceptor, DataExchangeSemantics {
private Mediator mediator;
private Operation sourceOperation;
private Operation targetOperation;
- private boolean copyArgs;
-
+ private boolean passByValue;
+
/**
* Construct a SCABindingInvoker that delegates to the service invocaiton chain
*/
- public SCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator) {
+ public SCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator, boolean passByValue) {
super();
this.chain = chain;
this.mediator = mediator;
this.sourceOperation = sourceOperation;
this.targetOperation = chain.getTargetOperation();
- initCopyArgs();
+ this.passByValue = passByValue;
}
/**
* @see org.apache.tuscany.sca.invocation.Interceptor#getNext()
*/
public Invoker getNext() {
- return chain.getHeadInvoker();
+ return chain.getHeadInvoker(Phase.SERVICE_POLICY);
}
/**
@@ -68,13 +69,13 @@ public class SCABindingInvoker implements Interceptor, DataExchangeSemantics {
*/
public Message invoke(Message msg) {
- if (copyArgs) {
+ if (passByValue) {
msg.setBody(mediator.copyInput(msg.getBody(), sourceOperation, targetOperation));
}
-
+
Message resultMsg = getNext().invoke(msg);
-
- if (copyArgs) {
+
+ if (passByValue) {
// Note source and target operation swapped so result is in source class loader
if (resultMsg.isFault()) {
resultMsg.setFaultBody(mediator.copyFault(resultMsg.getBody(), targetOperation, sourceOperation));
@@ -89,39 +90,6 @@ public class SCABindingInvoker implements Interceptor, DataExchangeSemantics {
}
/**
- * Work out if pass-by-value copies or cross classloader copies need to be done
- * - if source and target are in different classloaders
- * - if the interfaces are remotable unless @AllowsPassByReference or
- * a data transformation has been done in the chain
- * - what else?
- * - have a flag to optionally disable copies for individual composite/service/operation
- * to improve the performance of specific local invocations?
- */
- private void initCopyArgs() {
- this.copyArgs = crossClassLoaders() || isRemotable();
- }
-
- private boolean crossClassLoaders() {
- // TODO: for now if the operation is remotable the cross classloader copying will
- // happen automatically but this needs also to check the non-remotable operation classloaders
- return false;
- }
-
- /**
- * Pass-by-value copies are required if the interfaces are remotable unless the
- * implementation uses the @AllowsPassByReference annotation.
- */
- protected boolean isRemotable() {
- if (!sourceOperation.getInterface().isRemotable()) {
- return false;
- }
- if (!chain.getTargetOperation().getInterface().isRemotable()) {
- return false;
- }
- return true;
- }
-
- /**
* @see org.apache.tuscany.sca.invocation.DataExchangeSemantics#allowsPassByReference()
*/
public boolean allowsPassByReference() {