summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/node-impl/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:37 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:37 +0000
commitb2c79131670c993537ecb55f7628190c85a959b8 (patch)
tree99e4baebc518a3e9d6e84665c7a8f446b582ab9d /sca-java-2.x/trunk/modules/node-impl/src
parent56b8d0862d1eb3b241bda34c6969ecb2f80426eb (diff)
TUSCANY-3496 - Adding extensibility to node api to allow other applications to tap to it and provide services that require introspecting node metadata
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1086667 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-impl/src')
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java132
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java85
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint19
3 files changed, 202 insertions, 34 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java
new file mode 100644
index 0000000000..8226b12078
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/extensibility/impl/DefaultNodeActivatorExtensionPoint.java
@@ -0,0 +1,132 @@
+/*
+ * 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.extensibility.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.extensibility.NodeActivator;
+import org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint;
+
+public class DefaultNodeActivatorExtensionPoint implements NodeActivatorExtensionPoint {
+ private final static Logger logger = Logger.getLogger(DefaultNodeActivatorExtensionPoint.class.getName());
+ private List<NodeActivator> activators = new ArrayList<NodeActivator>();
+ private ExtensionPointRegistry registry;
+ private boolean loadedActivators;
+
+ public DefaultNodeActivatorExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ public void addNodeActivator(NodeActivator activator) {
+ this.activators.add(activator);
+ }
+
+ @Override
+ public void removeNodeActivator(NodeActivator activator) {
+ this.activators.remove(activator);
+ }
+
+ @Override
+ public List<NodeActivator> getNodeActivators() {
+ loadModuleActivators();
+ return activators;
+ }
+
+ @Override
+ public void nodeStarted(Node node) {
+ for(NodeActivator activator : activators) {
+ activator.nodeStarted(node);
+ }
+ }
+
+ @Override
+ public void nodeStopped(Node node) {
+ for(NodeActivator activator : activators) {
+ activator.nodeStopped(node);
+ }
+ }
+
+
+
+ /**
+ * Dynamically load node activators declared under META-INF/services
+ */
+ private synchronized void loadModuleActivators() {
+ if (loadedActivators)
+ return;
+
+ // Get the activator service declarations
+ Collection<ServiceDeclaration> activatorDeclarations;
+ try {
+ // Load the module activators by ranking
+ activatorDeclarations = registry.getServiceDiscovery().getServiceDeclarations(NodeActivator.class.getName(), true);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load and instantiate module activators
+ for (ServiceDeclaration activatorDeclaration : activatorDeclarations) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Loading " + activatorDeclaration.getClassName());
+ }
+ NodeActivator activator = null;
+ try {
+ Class<NodeActivator> activatorClass = (Class<NodeActivator>)activatorDeclaration.loadClass();
+ try {
+ activator = ServiceHelper.newInstance(activatorClass, ExtensionPointRegistry.class, registry);
+ } catch (NoSuchMethodException e) {
+ try {
+ activator =
+ ServiceHelper.newInstance(activatorClass,
+ new Class<?>[] {ExtensionPointRegistry.class, Map.class},
+ registry,
+ activatorDeclaration.getAttributes());
+
+ } catch (NoSuchMethodException e1) {
+ activator = ServiceHelper.newInstance(activatorClass);
+
+ }
+ }
+ } catch (Throwable e) {
+ String optional = activatorDeclaration.getAttributes().get("optional");
+ if ("true".equalsIgnoreCase(optional)) {
+ // If the optional flag is true, just log the error
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ continue;
+ } else {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ addNodeActivator(activator);
+ }
+
+ loadedActivators = true;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index c32c1e0271..b41237b5ea 100644
--- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -44,6 +44,9 @@ import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.node.extensibility.NodeActivator;
+import org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint;
+import org.apache.tuscany.sca.node.extensibility.NodeExtension;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.CompositeActivator;
import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
@@ -58,7 +61,7 @@ import org.oasisopen.sca.ServiceUnavailableException;
/**
* An SCA Node that is managed by the NodeManager
*/
-public class NodeImpl implements Node {
+public class NodeImpl implements Node, NodeExtension {
private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
private ProxyFactory proxyFactory;
private CompositeActivator compositeActivator;
@@ -67,6 +70,7 @@ public class NodeImpl implements Node {
private NodeConfiguration configuration;
private NodeFactoryImpl nodeFactory;
private List<Contribution> contributions;
+ private NodeActivatorExtensionPoint nodeActivators;
// private NodeManager mbean;
/**
@@ -78,8 +82,9 @@ public class NodeImpl implements Node {
super();
this.configuration = configuration;
this.nodeFactory = nodeFactory;
+ this.nodeActivators = nodeFactory.getExtensionPointRegistry().getExtensionPoint(NodeActivatorExtensionPoint.class);
}
-
+
/**
* Create a node from the configuration and loaded contributions
* @param manager
@@ -90,6 +95,7 @@ public class NodeImpl implements Node {
super();
this.configuration = configuration;
this.nodeFactory = manager;
+ this.nodeActivators = nodeFactory.getExtensionPointRegistry().getExtensionPoint(NodeActivatorExtensionPoint.class);
this.contributions = new ArrayList<Contribution>(contributions);
}
@@ -97,54 +103,58 @@ public class NodeImpl implements Node {
return getConfiguration().getURI();
}
+ public String getDomainURI() {
+ return getConfiguration().getDomainURI();
+ }
+
public Node start() {
logger.log(nodeFactory.quietLogging? Level.FINE : Level.INFO, "Starting node: " + configuration.getURI() + " domain: " + configuration.getDomainURI());
nodeFactory.init();
nodeFactory.addNode(configuration, this);
this.proxyFactory = nodeFactory.proxyFactory;
-
+
try {
Monitor monitor = nodeFactory.monitorFactory.createMonitor();
ProcessorContext context = new ProcessorContext(monitor);
-
+
// Set up the thead context monitor
Monitor tcm = nodeFactory.monitorFactory.setContextMonitor(monitor);
try {
// Use the lack of the contributions collection as an indicator for when the node
- // is being started for the first time. If it is the first time do all the work
+ // is being started for the first time. If it is the first time do all the work
// to read the contributions and create the domain composite
if (contributions == null) {
contributions = nodeFactory.loadContributions(configuration, context);
}
-
- if (domainComposite == null) {
-
+
+ if (domainComposite == null) {
+
UtilityExtensionPoint utilities = nodeFactory.registry.getExtensionPoint(UtilityExtensionPoint.class);
this.compositeActivator = utilities.getUtility(CompositeActivator.class);
domainComposite = nodeFactory.configureNode(configuration, contributions, context);
-
+
DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(nodeFactory.registry);
EndpointRegistry endpointRegistry =
domainRegistryFactory.getEndpointRegistry(configuration.getDomainRegistryURI(), configuration.getDomainURI());
this.compositeContext =
- new CompositeContext(nodeFactory.registry,
- endpointRegistry,
- domainComposite,
- configuration.getDomainURI(),
+ new CompositeContext(nodeFactory.registry,
+ endpointRegistry,
+ domainComposite,
+ configuration.getDomainURI(),
configuration.getURI(),
nodeFactory.getDeployer().getSystemDefinitions());
// Pass down the context attributes
compositeContext.getAttributes().putAll(configuration.getAttributes());
}
-
+
} finally {
// Reset the thread context monitor
nodeFactory.monitorFactory.setContextMonitor(tcm);
}
-
+
// Activate the composite
compositeActivator.activate(compositeContext, domainComposite);
@@ -172,6 +182,9 @@ public class NodeImpl implements Node {
logger.log(Level.SEVERE, e.getMessage(), e);
}
+ for(NodeActivator activator : nodeActivators.getNodeActivators()) {
+ activator.nodeStarted(this);
+ }
return this;
} catch (Throwable e) {
@@ -212,13 +225,17 @@ public class NodeImpl implements Node {
} // end if
nodeFactory.removeNode(configuration);
-/*
+/*
this.compositeActivator = null;
this.proxyFactory = null;
this.domainComposite = null;
this.compositeContext = null;
-*/
-
+*/
+
+ for(NodeActivator activator : nodeActivators.getNodeActivators()) {
+ activator.nodeStopped(this);
+ }
+
ThreadMessageContext.removeMessageContext();
} catch (ActivationException e) {
@@ -269,7 +286,7 @@ public class NodeImpl implements Node {
if (component == null) {
throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain");
}
-
+
return ((RuntimeComponent)component).getServiceReference(businessInterface, serviceName);
}
@@ -303,47 +320,47 @@ public class NodeImpl implements Node {
}
return endpoints;
}
-
+
public Composite getDomainComposite() {
return domainComposite;
- }
-
+ }
+
public String dumpDomainComposite() {
-
- StAXArtifactProcessorExtensionPoint xmlProcessors =
+
+ StAXArtifactProcessorExtensionPoint xmlProcessors =
getExtensionPointRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- StAXArtifactProcessor<Composite> compositeProcessor =
- xmlProcessors.getProcessor(Composite.class);
-
+ StAXArtifactProcessor<Composite> compositeProcessor =
+ xmlProcessors.getProcessor(Composite.class);
+
return writeComposite(getDomainComposite(), compositeProcessor);
}
-
+
private String writeComposite(Composite composite, StAXArtifactProcessor<Composite> compositeProcessor){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLOutputFactory outputFactory =
nodeFactory.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class)
.getFactory(XMLOutputFactory.class);
-
+
try {
compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(nodeFactory.registry));
} catch(Exception ex) {
return ex.toString();
}
-
+
String result = bos.toString();
-
+
// write out and nested composites
for (Component component : composite.getComponents()) {
if (component.getImplementation() instanceof Composite) {
- result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" +
+ result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" +
writeComposite((Composite)component.getImplementation(),
compositeProcessor);
}
}
-
+
return result;
}
-
+
public List<Contribution> getContributions() {
return contributions;
}
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint b/sca-java-2.x/trunk/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint
new file mode 100644
index 0000000000..3c83b6f38e
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivatorExtensionPoint
@@ -0,0 +1,19 @@
+# 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.
+
+org.apache.tuscany.sca.node.extensibility.impl.DefaultNodeActivatorExtensionPoint
+