diff options
Diffstat (limited to 'branches/sca-equinox')
12 files changed, 339 insertions, 949 deletions
diff --git a/branches/sca-equinox/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/branches/sca-equinox/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java index 77d621c931..834bcb2112 100644 --- a/branches/sca-equinox/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java +++ b/branches/sca-equinox/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java @@ -91,7 +91,7 @@ public abstract class BaseConfigurationBuilderImpl { * @param monitor */ protected void configureComponents(Composite composite, SCADefinitions definitions, Monitor monitor) throws CompositeBuilderException { - configureComponents(composite, null, monitor); + configureComponents(composite, null, definitions, monitor); configureSourcedProperties(composite, null); } diff --git a/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java b/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java index f51931c53b..61f1f6494c 100644 --- a/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java +++ b/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java @@ -38,12 +38,19 @@ import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.context.ComponentContextHelper; import org.apache.tuscany.sca.core.context.ComponentContextImpl; import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor; import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.core.scope.ConversationalScopeContainer; import org.apache.tuscany.sca.core.scope.Scope; import org.apache.tuscany.sca.core.scope.ScopeContainer; @@ -71,6 +78,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeWire; import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; import org.apache.tuscany.sca.work.WorkScheduler; /** @@ -96,15 +104,28 @@ public class CompositeActivatorImpl implements CompositeActivator { private final ComponentContextHelper componentContextHelper; private Composite domainComposite; + + public CompositeActivatorImpl(ExtensionPointRegistry extensionPoints) { + FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = factories.getFactory(AssemblyFactory.class); + this.messageFactory = factories.getFactory(MessageFactory.class); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + this.scopeRegistry = utilities.getUtility(ScopeRegistry.class); + this.workScheduler = utilities.getUtility(WorkScheduler.class); + this.wireProcessor = new ExtensibleWireProcessor(extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class)); + this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + this.endpointResolverFactories = extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); + this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); + ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class); + this.requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); + ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); + proxyFactory = new ExtensibleProxyFactory(proxyFactories); + this.conversationManager = utilities.getUtility(ConversationManager.class); + StAXArtifactProcessorExtensionPoint processors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + this.componentContextHelper = new ComponentContextHelper(assemblyFactory, javaInterfaceFactory, processors); + } - /** - * @param assemblyFactory - * @param interfaceContractMapper - * @param workScheduler - * @param conversationManager TODO - * @param workContext - * @param wirePostProcessorRegistry - */ public CompositeActivatorImpl(AssemblyFactory assemblyFactory, MessageFactory messageFactory, JavaInterfaceFactory javaInterfaceFactory, diff --git a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java b/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/DefaultScopeRegistry.java index a1d4ddb2b1..94f26845ed 100644 --- a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java +++ b/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/DefaultScopeRegistry.java @@ -17,17 +17,24 @@ * under the License. */ -package org.apache.tuscany.sca.node; - - +package org.apache.tuscany.sca.core.scope; /** - * Represents an SCA processing node. - * A node is loaded with an SCA composites. It can start and stop that composite. + * A default scope registry implementation. * - * @version $Rev$ $Date$ - * @deprecated Use SCANode instead + * @version $Rev: $ $Date: $ */ -@Deprecated -public interface SCANode2 extends SCANode { +public class DefaultScopeRegistry extends ScopeRegistryImpl implements ScopeRegistry { + + public DefaultScopeRegistry() { + ScopeContainerFactory[] factories = + new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(), + new RequestScopeContainerFactory(), + new ConversationalScopeContainerFactory(null), + // new HttpSessionScopeContainer(monitor) + }; + for (ScopeContainerFactory f : factories) { + register(f); + } + } } diff --git a/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.CompositeActivator b/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.CompositeActivator new file mode 100644 index 0000000000..fc2760f73f --- /dev/null +++ b/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.CompositeActivator @@ -0,0 +1,18 @@ +# 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.core.assembly.CompositeActivatorImpl
diff --git a/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.scope.ScopeRegistry b/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.scope.ScopeRegistry new file mode 100644 index 0000000000..a4a0154987 --- /dev/null +++ b/branches/sca-equinox/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.scope.ScopeRegistry @@ -0,0 +1,18 @@ +# 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.core.scope.DefaultScopeRegistry
diff --git a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java b/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java index 2c91032653..bca649dbae 100644 --- a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java +++ b/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java @@ -148,21 +148,6 @@ public abstract class SCANodeFactory { } /** - * Create a SCA node based on the discovery of the contribution on the classpath for the - * given classloader. This method should be treated a convinient shortcut with the following - * assumptions: - * <ul> - * <li>This is a standalone application and there is a deployable composite file on the classpath. - * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. - * </ul> - * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution - * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null, - * then thread context classloader will be used - * @return A newly created SCA node - */ - public abstract SCANode createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader); - - /** * Creates a new SCA node from the configuration URL * * @param configurationURL the URL of the node configuration which is the ATOM feed 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 18b166acdd..946c6b06e0 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 @@ -33,11 +33,6 @@ public class NodeFactoryImpl extends SCANodeFactory { } @Override - public SCANode createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader) { - return new NodeImpl(classLoader, compositeURI); - } - - @Override public SCANode createSCANodeFromURL(String configurationURI) { return new NodeImpl(configurationURI); } 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 fef0a8391e..e53f478864 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 @@ -19,32 +19,27 @@ package org.apache.tuscany.sca.node.impl; -import static org.apache.tuscany.sca.node.impl.NodeUtil.collectJARs; -import static org.apache.tuscany.sca.node.impl.NodeUtil.createContribution; +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.getContributionURL; -import static org.apache.tuscany.sca.node.impl.NodeUtil.getResource; +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.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.TransformerFactory; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; @@ -53,11 +48,9 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; @@ -73,6 +66,11 @@ import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.ActivationException; import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation; import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory; import org.apache.tuscany.sca.monitor.Monitor; @@ -84,6 +82,7 @@ import org.apache.tuscany.sca.node.SCAContribution; import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.work.WorkScheduler; import org.apache.tuscany.sca.workspace.Workspace; import org.apache.tuscany.sca.workspace.WorkspaceFactory; import org.apache.tuscany.sca.workspace.builder.ContributionBuilder; @@ -107,6 +106,7 @@ public class NodeImpl implements SCANode, SCAClient { // The composite loaded into this node private Composite composite; + private ExtensionPointRegistry extensionPoints; private Monitor monitor; private URLArtifactProcessor<Contribution> contributionProcessor; private ModelResolverExtensionPoint modelResolvers; @@ -115,16 +115,14 @@ public class NodeImpl implements SCANode, SCAClient { private ContributionFactory contributionFactory; private AssemblyFactory assemblyFactory; private XMLInputFactory inputFactory; - private XMLOutputFactory outputFactory; - private DocumentBuilderFactory documentBuilderFactory; - private TransformerFactory transformerFactory; - private StAXArtifactProcessor<Object> xmlProcessor; private ContributionBuilder contributionDependencyBuilder; - private CompositeBuilder domainCompositeBuilder; + private CompositeBuilder compositeBuilder; private StAXArtifactProcessorExtensionPoint xmlProcessors; - private URLArtifactProcessorExtensionPoint documentProcessors; - private RuntimeBootStrapper runtime; + private StAXArtifactProcessor<Composite> compositeProcessor; + private ProxyFactory proxyFactory; + private List<ModuleActivator> modules; private CompositeActivator compositeActivator; + private WorkScheduler workScheduler; /** * Constructs a new SCA node. @@ -166,94 +164,6 @@ public class NodeImpl implements SCANode, SCAClient { } } - /** - * Construct a node by discovering the node configuration (composite+contrbutions) on the classpath - * @param classLoader - * @param compositeURI - */ - NodeImpl(ClassLoader classLoader, String compositeURI) { - configurationName = compositeURI; - logger.log(Level.INFO, "Creating node: " + configurationName); - - if (compositeURI != null) { - URI uri = URI.create(compositeURI); - if (uri.isAbsolute()) { - throw new IllegalArgumentException("Composite URI must be a resource name: " + compositeURI); - } - } - try { - // Initialize the runtime - init(); - - ConfiguredNodeImplementation config = findNodeConfiguration(compositeURI, classLoader); - configureNode(config); - } catch (Throwable e) { - throw new ServiceRuntimeException(e); - } - } - - /** - * Discover the contribution on the classpath - * @param compositeURI - * @param classLoader - * @return A configured node implementation - * @throws Exception - */ - private ConfiguredNodeImplementation findNodeConfiguration(final String compositeURI, ClassLoader classLoader) - throws Exception { - NodeImplementationFactory nodeImplementationFactory = - modelFactories.getFactory(NodeImplementationFactory.class); - ConfiguredNodeImplementation config = nodeImplementationFactory.createConfiguredNodeImplementation(); - - // Default to thread context classloader - if (classLoader == null) { - classLoader = Thread.currentThread().getContextClassLoader(); - } - String contributionArtifactPath = compositeURI; - URL contributionArtifactURL = null; - if (compositeURI != null) { - contributionArtifactURL = getResource(classLoader, compositeURI); - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath); - } - // Set to relative URI to avoid duplicate loading - Composite composite = createComposite(compositeURI); - config.setComposite(composite); - } else { - // No composite is specified, tring to search the SCA metadata files - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META; - contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_META); - - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META; - contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_GENERATED_META); - } - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES; - contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_DEPLOYABLES); - } - - // No contribution can be discovered - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("No default contribution can be discovered on the classpath"); - } - - // No composite will be created, all deployable composites will be used later - } - - Contribution c = getContribution(contributionArtifactURL, contributionArtifactPath); - config.getContributions().add(c); - - return config; - } - - private Contribution getContribution(URL contributionArtifactURL, String contributionArtifactPath) { - URL contributionURL = getContributionURL(contributionArtifactURL, contributionArtifactPath); - SCAContribution contribution = new SCAContribution(contributionURL.toString(), contributionURL.toString()); - Contribution c = createContribution(contributionFactory, contribution); - return c; - } - /** * Constructs a new SCA node. * @@ -268,28 +178,21 @@ public class NodeImpl implements SCANode, SCAClient { // Initialize the runtime init(); - URI uri = compositeURI == null ? null : URI.create(compositeURI); - ConfiguredNodeImplementation configuration = null; - if (contributions == null || contributions.length == 0) { - if (uri != null && uri.getScheme() != null) { - throw new IllegalArgumentException("No SCA contributions are provided"); - } - configuration = findNodeConfiguration(compositeURI, null); - } else { - - // Create a node configuration - NodeImplementationFactory nodeImplementationFactory = - modelFactories.getFactory(NodeImplementationFactory.class); - configuration = nodeImplementationFactory.createConfiguredNodeImplementation(); + // Create a node configuration + NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class); + ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation(); - Composite composite = compositeURI == null ? null : createComposite(compositeURI); + if (compositeURI != null) { + Composite composite = assemblyFactory.createComposite(); + composite.setURI(compositeURI); + composite.setUnresolved(true); configuration.setComposite(composite); + } // Create contribution models - for (SCAContribution c : contributions) { - Contribution contribution = createContribution(contributionFactory, c); - configuration.getContributions().add(contribution); - } + for (SCAContribution c : contributions) { + Contribution contribution = contribution(contributionFactory, c); + configuration.getContributions().add(contribution); } // Configure the node @@ -300,14 +203,6 @@ public class NodeImpl implements SCANode, SCAClient { } } - private Composite createComposite(String compositeURI) { - // Create composite model - Composite composite = assemblyFactory.createComposite(); - composite.setURI(compositeURI); - composite.setUnresolved(true); - return composite; - } - /** * Constructs a new SCA node. * @@ -323,32 +218,29 @@ public class NodeImpl implements SCANode, SCAClient { // Initialize the runtime init(); - ConfiguredNodeImplementation configuration = null; - if (contributions == null || contributions.length == 0) { - configuration = findNodeConfiguration(compositeURI, null); - } else { - // Create a node configuration - NodeImplementationFactory nodeImplementationFactory = - modelFactories.getFactory(NodeImplementationFactory.class); - configuration = nodeImplementationFactory.createConfiguredNodeImplementation(); - - // Read the composite model - StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class); - // URL compositeURL = new URL(compositeURI); - logger.log(Level.INFO, "Loading composite: " + compositeURI); + // Create a node configuration + NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class); + ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation(); - CompositeDocumentProcessor compositeDocProcessor = (CompositeDocumentProcessor)documentProcessors.getProcessor(Composite.class); - composite = compositeDocProcessor.read(URI.create(compositeURI), new ByteArrayInputStream(compositeContent.getBytes("UTF-8"))); + // Read the composite model + logger.log(Level.INFO, "Loading composite: " + compositeURI); - analyzeProblems(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(new ByteArrayInputStream(compositeContent.getBytes("UTF-8"))); + reader.nextTag(); + + // Read the composite model + composite = (Composite)compositeProcessor.read(reader); + if (composite != null) { + composite.setURI(compositeURI); + } + analyzeProblems(); - configuration.setComposite(composite); + configuration.setComposite(composite); - // Create contribution models - for (SCAContribution c : contributions) { - Contribution contribution = createContribution(contributionFactory, c); - configuration.getContributions().add(contribution); - } + // Create contribution models + for (SCAContribution c : contributions) { + Contribution contribution = contribution(contributionFactory, c); + configuration.getContributions().add(contribution); } // Configure the node @@ -360,9 +252,10 @@ public class NodeImpl implements SCANode, SCAClient { } private void init() { + long start = currentTimeMillis(); // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -378,17 +271,19 @@ public class NodeImpl implements SCANode, SCAClient { // Get XML input/output factories modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); inputFactory = modelFactories.getFactory(XMLInputFactory.class); - outputFactory = modelFactories.getFactory(XMLOutputFactory.class); // Get contribution workspace and assembly model factories contributionFactory = modelFactories.getFactory(ContributionFactory.class); workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + + // Use the runtime-enabled assembly factory + assemblyFactory = new RuntimeAssemblyFactory(); + modelFactories.addFactory(assemblyFactory); // Create XML artifact processors xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessors, inputFactory, outputFactory, monitor); + compositeProcessor = xmlProcessors.getProcessor(Composite.class); // Create contribution content processor URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); @@ -403,25 +298,39 @@ public class NodeImpl implements SCANode, SCAClient { // Get composite builders CompositeBuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class); - domainCompositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - } - - /** - * Initialize the Tuscany runtime. - * - * @throws Exception - */ - private void initRuntime() throws Exception { + compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + // Initialize runtime - // Create a node runtime - runtime = new RuntimeBootStrapper(Thread.currentThread().getContextClassLoader()); - runtime.start(); + // Load the runtime modules + try { + modules = loadModules(extensionPoints); - // Save the composite activator - compositeActivator = runtime.getCompositeActivator(); + // 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); + // Get the composite activator + compositeActivator = utilities.getUtility(CompositeActivator.class); + + workScheduler = utilities.getUtility(WorkScheduler.class); + + // Load the definitions.xml + //loadSCADefinitions(); + + if (logger.isLoggable(Level.FINE)) { + long end = currentTimeMillis(); + logger.fine("The tuscany runtime started in " + (end - start) + " ms."); + } + } + private void configureNode(ConfiguredNodeImplementation configuration) throws Exception { // Create workspace model @@ -460,20 +369,46 @@ public class NodeImpl implements SCANode, SCAClient { } composite = configuration.getComposite(); - if (composite.isUnresolved()) { - - // Find the composite in the given contributions - for (Contribution contribution: workspace.getContributions()) { - composite = contribution.getModelResolver().resolveModel(Composite.class, composite); + + // Find the composite in the given contributions + boolean found = false; + Artifact compositeFile = contributionFactory.createArtifact(); + compositeFile.setUnresolved(true); + compositeFile.setURI(composite.getURI()); + for (Contribution contribution: workspace.getContributions()) { + ModelResolver resolver = contribution.getModelResolver(); + Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile); + if (!resolvedArtifact.isUnresolved() && resolvedArtifact.getModel() instanceof Composite) { + if (!composite.isUnresolved()) { - break; + + // The composite content was passed into the node and read into a composite model, + // don't use the composite found in the contribution, use that composite, but just resolve + // it within the context of the contribution + compositeProcessor.resolve(composite, resolver); + + } else { + + // Use the resolved composite we've found in the contribution + composite = (Composite)resolvedArtifact.getModel(); } + found = true; + break; } } + if (!found) { + throw new IllegalArgumentException("Composite not found: " + composite.getURI()); + } + // Build an aggregated SCA definitions model + SCADefinitions definitions = null; + //definitions = new SCADefinitionsImpl(); + //for (SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions)) { + // SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions); + //} + // Build the composite and wire the components included in it - domainCompositeBuilder.build(composite); - + compositeBuilder.build(composite, definitions, monitor); analyzeProblems(); // Create a top level composite to host our composite @@ -489,44 +424,49 @@ public class NodeImpl implements SCANode, SCAClient { // logic in callable reference resolution relies on this being // available compositeActivator.setDomainComposite(tempComposite); - } public void start() { logger.log(Level.INFO, "Starting node: " + configurationName); try { - + // Activate the composite compositeActivator.activate(composite); // Start the composite compositeActivator.start(composite); - + } catch (ActivationException e) { - throw new ServiceRuntimeException(e); + throw new IllegalStateException(e); } + } public void stop() { logger.log(Level.INFO, "Stopping node: " + configurationName); try { - + // Stop the composite compositeActivator.stop(composite); - + // Deactivate the composite compositeActivator.deactivate(composite); - runtime.stop(); } catch (ActivationException e) { - throw new ServiceRuntimeException(e); + throw new IllegalStateException(e); } + + // Stop the runtime modules + stopModules(extensionPoints, modules); + + // Stop and destroy the work manager + workScheduler.destroy(); } public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException { - return (R)runtime.getProxyFactory().cast(target); + return (R)proxyFactory.cast(target); } public <B> B getService(Class<B> businessInterface, String serviceName) { 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 f315be8431..0aaee432a8 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 @@ -20,19 +20,28 @@ package org.apache.tuscany.sca.node.impl; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Map; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.service.util.FileHelper; +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; /** @@ -41,16 +50,9 @@ import org.apache.tuscany.sca.node.SCAContribution; * @version $Rev: $ $Date: $ */ public class NodeUtil { + private static final Logger logger = Logger.getLogger(NodeImpl.class.getName()); - static URL getResource(final ClassLoader classLoader, final String compositeURI) { - return AccessController.doPrivileged(new PrivilegedAction<URL>() { - public URL run() { - return classLoader.getResource(compositeURI); - } - }); - } - - static Contribution createContribution(ContributionFactory contributionFactory, SCAContribution c) { + static Contribution contribution(ContributionFactory contributionFactory, SCAContribution c) { Contribution contribution = contributionFactory.createContribution(); contribution.setURI(c.getURI()); contribution.setLocation(c.getLocation()); @@ -70,88 +72,118 @@ public class NodeUtil { return URI.create(uri); } - /** - * Collect JARs on the classpath of a URLClassLoader - * @param urls - * @param cl - */ - static void collectJARs(Map<String, URL> urls, ClassLoader cl) { - if (cl == null) { - return; - } - - // Collect JARs from the URLClassLoader's classpath - if (cl instanceof URLClassLoader) { - URL[] jarURLs = ((URLClassLoader)cl).getURLs(); - if (jarURLs != null) { - for (URL jarURL : jarURLs) { - String file = jarURL.getPath(); - int i = file.lastIndexOf('/'); - if (i != -1 && i < file.length() - 1) { - file = file.substring(i + 1); - urls.put(file, jarURL); - } + 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); } - - // Collect JARs from the parent ClassLoader - collectJARs(urls, cl.getParent()); + + return modules; } - static URL getContributionURL(URL contributionArtifactURL, String contributionArtifactPath) { - URL contributionURL = null; - // "jar:file://....../something.jar!/a/b/c/app.composite" - try { - String url = contributionArtifactURL.toExternalForm(); - String protocol = contributionArtifactURL.getProtocol(); - if ("file".equals(protocol)) { - // directory contribution - if (url.endsWith(contributionArtifactPath)) { - final String location = url.substring(0, url.lastIndexOf(contributionArtifactPath)); - // workaround from evil URL/URI form Maven - // contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - // Allow privileged access to open URL stream. Add FilePermission to added to - // security policy file. - try { - contributionURL = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() { - public URL run() throws IOException { - return FileHelper.toFile(new URL(location)).toURI().toURL(); - } - }); - } catch (PrivilegedActionException e) { - throw (MalformedURLException)e.getException(); - } + 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."); } - - } else if ("jar".equals(protocol)) { - // jar contribution - String location = url.substring(4, url.lastIndexOf("!/")); - // workaround for evil URL/URI from Maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - - } else if ("wsjar".equals(protocol)) { - // See https://issues.apache.org/jira/browse/TUSCANY-2219 - // wsjar contribution - String location = url.substring(6, url.lastIndexOf("!/")); - // workaround for evil url/uri from maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - - } else if ("zip".equals(protocol)) { - // See https://issues.apache.org/jira/browse/TUSCANY-2598 - // zip contribution, remove the zip prefix and pad with file: - String location = "file:"+url.substring(4, url.lastIndexOf("!/")); - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - - } else if (protocol != null && (protocol.equals("bundle") || protocol.equals("bundleresource"))) { - contributionURL = - new URL(contributionArtifactURL.getProtocol(), contributionArtifactURL.getHost(), - contributionArtifactURL.getPort(), "/"); + } 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."); } - } catch (MalformedURLException mfe) { - throw new IllegalArgumentException(mfe); } - return contributionURL; } +// private void loadSCADefinitions() throws ActivationException { +// try { +// URLArtifactProcessorExtensionPoint documentProcessors = +// registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); +// URLArtifactProcessor<SCADefinitions> definitionsProcessor = +// documentProcessors.getProcessor(SCADefinitions.class); +// SCADefinitionsProviderExtensionPoint scaDefnProviders = +// registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class); +// +// SCADefinitions systemSCADefinitions = new SCADefinitionsImpl(); +// SCADefinitions aSCADefn = null; +// for (SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders()) { +// aSCADefn = aProvider.getSCADefinition(); +// SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions); +// } +// +// policyDefinitions.add(systemSCADefinitions); +// +// //we cannot expect that providers will add the intents and policysets into the resolver +// //so we do this here explicitly +// for (Intent intent : systemSCADefinitions.getPolicyIntents()) { +// policyDefinitionsResolver.addModel(intent); +// } +// +// for (PolicySet policySet : systemSCADefinitions.getPolicySets()) { +// policyDefinitionsResolver.addModel(policySet); +// } +// +// for (IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes()) { +// policyDefinitionsResolver.addModel(attachPoinType); +// } +// +// for (IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes()) { +// policyDefinitionsResolver.addModel(attachPoinType); +// } +// +// //now that all system sca definitions have been read, lets resolve them right away +// definitionsProcessor.resolve(systemSCADefinitions, policyDefinitionsResolver); +// +// } catch (Exception e) { +// throw new ActivationException(e); +// } +// } + } diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java deleted file mode 100644 index a378e57d31..0000000000 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * 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 java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.ModuleActivator; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; -import org.apache.tuscany.sca.core.scope.ScopeRegistry; -import org.apache.tuscany.sca.definitions.SCADefinitions; -import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl; -import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory; -import org.apache.tuscany.sca.policy.DefaultPolicyFactory; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.IntentAttachPointType; -import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.provider.SCADefinitionsProvider; -import org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint; -import org.apache.tuscany.sca.work.WorkScheduler; - -/** - * - * @version $Rev$ $Date$ - */ -public class RuntimeBootStrapper { - private static final Logger logger = Logger.getLogger(RuntimeBootStrapper.class.getName()); - private List<ModuleActivator> modules; - - private ClassLoader classLoader; - private CompositeActivator compositeActivator; - private WorkScheduler workScheduler; - private ScopeRegistry scopeRegistry; - private ProxyFactory proxyFactory; - private List<SCADefinitions> policyDefinitions; - private ModelResolver policyDefinitionsResolver; - - public RuntimeBootStrapper(ClassLoader classLoader) { - this.classLoader = classLoader; - } - - public void startRuntime() throws ActivationException { - long start = System.currentTimeMillis(); - - // Create our extension point registry - registry = new DefaultExtensionPointRegistry(); - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - - // Get work scheduler - workScheduler = utilities.getUtility(WorkScheduler.class); - - // Create an interface contract mapper - InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); - - // Get factory extension point - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - - // Get Message factory - MessageFactory messageFactory = factories.getFactory(MessageFactory.class); - - // Get proxy factory - ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); - proxyFactory = new ExtensibleProxyFactory(proxyFactories); - - // Create model factories - assemblyFactory = new RuntimeAssemblyFactory(); - factories.addFactory(assemblyFactory); - PolicyFactory policyFactory = new DefaultPolicyFactory(); - factories.addFactory(policyFactory); - - // Load the runtime modules - modules = loadModules(registry); - - // Start the runtime modules - startModules(registry, modules); - - SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class); - IntentAttachPointTypeFactory intentAttachPointTypeFactory = new DefaultIntentAttachPointTypeFactory(); - factories.addFactory(intentAttachPointTypeFactory); - ContributionFactory contributionFactory = factories.getFactory(ContributionFactory.class); - - // Create a monitor - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - } else { - monitorFactory = new DefaultMonitorFactory(); - monitor = monitorFactory.createMonitor(); - utilities.addUtility(monitorFactory); - //logger.fine("No MonitorFactory is found on the classpath."); - } - - // Create a contribution service - policyDefinitions = new ArrayList<SCADefinitions>(); - policyDefinitionsResolver = new DefaultModelResolver(); - contributionService = - RuntimeBuilder.createContributionService(classLoader, - registry, - contributionFactory, - assemblyFactory, - policyFactory, - mapper, - policyDefinitions, - policyDefinitionsResolver, - monitor); - - // Create the ScopeRegistry - scopeRegistry = RuntimeBuilder.createScopeRegistry(registry); - - // Create a composite activator - compositeActivator = - RuntimeBuilder.createCompositeActivator(registry, - assemblyFactory, - messageFactory, - scaBindingFactory, - mapper, - proxyFactory, - scopeRegistry, - workScheduler); - - // Load the definitions.xml - loadSCADefinitions(); - - if (logger.isLoggable(Level.FINE)) { - long end = System.currentTimeMillis(); - logger.fine("The tuscany runtime is started in " + (end - start) + " ms."); - } - } - - public void stopRuntime() throws ActivationException { - long start = System.currentTimeMillis(); - - // Stop the runtime modules - stopModules(registry, modules); - - // Stop and destroy the work manager - workScheduler.destroy(); - - // Cleanup - modules = null; - registry = null; - assemblyFactory = null; - compositeActivator = null; - workScheduler = null; - scopeRegistry = null; - - if (logger.isLoggable(Level.FINE)) { - long end = System.currentTimeMillis(); - logger.fine("The tuscany runtime is stopped in " + (end - start) + " ms."); - } - } - - public void buildComposite(Composite composite) throws CompositeBuilderException { - - SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl(); - for (SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions)) { - SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions); - } - - } - - private void loadSCADefinitions() throws ActivationException { - try { - URLArtifactProcessorExtensionPoint documentProcessors = - registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - URLArtifactProcessor<SCADefinitions> definitionsProcessor = - documentProcessors.getProcessor(SCADefinitions.class); - SCADefinitionsProviderExtensionPoint scaDefnProviders = - registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class); - - SCADefinitions systemSCADefinitions = new SCADefinitionsImpl(); - SCADefinitions aSCADefn = null; - for (SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders()) { - aSCADefn = aProvider.getSCADefinition(); - SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions); - } - - policyDefinitions.add(systemSCADefinitions); - - //we cannot expect that providers will add the intents and policysets into the resolver - //so we do this here explicitly - for (Intent intent : systemSCADefinitions.getPolicyIntents()) { - policyDefinitionsResolver.addModel(intent); - } - - for (PolicySet policySet : systemSCADefinitions.getPolicySets()) { - policyDefinitionsResolver.addModel(policySet); - } - - for (IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes()) { - policyDefinitionsResolver.addModel(attachPoinType); - } - - for (IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes()) { - policyDefinitionsResolver.addModel(attachPoinType); - } - - //now that all system sca definitions have been read, lets resolve them right away - definitionsProcessor.resolve(systemSCADefinitions, policyDefinitionsResolver); - - } catch (Exception e) { - throw new ActivationException(e); - } - } - - private List<ModuleActivator> loadModules(ExtensionPointRegistry registry) throws ActivationException { - - // Load and instantiate the modules found on the classpath (or any registered ClassLoaders) - 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; - } - - private 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); - } - } - } - - private 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."); - } - } - } - - /** - * @return the proxyFactory - */ - public ProxyFactory getProxyFactory() { - return proxyFactory; - } - -} diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java deleted file mode 100644 index d7cda91b74..0000000000 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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 java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.List; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.transform.TransformerFactory; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.EndpointFactory; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; -import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor; -import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; -import org.apache.tuscany.sca.context.RequestContextFactory; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory; -import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.PackageProcessor; -import org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionRepository; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener; -import org.apache.tuscany.sca.contribution.service.TypeDescriber; -import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl; -import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl; -import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl; -import org.apache.tuscany.sca.core.conversation.ConversationManager; -import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; -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.definitions.SCADefinitions; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; -import org.apache.tuscany.sca.work.WorkScheduler; - -/** - * - * @version $Rev$ $Date$ - */ -public class RuntimeBuilder { - - // private static final Logger logger = Logger.getLogger(RuntimeBuilder.class.getName()); - - public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry, - AssemblyFactory assemblyFactory, - MessageFactory messageFactory, - SCABindingFactory scaBindingFactory, - InterfaceContractMapper mapper, - ProxyFactory proxyFactory, - ScopeRegistry scopeRegistry, - WorkScheduler workScheduler) { - - // Create a wire post processor extension point - RuntimeWireProcessorExtensionPoint wireProcessors = - registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); - RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors); - - // Retrieve the processors extension point - StAXArtifactProcessorExtensionPoint processors = - registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - - // Create a provider factory extension point - ProviderFactoryExtensionPoint providerFactories = - registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); - - // Create a endpoint resolver factory extension point - EndpointResolverFactoryExtensionPoint endpointResolverFactories = - registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); - - JavaInterfaceFactory javaInterfaceFactory = - registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class); - RequestContextFactory requestContextFactory = - registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class); - - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - ConversationManager conversationManager = utilities.getUtility(ConversationManager.class); - - // Create the composite activator - CompositeActivator compositeActivator = - new CompositeActivatorImpl(assemblyFactory, messageFactory, javaInterfaceFactory, scaBindingFactory, - mapper, scopeRegistry, workScheduler, wireProcessor, requestContextFactory, - proxyFactory, providerFactories, endpointResolverFactories, processors, - conversationManager); - - return compositeActivator; - } - - /** - * Create the contribution service used by this domain. - * - * @throws ActivationException - */ - public static ContributionService createContributionService(ClassLoader classLoader, - ExtensionPointRegistry registry, - ContributionFactory contributionFactory, - AssemblyFactory assemblyFactory, - PolicyFactory policyFactory, - InterfaceContractMapper mapper, - List<SCADefinitions> policyDefinitions, - ModelResolver policyDefinitionResolver, - Monitor monitor) throws ActivationException { - - // Get the model factory extension point - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - - // Create a new XML input factory - XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); - - // Create a validation XML schema extension point - ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); - - // Create a validating XML input factory - XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, monitor); - modelFactories.addFactory(validatingInputFactory); - - // Create StAX artifact processor extension point - StAXArtifactProcessorExtensionPoint staxProcessors = - registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - - // Create and register StAX processors for SCA assembly XML - // Allow privileged access to factory. Requires RuntimePermission in security policy file. - XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); - ExtensibleStAXArtifactProcessor staxProcessor = - new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); - - // Create URL artifact processor extension point - URLArtifactProcessorExtensionPoint documentProcessors = - registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - - // Create and register document processors for SCA assembly XML - DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); - documentBuilderFactory.setNamespaceAware(true); - documentProcessors.getProcessor(Composite.class); - documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, - documentBuilderFactory, policyDefinitions, monitor)); - - // Create Model Resolver extension point - ModelResolverExtensionPoint modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class); - - // Create contribution package processor extension point - TypeDescriber describer = new PackageTypeDescriberImpl(); - PackageProcessor packageProcessor = - new ExtensiblePackageProcessor(registry.getExtensionPoint(PackageProcessorExtensionPoint.class), describer, - monitor); - - // Create contribution listener - ExtensibleContributionListener contributionListener = - new ExtensibleContributionListener(registry.getExtensionPoint(ContributionListenerExtensionPoint.class)); - - // Create a contribution repository - ContributionRepository repository; - try { - repository = new ContributionRepositoryImpl("target", inputFactory, monitor); - } catch (IOException e) { - throw new ActivationException(e); - } - - ExtensibleURLArtifactProcessor documentProcessor = - new ExtensibleURLArtifactProcessor(documentProcessors, monitor); - - // Create the contribution service - ContributionService contributionService = - new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor, - contributionListener, policyDefinitionResolver, modelResolvers, modelFactories, - assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor); - return contributionService; - } - - public static ScopeRegistry createScopeRegistry(ExtensionPointRegistry registry) { - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - ScopeContainerFactory[] factories = - new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(), - new RequestScopeContainerFactory(), - new ConversationalScopeContainerFactory(null), - // new HttpSessionScopeContainer(monitor) - }; - for (ScopeContainerFactory f : factories) { - scopeRegistry.register(f); - } - - //FIXME Pass the scope container differently as it's not an extension point - registry.addExtensionPoint(scopeRegistry); - - return scopeRegistry; - } - -} 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 d620f6b62a..e91f399a57 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 @@ -49,35 +49,12 @@ public class NodeImplTestCase { public void testNodeWithCompositeContent() { SCANodeFactory factory = new NodeFactoryImpl(); SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); - SCANode node = factory.createSCANode("HelloWorld.composite", composite, contribution); - testNode(node); - } - - @Test - public void testNodeWithCompositeContentAndNoContribution() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCANode node = factory.createSCANode("HelloWorld.composite", composite); - testNode(node); - } - - @Test - public void testNodeWithoutCompositeURI() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); - SCANode node = factory.createSCANode(null, contribution); + String compositeURI = "HelloWorld.composite"; + SCANode node = factory.createSCANode(compositeURI, composite, contribution); testNode(node); } @Test - public void testNodeWithCompositeURI() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); - String compositeURI = new File("target/test-classes/HelloWorld.composite").toURI().toString(); - SCANode node = factory.createSCANode(compositeURI, contribution); - testNode(node); - } - - @Test public void testNodeWithRelativeCompositeURI() { SCANodeFactory factory = new NodeFactoryImpl(); SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString()); @@ -86,29 +63,6 @@ public class NodeImplTestCase { testNode(node); } - @Test - public void testNodeWithRelativeCompositeURIAndNoContribution() { - SCANodeFactory factory = new NodeFactoryImpl(); - String compositeURI = "HelloWorld.composite"; - SCANode node = factory.createSCANode(compositeURI, new SCAContribution[0]); - testNode(node); - } - - @Test - public void testNodeWithClassLoader() { - SCANodeFactory factory = new NodeFactoryImpl(); - String compositeURI = "HelloWorld.composite"; - SCANode node = factory.createSCANodeFromClassLoader(compositeURI, HelloWorld.class.getClassLoader()); - testNode(node); - } - - @Test - public void testNodeWithClassLoaderAndNullComposite() { - SCANodeFactory factory = new NodeFactoryImpl(); - SCANode node = factory.createSCANodeFromClassLoader(null, HelloWorld.class.getClassLoader()); - testNode(node); - } - private void testNode(SCANode node) { node.start(); HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld"); |