diff options
Diffstat (limited to 'java/sca/modules/core/src')
8 files changed, 223 insertions, 80 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java index de304ac3b5..1d6b652402 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointReference2; +import org.apache.tuscany.sca.assembly.EndpointRegistry; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; @@ -82,6 +83,7 @@ import org.apache.tuscany.sca.work.WorkScheduler; public class CompositeActivatorImpl2 implements CompositeActivator { private static final Logger logger = Logger.getLogger(CompositeActivatorImpl2.class.getName()); + private final ExtensionPointRegistry extensionPoints; private final AssemblyFactory assemblyFactory; private final MessageFactory messageFactory; private final InterfaceContractMapper interfaceContractMapper; @@ -95,6 +97,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { private final ProxyFactory proxyFactory; private final JavaInterfaceFactory javaInterfaceFactory; private final PropertyValueFactory propertyValueFactory; + private final EndpointRegistry endpointRegistry; private final ConversationManager conversationManager; @@ -103,6 +106,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { private Composite domainComposite; public CompositeActivatorImpl2(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; this.compositeContext = new CompositeContextImpl(extensionPoints); FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); this.assemblyFactory = factories.getFactory(AssemblyFactory.class); @@ -120,6 +124,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { this.requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); proxyFactory = compositeContext.getProxyFactory(); this.conversationManager = compositeContext.getConversationManager(); + this.endpointRegistry = utilities.getUtility(EndpointRegistry.class); } //========================================================================= @@ -376,7 +381,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator { endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding())); // create the wire - RuntimeWire wire = new RuntimeWireImpl2(false, + RuntimeWire wire = new RuntimeWireImpl2(extensionPoints, + false, endpointReference, endpoint, interfaceContractMapper, @@ -416,14 +422,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { if (logger.isLoggable(Level.FINE)) { logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName()); } - - // TODO this may need to move into the code where we check that an endpoint is resolved - for (EndpointReference2 endpointReference : reference.getEndpointReferences()) { - if (endpointReference.getBinding() != null){ - addReferenceBindingProvider(component, reference, endpointReference.getBinding()); - } - } - + // set the parent component onto the reference. It's used at start time when the // reference is asked to return it's runtime wires. If there are none the reference // asks the component context to start the reference which creates the wires @@ -443,7 +442,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { } } } - +/* private ReferenceBindingProvider addReferenceBindingProvider( RuntimeComponent component, RuntimeComponentReference reference, Binding binding) { @@ -476,7 +475,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { + binding.getClass().getName()); } } - +*/ private void removeReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, Binding binding) { reference.setBindingProvider(binding, null); @@ -535,29 +534,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator { } configureComponentContext(runtimeComponent); - -/* TODO - EPR won't start until reference is actually started later - for (ComponentReference reference : component.getReferences()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); - } - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); - runtimeRef.setComponent(runtimeComponent); - - for (Binding binding : reference.getBindings()) { - final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); - if (bindingProvider != null) { - // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.start(); - return null; - } - }); - } - } - } -*/ + + // Reference bindings aren't started until the wire is first used for (ComponentService service : component.getServices()) { if (logger.isLoggable(Level.FINE)) { @@ -565,6 +543,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { } RuntimeComponentService runtimeService = (RuntimeComponentService)service; for (Endpoint2 endpoint : service.getEndpoints()) { + endpointRegistry.addEndpoint(endpoint); final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding()); if (bindingProvider != null) { // bindingProvider.start(); @@ -611,6 +590,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName()); } for (Endpoint2 endpoint : service.getEndpoints()) { + endpointRegistry.removeEndpoint(endpoint); final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding()); if (bindingProvider != null) { // Allow bindings to read properties. Requires PropertyPermission read in security policy. @@ -689,6 +669,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { return; } + /* The way it was // create a wire for each endpoint reference. An endpoint reference says that a // target has been specified and hence the reference has been wired in some way. // The service may not have been found yet, depending on the way the composite @@ -725,7 +706,21 @@ public class CompositeActivatorImpl2 implements CompositeActivator { // add the wire addReferenceWire(component, componentReference, endpointReference); } - } + } + */ + + // create a wire for each endpoint reference. An endpoint reference says either that + // - a target has been specified and hence the reference has been wired in some way. + // - an unwired binding ha been specified + // and endpoint reference representing a wired reference may not at this point + // be resolved (the service to which it points may not be present in the + // current composite). Endpoint reference resolution takes place when the wire + // is first used (when the chains are created) + for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){ + addReferenceWire(component, componentReference, endpointReference); + endpointRegistry.addEndpointReference(endpointReference); + } + } } @@ -735,6 +730,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { } RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); for ( EndpointReference2 endpointReference : runtimeRef.getEndpointReferences()){ + endpointRegistry.removeEndpointReference(endpointReference); ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding()); if (bindingProvider != null) { bindingProvider.stop(); @@ -759,6 +755,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator { // TODO - EPR - interface contract seems to be null in the implementation.web // case. Not introspecting the CT properly? if (sourceContract == null){ + // TODO - Can't do this with move of matching to wire // take the contract from the service to which the reference is connected sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract(); reference.setInterfaceContract(sourceContract); @@ -790,9 +787,11 @@ public class CompositeActivatorImpl2 implements CompositeActivator { } */ +/* TODO - EPR can't do this until the binding matches the EPR InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding()); Endpoint2 endpoint = endpointReference.getTargetEndpoint(); endpoint.setInterfaceContract(bindingContract); +*/ /* TODO - EPR review in the light of new matching code // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a @@ -803,9 +802,12 @@ public class CompositeActivatorImpl2 implements CompositeActivator { */ // create the wire - RuntimeWire wire = new RuntimeWireImpl2(true, + // null endpoint passed in here as the endpoint reference may + // not be resolved yet + RuntimeWire wire = new RuntimeWireImpl2(extensionPoints, + true, endpointReference, - endpoint, + null, interfaceContractMapper, workScheduler, wireProcessor, diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java index 754f6063cb..3911d6dd49 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java @@ -20,6 +20,8 @@ package org.apache.tuscany.sca.core.assembly.impl; import java.lang.reflect.InvocationTargetException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; @@ -29,6 +31,11 @@ import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointReference2; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.conversation.ConversationManager; import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker; @@ -42,9 +49,13 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; import org.apache.tuscany.sca.provider.PolicyProviderRRB; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; import org.apache.tuscany.sca.provider.ServiceBindingProvider; @@ -62,6 +73,9 @@ import org.oasisopen.sca.ServiceRuntimeException; * @version $Rev$ $Date$ */ public class RuntimeWireImpl2 implements RuntimeWire { + + private ExtensionPointRegistry extensionPoints; + private Boolean isReferenceWire = false; private EndpointReference2 endpointReference; private Endpoint2 endpoint; @@ -82,6 +96,9 @@ public class RuntimeWireImpl2 implements RuntimeWire { private List<InvocationChain> chains; private InvocationChain bindingInvocationChain; + + private EndpointReferenceBuilder endpointReferenceBuilder; + private final ProviderFactoryExtensionPoint providerFactories; /** * @param source @@ -92,7 +109,8 @@ public class RuntimeWireImpl2 implements RuntimeWire { * @param messageFactory * @param conversationManager */ - public RuntimeWireImpl2(boolean isReferenceWire, + public RuntimeWireImpl2(ExtensionPointRegistry extensionPoints, + boolean isReferenceWire, EndpointReference2 endpointReference, Endpoint2 endpoint, InterfaceContractMapper interfaceContractMapper, @@ -101,6 +119,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { MessageFactory messageFactory, ConversationManager conversationManager) { super(); + this.extensionPoints = extensionPoints; this.isReferenceWire = isReferenceWire; this.endpointReference = endpointReference; this.endpoint = endpoint; @@ -110,6 +129,10 @@ public class RuntimeWireImpl2 implements RuntimeWire { this.messageFactory = messageFactory; this.conversationManager = conversationManager; this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class); + this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); } public synchronized List<InvocationChain> getInvocationChains() { @@ -164,12 +187,15 @@ public class RuntimeWireImpl2 implements RuntimeWire { * Initialize the invocation chains */ private void initInvocationChains() { + chains = new ArrayList<InvocationChain>(); InterfaceContract sourceContract = endpointReference.getInterfaceContract(); - InterfaceContract targetContract = endpoint.getInterfaceContract(); if (isReferenceWire) { // It's the reference wire + resolveEndpointReference(); + + InterfaceContract targetContract = endpoint.getInterfaceContract(); RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference(); Binding refBinding = endpointReference.getBinding(); for (Operation operation : sourceContract.getInterface().getOperations()) { @@ -191,6 +217,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { } else { // It's the service wire + InterfaceContract targetContract = endpoint.getInterfaceContract(); RuntimeComponentService service = (RuntimeComponentService)endpoint.getService(); RuntimeComponent serviceComponent = (RuntimeComponent)endpoint.getComponent(); Binding serviceBinding = endpoint.getBinding(); @@ -216,6 +243,88 @@ public class RuntimeWireImpl2 implements RuntimeWire { wireProcessor.process(this); } + /** + * This code used to be in the activator but has moved here as + * the endpoint reference may not now be resolved until the wire + * is first used + */ + private void resolveEndpointReference(){ + endpointReferenceBuilder.build(endpointReference, null); + + // set the endpoint based on the resolved endpoint + endpoint = endpointReference.getTargetEndpoint(); + + RuntimeComponentReference runtimeRef = (RuntimeComponentReference)endpointReference.getReference(); + + if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) { + addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(), + runtimeRef, + endpointReference.getBinding()); + } + + // start the binding provider + final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding()); + + if (bindingProvider != null) { + // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. + AccessController.doPrivileged(new PrivilegedAction<Object>() { + public Object run() { + bindingProvider.start(); + return null; + } + }); + } + + InterfaceContract bindingContract = getInterfaceContract(endpointReference.getReference(), endpointReference.getBinding()); + Endpoint2 endpoint = endpointReference.getTargetEndpoint(); + endpoint.setInterfaceContract(bindingContract); + } + + private ReferenceBindingProvider addReferenceBindingProvider( + RuntimeComponent component, RuntimeComponentReference reference, + Binding binding) { + BindingProviderFactory providerFactory = (BindingProviderFactory) providerFactories + .getProviderFactory(binding.getClass()); + if (providerFactory != null) { + @SuppressWarnings("unchecked") + ReferenceBindingProvider bindingProvider = providerFactory + .createReferenceBindingProvider( + (RuntimeComponent) component, + (RuntimeComponentReference) reference, binding); + if (bindingProvider != null) { + ((RuntimeComponentReference) reference).setBindingProvider( + binding, bindingProvider); + } + for (PolicyProviderFactory f : providerFactories + .getPolicyProviderFactories()) { + PolicyProvider policyProvider = f + .createReferencePolicyProvider(component, reference, + binding); + if (policyProvider != null) { + reference.addPolicyProvider(binding, policyProvider); + } + } + + return bindingProvider; + } else { + throw new IllegalStateException( + "Provider factory not found for class: " + + binding.getClass().getName()); + } + } + + private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) { + InterfaceContract interfaceContract = reference.getInterfaceContract(); + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract.makeUnidirectional(false); + } + private void initReferenceBindingInvocationChains() { RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference(); Binding referenceBinding = endpointReference.getBinding(); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java index 205ad6a62c..e0ef3d5c97 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java @@ -81,9 +81,6 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { protected transient RuntimeComponent component; protected transient RuntimeComponentReference reference; - // TODO - EPR - remove wire indexing on bindings as enpoint references - // can share reference bindings - protected transient Binding binding; protected transient EndpointReference2 endpointReference; protected String scdl; @@ -110,36 +107,33 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { protected CallableReferenceImpl(Class<B> businessInterface, RuntimeComponent component, RuntimeComponentReference reference, - Binding binding, + EndpointReference2 endpointReference, ProxyFactory proxyFactory, CompositeActivator compositeActivator) { this.proxyFactory = proxyFactory; this.businessInterface = businessInterface; this.component = component; this.reference = reference; - this.binding = binding; + this.endpointReference = endpointReference; // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference - if (this.binding == null) { - this.binding = this.reference.getBinding(SCABinding.class); - if (this.binding == null) { - - // TODO: TUSCANY-2580: if the refernece doesn't have a binding yet then instead of NPE use a candidate one if its avaialable - if (reference.getBindings() != null && reference.getBindings().size() > 0) { - this.binding = this.reference.getBindings().get(0); - } + if (this.endpointReference == null) { + + // TODO - EPR - If no endpoint reference specified assume the first one + // This will happen when a self reference is created in which case the + // the reference should only have on endpointReference so use that + if (this.reference.getEndpointReferences().size() == 0){ + throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " + + component.getName() + " has no endpoint references"); } - // TODO - EPR - If no binding specified assume default binding and find the endpoint reference - // related to it - for (EndpointReference2 endpointReference : this.reference.getEndpointReferences()){ - if ((endpointReference.getBinding() != null) && - (endpointReference.getBinding() instanceof SCABinding)){ - this.endpointReference = endpointReference; - break; - } + if (this.reference.getEndpointReferences().size() > 1){ + throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " + + component.getName() + " has more than one endpoint reference"); } + + this.endpointReference = this.reference.getEndpointReferences().get(0); } // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding? @@ -160,8 +154,6 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { resolve(); if (endpointReference != null){ return reference.getRuntimeWire(endpointReference); - } else if (reference != null) { - return reference.getRuntimeWire(binding); } else { return null; } @@ -174,7 +166,6 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { if (wire != null) { this.component = wire.getSource().getComponent(); this.reference = (RuntimeComponentReference)wire.getSource().getContract(); - this.binding = wire.getSource().getBinding(); this.endpointReference = wire.getEndpointReference(); this.compositeActivator = ((ComponentContextExt)component.getComponentContext()).getCompositeActivator(); this.conversationManager = this.compositeActivator.getCompositeContext().getConversationManager(); @@ -276,6 +267,8 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { /** * @throws IOException */ + // TODO - EPR all needs sorting out for endpoint references + private synchronized void resolve() throws Exception { if ((scdl != null || xmlReader != null) && component == null && reference == null) { CompositeContext componentContextHelper = CompositeContext.getCurrentCompositeContext(); @@ -308,6 +301,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { attachConversation(parameters.getConversationID()); } + // TODO - EPR all needs sorting out for endpoint references for (Binding binding : reference.getBindings()) { if (binding instanceof OptimizableBinding) { // Resolve the Component @@ -341,6 +335,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { } } } +/* // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference if (binding == null) { @@ -349,6 +344,8 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { binding = reference.getBindings().get(0); } } +*/ + Interface i = reference.getInterfaceContract().getInterface(); if (i instanceof JavaInterface) { JavaInterface javaInterface = (JavaInterface)i; @@ -370,9 +367,11 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { } this.businessInterface = (Class<B>)javaInterface.getJavaClass(); } +/* if (binding instanceof BindingBuilderExtension) { ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null); } +*/ this.proxyFactory = compositeActivator.getCompositeContext().getProxyFactory(); } } else { @@ -508,6 +507,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { return parameters; } + // TODO - EPR - needs sorting out for new endpoint references public EndpointReference getEndpointReference() { try { resolve(); @@ -517,7 +517,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { InterfaceContract sourceContract = componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract(); sourceContract = sourceContract.makeUnidirectional(false); - EndpointReference epr = new EndpointReferenceImpl(component, reference, binding, sourceContract); + EndpointReference epr = new EndpointReferenceImpl(component, reference, null /*binding*/, sourceContract); ReferenceParameters parameters = getReferenceParameters(); epr.setReferenceParameters(parameters); return epr; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index 0b4c33c341..d1bbf4b475 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -215,7 +215,7 @@ public class ComponentContextImpl implements ComponentContextExt { */ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, RuntimeComponentReference reference, - Binding binding) { + EndpointReference2 endpointReference) { try { RuntimeComponentReference ref = (RuntimeComponentReference)reference; InterfaceContract interfaceContract = reference.getInterfaceContract(); @@ -233,7 +233,7 @@ public class ComponentContextImpl implements ComponentContextExt { } } ref.setComponent(component); - return new ServiceReferenceImpl<B>(businessInterface, component, ref, binding, proxyFactory, + return new ServiceReferenceImpl<B>(businessInterface, component, ref, endpointReference, proxyFactory, compositeActivator); } catch (Exception e) { throw new ServiceRuntimeException(e); @@ -452,9 +452,9 @@ public class ComponentContextImpl implements ComponentContextExt { for (ComponentReference ref : component.getReferences()) { if (referenceName.equals(ref.getName())) { ArrayList<ServiceReference<B>> serviceRefs = new ArrayList<ServiceReference<B>>(); - for (Binding binding : ref.getBindings()) { + for (EndpointReference2 endpointReference : ref.getEndpointReferences()) { serviceRefs - .add(getServiceReference(businessInterface, (RuntimeComponentReference)ref, binding)); + .add(getServiceReference(businessInterface, (RuntimeComponentReference)ref, endpointReference)); } return serviceRefs; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java index 8aec07ceda..52f506c6cd 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.core.context.impl; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.context.ServiceReferenceExt; @@ -79,10 +80,10 @@ public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements public ServiceReferenceImpl(Class<B> businessInterface, RuntimeComponent component, RuntimeComponentReference reference, - Binding binding, + EndpointReference2 endpointReference, ProxyFactory proxyFactory, CompositeActivator compositeActivator) { - super(businessInterface, component, reference, binding, proxyFactory, compositeActivator); + super(businessInterface, component, reference, endpointReference, proxyFactory, compositeActivator); } public Object getConversationID() { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java index 8a54b7568f..3f4d03ee92 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.core.invocation; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.factory.ObjectCreationException; import org.apache.tuscany.sca.core.factory.ObjectFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -34,7 +35,7 @@ public class CallableReferenceObjectFactory implements ObjectFactory<CallableRef private Class<?> businessInterface; private RuntimeComponent component; private RuntimeComponentReference reference; - private Binding binding; + private EndpointReference2 endpointReference; /** * Constructor. @@ -49,15 +50,15 @@ public class CallableReferenceObjectFactory implements ObjectFactory<CallableRef public CallableReferenceObjectFactory(Class<?> businessInterface, RuntimeComponent component, RuntimeComponentReference reference, - Binding binding) { + EndpointReference2 endpointReference) { this.businessInterface = businessInterface; this.component = component; this.reference = reference; - this.binding = binding; + this.endpointReference = endpointReference; } public CallableReference<?> getInstance() throws ObjectCreationException { - return component.getComponentContext().getServiceReference(businessInterface, reference, binding); + return component.getComponentContext().getServiceReference(businessInterface, reference, endpointReference); } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java index 301771d879..5071a7ef94 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java @@ -137,6 +137,9 @@ public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> { }
/**
+ * Gets the endpoint reference from the incoming message that points
+ * back to the callback service
+ *
* @param msgContext
*/
private static EndpointReference getCallbackEndpoint(Message msgContext) {
@@ -159,20 +162,34 @@ public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> { RuntimeComponentReference ref = null;
if (contract == null) {
//TODO - EPR - does it ever go through here?
+ // in what situation is there no reference in the endpoint reference
+ // pointing back to the callbac service
boundWire = (RuntimeWire)wire.clone();
} else if (contract instanceof RuntimeComponentReference) {
+ // TODO - EPP - the endpoint reference pointing back to the
+ // callback service holds a reference representing
+ // a reference to the callback service. This is true if a
+ // callback object has been set into the reference on the
+ // client side
ref = (RuntimeComponentReference)contract;
- //TODO - EPR - get the bound wire based on endpont reference no binding
- //boundWire = ref.getRuntimeWire(resolvedEndpoint.getBinding());
+
+ // TODO - EPR - get the wire from the reference that matches the
+ // injected callback reference wire. We don't have bindings yet as the
+ // callback object wire hasn't been initialized
+/*
for (RuntimeWire runtimeWire : ref.getRuntimeWires()){
- if (runtimeWire.getEndpointReference().getBinding().getName().equals(resolvedEndpoint.getBinding().getName())){
+ if (runtimeWire.getEndpointReference().getBinding().getName().equals(wire.getEndpointReference().getBinding().getName())){
boundWire = runtimeWire;
break;
}
}
+*/
+ // just get the first one for now
+ boundWire = ref.getRuntimeWires().get(0);
} else { // contract instanceof RuntimeComponentService
+ //TODO - EPR - I think it does this if no callback object has been set explicitly
ref = bind((RuntimeComponentReference)wire.getSource().getContract(),
resolvedEndpoint);
boundWire = ref.getRuntimeWires().get(0);
@@ -242,7 +259,9 @@ public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> { RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract();
// TODO - EPR
- wire.getEndpointReference().getTargetEndpoint().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
+ // needs to be set after the chains have been created for the first time
+ // as now the binding provider won't be created until that time
+ //wire.getEndpointReference().getTargetEndpoint().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
}
/**
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index 8ef17503c4..a4a2d8c99a 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -149,10 +149,15 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { throw new ServiceRuntimeException("No runtime wire is available"); } InvocationChain chain = getInvocationChain(method, wire); + if (chain == null) { throw new IllegalArgumentException("No matching operation is found: " + method); } + // The EndpointReference is not now resolved until the invocation chain + // is first created so reset the source here + source = wire.getSource(); + // send the invocation down the wire Object result = invoke(chain, args, wire, source); @@ -349,11 +354,17 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID()); } } - + Interface interfaze = msg.getFrom().getCallbackEndpoint().getInterfaceContract().getInterface(); if (callbackObject != null) { if (callbackObject instanceof ServiceReference) { - EndpointReference callbackRef = ((CallableReferenceExt<?>)callbackObject).getEndpointReference(); + CallableReferenceExt<?> callableReference = (CallableReferenceExt<?>)callbackObject; + EndpointReference callbackRef = callableReference.getEndpointReference(); + + // TODO - EPR - create chains on the callback reference in case this hasn't already happened + // needed as the bindings are not now matched until the chanins are created + callableReference.getRuntimeWire().getInvocationChains(); + parameters.setCallbackReference(callbackRef); } else { if (interfaze != null) { |