diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-17 13:35:35 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-17 13:35:35 +0000 |
commit | eacb7008ce0c179eefd9cabd8bcd7328b1bf75a8 (patch) | |
tree | 180707f01a67d7474b2f86d4cb756533eb76a031 /sca-java-2.x/trunk/modules/core/src | |
parent | e791c5c55cd0c2bca782c4b524761f02dde38c8b (diff) |
Update deserialization of RuntimeEndpointImpl & RuntimeEndpointReferenceImpl to cope with Threads which dont have a ComponentContext available - in support of TUSCANY-3811
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1059921 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core/src')
2 files changed, 110 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java index 5c21041413..263ba6a8c7 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java @@ -43,6 +43,7 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; @@ -81,6 +82,7 @@ import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; 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.node.NodeFactory; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.EndpointAsyncProvider; import org.apache.tuscany.sca.provider.EndpointProvider; @@ -91,8 +93,10 @@ import org.apache.tuscany.sca.provider.PolicyProvider; import org.apache.tuscany.sca.provider.PolicyProviderFactory; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointSerializer; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -892,18 +896,63 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint if (compositeContext != null) { bind(compositeContext); } - } + } // end if if (serializer != null) { RuntimeEndpointImpl ep = (RuntimeEndpointImpl)serializer.readEndpoint(xml); copyFrom(ep); } else { - // FIXME: [rfeng] What should we do here? - } - } + // In this case, we assume that we're running on a detached (non Tuscany) thread and + // as a result we need to connect back to the Tuscany environment... + for( NodeFactory factory : NodeFactory.getNodeFactories() ) { + ExtensionPointRegistry registry = factory.getExtensionPointRegistry(); + if( registry != null ) { + this.registry = registry; + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + this.serializer = utilities.getUtility(EndpointSerializer.class); + RuntimeEndpointImpl ep = (RuntimeEndpointImpl)serializer.readEndpoint(xml); + // Find the actual Endpoint in the EndpointRegistry + ep = findActualEP( ep, registry ); + + if( ep != null ){ + copyFrom( ep ); + break; + } // end if + } // end if + } // end for + } // end if + } // end if super.resolve(); - } + } // end method resolve + + /** + * Find the actual Endpoint in the EndpointRegistry which corresponds to the configuration described + * in a deserialized Endpoint + * @param ep The deserialized endpoint + * @param registry - the main extension point Registry + * @return the corresponding Endpoint from the EndpointRegistry, or null if no match can be found + */ + private RuntimeEndpointImpl findActualEP(RuntimeEndpointImpl ep, + ExtensionPointRegistry registry) { + // Get the EndpointRegistry + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry); + + if( domainRegistryFactory == null ) return null; + + // TODO: For the moment, just use the first (and only!) EndpointRegistry... + EndpointRegistry endpointRegistry = (EndpointRegistry) domainRegistryFactory.getEndpointRegistries().toArray()[0]; + + if( endpointRegistry == null ) return null; + + for( Endpoint endpoint : endpointRegistry.findEndpoint(ep.getURI()) ) { + // TODO: For the present, simply return the first matching endpoint + return (RuntimeEndpointImpl) endpoint; + } // end for + + return null; + } // end method findActualEP - public InterfaceContract getBindingInterfaceContract() { + public InterfaceContract getBindingInterfaceContract() { resolve(); if (bindingInterfaceContract != null) { return bindingInterfaceContract; diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java index f86f90c6e6..368ec0ba87 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java @@ -38,6 +38,7 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; import org.apache.tuscany.sca.assembly.builder.BuilderContext; @@ -70,6 +71,7 @@ import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; 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.node.NodeFactory; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.EndpointReferenceProvider; import org.apache.tuscany.sca.provider.ImplementationAsyncProvider; @@ -78,9 +80,11 @@ import org.apache.tuscany.sca.provider.PolicyProvider; import org.apache.tuscany.sca.provider.PolicyProviderFactory; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointSerializer; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -633,11 +637,59 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen bind(compositeContext); } } - RuntimeEndpointReferenceImpl epr = (RuntimeEndpointReferenceImpl)serializer.readEndpointReference(xml); - copyFrom(epr); + if (serializer != null) { + RuntimeEndpointReferenceImpl epr = (RuntimeEndpointReferenceImpl)serializer.readEndpointReference(xml); + copyFrom(epr); + } else { + // In this case, we assume that we're running on a detached (non Tuscany) thread and + // as a result we need to connect back to the Tuscany environment... + for( NodeFactory factory : NodeFactory.getNodeFactories() ) { + ExtensionPointRegistry registry = factory.getExtensionPointRegistry(); + if( registry != null ) { + this.registry = registry; + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + this.serializer = utilities.getUtility(EndpointSerializer.class); + RuntimeEndpointReferenceImpl epr = (RuntimeEndpointReferenceImpl)serializer.readEndpointReference(xml); + // Find the actual Endpoint in the EndpointRegistry + epr = findActualEPR( epr, registry ); + + if( epr != null ){ + copyFrom( epr ); + break; + } // end if + } // end if + } // end for + } // end if } super.resolve(); - } + } // end method resolve + + /** + * Find the actual EndpointReference in the EndpointRegistry which corresponds to the configuration described + * in a deserialized EndpointReference + * @param ep The deserialized endpointReference + * @param registry - the main extension point Registry + * @return the corresponding EndpointReference from the EndpointRegistry, or null if no match can be found + */ + private RuntimeEndpointReferenceImpl findActualEPR(RuntimeEndpointReferenceImpl epr, + ExtensionPointRegistry registry) { + // Get the EndpointRegistry + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry); + if( domainRegistryFactory == null ) return null; + + // TODO: For the moment, just use the first (and only!) EndpointRegistry... + EndpointRegistry endpointRegistry = (EndpointRegistry) domainRegistryFactory.getEndpointRegistries().toArray()[0]; + if( endpointRegistry == null ) return null; + + for( EndpointReference epReference : endpointRegistry.getEndpointReferences() ) { + // TODO: For the present, simply return the first matching endpointReference + if( epReference.getURI().equals(epr.getURI()) ) { + return (RuntimeEndpointReferenceImpl) epReference; + } // end if + } // end for + + return null; + } // end method findActualEPR public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.uri = in.readUTF(); |