From b639e688a9d28d9a66ffe71ef3c382fdd63b1d7a Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 8 Jun 2009 09:30:48 +0000 Subject: TUSCANY-3081 - Enable the local endpoint registry implementation in the endpoint module. This delays endpoint reference resolution until chains are first created.Callback processing needs a thorough review as part of the next change to make EndpointReference2 serializable. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@782569 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultCompositeBuilderExtensionPoint.java | 15 +- ...onentReferenceEndpointReferenceBuilderImpl.java | 37 ++++- .../impl/ComponentServiceEndpointBuilderImpl.java | 8 +- .../sca/runtime/RuntimeComponentContext.java | 6 +- .../assembly/impl/CompositeActivatorImpl2.java | 76 +++++----- .../sca/core/assembly/impl/RuntimeWireImpl2.java | 113 ++++++++++++++- .../core/context/impl/CallableReferenceImpl.java | 50 +++---- .../core/context/impl/ComponentContextImpl.java | 8 +- .../core/context/impl/ServiceReferenceImpl.java | 5 +- .../invocation/CallableReferenceObjectFactory.java | 9 +- .../invocation/impl/CallbackReferenceImpl.java | 27 +++- .../core/invocation/impl/JDKInvocationHandler.java | 15 +- .../impl/EndpointReferenceBuilderImpl.java | 158 +++++++++------------ .../invocation/JavaComponentContextProvider.java | 4 +- 14 files changed, 343 insertions(+), 188 deletions(-) (limited to 'java') diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java index 80b95189ec..32444349b2 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java @@ -87,7 +87,7 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx Map attributes = builderDeclaration.getAttributes(); String id = attributes.get("id"); - CompositeBuilder builder = new LazyCompositeBuilder(id, builderDeclaration, this, factories, mapper); + CompositeBuilder builder = new LazyCompositeBuilder(registry, id, builderDeclaration, this, factories, mapper); builders.put(id, builder); } } @@ -98,6 +98,7 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx */ private static class LazyCompositeBuilder implements CompositeBuilder { + private ExtensionPointRegistry registry; private FactoryExtensionPoint factories; private InterfaceContractMapper mapper; private String id; @@ -105,8 +106,9 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx private CompositeBuilder builder; private CompositeBuilderExtensionPoint builders; - private LazyCompositeBuilder(String id, ServiceDeclaration factoryDeclaration, + private LazyCompositeBuilder(ExtensionPointRegistry registry, String id, ServiceDeclaration factoryDeclaration, CompositeBuilderExtensionPoint builders, FactoryExtensionPoint factories, InterfaceContractMapper mapper) { + this.registry = registry; this.id = id; this.builderDeclaration = factoryDeclaration; this.builders = builders; @@ -130,8 +132,13 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx Constructor constructor = builderClass.getConstructor(FactoryExtensionPoint.class, InterfaceContractMapper.class); builder = constructor.newInstance(factories, mapper); } catch (NoSuchMethodException e) { - Constructor constructor = builderClass.getConstructor(CompositeBuilderExtensionPoint.class, FactoryExtensionPoint.class, InterfaceContractMapper.class); - builder = constructor.newInstance(builders, factories, mapper); + try { + Constructor constructor = builderClass.getConstructor(CompositeBuilderExtensionPoint.class, FactoryExtensionPoint.class, InterfaceContractMapper.class); + builder = constructor.newInstance(builders, factories, mapper); + } catch (NoSuchMethodException ex) { + Constructor constructor = builderClass.getConstructor(ExtensionPointRegistry.class); + builder = constructor.newInstance(registry); + } } } catch (Exception e) { throw new IllegalStateException(e); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java index 52b0f79775..b70597a352 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java @@ -210,7 +210,7 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } else { // add an unresolved endpoint reference with an unresolved endpoint to go with it EndpointReference2 endpointRef = createEndpointRef( component, reference, true ); - endpointRef.setTargetEndpoint(createEndpoint(true)); + endpointRef.setTargetEndpoint(createEndpoint(targetName)); reference.getEndpointReferences().add(endpointRef); warning(monitor, "ComponentReferenceTargetNotFound", composite, @@ -342,10 +342,11 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } // end if } // end if // (Debug) For the moment, print out the results - System.out.println( "Created endpointRef. Component = " + component.getName() + " Reference = " + - reference.getName() + " LeafComponent = " + endRef.getComponent().getName() + " LeafReference = " + - endRef.getReference().getName() + " Binding = " + endRef.getBinding() + " target Component = " + - endpoint.getComponent() + " target Service = " + endpoint.getService() ); + // disable for the time being - SL + //System.out.println( "Created endpointRef. Component = " + component.getName() + " Reference = " + + // reference.getName() + " LeafComponent = " + endRef.getComponent().getName() + " LeafReference = " + + // endRef.getReference().getName() + " Binding = " + endRef.getBinding() + " target Component = " + + // endpoint.getComponent() + " target Service = " + endpoint.getService() ); } // end for } // end for @@ -859,4 +860,30 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI return endpoint; } // end method createEndpoint + /** + * Helper method to create an Endpoint + * @param unresolved + * @return the endpoint + */ + private Endpoint2 createEndpoint(String targetName) { + String componentName; + String serviceName; + int i = targetName.lastIndexOf('/'); + if (i != -1) { + componentName = targetName.substring(0, i); + serviceName = targetName.substring(i + 1); + + } else { + componentName = targetName; + serviceName = null; + } + + Endpoint2 endpoint = assemblyFactory.createEndpoint(); + endpoint.setUnresolved(true); + endpoint.setComponentName(componentName); + endpoint.setServiceName(serviceName); + return endpoint; + } // end method createEndpoint + + } // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java index 0e75dab000..e5e97a7190 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java @@ -144,9 +144,11 @@ public class ComponentServiceEndpointBuilderImpl implements CompositeBuilder { leafService.getEndpoints().add(endpoint); } // end if } // end if - System.out.println( "Endpoint created for Component = " + component.getName() + " Leaf component = " + - endpoint.getComponent().getName() + " service = " + - endpoint.getService().getName() + " binding = " + endpoint.getBinding() ); + // debug + // disabled for the time being - SL + //System.out.println( "Endpoint created for Component = " + component.getName() + " Leaf component = " + + // endpoint.getComponent().getName() + " service = " + + // endpoint.getService().getName() + " binding = " + endpoint.getBinding() ); } // end for } // end for // Handle composites as implementations diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java index e63bdf89c7..6d95bbca1c 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java @@ -25,6 +25,7 @@ import java.io.Writer; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.oasisopen.sca.CallableReference; import org.oasisopen.sca.ComponentContext; @@ -61,13 +62,12 @@ public interface RuntimeComponentContext extends ComponentContext { * @param * @param businessInterface The business interface * @param reference The reference to be wired - * @param binding The binding to be used, if it's null, either binding.sca or the 1st binding - * will be selected + * @param endpointReference The endpointReference to be used * @return A service reference representing the wire */ ServiceReference getServiceReference(Class businessInterface, RuntimeComponentReference reference, - Binding binding); + EndpointReference2 endpointReference); /** * Bind the reference to a target component/componentService 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() { - 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 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 getInvocationChains() { @@ -164,12 +187,15 @@ public class RuntimeWireImpl2 implements RuntimeWire { * Initialize the invocation chains */ private void initInvocationChains() { + chains = new ArrayList(); 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() { + 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 implements CallableReferenceExt { 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 implements CallableReferenceExt { protected CallableReferenceImpl(Class 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 implements CallableReferenceExt { 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 implements CallableReferenceExt { 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 implements CallableReferenceExt { /** * @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 implements CallableReferenceExt { 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 implements CallableReferenceExt { } } } +/* // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference if (binding == null) { @@ -349,6 +344,8 @@ public class CallableReferenceImpl implements CallableReferenceExt { 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 implements CallableReferenceExt { } this.businessInterface = (Class)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 implements CallableReferenceExt { return parameters; } + // TODO - EPR - needs sorting out for new endpoint references public EndpointReference getEndpointReference() { try { resolve(); @@ -517,7 +517,7 @@ public class CallableReferenceImpl implements CallableReferenceExt { 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 ServiceReference getServiceReference(Class 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(businessInterface, component, ref, binding, proxyFactory, + return new ServiceReferenceImpl(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> serviceRefs = new ArrayList>(); - 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 extends CallableReferenceImpl implements public ServiceReferenceImpl(Class 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 businessInterface; private RuntimeComponent component; private RuntimeComponentReference reference; - private Binding binding; + private EndpointReference2 endpointReference; /** * Constructor. @@ -49,15 +50,15 @@ public class CallableReferenceObjectFactory implements ObjectFactory 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 extends CallableReferenceImpl { } /** + * 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 extends CallableReferenceImpl { 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 extends CallableReferenceImpl { 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) { diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java index f65ff634b4..327f674b38 100644 --- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java +++ b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java @@ -32,6 +32,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.OptimizableBinding; import org.apache.tuscany.sca.assembly.SCABinding; @@ -40,6 +41,7 @@ import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder; 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.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; @@ -47,6 +49,7 @@ import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.PolicySubject; +import org.oasisopen.sca.SCARuntimeException; /** * An builder that takes endpoint references and resolves them. It either finds local @@ -62,15 +65,19 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR protected ExtensionPointRegistry extensionPoints; protected AssemblyFactory assemblyFactory; protected InterfaceContractMapper interfaceContractMapper; + protected EndpointRegistry endpointRegistry; public EndpointReferenceBuilderImpl(ExtensionPointRegistry extensionPoints) { this.extensionPoints = extensionPoints; - } - - public EndpointReferenceBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) { + + FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); this.assemblyFactory = factories.getFactory(AssemblyFactory.class); - this.interfaceContractMapper = mapper; + + UtilityExtensionPoint utils = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class); + + this.endpointRegistry = utils.getUtility(EndpointRegistry.class); } public String getID() { @@ -121,58 +128,6 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR monitor.problem(problem); } } - - /** - * Index components inside a composite - * - * @param composite - * @param componentServices - - */ - protected void indexComponents(Composite composite, - Map components) { - for (Component component : composite.getComponents()) { - // Index components by name - components.put(component.getName(), component); - } - } - - /** - * Index services inside a composite - * - * @param composite - * @param componentServices - */ - protected void indexServices(Composite composite, - Map componentServices) { - - for (Component component : composite.getComponents()) { - - ComponentService nonCallbackService = null; - int nonCallbackServiceCount = 0; - - for (ComponentService componentService : component.getServices()) { - // Index component services by component name / service name - String uri = component.getName() + '/' + componentService.getName(); - componentServices.put(uri, componentService); - - // count how many non-callback there are - if (!componentService.isCallback()) { - - if (nonCallbackServiceCount == 0) { - nonCallbackService = componentService; - } - nonCallbackServiceCount++; - } - } - if (nonCallbackServiceCount == 1) { - // If we have a single non callback service, index it by - // component name as well - componentServices.put(component.getName(), nonCallbackService); - } - } - } - /** * Build all the endpoint references @@ -181,46 +136,37 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR */ public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { - // process top level composite references - // TODO - I don't think OASIS allows for these - // - //processCompositeReferences(composite); - - // process component services - processComponentReferences(composite, monitor); - } - - private void processCompositeReferences(Composite composite) { - // TODO do we need this for OASIS? + // Not used now } - - private void processComponentReferences(Composite composite, Monitor monitor) { - - // index all of the components in the composite - Map components = new HashMap(); - indexComponents(composite, components); - - // index all of the services in the composite - Map componentServices = new HashMap(); - indexServices(composite, componentServices); + + /* + private void populateEndpointRegistry(Composite composite, Monitor monitor) { - // create endpoint references for each component's references + // register endpoints (and endpoint references) for each component for (Component component : composite.getComponents()) { // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - processComponentReferences((Composite)implementation, monitor); + populateEndpointRegistry((Composite)implementation, monitor); + } + + // register endpoints + for (ComponentService service : component.getServices()) { + for (Endpoint2 endpoint : service.getEndpoints()){ + endpointRegistry.addEndpoint(endpoint); + } } - // build endpoint references + // register endpoint references for (ComponentReference reference : component.getReferences()) { for (EndpointReference2 endpointReference : reference.getEndpointReferences()){ - build(endpointReference, monitor); + endpointRegistry.addEndpointReference(endpointReference); } - } + } } - } - + } + */ + /** * Build a single endpoint reference * @@ -234,23 +180,50 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR // an error? } else { if (endpoint.isUnresolved() == false){ - // everything is resolved + // Wired - service resolved - binding matched + // The service is in the same composite return; } if (endpointReference.isUnresolved() == false ){ - // TODO - bring resolution and binding matching together - // just do binding matching + // Wired - service resolved - binding not matched + // The service is in the same composite + // TODO - How do we get to here? matchForwardBinding(endpointReference, monitor); matchCallbackBinding(endpointReference, monitor); } else { - // resolve the endpoint reference in the domain and then - // match bindings + // Wired - service specified but unresolved + // The service is in a remote composite somewhere else in the domain + + // find the service in the endpoint registry + List endpoints = endpointRegistry.findEndpoint(endpointReference); + + // TODO - do we exepect to find more than one endpoint in + // anything other than the autowire case? + if (endpoints.size() == 0) { + throw new SCARuntimeException("No endpoints found for EndpointReference " + endpointReference.toString()); + } + + if (endpoints.size() > 1) { + throw new SCARuntimeException("More than one endpoint found for EndpointReference" + endpointReference.toString()); + } + + endpointReference.setTargetEndpoint(endpoints.get(0)); + + matchForwardBinding(endpointReference, + monitor); + + matchCallbackBinding(endpointReference, + monitor); } - } + } + + if (endpointReference.isUnresolved()){ + throw new SCARuntimeException("EndpointReference can't be resolved"); + } } // TODO - EPR - In OASIS case there are no bindings to match with on the @@ -279,7 +252,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR if (matchedReferenceBinding.isEmpty()) { // No matching binding endpointReference.setBinding(null); - endpointReference.setTargetEndpoint(null); + endpointReference.setUnresolved(true); warning(monitor, "NoMatchingBinding", endpointReference.getReference(), @@ -324,6 +297,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR Endpoint2 clonedEndpoint = (Endpoint2)serviceEndpoint.clone(); endpointReference.setTargetEndpoint(clonedEndpoint); + endpointReference.setUnresolved(false); } catch (Exception ex) { // do nothing @@ -368,6 +342,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR if (matchedEndpoint.isEmpty()) { // No matching binding endpointReference.setCallbackEndpoint(null); + endpointReference.setUnresolved(true); warning(monitor, "NoMatchingCallbackBinding", endpointReference.getReference(), @@ -386,6 +361,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR } endpointReference.setCallbackEndpoint(matchedEndpoint.get(selectedEndpoint)); + endpointReference.setUnresolved(false); } } diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java index 141d991d27..e73fe3a13d 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java @@ -221,7 +221,7 @@ public class JavaComponentContextProvider { new CallableReferenceObjectFactory(businessInterface, component, (RuntimeComponentReference)wireList.get(i) .getSource().getContract(), wireList.get(i) - .getSource().getBinding()); + .getEndpointReference()); } else { factory = createObjectFactory(baseType, wireList.get(i)); } @@ -246,7 +246,7 @@ public class JavaComponentContextProvider { .getGenericType()); factory = new CallableReferenceObjectFactory(businessInterface, component, - (RuntimeComponentReference)componentReference, null); + (RuntimeComponentReference)componentReference, wireList.get(0).getEndpointReference()); } else { factory = createObjectFactory(element.getType(), wireList.get(0)); } -- cgit v1.2.3