summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java5
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java160
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java7
3 files changed, 92 insertions, 80 deletions
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
index 861ca2d6f9..cf2042a0ae 100644
--- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
+++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
@@ -29,11 +29,6 @@ import org.oasisopen.sca.ServiceReference;
* @version $Rev$ $Date$
*/
public interface RuntimeComponentContext extends ComponentContext {
- /**
- * Activate the reference (creating runtime wires)
- * @param reference
- */
- void start(RuntimeComponentReference reference);
/**
* Get the CallableReference for a given component reference
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 ******************** */
/**