diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-09 06:33:54 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-09 06:33:54 +0000 |
commit | efe3363a815a777ecd283928900404dea84a7e1f (patch) | |
tree | 42522fd01e6af981f8ff94663d911d56744154d5 /branches/sca-equinox/modules/node-impl/src/main/java/org/apache | |
parent | aacabe1650e380595a8d701123394d791656d17d (diff) |
Work in progress. Fixed implementation of NodeImpl, now working without dependencies on implementations from other bundles (except RuntimeAssemblyFactory, which will need to be cleaned up too). Started to remove dependencies on host-embedded and port code to NodeFactory and Node, as an interim step to bring them up, before porting them to the OSGi-enabled node launcher.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@703068 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/node-impl/src/main/java/org/apache')
3 files changed, 27 insertions, 113 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 = |