diff options
Diffstat (limited to 'sca-java-2.x')
10 files changed, 313 insertions, 41 deletions
diff --git a/sca-java-2.x/trunk/modules/node-api/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/node-api/META-INF/MANIFEST.MF index ac89f5383a..4c51f30ed5 100644 --- a/sca-java-2.x/trunk/modules/node-api/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/node-api/META-INF/MANIFEST.MF @@ -1,6 +1,7 @@ Manifest-Version: 1.0
Export-Package: org.apache.tuscany.sca.node;version="2.0.0";uses:="org.oasisopen.sca",
- org.apache.tuscany.sca.node.configuration;version="2.0.0"
+ org.apache.tuscany.sca.node.configuration;version="2.0.0",
+ org.apache.tuscany.sca.node.extensibility
SCA-Version: 1.1
Bundle-Name: Apache Tuscany SCA Node API
DynamicImport-Package: org.apache.tuscany.sca.node.impl,org.apache.tus
@@ -10,7 +11,8 @@ Bundle-Version: 2.0.0 Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Node API
-Import-Package: org.apache.tuscany.sca.node;version="2.0.0",
+Import-Package: org.apache.tuscany.sca.assembly,
+ org.apache.tuscany.sca.node;version="2.0.0",
org.apache.tuscany.sca.node.configuration;version="2.0.0",
org.oasisopen.sca;version="2.0.0"
Bundle-SymbolicName: org.apache.tuscany.sca.node.api
diff --git a/sca-java-2.x/trunk/modules/node-api/pom.xml b/sca-java-2.x/trunk/modules/node-api/pom.xml index 2de9c088a6..2701dc6695 100644 --- a/sca-java-2.x/trunk/modules/node-api/pom.xml +++ b/sca-java-2.x/trunk/modules/node-api/pom.xml @@ -30,12 +30,17 @@ <artifactId>tuscany-node-api</artifactId> <name>Apache Tuscany SCA Node API</name> - <dependencies> + <dependencies> <dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-sca-api</artifactId> <version>2.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> </dependencies> </project> diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java index 502b2f854c..1dfaea6a0a 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java @@ -22,9 +22,6 @@ package org.apache.tuscany.sca.node; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.oasisopen.sca.ServiceReference; - - - /** * Represents an SCA processing node. * A node is loaded with an SCA composites. It can start and stop that composite. @@ -82,5 +79,5 @@ public interface Node { * @param <B> the Java type of the business interface for the service * @return a ServiceReference for the designated service */ - <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName); + <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName); } diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivator.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivator.java new file mode 100644 index 0000000000..9a63746908 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivator.java @@ -0,0 +1,29 @@ +/* + * 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; + +import org.apache.tuscany.sca.node.Node; + +public interface NodeActivator { + + void nodeStarted(Node node); + + void nodeStopped(Node node); +} diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivatorExtensionPoint.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivatorExtensionPoint.java new file mode 100644 index 0000000000..e78c46e8d4 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeActivatorExtensionPoint.java @@ -0,0 +1,32 @@ +/* + * 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; + +import java.util.List; + + +public interface NodeActivatorExtensionPoint extends NodeActivator { + + void addNodeActivator(NodeActivator listener); + + void removeNodeActivator(NodeActivator listener); + + List<NodeActivator> getNodeActivators(); +} diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeExtension.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeExtension.java new file mode 100644 index 0000000000..80c304b078 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/extensibility/NodeExtension.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; + +public interface NodeExtension extends Node { + + String getURI(); + + String getDomainURI(); + + NodeConfiguration getConfiguration(); + + Composite getDomainComposite(); + + ExtensionPointRegistry getExtensionPointRegistry(); +} diff --git a/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF index 15eeb4cf15..8d0141e369 100644 --- a/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF @@ -30,6 +30,7 @@ Import-Package: javax.management;resolution:=optional, org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
org.apache.tuscany.sca.node.configuration;version="2.0.0",
+ org.apache.tuscany.sca.node.extensibility,
org.apache.tuscany.sca.node.impl;version="2.0.0",
org.apache.tuscany.sca.runtime;version="2.0.0",
org.apache.tuscany.sca.work;version="2.0.0",
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 + |