diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-14 11:34:37 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-14 11:34:37 +0000 |
commit | ce799b93742072dc9023c6860c981795a15b5266 (patch) | |
tree | 8fc2b4a75d901016298472226aae61f1fd1f2bfe /sca-java-2.x/trunk/modules/core | |
parent | f3235262495bdf4740632a822794b7ef0a3a9ea7 (diff) |
TUSCANY-3788 - Resolved async references are now started at start time to give them a chance to create a response listener. Plus remove an unused reference starting interface from the component context as it;s all handled by endpoint references now.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1058955 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core')
2 files changed, 92 insertions, 75 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java index da28cab2a2..6ec740ae20 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java @@ -41,6 +41,7 @@ import org.apache.tuscany.sca.core.scope.ScopeContainer; import org.apache.tuscany.sca.core.scope.ScopeRegistry; import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.EndpointReferenceAsyncProvider; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.ImplementationProviderFactory; import org.apache.tuscany.sca.provider.PolicyProvider; @@ -345,6 +346,18 @@ public class CompositeActivatorImpl implements CompositeActivator { start(compositeContext, (ScopedRuntimeComponent)component); } } + + // start reference last. In allowing references to start at "start" time + // as well as when they are first used (for late bound references) we need + // to make sure that all potential target services and component implementations + // are started first to take account of the default binding optimization case + for (Component component : composite.getComponents()) { + for (ComponentReference reference : component.getReferences()) { + start(compositeContext, + (RuntimeComponent)component, + (RuntimeComponentReference)reference); + } + } } public void stop(CompositeContext compositeContext, Composite composite) { @@ -396,9 +409,6 @@ public class CompositeActivatorImpl implements CompositeActivator { } } - // Reference bindings aren't started until the wire is first used although this may - // happen when the scope container is started in the case of @EagerInit - for (ComponentService service : component.getServices()) { if (logger.isLoggable(Level.FINE)) { logger.fine("Starting component service: " + component.getURI() + "#" + service.getName()); @@ -408,6 +418,10 @@ public class CompositeActivatorImpl implements CompositeActivator { startEndpoint(compositeContext, ep, providers); } } + + // Reference start is done after all components have been started to make sure everything + // is up and running before we try and connect references to services + } catch (Throwable e) { for (int i = providers.size() - 1; i >= 0; i--) { try { @@ -432,36 +446,6 @@ public class CompositeActivatorImpl implements CompositeActivator { } } - public void start(CompositeContext compositeContext, RuntimeEndpoint ep) { - startEndpoint(compositeContext, ep, null); - } - - private void startEndpoint(CompositeContext compositeContext, RuntimeEndpoint ep, final List<RuntimeProvider> providers) { - // FIXME: Should the policy providers be started before the endpoint is started? - for (PolicyProvider policyProvider : ep.getPolicyProviders()) { - policyProvider.start(); - if (providers != null) { - providers.add(policyProvider); - } - } - - final ServiceBindingProvider bindingProvider = ep.getBindingProvider(); - if (bindingProvider != null) { - // bindingProvider.start(); - // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.start(); - if (providers != null) { - providers.add(bindingProvider); - } - return null; - } - }); - compositeContext.getEndpointRegistry().addEndpoint(ep); - } - } - public void stop(CompositeContext compositeContext, Component component) { if (!((RuntimeComponent)component).isStarted()) { return; @@ -519,6 +503,48 @@ public class CompositeActivatorImpl implements CompositeActivator { ((RuntimeComponent)component).setStarted(false); } + + // Scope container start/stop + // separate off from component start that all endpoints are + // registered before any @EagerInit takes place + public void start(CompositeContext compositeContext, ScopedRuntimeComponent scopedRuntimeComponent) { + if (scopedRuntimeComponent.getScopeContainer() != null) { + scopedRuntimeComponent.getScopeContainer().start(); + } + } + + // Service start/stop + + public void start(CompositeContext compositeContext, RuntimeEndpoint ep) { + startEndpoint(compositeContext, ep, null); + } + + private void startEndpoint(CompositeContext compositeContext, RuntimeEndpoint ep, final List<RuntimeProvider> providers) { + // FIXME: Should the policy providers be started before the endpoint is started? + for (PolicyProvider policyProvider : ep.getPolicyProviders()) { + policyProvider.start(); + if (providers != null) { + providers.add(policyProvider); + } + } + + final ServiceBindingProvider bindingProvider = ep.getBindingProvider(); + if (bindingProvider != null) { + // bindingProvider.start(); + // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. + AccessController.doPrivileged(new PrivilegedAction<Object>() { + public Object run() { + bindingProvider.start(); + if (providers != null) { + providers.add(bindingProvider); + } + return null; + } + }); + compositeContext.getEndpointRegistry().addEndpoint(ep); + } + } + public void stop(RuntimeEndpoint ep) { ep.getCompositeContext().getEndpointRegistry().removeEndpoint(ep); final ServiceBindingProvider bindingProvider = ep.getBindingProvider(); @@ -536,48 +562,38 @@ public class CompositeActivatorImpl implements CompositeActivator { } } - // Scope container start/stop - // separate off from component start that all endpoints are - // registered before any @EagerInit takes place - public void start(CompositeContext compositeContext, ScopedRuntimeComponent scopedRuntimeComponent) { - if (scopedRuntimeComponent.getScopeContainer() != null) { - scopedRuntimeComponent.getScopeContainer().start(); - } - } - - // Service start/stop - - // done as part of the component start above // Reference start/stop - // Used by component context start - - public void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference componentReference) { - synchronized (componentReference) { - if (!(componentReference instanceof RuntimeComponentReference)) { - return; - } - - // 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 (EndpointReference endpointReference : componentReference.getEndpointReferences()){ - // addReferenceWire(compositeContext, endpointReference); - start(compositeContext, (RuntimeEndpointReference) endpointReference); + public void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference reference) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); + } + + for (EndpointReference endpointReference : reference.getEndpointReferences()){ + RuntimeEndpointReference epr = (RuntimeEndpointReference)endpointReference; + + // If the reference is already resolved then start it now. This currently + // important for async references which have native async bindings as the + // reference provider has to register a response listener regardless of + // whether the reference has been used or not. + if (epr.getStatus() == EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED || + epr.getStatus() == EndpointReference.Status.RESOLVED_BINDING){ + + // As we only care about starting references at build time in the + // async case at the moment check that the binding supports native async + // and that the reference is an async reference + ReferenceBindingProvider bindingProvider = epr.getBindingProvider(); + if (bindingProvider instanceof EndpointReferenceAsyncProvider && + ((EndpointReferenceAsyncProvider)bindingProvider).supportsNativeAsync() && + epr.isAsyncInvocation()){ + // it's resolved so start it now + start(compositeContext, epr); + } } - } } - public void start(CompositeContext compositeContext, RuntimeEndpointReference endpointReference) { - compositeContext.getEndpointRegistry().addEndpointReference(endpointReference); - } - public void stop(Component component, ComponentReference reference) { if (logger.isLoggable(Level.FINE)) { logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName()); @@ -588,6 +604,14 @@ public class CompositeActivatorImpl implements CompositeActivator { stop(epr); } } + + public void start(CompositeContext compositeContext, RuntimeEndpointReference endpointReference) { + compositeContext.getEndpointRegistry().addEndpointReference(endpointReference); + + // The act of getting invocation chains starts the reference in the late binding case + // so just use that here + endpointReference.getInvocationChains(); + } public void stop(RuntimeEndpointReference epr) { if (epr.isStarted()) { diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index 003acce0fb..d9cb512501 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -481,13 +481,6 @@ public class ComponentContextImpl implements RuntimeComponentContext { return interfaceContract; } - /** - * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#start(org.apache.tuscany.sca.runtime.RuntimeComponentReference) - */ - public void start(RuntimeComponentReference reference) { - compositeActivator.start(compositeContext, component, reference); - } - /* ******************** Contribution for issue TUSCANY-2281 ******************** */ /** |