diff options
Diffstat (limited to 'branches/sca-equinox/modules/node-impl/src')
4 files changed, 39 insertions, 125 deletions
diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java index 946c6b06e0..62758e8332 100644 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -19,31 +19,31 @@ package org.apache.tuscany.sca.node.impl; -import org.apache.tuscany.sca.node.SCAContribution; -import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.SCANodeFactory; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; /** * Default implementation of an SCA node factory. * * @version $Rev$ $Date$ */ -public class NodeFactoryImpl extends SCANodeFactory { +public class NodeFactoryImpl extends NodeFactory { public NodeFactoryImpl() { } @Override - public SCANode createSCANodeFromURL(String configurationURI) { + public Node createNode(String configurationURI) { return new NodeImpl(configurationURI); } @Override - public SCANode createSCANode(String compositeURI, SCAContribution... contributions) { + public Node createNode(String compositeURI, Contribution... contributions) { return new NodeImpl(compositeURI, contributions); } @Override - public SCANode createSCANode(String compositeURI, String compositeContent, SCAContribution... contributions) { + public Node createNode(String compositeURI, String compositeContent, Contribution... contributions) { return new NodeImpl(compositeURI, compositeContent, contributions); } diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index e53f478864..fb22d2ea5d 100644 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -22,15 +22,13 @@ package org.apache.tuscany.sca.node.impl; import static java.lang.System.currentTimeMillis; import static org.apache.tuscany.sca.node.impl.NodeUtil.contribution; import static org.apache.tuscany.sca.node.impl.NodeUtil.createURI; -import static org.apache.tuscany.sca.node.impl.NodeUtil.loadModules; -import static org.apache.tuscany.sca.node.impl.NodeUtil.startModules; -import static org.apache.tuscany.sca.node.impl.NodeUtil.stopModules; import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -77,9 +75,8 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCAContribution; -import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.Client; +import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentContext; import org.apache.tuscany.sca.work.WorkScheduler; @@ -96,7 +93,7 @@ import org.osoa.sca.ServiceRuntimeException; * * @version $Rev$ $Date$ */ -public class NodeImpl implements SCANode, SCAClient { +public class NodeImpl implements Node, Client { private static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); @@ -120,7 +117,7 @@ public class NodeImpl implements SCANode, SCAClient { private StAXArtifactProcessorExtensionPoint xmlProcessors; private StAXArtifactProcessor<Composite> compositeProcessor; private ProxyFactory proxyFactory; - private List<ModuleActivator> modules; + private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>(); private CompositeActivator compositeActivator; private WorkScheduler workScheduler; @@ -170,7 +167,7 @@ public class NodeImpl implements SCANode, SCAClient { * @param compositeURI * @param contributions */ - NodeImpl(String compositeURI, SCAContribution[] contributions) { + NodeImpl(String compositeURI, org.apache.tuscany.sca.node.Contribution[] contributions) { configurationName = compositeURI; logger.log(Level.INFO, "Creating node: " + configurationName); @@ -190,7 +187,7 @@ public class NodeImpl implements SCANode, SCAClient { } // Create contribution models - for (SCAContribution c : contributions) { + for (org.apache.tuscany.sca.node.Contribution c : contributions) { Contribution contribution = contribution(contributionFactory, c); configuration.getContributions().add(contribution); } @@ -210,7 +207,7 @@ public class NodeImpl implements SCANode, SCAClient { * @param compositeContent * @param contributions */ - NodeImpl(String compositeURI, String compositeContent, SCAContribution[] contributions) { + NodeImpl(String compositeURI, String compositeContent, org.apache.tuscany.sca.node.Contribution[] contributions) { configurationName = compositeURI; logger.log(Level.INFO, "Creating node: " + configurationName); @@ -238,7 +235,7 @@ public class NodeImpl implements SCANode, SCAClient { configuration.setComposite(composite); // Create contribution models - for (SCAContribution c : contributions) { + for (org.apache.tuscany.sca.node.Contribution c : contributions) { Contribution contribution = contribution(contributionFactory, c); configuration.getContributions().add(contribution); } @@ -263,9 +260,10 @@ public class NodeImpl implements SCANode, SCAClient { monitor = monitorFactory.createMonitor(); // Initialize the Tuscany module activators - ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); - for (ModuleActivator activator: moduleActivators.getModuleActivators()) { - activator.start(extensionPoints); + ModuleActivatorExtensionPoint activators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator moduleActivator: activators.getModuleActivators()) { + moduleActivator.start(extensionPoints); + moduleActivators.add(moduleActivator); } // Get XML input/output factories @@ -302,17 +300,6 @@ public class NodeImpl implements SCANode, SCAClient { // Initialize runtime - // Load the runtime modules - try { - modules = loadModules(extensionPoints); - - // Start the runtime modules - startModules(extensionPoints, modules); - - } catch (ActivationException e) { - throw new IllegalStateException(e); - } - // Get proxy factory ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); proxyFactory = new ExtensibleProxyFactory(proxyFactories); @@ -458,8 +445,13 @@ public class NodeImpl implements SCANode, SCAClient { throw new IllegalStateException(e); } + } + + public void destroy() { // Stop the runtime modules - stopModules(extensionPoints, modules); + for (ModuleActivator moduleActivator: moduleActivators) { + moduleActivator.stop(extensionPoints); + } // Stop and destroy the work manager workScheduler.destroy(); diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java index 0aaee432a8..2a4d6c7e69 100644 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java +++ b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java @@ -33,16 +33,8 @@ import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.ModuleActivator; import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory; -import org.apache.tuscany.sca.core.scope.ConversationalScopeContainerFactory; -import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory; -import org.apache.tuscany.sca.core.scope.ScopeContainerFactory; -import org.apache.tuscany.sca.core.scope.ScopeRegistry; -import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl; -import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.node.SCAContribution; /** * NodeUtil @@ -52,7 +44,7 @@ import org.apache.tuscany.sca.node.SCAContribution; public class NodeUtil { private static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); - static Contribution contribution(ContributionFactory contributionFactory, SCAContribution c) { + static Contribution contribution(ContributionFactory contributionFactory, org.apache.tuscany.sca.node.Contribution c) { Contribution contribution = contributionFactory.createContribution(); contribution.setURI(c.getURI()); contribution.setLocation(c.getLocation()); @@ -72,76 +64,6 @@ public class NodeUtil { return URI.create(uri); } - static List<ModuleActivator> loadModules(ExtensionPointRegistry registry) throws ActivationException { - - // Load and instantiate the modules found on the classpath (or any registered ClassLoaders) - List<ModuleActivator> modules = new ArrayList<ModuleActivator>(); - try { - Set<ServiceDeclaration> moduleActivators = ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class.getName()); - Set<String> moduleClasses = new HashSet<String>(); - for (ServiceDeclaration moduleDeclarator : moduleActivators) { - if (moduleClasses.contains(moduleDeclarator.getClassName())) { - continue; - } - moduleClasses.add(moduleDeclarator.getClassName()); - Class<?> moduleClass = moduleDeclarator.loadClass(); - ModuleActivator module = (ModuleActivator)moduleClass.newInstance(); - modules.add(module); - } - } catch (IOException e) { - throw new ActivationException(e); - } catch (ClassNotFoundException e) { - throw new ActivationException(e); - } catch (InstantiationException e) { - throw new ActivationException(e); - } catch (IllegalAccessException e) { - throw new ActivationException(e); - } - - return modules; - } - - static void startModules(ExtensionPointRegistry registry, List<ModuleActivator> modules) throws ActivationException { - boolean debug = logger.isLoggable(Level.FINE); - - // Start all the extension modules - for (ModuleActivator module : modules) { - long start = 0L; - if (debug) { - logger.fine(module.getClass().getName() + " is starting."); - start = System.currentTimeMillis(); - } - try { - module.start(registry); - if (debug) { - long end = System.currentTimeMillis(); - logger.fine(module.getClass().getName() + " is started in " + (end - start) + " ms."); - } - } catch (Throwable e) { - logger.log(Level.WARNING, "Exception starting module " + module.getClass().getName() - + " :" - + e.getMessage()); - logger.log(Level.FINE, "Exception starting module " + module.getClass().getName(), e); - } - } - } - - static void stopModules(final ExtensionPointRegistry registry, List<ModuleActivator> modules) { - boolean debug = logger.isLoggable(Level.FINE); - for (ModuleActivator module : modules) { - long start = 0L; - if (debug) { - logger.fine(module.getClass().getName() + " is stopping."); - start = System.currentTimeMillis(); - } - module.stop(registry); - if (debug) { - long end = System.currentTimeMillis(); - logger.fine(module.getClass().getName() + " is stopped in " + (end - start) + " ms."); - } - } - } - // private void loadSCADefinitions() throws ActivationException { // try { // URLArtifactProcessorExtensionPoint documentProcessors = diff --git a/branches/sca-equinox/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/branches/sca-equinox/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java index e91f399a57..bd760d613d 100644 --- a/branches/sca-equinox/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ b/branches/sca-equinox/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -25,10 +25,10 @@ import java.io.File; import junit.framework.Assert; -import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCAContribution; -import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.SCANodeFactory; +import org.apache.tuscany.sca.node.Client; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; import org.junit.Test; /** @@ -47,25 +47,25 @@ public class NodeImplTestCase { @Test public void testNodeWithCompositeContent() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); String compositeURI = "HelloWorld.composite"; - SCANode node = factory.createSCANode(compositeURI, composite, contribution); + Node node = factory.createNode(compositeURI, composite, contribution); testNode(node); } @Test public void testNodeWithRelativeCompositeURI() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); String compositeURI = "HelloWorld.composite"; - SCANode node = factory.createSCANode(compositeURI, contribution); + Node node = factory.createNode(compositeURI, contribution); testNode(node); } - private void testNode(SCANode node) { + private void testNode(Node node) { node.start(); - HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld"); + HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld"); Assert.assertEquals("Hello, Node", hw.hello("Node")); node.stop(); } |