summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-impl/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 00:38:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 00:38:31 +0000
commitefa0cb0a3d5564bf3880ad2aa20f1c418d63aa7b (patch)
tree514b04eb9d94a53d58902a832053215d52a0c917 /java/sca/modules/node-impl/src
parent9d8f01864f34586fdaf5bf96bad30e2fe06226c1 (diff)
Make CompositeActivator a stateless utility by using CompositeContext to hold the context from the Node including the endpointRegistry
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@820854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-impl/src')
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java59
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java41
2 files changed, 82 insertions, 18 deletions
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java
new file mode 100644
index 0000000000..4a3366e6fb
--- /dev/null
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.CompositeContext;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeContextImpl extends CompositeContext {
+ private final ExtensionPointRegistry extensionPointRegistry;
+ private final EndpointRegistry endpointRegistry;
+ private final ComponentContextFactory componentContextFactory;
+
+ public CompositeContextImpl(ExtensionPointRegistry registry, EndpointRegistry endpointRegistry) {
+ this.extensionPointRegistry = registry;
+ this.endpointRegistry = endpointRegistry;
+ ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class);
+ this.componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class);
+ }
+
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return extensionPointRegistry;
+ }
+
+ public EndpointRegistry getEndpointRegistry() {
+ return endpointRegistry;
+ }
+
+ public void configureComponentContext(RuntimeComponent runtimeComponent) {
+ RuntimeComponentContext componentContext =
+ (RuntimeComponentContext)componentContextFactory.createComponentContext(this, runtimeComponent);
+ runtimeComponent.setComponentContext(componentContext);
+ }
+
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index 82a5b01726..aeb962faf8 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -36,6 +36,7 @@ import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.common.java.io.IOHelper;
+import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.context.ThreadMessageContext;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
@@ -50,6 +51,7 @@ import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.node.management.NodeManager;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
@@ -64,6 +66,8 @@ public class NodeImpl implements Node, Client {
private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
private ProxyFactory proxyFactory;
private CompositeActivator compositeActivator;
+ private CompositeContext compositeContext;
+ private Composite domainComposite;
private NodeConfiguration configuration;
private NodeFactoryImpl manager;
private List<Contribution> contributions;
@@ -106,20 +110,20 @@ public class NodeImpl implements Node, Client {
manager.init();
manager.addNode(configuration, this);
this.proxyFactory = manager.proxyFactory;
- this.compositeActivator =
- manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class,
- manager.getNodeKey(configuration));
+ UtilityExtensionPoint utilities = manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+
+ // FIXME: Get the endpoint registry by the Node configuration
+ EndpointRegistry endpointRegistry = utilities.getUtility(EndpointRegistry.class);
+ this.compositeContext = new CompositeContextImpl(manager.extensionPoints, endpointRegistry);
+ this.compositeActivator = utilities.getUtility(CompositeActivator.class);
try {
- Composite composite = manager.configureNode(configuration, contributions);
+ domainComposite = manager.configureNode(configuration, contributions);
- // get the top level composite for this node
- compositeActivator.setDomainComposite(composite);
-
// Activate the composite
- compositeActivator.activate(compositeActivator.getDomainComposite());
+ compositeActivator.activate(domainComposite);
// Start the composite
- compositeActivator.start(compositeActivator.getDomainComposite());
+ compositeActivator.start(compositeContext, domainComposite);
NodeFinder.addNode(IOHelper.createURI(configuration.getDomainURI()), this);
@@ -170,13 +174,13 @@ public class NodeImpl implements Node, Client {
}
NodeFinder.removeNode(this);
- if( compositeActivator.getDomainComposite() != null ) {
+ if( domainComposite != null ) {
// Stop the composite
- compositeActivator.stop(compositeActivator.getDomainComposite());
+ compositeActivator.stop(compositeContext, domainComposite);
// Deactivate the composite
- compositeActivator.deactivate(compositeActivator.getDomainComposite());
+ compositeActivator.deactivate(domainComposite);
} // end if
@@ -225,7 +229,7 @@ public class NodeImpl implements Node, Client {
// Lookup the component
Component component = null;
- for (Component compositeComponent : compositeActivator.getDomainComposite().getComponents()) {
+ for (Component compositeComponent : domainComposite.getComponents()) {
if (compositeComponent.getName().equals(componentName)) {
component = compositeComponent;
}
@@ -279,7 +283,6 @@ public class NodeImpl implements Node, Client {
public List<Endpoint> getServiceEndpoints() {
List<Endpoint> endpoints = new ArrayList<Endpoint>();
if (compositeActivator != null) {
- Composite domainComposite = compositeActivator.getDomainComposite();
if (domainComposite != null) {
for (Component component : domainComposite.getComponents()) {
for (Service service : component.getServices()) {
@@ -296,7 +299,7 @@ public class NodeImpl implements Node, Client {
}
public Composite getDomainComposite() {
- return compositeActivator.getDomainComposite();
+ return domainComposite;
}
public String dumpDomainComposite() {
@@ -322,10 +325,12 @@ public class NodeImpl implements Node, Client {
String result = bos.toString();
// write out and nested composites
- for(Component component : composite.getComponents()){
+ for (Component component : composite.getComponents()) {
if (component.getImplementation() instanceof Composite) {
- result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" +
- writeComposite((Composite)component.getImplementation(), compositeProcessor);
+ result +=
+ "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" + writeComposite((Composite)component
+ .getImplementation(),
+ compositeProcessor);
}
}