Change the NodeFactoryImpl to be capable of hosting multiple instances of SCA node in the same JVM and align the OSGiNodeFactoryImpl to that feature
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08ba6e5320
commit
9182bba609
17 changed files with 849 additions and 1425 deletions
|
@ -1,6 +1,9 @@
|
|||
import java.net.URI;
|
||||
package test.scaclient;
|
||||
|
||||
import itest.HelloworldService;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
|
@ -9,7 +12,7 @@ import org.oasisopen.sca.client.SCAClientFactory;
|
|||
|
||||
/**
|
||||
* Test SCADomain.newInstance and invocation of a service.
|
||||
*
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class SCAClientTestCase extends TestCase {
|
||||
|
@ -23,7 +26,10 @@ public class SCAClientTestCase extends TestCase {
|
|||
}
|
||||
|
||||
public void testInvoke() throws Exception {
|
||||
HelloworldService service = SCAClientFactory.newInstance().getService(HelloworldService.class, "HelloworldComponent", URI.create("default"));
|
||||
HelloworldService service =
|
||||
SCAClientFactory.newInstance().getService(HelloworldService.class,
|
||||
"HelloworldComponent",
|
||||
URI.create(Node.DEFAULT_DOMAIN_URI));
|
||||
assertEquals("Hello petra", service.sayHello("petra"));
|
||||
}
|
||||
|
|
@ -6,20 +6,24 @@
|
|||
* 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.
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.extensibility;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -27,7 +31,7 @@ import java.util.logging.Logger;
|
|||
* Service discovery for Tuscany based on J2SE Jar service provider spec.
|
||||
* Services are described using configuration files in META-INF/services.
|
||||
* Service description specifies a class name followed by optional properties.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
|
@ -37,14 +41,14 @@ public final class ServiceDiscovery implements ServiceDiscoverer {
|
|||
private final static ServiceDiscovery INSTANCE = new ServiceDiscovery();
|
||||
|
||||
private ServiceDiscoverer discoverer;
|
||||
|
||||
|
||||
private ServiceDiscovery() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Get an instance of Service discovery, one instance is created per
|
||||
* ClassLoader that this class is loaded from
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ServiceDiscovery getInstance() {
|
||||
|
@ -80,8 +84,34 @@ public final class ServiceDiscovery implements ServiceDiscoverer {
|
|||
}
|
||||
|
||||
public ServiceDeclaration getFirstServiceDeclaration(final String name) throws IOException {
|
||||
ServiceDeclaration service = getServiceDiscoverer().getFirstServiceDeclaration(name);
|
||||
return service;
|
||||
// ServiceDeclaration service = getServiceDiscoverer().getFirstServiceDeclaration(name);
|
||||
// return service;
|
||||
Set<ServiceDeclaration> declarations = getServiceDeclarations(name);
|
||||
if (!declarations.isEmpty()) {
|
||||
List<ServiceDeclaration> declarationList = new ArrayList<ServiceDeclaration>(declarations);
|
||||
Collections.sort(declarationList, ServiceComparator.INSTANCE);
|
||||
return declarationList.get(declarationList.size() - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ServiceComparator implements Comparator<ServiceDeclaration> {
|
||||
private final static ServiceComparator INSTANCE = new ServiceComparator();
|
||||
|
||||
public int compare(ServiceDeclaration o1, ServiceDeclaration o2) {
|
||||
int rank1 = 0;
|
||||
String r1 = o1.getAttributes().get("ranking");
|
||||
if (r1 != null) {
|
||||
rank1 = Integer.parseInt(r1);
|
||||
}
|
||||
int rank2 = 0;
|
||||
String r2 = o2.getAttributes().get("ranking");
|
||||
if (r2 != null) {
|
||||
rank2 = Integer.parseInt(r2);
|
||||
}
|
||||
return rank1 - rank2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package org.apache.tuscany.sca.node;
|
||||
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -28,7 +31,8 @@ package org.apache.tuscany.sca.node;
|
|||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public interface Node extends Client {
|
||||
|
||||
String DEFAULT_DOMAIN_URI = NodeConfiguration.DEFAULT_DOMAIN_URI;
|
||||
String DEFAULT_NODE_URI = NodeConfiguration.DEFAULT_NODE_URI;
|
||||
/**
|
||||
* Start the composite loaded in the node.
|
||||
* @return Return the node itself so that we can call NodeFactory.newInstance().createNode(...).start()
|
||||
|
@ -45,4 +49,6 @@ public interface Node extends Client {
|
|||
*/
|
||||
void destroy();
|
||||
|
||||
// NodeConfiguration getConfiguration();
|
||||
|
||||
}
|
||||
|
|
|
@ -426,6 +426,9 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
|
|||
return contributions;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SCA node based on the configuration
|
||||
* @param configuration The configuration of a node
|
||||
|
|
|
@ -31,6 +31,8 @@ import javax.xml.namespace.QName;
|
|||
* The configuration for a Node which represents the deployment of an SCA composite application
|
||||
*/
|
||||
public interface NodeConfiguration {
|
||||
String DEFAULT_DOMAIN_URI = "http://tuscany.apache.org/sca/1.1/domains/default";
|
||||
String DEFAULT_NODE_URI = "http://tuscany.apache.org/sca/1.1/nodes/default";
|
||||
/**
|
||||
* Get the URI of the SCA domain that manages the composite application
|
||||
* @return The URI of the SCA domain
|
||||
|
@ -80,4 +82,6 @@ public interface NodeConfiguration {
|
|||
NodeConfiguration addBinding(BindingConfiguration binding);
|
||||
NodeConfiguration addBinding(QName bindingType, String...baseURIs);
|
||||
NodeConfiguration addBinding(QName bindingType, URI...baseURIs);
|
||||
|
||||
List<Object> getExtensions();
|
||||
}
|
||||
|
|
|
@ -36,10 +36,11 @@ import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
|||
* Default implementation of NodeConfiguration
|
||||
*/
|
||||
public class NodeConfigurationImpl implements NodeConfiguration {
|
||||
private String uri;
|
||||
private String domainURI = "default";
|
||||
private String uri = DEFAULT_NODE_URI;
|
||||
private String domainURI = DEFAULT_DOMAIN_URI;
|
||||
private List<ContributionConfiguration> contributions = new ArrayList<ContributionConfiguration>();
|
||||
private List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
|
||||
private List<Object> extensions =new ArrayList<Object>();
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
|
@ -146,4 +147,8 @@ public class NodeConfigurationImpl implements NodeConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
public List<Object> getExtensions() {
|
||||
return extensions;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,14 @@ Import-Package: javax.xml.namespace,
|
|||
org.apache.tuscany.sca.implementation.node;version="2.0.0",
|
||||
org.apache.tuscany.sca.monitor;version="2.0.0",
|
||||
org.apache.tuscany.sca.node;version="2.0.0",
|
||||
org.apache.tuscany.sca.node.configuration;version="2.0.0",
|
||||
org.apache.tuscany.sca.node.impl;version="2.0.0",
|
||||
org.apache.tuscany.sca.policy;version="2.0.0",
|
||||
org.apache.tuscany.sca.provider;version="2.0.0",
|
||||
org.apache.tuscany.sca.runtime;version="2.0.0",
|
||||
org.apache.tuscany.sca.work;version="2.0.0",
|
||||
org.apache.tuscany.sca.workspace;version="2.0.0",
|
||||
org.apache.tuscany.sca.workspace.builder;version="2.0.0",
|
||||
org.apache.tuscany.sca.workspace;version="2.0.0";resolution:=optional,
|
||||
org.apache.tuscany.sca.workspace.builder;version="2.0.0";resolution:=optional,
|
||||
org.oasisopen.sca;version="2.0.0",
|
||||
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
|
||||
org.osgi.framework;version="1.4.0",
|
||||
|
|
|
@ -70,18 +70,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-assembly</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-contribution</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-extensibility-equinox</artifactId>
|
||||
|
@ -89,6 +77,12 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-workspace-impl</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-contribution-osgi</artifactId>
|
||||
|
@ -98,97 +92,10 @@
|
|||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-node-api</artifactId>
|
||||
<artifactId>tuscany-node-impl</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-implementation-node</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-core</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-contribution</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-assembly-xml</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-workspace</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-workspace-impl</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-definitions-xml</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-binding-sca-runtime</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-policy-xml</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-core-databinding</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-assembly-xsd</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-endpoint</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-implementation-java-runtime</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-node-launcher-equinox</artifactId>
|
||||
|
@ -196,27 +103,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-binding-rmi-runtime</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-binding-rmi</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-host-rmi</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-implementation-osgi</artifactId>
|
||||
|
@ -231,13 +117,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,704 +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.osgi.impl;
|
||||
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.tuscany.sca.node.osgi.impl.NodeUtil.contribution;
|
||||
import static org.apache.tuscany.sca.node.osgi.impl.NodeUtil.createURI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.AssemblyFactory;
|
||||
import org.apache.tuscany.sca.assembly.Component;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
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.contribution.Artifact;
|
||||
import org.apache.tuscany.sca.contribution.Contribution;
|
||||
import org.apache.tuscany.sca.contribution.ContributionFactory;
|
||||
import org.apache.tuscany.sca.contribution.DefaultImport;
|
||||
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
|
||||
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
|
||||
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
|
||||
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
|
||||
import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
|
||||
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.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.Definitions;
|
||||
import org.apache.tuscany.sca.definitions.DefinitionsFactory;
|
||||
import org.apache.tuscany.sca.definitions.util.DefinitionsUtil;
|
||||
import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint;
|
||||
import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation;
|
||||
import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
|
||||
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.Client;
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProvider;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderException;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint;
|
||||
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;
|
||||
import org.apache.tuscany.sca.workspace.builder.ContributionBuilderExtensionPoint;
|
||||
import org.oasisopen.sca.CallableReference;
|
||||
import org.oasisopen.sca.ServiceReference;
|
||||
import org.oasisopen.sca.ServiceRuntimeException;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
/**
|
||||
* Represents an SCA runtime node.
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class NodeFactoryImpl {
|
||||
|
||||
private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
|
||||
|
||||
private static final Logger logger = Logger.getLogger(NodeFactoryImpl.class.getName());
|
||||
|
||||
private boolean inited;
|
||||
private BundleContext bundleContext;
|
||||
private ServiceRegistration registration;
|
||||
|
||||
private ExtensionPointRegistry extensionPoints;
|
||||
private UtilityExtensionPoint utilities;
|
||||
private Monitor monitor;
|
||||
private URLArtifactProcessor<Contribution> contributionProcessor;
|
||||
private ModelResolverExtensionPoint modelResolvers;
|
||||
private FactoryExtensionPoint modelFactories;
|
||||
private WorkspaceFactory workspaceFactory;
|
||||
private ContributionFactory contributionFactory;
|
||||
private AssemblyFactory assemblyFactory;
|
||||
private XMLInputFactory inputFactory;
|
||||
private ContributionBuilder contributionDependencyBuilder;
|
||||
private CompositeBuilder compositeBuilder;
|
||||
private StAXArtifactProcessorExtensionPoint xmlProcessors;
|
||||
private StAXArtifactProcessor<Composite> compositeProcessor;
|
||||
private ProxyFactory proxyFactory;
|
||||
private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
|
||||
private WorkScheduler workScheduler;
|
||||
private Contribution systemContribution;
|
||||
private Definitions systemDefinitions;
|
||||
|
||||
private Map<Bundle, Node> nodes = new ConcurrentHashMap<Bundle, Node>();
|
||||
|
||||
/**
|
||||
* Constructs a new Node controller
|
||||
*/
|
||||
public NodeFactoryImpl(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
|
||||
private ConfiguredNodeImplementation getNodeConfiguration(Bundle bundle) {
|
||||
// Create a node configuration
|
||||
NodeImplementationFactory nodeImplementationFactory =
|
||||
modelFactories.getFactory(NodeImplementationFactory.class);
|
||||
ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
|
||||
|
||||
String compositeURI = (String)bundle.getHeaders().get("SCA-Composite");
|
||||
if (compositeURI == null) {
|
||||
compositeURI = "OSGI-INF/sca/bundle.composite";
|
||||
}
|
||||
if (compositeURI != null) {
|
||||
Composite composite = assemblyFactory.createComposite();
|
||||
composite.setURI(compositeURI);
|
||||
composite.setUnresolved(true);
|
||||
configuration.setComposite(composite);
|
||||
}
|
||||
|
||||
URL root = bundle.getEntry("/");
|
||||
org.apache.tuscany.sca.node.Contribution bundleContribution =
|
||||
new org.apache.tuscany.sca.node.Contribution(bundle.getSymbolicName(), root.toString());
|
||||
|
||||
Contribution contribution = contribution(contributionFactory, bundleContribution);
|
||||
configuration.getContributions().add(contribution);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private ConfiguredNodeImplementation getNodeConfiguration(Bundle bundle, String compositeContent) throws Exception {
|
||||
|
||||
ConfiguredNodeImplementation configuration = getNodeConfiguration(bundle);
|
||||
if (compositeContent != null) {
|
||||
|
||||
Composite deploymentComposite =
|
||||
addDeploymentComposite(configuration.getContributions().get(0), compositeContent);
|
||||
|
||||
configuration.setComposite(deploymentComposite);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the deployment composite to an installed SCA contribution
|
||||
* @param compositeContent The XML string for the deployment composite
|
||||
* @return The deployment composite
|
||||
* @throws Exception
|
||||
*/
|
||||
private Composite addDeploymentComposite(Contribution contrib, String compositeContent) throws Exception {
|
||||
|
||||
// Load the deployment composite
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(compositeContent));
|
||||
reader.nextTag();
|
||||
|
||||
// Read the composite model
|
||||
Composite deploymentComposite = (Composite)compositeProcessor.read(reader);
|
||||
|
||||
Artifact compositeArtifact = contributionFactory.createArtifact();
|
||||
compositeArtifact.setModel(deploymentComposite);
|
||||
compositeArtifact.setURI(deploymentComposite.getName()+".composite");
|
||||
compositeArtifact.setUnresolved(false);
|
||||
|
||||
contrib.getArtifacts().add(compositeArtifact);
|
||||
contrib.getDeployables().add(deploymentComposite);
|
||||
|
||||
analyzeProblems();
|
||||
return deploymentComposite;
|
||||
}
|
||||
|
||||
private synchronized void init() {
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
long start = currentTimeMillis();
|
||||
|
||||
// Create extension point registry
|
||||
extensionPoints = new DefaultExtensionPointRegistry();
|
||||
|
||||
utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
|
||||
|
||||
// Add the OSGi BundleContext as a system utility
|
||||
utilities.addUtility(bundleContext);
|
||||
|
||||
// Register the ExtensionPointRegistry as an OSGi service
|
||||
Dictionary<Object, Object> props = new Hashtable<Object, Object>();
|
||||
registration = bundleContext.registerService(ExtensionPointRegistry.class.getName(), extensionPoints, props);
|
||||
|
||||
// Enable schema validation only of the logger level is FINE or higher
|
||||
ValidationSchemaExtensionPoint schemas =
|
||||
extensionPoints.getExtensionPoint(ValidationSchemaExtensionPoint.class);
|
||||
if (schemas != null) {
|
||||
schemas.setEnabled(logger.isLoggable(Level.FINE));
|
||||
}
|
||||
|
||||
// Use the runtime-enabled assembly factory
|
||||
modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
|
||||
assemblyFactory = new RuntimeAssemblyFactory();
|
||||
modelFactories.addFactory(assemblyFactory);
|
||||
|
||||
// Create a monitor
|
||||
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
|
||||
monitor = monitorFactory.createMonitor();
|
||||
|
||||
// Initialize the Tuscany module activators
|
||||
ModuleActivatorExtensionPoint activators =
|
||||
extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
|
||||
for (ModuleActivator moduleActivator : activators.getModuleActivators()) {
|
||||
try {
|
||||
moduleActivator.start(extensionPoints);
|
||||
moduleActivators.add(moduleActivator);
|
||||
} catch (Throwable e) {
|
||||
// Ignore the failing module for now
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Get XML input/output factories
|
||||
inputFactory = modelFactories.getFactory(XMLInputFactory.class);
|
||||
|
||||
// Get contribution workspace and assembly model factories
|
||||
contributionFactory = modelFactories.getFactory(ContributionFactory.class);
|
||||
workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class);
|
||||
|
||||
// Create XML artifact processors
|
||||
xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
|
||||
compositeProcessor = xmlProcessors.getProcessor(Composite.class);
|
||||
|
||||
// Create contribution content processor
|
||||
URLArtifactProcessorExtensionPoint docProcessorExtensions =
|
||||
extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
|
||||
contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class);
|
||||
|
||||
// Get the model resolvers
|
||||
modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
|
||||
|
||||
// Get a contribution dependency builder
|
||||
ContributionBuilderExtensionPoint contributionBuilders =
|
||||
extensionPoints.getExtensionPoint(ContributionBuilderExtensionPoint.class);
|
||||
contributionDependencyBuilder =
|
||||
contributionBuilders
|
||||
.getContributionBuilder("org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder");
|
||||
|
||||
// Get composite builders
|
||||
CompositeBuilderExtensionPoint compositeBuilders =
|
||||
extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class);
|
||||
compositeBuilder =
|
||||
compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
|
||||
|
||||
// Initialize runtime
|
||||
|
||||
// Get proxy factory
|
||||
ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class);
|
||||
proxyFactory = new ExtensibleProxyFactory(proxyFactories);
|
||||
|
||||
workScheduler = utilities.getUtility(WorkScheduler.class);
|
||||
|
||||
// Load the system definitions.xml from all of the loaded extension points
|
||||
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
|
||||
systemDefinitions = definitionsFactory.createDefinitions();
|
||||
|
||||
DefinitionsExtensionPoint definitionsExtensionPoint = extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class);
|
||||
for(Definitions defs: definitionsExtensionPoint.getDefinitions()) {
|
||||
DefinitionsUtil.aggregate(systemDefinitions, defs);
|
||||
}
|
||||
|
||||
DefinitionsProviderExtensionPoint definitionsProviders =
|
||||
extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
|
||||
|
||||
// aggregate all the definitions into a single definitions model
|
||||
try {
|
||||
for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
|
||||
DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions);
|
||||
}
|
||||
} catch (DefinitionsProviderException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
// create a system contribution to hold the definitions. The contribution
|
||||
// will be extended later with definitions from application contributions
|
||||
systemContribution = contributionFactory.createContribution();
|
||||
systemContribution.setURI(SCA11_TUSCANY_NS + "/contributions/_system_");
|
||||
systemContribution.setLocation(SCA11_TUSCANY_NS + "/contributions/_system_");
|
||||
ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories);
|
||||
systemContribution.setModelResolver(modelResolver);
|
||||
systemContribution.setUnresolved(true);
|
||||
|
||||
// create an artifact to represent the system defintions and
|
||||
// add it to the contribution
|
||||
List<Artifact> artifacts = systemContribution.getArtifacts();
|
||||
Artifact artifact = contributionFactory.createArtifact();
|
||||
artifact.setURI(SCA11_TUSCANY_NS + "/contributions/_system_/definitions");
|
||||
artifact.setLocation(SCA11_TUSCANY_NS + "/contributions/_system_/definitions");
|
||||
artifact.setModel(systemDefinitions);
|
||||
artifacts.add(artifact);
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
long end = currentTimeMillis();
|
||||
logger.fine("The tuscany runtime started in " + (end - start) + " ms.");
|
||||
}
|
||||
inited = true;
|
||||
}
|
||||
|
||||
private Composite configureNode(ConfiguredNodeImplementation configuration) throws Exception {
|
||||
|
||||
// Create workspace model
|
||||
Workspace workspace = workspaceFactory.createWorkspace();
|
||||
workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories));
|
||||
|
||||
// Load the specified contributions
|
||||
for (Contribution c : configuration.getContributions()) {
|
||||
URI contributionURI = NodeUtil.createURI(c.getURI());
|
||||
|
||||
URI uri = createURI(c.getLocation());
|
||||
if (uri.getScheme() == null) {
|
||||
uri = new File(c.getLocation()).toURI();
|
||||
}
|
||||
URL contributionURL = uri.toURL();
|
||||
|
||||
// Load the contribution
|
||||
logger.log(Level.INFO, "Loading contribution: " + contributionURL);
|
||||
Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
|
||||
workspace.getContributions().add(contribution);
|
||||
analyzeProblems();
|
||||
}
|
||||
|
||||
// Build an aggregated SCA definitions model. Must be done before we try and
|
||||
// resolve any contributions or composites as they may depend on the full
|
||||
// definitions.xml picture
|
||||
|
||||
// get all definitions.xml artifacts from contributions and aggregate
|
||||
// into the system contribution. In turn add a default import into
|
||||
// each contribution so that for unresolved items the resolution
|
||||
// processing will look in the system contribution
|
||||
for (Contribution contribution : workspace.getContributions()) {
|
||||
// aggregate definitions
|
||||
for (Artifact artifact : contribution.getArtifacts()) {
|
||||
Object model = artifact.getModel();
|
||||
if (model instanceof Definitions) {
|
||||
DefinitionsUtil.aggregate((Definitions)model, systemDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
// create a default import and wire it up to the system contribution
|
||||
// model resolver. This is the trick that makes the resolution processing
|
||||
// skip over to the system contribution if resolution is unsuccessful
|
||||
// in the current contribution
|
||||
DefaultImport defaultImport = contributionFactory.createDefaultImport();
|
||||
defaultImport.setModelResolver(systemContribution.getModelResolver());
|
||||
contribution.getImports().add(defaultImport);
|
||||
}
|
||||
|
||||
// now resolve the system contribution and add the contribution
|
||||
// to the workspace
|
||||
contributionProcessor.resolve(systemContribution, workspace.getModelResolver());
|
||||
workspace.getContributions().add(systemContribution);
|
||||
|
||||
// TODO - Now we can calculate applicable policy sets for each composite
|
||||
|
||||
// Build the contribution dependencies
|
||||
Set<Contribution> resolved = new HashSet<Contribution>();
|
||||
for (Contribution contribution : workspace.getContributions()) {
|
||||
contributionDependencyBuilder.build(contribution, workspace, monitor);
|
||||
|
||||
// Resolve contributions
|
||||
for (Contribution dependency : contribution.getDependencies()) {
|
||||
if (!resolved.contains(dependency)) {
|
||||
resolved.add(dependency);
|
||||
contributionProcessor.resolve(dependency, workspace.getModelResolver());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Composite composite = configuration.getComposite();
|
||||
|
||||
if (composite == null) {
|
||||
composite = getDefaultComposite(configuration, workspace);
|
||||
}
|
||||
|
||||
// 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();
|
||||
// for (Artifact artifact : contribution.getArtifacts()){
|
||||
// logger.log(Level.INFO,"artifact - " + artifact.getURI());
|
||||
// }
|
||||
Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile);
|
||||
// if (!resolvedArtifact.isUnresolved() && resolvedArtifact.getModel() instanceof Composite) {
|
||||
|
||||
if (!composite.isUnresolved()) {
|
||||
|
||||
// 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 the composite and wire the components included in it
|
||||
compositeBuilder.build(composite, systemDefinitions, monitor);
|
||||
analyzeProblems();
|
||||
|
||||
// Create a top level composite to host our composite
|
||||
// This is temporary to make the activator happy
|
||||
Composite tempComposite = assemblyFactory.createComposite();
|
||||
tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_domain_fragment_"));
|
||||
tempComposite.setURI(SCA11_TUSCANY_NS + "_domain_fragment_.composite");
|
||||
|
||||
// Include the node composite in the top-level composite
|
||||
tempComposite.getIncludes().add(composite);
|
||||
|
||||
/*
|
||||
// The following line may return null, to be investigated
|
||||
XPathFactory xPathFactory = modelFactories.getFactory(XPathFactory.class);
|
||||
|
||||
for (PolicySet policySet : systemDefinitions.getPolicySets()) {
|
||||
if (policySet.getAppliesTo() != null) {
|
||||
XPath xpath = xPathFactory.newXPath();
|
||||
// FIXME: We need to develop a xpath function resolver to
|
||||
// deal with the SCA functions
|
||||
// xpath.setXPathFunctionResolver(resolver);
|
||||
XPathExpression exp = xpath.compile(policySet.getAppliesTo());
|
||||
// exp.evaluate(item, XPathConstants.BOOLEAN);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return tempComposite;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (registration != null) {
|
||||
registration.unregister();
|
||||
}
|
||||
|
||||
// Stop the runtime modules
|
||||
for (ModuleActivator moduleActivator : moduleActivators) {
|
||||
moduleActivator.stop(extensionPoints);
|
||||
}
|
||||
|
||||
// Stop and destroy the work manager
|
||||
workScheduler.destroy();
|
||||
}
|
||||
|
||||
public Node createNode(Bundle bundle) {
|
||||
Node node = new NodeImpl(bundle);
|
||||
nodes.put(bundle, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
public Node createNode(Bundle bundle, String compositeContent) {
|
||||
Node node = new NodeImpl(bundle, compositeContent);
|
||||
nodes.put(bundle, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze problems reported by the artifact processors and builders.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void analyzeProblems() throws Exception {
|
||||
for (Problem problem : monitor.getProblems()) {
|
||||
if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) {
|
||||
if (problem.getCause() != null) {
|
||||
throw problem.getCause();
|
||||
} else {
|
||||
throw new ServiceRuntimeException(problem.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets a default composite by using any deployable one.
|
||||
*/
|
||||
private Composite getDefaultComposite(ConfiguredNodeImplementation configuration, Workspace workspace) {
|
||||
// just use the first deployable composte
|
||||
for (Contribution contribution : workspace.getContributions()) {
|
||||
for (Composite c : contribution.getDeployables()) {
|
||||
Composite composite = assemblyFactory.createComposite();
|
||||
composite.setURI(c.getURI());
|
||||
composite.setUnresolved(true);
|
||||
configuration.setComposite(composite);
|
||||
return composite;
|
||||
}
|
||||
}
|
||||
throw new ServiceRuntimeException("no deployable composite found");
|
||||
}
|
||||
|
||||
public ExtensionPointRegistry getExtensionPoints() {
|
||||
return extensionPoints;
|
||||
}
|
||||
|
||||
public class NodeImpl implements Node, Client {
|
||||
private Bundle bundle;
|
||||
private Composite domainFragementComposite;
|
||||
private CompositeActivator compositeActivator;
|
||||
private ConfiguredNodeImplementation configuration;
|
||||
|
||||
public NodeImpl(Bundle bundle) {
|
||||
this(bundle, null);
|
||||
}
|
||||
|
||||
public NodeImpl(Bundle bundle, String compositeContent) {
|
||||
try {
|
||||
// Initialize the runtime
|
||||
init();
|
||||
|
||||
this.bundle = bundle;
|
||||
this.configuration = getNodeConfiguration(bundle, compositeContent);
|
||||
|
||||
// Configure the node
|
||||
this.domainFragementComposite = configureNode(configuration);
|
||||
this.compositeActivator = utilities.getUtility(CompositeActivator.class, true);
|
||||
this.compositeActivator.setDomainComposite(domainFragementComposite);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Node start() {
|
||||
logger.log(Level.INFO, "Starting node: " + bundle.getSymbolicName());
|
||||
|
||||
try {
|
||||
|
||||
Composite composite = domainFragementComposite.getIncludes().get(0);
|
||||
// Activate the composite
|
||||
compositeActivator.activate(composite);
|
||||
|
||||
// Start the composite
|
||||
compositeActivator.start(composite);
|
||||
|
||||
return this;
|
||||
|
||||
} catch (ActivationException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
logger.log(Level.INFO, "Stopping node: " + bundle.getSymbolicName());
|
||||
|
||||
try {
|
||||
|
||||
Composite composite = domainFragementComposite.getIncludes().get(0);
|
||||
// Stop the composite
|
||||
compositeActivator.stop(composite);
|
||||
|
||||
// Deactivate the composite
|
||||
compositeActivator.deactivate(composite);
|
||||
|
||||
} catch (ActivationException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
|
||||
return (R)proxyFactory.cast(target);
|
||||
}
|
||||
|
||||
public <B> B getService(Class<B> businessInterface, String serviceName) {
|
||||
|
||||
ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
|
||||
if (serviceReference == null) {
|
||||
throw new ServiceRuntimeException("Service not found: " + serviceName);
|
||||
}
|
||||
return serviceReference.getService();
|
||||
}
|
||||
|
||||
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
|
||||
|
||||
// Extract the component name
|
||||
String componentName;
|
||||
String serviceName;
|
||||
int i = name.indexOf('/');
|
||||
if (i != -1) {
|
||||
componentName = name.substring(0, i);
|
||||
serviceName = name.substring(i + 1);
|
||||
|
||||
} else {
|
||||
componentName = name;
|
||||
serviceName = null;
|
||||
}
|
||||
|
||||
// Lookup the component
|
||||
Component component = null;
|
||||
|
||||
for (Component compositeComponent : domainFragementComposite.getIncludes().get(0).getComponents()) {
|
||||
if (compositeComponent.getName().equals(componentName)) {
|
||||
component = compositeComponent;
|
||||
}
|
||||
}
|
||||
|
||||
if (component == null) {
|
||||
throw new ServiceRuntimeException("The service " + name + " has not been contributed to the domain");
|
||||
}
|
||||
RuntimeComponentContext componentContext = null;
|
||||
|
||||
// If the component is a composite, then we need to find the
|
||||
// non-composite component that provides the requested service
|
||||
if (component.getImplementation() instanceof Composite) {
|
||||
for (ComponentService componentService : component.getServices()) {
|
||||
if (serviceName == null || serviceName.equals(componentService.getName())) {
|
||||
CompositeService compositeService = (CompositeService)componentService.getService();
|
||||
if (compositeService != null) {
|
||||
if (serviceName != null) {
|
||||
serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
|
||||
}
|
||||
componentContext =
|
||||
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
|
||||
return componentContext.createSelfReference(businessInterface, compositeService
|
||||
.getPromotedService());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// No matching service found
|
||||
throw new ServiceRuntimeException("Composite service not found: " + name);
|
||||
} else {
|
||||
componentContext = ((RuntimeComponent)component).getComponentContext();
|
||||
if (serviceName != null) {
|
||||
return componentContext.createSelfReference(businessInterface, serviceName);
|
||||
} else {
|
||||
return componentContext.createSelfReference(businessInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
this.bundle = null;
|
||||
this.domainFragementComposite = null;
|
||||
this.compositeActivator = null;
|
||||
this.configuration = null;
|
||||
nodes.remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Map<Bundle, Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.BundleEvent;
|
||||
|
@ -38,11 +39,12 @@ import org.osgi.framework.SynchronousBundleListener;
|
|||
public class NodeManager implements SynchronousBundleListener, ServiceListener {
|
||||
private static final Logger logger = Logger.getLogger(NodeManager.class.getName());
|
||||
private BundleContext bundleContext;
|
||||
private NodeFactoryImpl factory;
|
||||
private OSGiNodeFactoryImpl factory;
|
||||
|
||||
public NodeManager(BundleContext bundleContext) {
|
||||
super();
|
||||
this.bundleContext = bundleContext;
|
||||
this.factory = new NodeFactoryImpl(this.bundleContext);
|
||||
this.factory = new OSGiNodeFactoryImpl(this.bundleContext);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
@ -95,7 +97,8 @@ public class NodeManager implements SynchronousBundleListener, ServiceListener {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
Node node = factory.createNode(bundle);
|
||||
NodeConfiguration configuration = factory.getConfiguration(bundle, null);
|
||||
Node node = factory.createNode(configuration);
|
||||
node.start();
|
||||
} catch (Throwable e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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.osgi.impl;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.net.URL;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
|
||||
import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
/**
|
||||
* The OSGi based NodeFactory
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class OSGiNodeFactoryImpl extends NodeFactoryImpl {
|
||||
private ServiceRegistration registration;
|
||||
private BundleContext bundleContext;
|
||||
|
||||
/**
|
||||
* Constructs a new Node controller
|
||||
*/
|
||||
public OSGiNodeFactoryImpl(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
setNodeFactory(this);
|
||||
}
|
||||
|
||||
protected NodeConfiguration getConfiguration(Bundle bundle, String compositeContent) {
|
||||
init();
|
||||
|
||||
// Create a node configuration
|
||||
NodeConfigurationFactory configurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class);
|
||||
NodeConfiguration configuration = configurationFactory.createNodeConfiguration();
|
||||
|
||||
URL location = bundle.getEntry("/");
|
||||
String uri = bundle.getSymbolicName();
|
||||
configuration.setURI(uri).addContribution(uri, location);
|
||||
|
||||
if (compositeContent != null) {
|
||||
configuration.addDeploymentComposite(uri, new StringReader(compositeContent));
|
||||
} else {
|
||||
String compositeURI = (String)bundle.getHeaders().get("SCA-Composite");
|
||||
if (compositeURI == null) {
|
||||
compositeURI = "OSGI-INF/sca/bundle.composite";
|
||||
}
|
||||
if (compositeURI != null) {
|
||||
configuration.addDeploymentComposite(uri, compositeURI);
|
||||
}
|
||||
}
|
||||
// Set the bundle
|
||||
configuration.getExtensions().add(bundle);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public synchronized void init() {
|
||||
if (!inited) {
|
||||
super.init();
|
||||
|
||||
// Register the ExtensionPointRegistry as an OSGi service
|
||||
Dictionary<Object, Object> props = new Hashtable<Object, Object>();
|
||||
registration =
|
||||
bundleContext.registerService(ExtensionPointRegistry.class.getName(), extensionPoints, props);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void destroy() {
|
||||
if (inited) {
|
||||
if (registration != null) {
|
||||
registration.unregister();
|
||||
registration = null;
|
||||
}
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getNodeKey(NodeConfiguration configuration) {
|
||||
// Use the bundle as the key
|
||||
return configuration.getExtensions().get(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,13 +5,13 @@
|
|||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# org.apache.tuscany.sca.node.osgi.impl.NodeFactoryImpl
|
||||
# under the License.
|
||||
# org.apache.tuscany.sca.node.osgi.impl.OSGiNodeFactoryImpl
|
|
@ -19,32 +19,127 @@
|
|||
|
||||
package org.apache.tuscany.sca.node.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.tuscany.sca.node.impl.NodeUtil.createURI;
|
||||
import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.AssemblyFactory;
|
||||
import org.apache.tuscany.sca.assembly.Composite;
|
||||
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
|
||||
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
|
||||
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.DefaultImport;
|
||||
import org.apache.tuscany.sca.contribution.Export;
|
||||
import org.apache.tuscany.sca.contribution.Import;
|
||||
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
|
||||
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
|
||||
import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor;
|
||||
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
|
||||
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.DefaultImportModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
|
||||
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.ModuleActivatorExtensionPoint;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
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.Definitions;
|
||||
import org.apache.tuscany.sca.definitions.DefinitionsFactory;
|
||||
import org.apache.tuscany.sca.definitions.util.DefinitionsUtil;
|
||||
import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint;
|
||||
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
|
||||
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
|
||||
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.Node;
|
||||
import org.apache.tuscany.sca.node.NodeFactory;
|
||||
import org.apache.tuscany.sca.node.configuration.ContributionConfiguration;
|
||||
import org.apache.tuscany.sca.node.configuration.DeploymentComposite;
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.apache.tuscany.sca.node.configuration.xml.NodeConfigurationProcessor;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProvider;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderException;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint;
|
||||
import org.apache.tuscany.sca.work.WorkScheduler;
|
||||
import org.oasisopen.sca.ServiceRuntimeException;
|
||||
|
||||
/**
|
||||
* Default implementation of an SCA node factory.
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class NodeFactoryImpl extends NodeFactory {
|
||||
public NodeFactoryImpl() {
|
||||
}
|
||||
protected static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
|
||||
private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
|
||||
|
||||
protected boolean inited;
|
||||
protected Map<Object, Node> nodes = new ConcurrentHashMap<Object, Node>();
|
||||
|
||||
private AssemblyFactory assemblyFactory;
|
||||
private CompositeBuilder compositeBuilder;
|
||||
private StAXArtifactProcessor<Composite> compositeProcessor;
|
||||
private ContributionFactory contributionFactory;
|
||||
private ExtendedURLArtifactProcessor<Contribution> contributionProcessor;
|
||||
private CompositeBuilder endpointReferenceBuilder;
|
||||
protected ExtensionPointRegistry extensionPoints;
|
||||
private XMLInputFactory inputFactory;
|
||||
protected FactoryExtensionPoint modelFactories;
|
||||
private ModelResolverExtensionPoint modelResolvers;
|
||||
private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
|
||||
private Monitor monitor;
|
||||
protected ProxyFactory proxyFactory;
|
||||
private Contribution systemContribution;
|
||||
private Definitions systemDefinitions;
|
||||
private WorkScheduler workScheduler;
|
||||
private StAXArtifactProcessorExtensionPoint xmlProcessors;
|
||||
|
||||
@Override
|
||||
public Node createNode(NodeConfiguration configuration) {
|
||||
return new NodeImpl(configuration);
|
||||
return new NodeImpl(this, configuration);
|
||||
}
|
||||
|
||||
protected Node removeNode(NodeConfiguration configuration) {
|
||||
return nodes.remove(getNodeKey(configuration));
|
||||
}
|
||||
|
||||
protected void addNode(NodeConfiguration configuration, Node node) {
|
||||
nodes.put(getNodeKey(configuration), node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,4 +172,490 @@ public class NodeFactoryImpl extends NodeFactory {
|
|||
throw new ServiceRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Object, Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
protected Object getNodeKey(NodeConfiguration configuration) {
|
||||
return new NodeKey(configuration);
|
||||
}
|
||||
|
||||
public synchronized void destroy() {
|
||||
if (inited) {
|
||||
for (Node node : nodes.values()) {
|
||||
node.stop();
|
||||
node.destroy();
|
||||
}
|
||||
nodes.clear();
|
||||
// Stop the runtime modules
|
||||
for (ModuleActivator moduleActivator : moduleActivators) {
|
||||
moduleActivator.stop(extensionPoints);
|
||||
}
|
||||
|
||||
// Stop and destroy the work manager
|
||||
workScheduler.destroy();
|
||||
inited = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSystemProperty(final String name) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
|
||||
if (monitor != null) {
|
||||
Problem problem = monitor.createProblem(NodeImpl.class.getName(), "workspace-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
|
||||
monitor.problem(problem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze a contribution and add its dependencies to the given dependency set.
|
||||
*/
|
||||
private void addContributionDependencies(Contribution contribution, List<Contribution> contributions, List<Contribution> dependencies, Set<Contribution> set, Monitor monitor) {
|
||||
|
||||
// Go through the contribution imports
|
||||
for (Import import_: contribution.getImports()) {
|
||||
boolean resolved = false;
|
||||
|
||||
// Go through all contribution candidates and their exports
|
||||
List<Export> matchingExports = new ArrayList<Export>();
|
||||
for (Contribution dependency: contributions) {
|
||||
if (dependency == contribution) {
|
||||
// Do not self import
|
||||
continue;
|
||||
}
|
||||
for (Export export: dependency.getExports()) {
|
||||
|
||||
// If an export from a contribution matches the import in hand
|
||||
// add that contribution to the dependency set
|
||||
if (import_.match(export)) {
|
||||
resolved = true;
|
||||
matchingExports.add(export);
|
||||
|
||||
if (!set.contains(dependency)) {
|
||||
set.add(dependency);
|
||||
dependencies.add(dependency);
|
||||
|
||||
// Now add the dependencies of that contribution
|
||||
addContributionDependencies(dependency, contributions, dependencies, set, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resolved) {
|
||||
|
||||
// Initialize the import's model resolver with a delegating model
|
||||
// resolver which will delegate to the matching exports
|
||||
import_.setModelResolver(new DefaultImportModelResolver(matchingExports));
|
||||
|
||||
} else {
|
||||
// Record import resolution issue
|
||||
if (!(import_ instanceof DefaultImport)) {
|
||||
warning(monitor, "UnresolvedImport", import_, import_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze problems reported by the artifact processors and builders.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void analyzeProblems() throws Exception {
|
||||
for (Problem problem : monitor.getProblems()) {
|
||||
if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) {
|
||||
if (problem.getCause() != null) {
|
||||
throw problem.getCause();
|
||||
} else {
|
||||
throw new ServiceRuntimeException(problem.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached)
|
||||
throws XMLStreamException, ContributionReadException {
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(xml);
|
||||
reader.nextTag();
|
||||
|
||||
// Read the composite model
|
||||
Composite composite = (Composite)compositeProcessor.read(reader);
|
||||
reader.close();
|
||||
|
||||
// Create an artifact for the deployment composite
|
||||
Artifact artifact = contributionFactory.createArtifact();
|
||||
String uri = composite.getName().getLocalPart() + ".composite";
|
||||
artifact.setURI(uri);
|
||||
// Set the location to avoid NPE
|
||||
if (location == null) {
|
||||
location = uri;
|
||||
}
|
||||
artifact.setLocation(location);
|
||||
artifact.setModel(composite);
|
||||
artifact.setUnresolved(false);
|
||||
// Add it to the contribution
|
||||
contribution.getArtifacts().add(artifact);
|
||||
|
||||
// Replace the deployable composites with the deployment composites
|
||||
// Clear the deployable composites if it's the first deployment composite
|
||||
if (!attached) {
|
||||
contribution.getDeployables().clear();
|
||||
attached = true;
|
||||
}
|
||||
contribution.getDeployables().add(composite);
|
||||
// REVIEW: Is it needed?
|
||||
contribution.getModelResolver().addModel(composite);
|
||||
return attached;
|
||||
}
|
||||
|
||||
private void buildDependencies(Contribution contribution, List<Contribution> contributions, Monitor monitor) {
|
||||
contribution.getDependencies().clear();
|
||||
|
||||
List<Contribution> dependencies = new ArrayList<Contribution>();
|
||||
Set<Contribution> set = new HashSet<Contribution>();
|
||||
|
||||
dependencies.add(contribution);
|
||||
set.add(contribution);
|
||||
addContributionDependencies(contribution, contributions, dependencies, set, monitor);
|
||||
|
||||
Collections.reverse(dependencies);
|
||||
|
||||
contribution.getDependencies().addAll(dependencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution
|
||||
* @param contributions - the contributions to preresolve
|
||||
* @param resolver - the ModelResolver to use
|
||||
* @throws ContributionResolveException
|
||||
*/
|
||||
private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver )
|
||||
throws ContributionResolveException {
|
||||
|
||||
for( Contribution contribution : contributions ) {
|
||||
contributionProcessor.preResolve(contribution, resolver);
|
||||
} // end for
|
||||
} // end method contributionsPreresolve
|
||||
|
||||
public ExtensionPointRegistry getExtensionPoints() {
|
||||
return extensionPoints;
|
||||
}
|
||||
|
||||
public synchronized void init() {
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
long start = currentTimeMillis();
|
||||
|
||||
// Create extension point registry
|
||||
extensionPoints = new DefaultExtensionPointRegistry();
|
||||
|
||||
// Enable schema validation only of the logger level is FINE or higher
|
||||
ValidationSchemaExtensionPoint schemas =
|
||||
extensionPoints.getExtensionPoint(ValidationSchemaExtensionPoint.class);
|
||||
if (schemas != null) {
|
||||
String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled");
|
||||
if (enabled == null) {
|
||||
enabled = "true";
|
||||
}
|
||||
boolean debug = logger.isLoggable(Level.FINE);
|
||||
schemas.setEnabled("true".equals(enabled) || debug);
|
||||
}
|
||||
|
||||
// Use the runtime-enabled assembly factory
|
||||
modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
|
||||
assemblyFactory = new RuntimeAssemblyFactory();
|
||||
modelFactories.addFactory(assemblyFactory);
|
||||
|
||||
// Create a monitor
|
||||
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
|
||||
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
|
||||
monitor = monitorFactory.createMonitor();
|
||||
|
||||
// Initialize the Tuscany module activators
|
||||
ModuleActivatorExtensionPoint activators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
|
||||
for (ModuleActivator moduleActivator: activators.getModuleActivators()) {
|
||||
try {
|
||||
moduleActivator.start(extensionPoints);
|
||||
moduleActivators.add(moduleActivator);
|
||||
} catch (Throwable e) {
|
||||
// Ignore the failing module for now
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Get XML input/output factories
|
||||
inputFactory = modelFactories.getFactory(XMLInputFactory.class);
|
||||
|
||||
// Get contribution workspace and assembly model factories
|
||||
contributionFactory = modelFactories.getFactory(ContributionFactory.class);
|
||||
|
||||
// Create XML artifact processors
|
||||
xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
|
||||
compositeProcessor = xmlProcessors.getProcessor(Composite.class);
|
||||
|
||||
// Create contribution content processor
|
||||
URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
|
||||
contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
|
||||
|
||||
// Get the model resolvers
|
||||
modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
|
||||
|
||||
// Get composite builders
|
||||
CompositeBuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class);
|
||||
compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
|
||||
|
||||
// Get endpoint builders
|
||||
// TODO - new extension point?
|
||||
endpointReferenceBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.endpoint.impl.EndpointReferenceBuilderImpl");
|
||||
|
||||
// Initialize runtime
|
||||
|
||||
// Get proxy factory
|
||||
ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class);
|
||||
proxyFactory = new ExtensibleProxyFactory(proxyFactories);
|
||||
|
||||
workScheduler = utilities.getUtility(WorkScheduler.class);
|
||||
|
||||
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
|
||||
systemDefinitions = definitionsFactory.createDefinitions();
|
||||
|
||||
DefinitionsExtensionPoint definitionsExtensionPoint = extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class);
|
||||
for(Definitions defs: definitionsExtensionPoint.getDefinitions()) {
|
||||
DefinitionsUtil.aggregate(systemDefinitions, defs);
|
||||
}
|
||||
|
||||
// Load the system definitions.xml from all of the loaded extension points
|
||||
DefinitionsProviderExtensionPoint definitionsProviders = extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
|
||||
|
||||
// aggregate all the definitions into a single definitions model
|
||||
try {
|
||||
for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
|
||||
DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions);
|
||||
}
|
||||
} catch (DefinitionsProviderException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
// create a system contribution to hold the definitions. The contribution
|
||||
// will be extended later with definitions from application contributions
|
||||
systemContribution = contributionFactory.createContribution();
|
||||
systemContribution.setURI("http://tuscany.apache.org/SystemContribution");
|
||||
systemContribution.setLocation("http://tuscany.apache.org/SystemContribution");
|
||||
ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories);
|
||||
systemContribution.setModelResolver(modelResolver);
|
||||
systemContribution.setUnresolved(true);
|
||||
|
||||
// create an artifact to represent the system defintions and
|
||||
// add it to the contribution
|
||||
List<Artifact> artifacts = systemContribution.getArtifacts();
|
||||
Artifact artifact = contributionFactory.createArtifact();
|
||||
artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions");
|
||||
artifact.setLocation("Derived");
|
||||
artifact.setModel(systemDefinitions);
|
||||
artifacts.add(artifact);
|
||||
|
||||
inited = true;
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
long end = currentTimeMillis();
|
||||
logger.fine("The tuscany runtime started in " + (end - start) + " ms.");
|
||||
}
|
||||
}
|
||||
|
||||
Composite configureNode(NodeConfiguration configuration) throws Exception {
|
||||
|
||||
List<Contribution> contributions = new ArrayList<Contribution>();
|
||||
|
||||
// Load the specified contributions
|
||||
for (ContributionConfiguration contrib : configuration.getContributions()) {
|
||||
URI contributionURI = createURI(contrib.getURI());
|
||||
|
||||
URI uri = createURI(contrib.getLocation());
|
||||
if (uri.getScheme() == null) {
|
||||
uri = new File(contrib.getLocation()).toURI();
|
||||
}
|
||||
URL contributionURL = uri.toURL();
|
||||
|
||||
// Load the contribution
|
||||
logger.log(Level.INFO, "Loading contribution: " + contributionURL);
|
||||
Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
|
||||
contributions.add(contribution);
|
||||
|
||||
boolean attached = false;
|
||||
for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
|
||||
if (dc.getContent() != null) {
|
||||
Reader xml = new StringReader(dc.getContent());
|
||||
attached = attachDeploymentComposite(contribution, xml, null, attached);
|
||||
} else if (dc.getLocation() != null) {
|
||||
URI dcURI = createURI(dc.getLocation());
|
||||
if (!dcURI.isAbsolute()) {
|
||||
Composite composite = null;
|
||||
// The location is pointing to an artifact within the contribution
|
||||
for (Artifact a : contribution.getArtifacts()) {
|
||||
if (dcURI.toString().equals(a.getURI())) {
|
||||
composite = (Composite)a.getModel();
|
||||
if (!attached) {
|
||||
contribution.getDeployables().clear();
|
||||
attached = true;
|
||||
}
|
||||
contribution.getDeployables().add(composite);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (composite == null) {
|
||||
// Not found
|
||||
throw new ServiceRuntimeException("Deployment composite " + dcURI
|
||||
+ " cannot be found within contribution "
|
||||
+ contribution.getLocation());
|
||||
}
|
||||
} else {
|
||||
URL url = dcURI.toURL();
|
||||
InputStream is = openStream(url);
|
||||
Reader xml = new InputStreamReader(is, "UTF-8");
|
||||
attached = attachDeploymentComposite(contribution, xml, url.toString(), attached);
|
||||
}
|
||||
}
|
||||
}
|
||||
analyzeProblems();
|
||||
}
|
||||
|
||||
// Build an aggregated SCA definitions model. Must be done before we try and
|
||||
// resolve any contributions or composites as they may depend on the full
|
||||
// definitions.xml picture
|
||||
|
||||
// get all definitions.xml artifacts from contributions and aggregate
|
||||
// into the system contribution. In turn add a default import into
|
||||
// each contribution so that for unresolved items the resolution
|
||||
// processing will look in the system contribution
|
||||
for (Contribution contribution: contributions) {
|
||||
// aggregate definitions
|
||||
for (Artifact artifact : contribution.getArtifacts()) {
|
||||
Object model = artifact.getModel();
|
||||
if (model instanceof Definitions) {
|
||||
DefinitionsUtil.aggregate((Definitions)model, systemDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
// create a default import and wire it up to the system contribution
|
||||
// model resolver. This is the trick that makes the resolution processing
|
||||
// skip over to the system contribution if resolution is unsuccessful
|
||||
// in the current contribution
|
||||
DefaultImport defaultImport = contributionFactory.createDefaultImport();
|
||||
defaultImport.setModelResolver(systemContribution.getModelResolver());
|
||||
contribution.getImports().add(defaultImport);
|
||||
}
|
||||
|
||||
ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories);
|
||||
|
||||
// now resolve and add the system contribution
|
||||
contributionProcessor.resolve(systemContribution, modelResolver);
|
||||
contributions.add(systemContribution);
|
||||
|
||||
// TODO - Now we can calculate applicable policy sets for each composite
|
||||
|
||||
// pre-resolve the contributions
|
||||
contributionsPreresolve(contributions, modelResolver);
|
||||
|
||||
// Build the contribution dependencies
|
||||
Set<Contribution> resolved = new HashSet<Contribution>();
|
||||
for (Contribution contribution: contributions) {
|
||||
buildDependencies(contribution, contributions, monitor);
|
||||
|
||||
// Resolve contributions
|
||||
for (Contribution dependency: contribution.getDependencies()) {
|
||||
if (!resolved.contains(dependency)) {
|
||||
resolved.add(dependency);
|
||||
contributionProcessor.resolve(dependency, modelResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a top level composite to host our composite
|
||||
// This is temporary to make the activator happy
|
||||
Composite tempComposite = assemblyFactory.createComposite();
|
||||
tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
|
||||
tempComposite.setURI(SCA11_TUSCANY_NS);
|
||||
|
||||
for (Contribution contribution : contributions) {
|
||||
for (Composite composite : contribution.getDeployables()) {
|
||||
|
||||
// Build the composite and wire the components included in it
|
||||
compositeBuilder.build(composite, systemDefinitions, monitor);
|
||||
analyzeProblems();
|
||||
|
||||
// build the endpoint references
|
||||
endpointReferenceBuilder.build(composite, systemDefinitions, monitor);
|
||||
analyzeProblems();
|
||||
|
||||
// Include the node composite in the top-level composite
|
||||
tempComposite.getIncludes().add(composite);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return tempComposite;
|
||||
|
||||
}
|
||||
|
||||
protected static class NodeKey {
|
||||
private String domainURI;
|
||||
private String nodeURI;
|
||||
|
||||
public NodeKey(NodeConfiguration configuration) {
|
||||
this.domainURI = configuration.getDomainURI();
|
||||
this.nodeURI = configuration.getURI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((domainURI == null) ? 0 : domainURI.hashCode());
|
||||
result = prime * result + ((nodeURI == null) ? 0 : nodeURI.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
NodeKey other = (NodeKey)obj;
|
||||
if (domainURI == null) {
|
||||
if (other.domainURI != null)
|
||||
return false;
|
||||
} else if (!domainURI.equals(other.domainURI))
|
||||
return false;
|
||||
if (nodeURI == null) {
|
||||
if (other.nodeURI != null)
|
||||
return false;
|
||||
} else if (!nodeURI.equals(other.nodeURI))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
if (domainURI != null) {
|
||||
buf.append("{").append(domainURI).append("}");
|
||||
}
|
||||
if (nodeURI != null) {
|
||||
buf.append(nodeURI);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,550 +1,77 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
* 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 static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.tuscany.sca.node.impl.NodeUtil.createURI;
|
||||
import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.AssemblyFactory;
|
||||
import org.apache.tuscany.sca.assembly.Component;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
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.contribution.Artifact;
|
||||
import org.apache.tuscany.sca.contribution.Contribution;
|
||||
import org.apache.tuscany.sca.contribution.ContributionFactory;
|
||||
import org.apache.tuscany.sca.contribution.DefaultImport;
|
||||
import org.apache.tuscany.sca.contribution.Export;
|
||||
import org.apache.tuscany.sca.contribution.Import;
|
||||
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
|
||||
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
|
||||
import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor;
|
||||
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
|
||||
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.DefaultImportModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
|
||||
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
|
||||
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.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.Definitions;
|
||||
import org.apache.tuscany.sca.definitions.DefinitionsFactory;
|
||||
import org.apache.tuscany.sca.definitions.util.DefinitionsUtil;
|
||||
import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint;
|
||||
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.Client;
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
import org.apache.tuscany.sca.node.NodeFinder;
|
||||
import org.apache.tuscany.sca.node.configuration.ContributionConfiguration;
|
||||
import org.apache.tuscany.sca.node.configuration.DeploymentComposite;
|
||||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProvider;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderException;
|
||||
import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint;
|
||||
import org.apache.tuscany.sca.runtime.RuntimeComponent;
|
||||
import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
|
||||
import org.apache.tuscany.sca.work.WorkScheduler;
|
||||
import org.oasisopen.sca.CallableReference;
|
||||
import org.oasisopen.sca.NoSuchDomainException;
|
||||
import org.oasisopen.sca.NoSuchServiceException;
|
||||
import org.oasisopen.sca.ServiceReference;
|
||||
import org.oasisopen.sca.ServiceRuntimeException;
|
||||
import org.oasisopen.sca.client.SCAClient;
|
||||
|
||||
/**
|
||||
* Represents an SCA runtime node.
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
* An SCA Node that is managed by the NodeManager
|
||||
*/
|
||||
public class NodeImpl implements Node, Client, SCAClient {
|
||||
|
||||
private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
|
||||
|
||||
public class NodeImpl implements Node, Client {
|
||||
private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
|
||||
|
||||
// The node configuration name, used for logging
|
||||
private String configurationName;
|
||||
|
||||
private ExtensionPointRegistry extensionPoints;
|
||||
private Monitor monitor;
|
||||
private ExtendedURLArtifactProcessor<Contribution> contributionProcessor;
|
||||
private ModelResolverExtensionPoint modelResolvers;
|
||||
private FactoryExtensionPoint modelFactories;
|
||||
private ContributionFactory contributionFactory;
|
||||
private AssemblyFactory assemblyFactory;
|
||||
private XMLInputFactory inputFactory;
|
||||
private CompositeBuilder compositeBuilder;
|
||||
private CompositeBuilder endpointReferenceBuilder;
|
||||
private StAXArtifactProcessorExtensionPoint xmlProcessors;
|
||||
private StAXArtifactProcessor<Composite> compositeProcessor;
|
||||
private ProxyFactory proxyFactory;
|
||||
private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
|
||||
private CompositeActivator compositeActivator;
|
||||
private WorkScheduler workScheduler;
|
||||
private Contribution systemContribution;
|
||||
private Definitions systemDefinitions;
|
||||
private NodeConfiguration configuration;
|
||||
private NodeFactoryImpl manager;
|
||||
|
||||
private URI domainURI;
|
||||
NodeImpl(NodeConfiguration configuration) {
|
||||
logger.log(Level.INFO, "Creating node: " + configuration.getURI());
|
||||
|
||||
try {
|
||||
// Initialize the runtime
|
||||
init();
|
||||
|
||||
// Configure the node
|
||||
configureNode(configuration);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException(e);
|
||||
}
|
||||
public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration) {
|
||||
super();
|
||||
this.configuration = configuration;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
private static String getSystemProperty(final String name) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty(name);
|
||||
}
|
||||
});
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
long start = currentTimeMillis();
|
||||
|
||||
// Create extension point registry
|
||||
extensionPoints = new DefaultExtensionPointRegistry();
|
||||
|
||||
// Enable schema validation only of the logger level is FINE or higher
|
||||
ValidationSchemaExtensionPoint schemas =
|
||||
extensionPoints.getExtensionPoint(ValidationSchemaExtensionPoint.class);
|
||||
if (schemas != null) {
|
||||
String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled");
|
||||
if (enabled == null) {
|
||||
enabled = "true";
|
||||
}
|
||||
boolean debug = logger.isLoggable(Level.FINE);
|
||||
schemas.setEnabled("true".equals(enabled) || debug);
|
||||
}
|
||||
|
||||
// Use the runtime-enabled assembly factory
|
||||
modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
|
||||
assemblyFactory = new RuntimeAssemblyFactory();
|
||||
modelFactories.addFactory(assemblyFactory);
|
||||
|
||||
// Create a monitor
|
||||
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
|
||||
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
|
||||
monitor = monitorFactory.createMonitor();
|
||||
|
||||
// Initialize the Tuscany module activators
|
||||
ModuleActivatorExtensionPoint activators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
|
||||
for (ModuleActivator moduleActivator: activators.getModuleActivators()) {
|
||||
try {
|
||||
moduleActivator.start(extensionPoints);
|
||||
moduleActivators.add(moduleActivator);
|
||||
} catch (Throwable e) {
|
||||
// Ignore the failing module for now
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Get XML input/output factories
|
||||
inputFactory = modelFactories.getFactory(XMLInputFactory.class);
|
||||
|
||||
// Get contribution workspace and assembly model factories
|
||||
contributionFactory = modelFactories.getFactory(ContributionFactory.class);
|
||||
|
||||
// Create XML artifact processors
|
||||
xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
|
||||
compositeProcessor = xmlProcessors.getProcessor(Composite.class);
|
||||
|
||||
// Create contribution content processor
|
||||
URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
|
||||
contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
|
||||
|
||||
// Get the model resolvers
|
||||
modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
|
||||
|
||||
// Get composite builders
|
||||
CompositeBuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class);
|
||||
compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
|
||||
|
||||
// Get endpoint builders
|
||||
// TODO - new extension point?
|
||||
endpointReferenceBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.endpoint.impl.EndpointReferenceBuilderImpl");
|
||||
|
||||
// Initialize runtime
|
||||
|
||||
// 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);
|
||||
|
||||
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
|
||||
systemDefinitions = definitionsFactory.createDefinitions();
|
||||
|
||||
DefinitionsExtensionPoint definitionsExtensionPoint = extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class);
|
||||
for(Definitions defs: definitionsExtensionPoint.getDefinitions()) {
|
||||
DefinitionsUtil.aggregate(systemDefinitions, defs);
|
||||
}
|
||||
|
||||
// Load the system definitions.xml from all of the loaded extension points
|
||||
DefinitionsProviderExtensionPoint definitionsProviders = extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
|
||||
|
||||
// aggregate all the definitions into a single definitions model
|
||||
try {
|
||||
for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
|
||||
DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions);
|
||||
}
|
||||
} catch (DefinitionsProviderException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
// create a system contribution to hold the definitions. The contribution
|
||||
// will be extended later with definitions from application contributions
|
||||
systemContribution = contributionFactory.createContribution();
|
||||
systemContribution.setURI("http://tuscany.apache.org/SystemContribution");
|
||||
systemContribution.setLocation("http://tuscany.apache.org/SystemContribution");
|
||||
ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories);
|
||||
systemContribution.setModelResolver(modelResolver);
|
||||
systemContribution.setUnresolved(true);
|
||||
|
||||
// create an artifact to represent the system defintions and
|
||||
// add it to the contribution
|
||||
List<Artifact> artifacts = systemContribution.getArtifacts();
|
||||
Artifact artifact = contributionFactory.createArtifact();
|
||||
artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions");
|
||||
artifact.setLocation("Derived");
|
||||
artifact.setModel(systemDefinitions);
|
||||
artifacts.add(artifact);
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
long end = currentTimeMillis();
|
||||
logger.fine("The tuscany runtime started in " + (end - start) + " ms.");
|
||||
}
|
||||
}
|
||||
|
||||
private void configureNode(NodeConfiguration configuration) throws Exception {
|
||||
|
||||
domainURI = URI.create(configuration.getDomainURI());
|
||||
|
||||
List<Contribution> contributions = new ArrayList<Contribution>();
|
||||
|
||||
// Load the specified contributions
|
||||
for (ContributionConfiguration contrib : configuration.getContributions()) {
|
||||
URI contributionURI = createURI(contrib.getURI());
|
||||
|
||||
URI uri = createURI(contrib.getLocation());
|
||||
if (uri.getScheme() == null) {
|
||||
uri = new File(contrib.getLocation()).toURI();
|
||||
}
|
||||
URL contributionURL = uri.toURL();
|
||||
|
||||
// Load the contribution
|
||||
logger.log(Level.INFO, "Loading contribution: " + contributionURL);
|
||||
Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
|
||||
contributions.add(contribution);
|
||||
|
||||
boolean attached = false;
|
||||
for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
|
||||
if (dc.getContent() != null) {
|
||||
Reader xml = new StringReader(dc.getContent());
|
||||
attached = attachDeploymentComposite(contribution, xml, null, attached);
|
||||
} else if (dc.getLocation() != null) {
|
||||
URI dcURI = createURI(dc.getLocation());
|
||||
if (!dcURI.isAbsolute()) {
|
||||
Composite composite = null;
|
||||
// The location is pointing to an artifact within the contribution
|
||||
for (Artifact a : contribution.getArtifacts()) {
|
||||
if (dcURI.toString().equals(a.getURI())) {
|
||||
composite = (Composite)a.getModel();
|
||||
if (!attached) {
|
||||
contribution.getDeployables().clear();
|
||||
attached = true;
|
||||
}
|
||||
contribution.getDeployables().add(composite);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (composite == null) {
|
||||
// Not found
|
||||
throw new ServiceRuntimeException("Deployment composite " + dcURI
|
||||
+ " cannot be found within contribution "
|
||||
+ contribution.getLocation());
|
||||
}
|
||||
} else {
|
||||
URL url = dcURI.toURL();
|
||||
InputStream is = openStream(url);
|
||||
Reader xml = new InputStreamReader(is, "UTF-8");
|
||||
attached = attachDeploymentComposite(contribution, xml, url.toString(), attached);
|
||||
}
|
||||
}
|
||||
}
|
||||
analyzeProblems();
|
||||
}
|
||||
|
||||
// Build an aggregated SCA definitions model. Must be done before we try and
|
||||
// resolve any contributions or composites as they may depend on the full
|
||||
// definitions.xml picture
|
||||
|
||||
// get all definitions.xml artifacts from contributions and aggregate
|
||||
// into the system contribution. In turn add a default import into
|
||||
// each contribution so that for unresolved items the resolution
|
||||
// processing will look in the system contribution
|
||||
for (Contribution contribution: contributions) {
|
||||
// aggregate definitions
|
||||
for (Artifact artifact : contribution.getArtifacts()) {
|
||||
Object model = artifact.getModel();
|
||||
if (model instanceof Definitions) {
|
||||
DefinitionsUtil.aggregate((Definitions)model, systemDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
// create a default import and wire it up to the system contribution
|
||||
// model resolver. This is the trick that makes the resolution processing
|
||||
// skip over to the system contribution if resolution is unsuccessful
|
||||
// in the current contribution
|
||||
DefaultImport defaultImport = contributionFactory.createDefaultImport();
|
||||
defaultImport.setModelResolver(systemContribution.getModelResolver());
|
||||
contribution.getImports().add(defaultImport);
|
||||
}
|
||||
|
||||
ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories);
|
||||
|
||||
// now resolve and add the system contribution
|
||||
contributionProcessor.resolve(systemContribution, modelResolver);
|
||||
contributions.add(systemContribution);
|
||||
|
||||
// TODO - Now we can calculate applicable policy sets for each composite
|
||||
|
||||
// pre-resolve the contributions
|
||||
contributionsPreresolve(contributions, modelResolver);
|
||||
|
||||
// Build the contribution dependencies
|
||||
Set<Contribution> resolved = new HashSet<Contribution>();
|
||||
for (Contribution contribution: contributions) {
|
||||
buildDependencies(contribution, contributions, monitor);
|
||||
|
||||
// Resolve contributions
|
||||
for (Contribution dependency: contribution.getDependencies()) {
|
||||
if (!resolved.contains(dependency)) {
|
||||
resolved.add(dependency);
|
||||
contributionProcessor.resolve(dependency, modelResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a top level composite to host our composite
|
||||
// This is temporary to make the activator happy
|
||||
Composite tempComposite = assemblyFactory.createComposite();
|
||||
tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
|
||||
tempComposite.setURI(SCA11_TUSCANY_NS);
|
||||
|
||||
for (Contribution contribution : contributions) {
|
||||
for (Composite composite : contribution.getDeployables()) {
|
||||
|
||||
// Build the composite and wire the components included in it
|
||||
compositeBuilder.build(composite, systemDefinitions, monitor);
|
||||
analyzeProblems();
|
||||
|
||||
// build the endpoint references
|
||||
endpointReferenceBuilder.build(composite, systemDefinitions, monitor);
|
||||
analyzeProblems();
|
||||
|
||||
// Include the node composite in the top-level composite
|
||||
tempComposite.getIncludes().add(composite);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Set the top level composite on the composite activator as
|
||||
// logic in callable reference resolution relies on this being
|
||||
// available
|
||||
compositeActivator.setDomainComposite(tempComposite);
|
||||
|
||||
}
|
||||
|
||||
private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached)
|
||||
throws XMLStreamException, ContributionReadException {
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(xml);
|
||||
reader.nextTag();
|
||||
|
||||
// Read the composite model
|
||||
Composite composite = (Composite)compositeProcessor.read(reader);
|
||||
reader.close();
|
||||
|
||||
// Create an artifact for the deployment composite
|
||||
Artifact artifact = contributionFactory.createArtifact();
|
||||
String uri = composite.getName().getLocalPart() + ".composite";
|
||||
artifact.setURI(uri);
|
||||
// Set the location to avoid NPE
|
||||
if (location == null) {
|
||||
location = uri;
|
||||
}
|
||||
artifact.setLocation(location);
|
||||
artifact.setModel(composite);
|
||||
artifact.setUnresolved(false);
|
||||
// Add it to the contribution
|
||||
contribution.getArtifacts().add(artifact);
|
||||
|
||||
// Replace the deployable composites with the deployment composites
|
||||
// Clear the deployable composites if it's the first deployment composite
|
||||
if (!attached) {
|
||||
contribution.getDeployables().clear();
|
||||
attached = true;
|
||||
}
|
||||
contribution.getDeployables().add(composite);
|
||||
// REVIEW: Is it needed?
|
||||
contribution.getModelResolver().addModel(composite);
|
||||
return attached;
|
||||
}
|
||||
|
||||
private void buildDependencies(Contribution contribution, List<Contribution> contributions, Monitor monitor) {
|
||||
contribution.getDependencies().clear();
|
||||
|
||||
List<Contribution> dependencies = new ArrayList<Contribution>();
|
||||
Set<Contribution> set = new HashSet<Contribution>();
|
||||
|
||||
dependencies.add(contribution);
|
||||
set.add(contribution);
|
||||
addContributionDependencies(contribution, contributions, dependencies, set, monitor);
|
||||
|
||||
Collections.reverse(dependencies);
|
||||
|
||||
contribution.getDependencies().addAll(dependencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze a contribution and add its dependencies to the given dependency set.
|
||||
*/
|
||||
private void addContributionDependencies(Contribution contribution, List<Contribution> contributions, List<Contribution> dependencies, Set<Contribution> set, Monitor monitor) {
|
||||
|
||||
// Go through the contribution imports
|
||||
for (Import import_: contribution.getImports()) {
|
||||
boolean resolved = false;
|
||||
|
||||
// Go through all contribution candidates and their exports
|
||||
List<Export> matchingExports = new ArrayList<Export>();
|
||||
for (Contribution dependency: contributions) {
|
||||
if (dependency == contribution) {
|
||||
// Do not self import
|
||||
continue;
|
||||
}
|
||||
for (Export export: dependency.getExports()) {
|
||||
|
||||
// If an export from a contribution matches the import in hand
|
||||
// add that contribution to the dependency set
|
||||
if (import_.match(export)) {
|
||||
resolved = true;
|
||||
matchingExports.add(export);
|
||||
|
||||
if (!set.contains(dependency)) {
|
||||
set.add(dependency);
|
||||
dependencies.add(dependency);
|
||||
|
||||
// Now add the dependencies of that contribution
|
||||
addContributionDependencies(dependency, contributions, dependencies, set, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resolved) {
|
||||
|
||||
// Initialize the import's model resolver with a delegating model
|
||||
// resolver which will delegate to the matching exports
|
||||
import_.setModelResolver(new DefaultImportModelResolver(matchingExports));
|
||||
|
||||
} else {
|
||||
// Record import resolution issue
|
||||
if (!(import_ instanceof DefaultImport)) {
|
||||
warning(monitor, "UnresolvedImport", import_, import_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution
|
||||
* @param contributions - the contributions to preresolve
|
||||
* @param resolver - the ModelResolver to use
|
||||
* @throws ContributionResolveException
|
||||
*/
|
||||
private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver )
|
||||
throws ContributionResolveException {
|
||||
|
||||
for( Contribution contribution : contributions ) {
|
||||
contributionProcessor.preResolve(contribution, resolver);
|
||||
} // end for
|
||||
} // end method contributionsPreresolve
|
||||
|
||||
public Node start() {
|
||||
logger.log(Level.INFO, "Starting node: " + configurationName);
|
||||
logger.log(Level.INFO, "Starting node: " + configuration.getURI());
|
||||
|
||||
manager.init();
|
||||
manager.addNode(configuration, this);
|
||||
this.proxyFactory = manager.proxyFactory;
|
||||
this.compositeActivator =
|
||||
manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class,
|
||||
true);
|
||||
try {
|
||||
|
||||
compositeActivator.setDomainComposite(manager.configureNode(configuration));
|
||||
for (Composite composite : compositeActivator.getDomainComposite().getIncludes()) {
|
||||
// Activate the composite
|
||||
compositeActivator.activate(composite);
|
||||
|
@ -553,22 +80,24 @@ public class NodeImpl implements Node, Client, SCAClient {
|
|||
compositeActivator.start(composite);
|
||||
}
|
||||
|
||||
NodeFinder.addNode(domainURI, this);
|
||||
NodeFinder.addNode(NodeUtil.createURI(configuration.getDomainURI()), this);
|
||||
|
||||
return this;
|
||||
|
||||
} catch (ActivationException e) {
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
logger.log(Level.INFO, "Stopping node: " + configurationName);
|
||||
logger.log(Level.INFO, "Stopping node: " + configuration.getURI());
|
||||
|
||||
try {
|
||||
|
||||
NodeFinder.removeNode(domainURI);
|
||||
if (compositeActivator == null) {
|
||||
return;
|
||||
}
|
||||
NodeFinder.removeNode(NodeUtil.createURI(configuration.getDomainURI()));
|
||||
List<Composite> composites = compositeActivator.getDomainComposite().getIncludes();
|
||||
for (Composite composite : composites) {
|
||||
|
||||
|
@ -581,22 +110,19 @@ public class NodeImpl implements Node, Client, SCAClient {
|
|||
}
|
||||
composites.clear();
|
||||
|
||||
manager.removeNode(configuration);
|
||||
this.compositeActivator = null;
|
||||
this.proxyFactory = null;
|
||||
if (manager.getNodes().isEmpty()) {
|
||||
manager.destroy();
|
||||
}
|
||||
|
||||
} catch (ActivationException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
// Stop the runtime modules
|
||||
for (ModuleActivator moduleActivator : moduleActivators) {
|
||||
moduleActivator.stop(extensionPoints);
|
||||
}
|
||||
|
||||
// Stop and destroy the work manager
|
||||
workScheduler.destroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
|
||||
return (R)proxyFactory.cast(target);
|
||||
|
@ -649,10 +175,6 @@ public class NodeImpl implements Node, Client, SCAClient {
|
|||
if (serviceName == null || serviceName.equals(componentService.getName())) {
|
||||
CompositeService compositeService = (CompositeService)componentService.getService();
|
||||
if (compositeService != null) {
|
||||
// TODO - EPR - $promoted$ no longer used
|
||||
//if (serviceName != null) {
|
||||
// serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
|
||||
//}
|
||||
componentContext =
|
||||
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
|
||||
return componentContext.createSelfReference(businessInterface, compositeService
|
||||
|
@ -673,35 +195,8 @@ public class NodeImpl implements Node, Client, SCAClient {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze problems reported by the artifact processors and builders.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void analyzeProblems() throws Exception {
|
||||
for (Problem problem : monitor.getProblems()) {
|
||||
if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) {
|
||||
if (problem.getCause() != null) {
|
||||
throw problem.getCause();
|
||||
} else {
|
||||
throw new ServiceRuntimeException(problem.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
public NodeConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public ExtensionPointRegistry getExtensionPoints() {
|
||||
return extensionPoints;
|
||||
}
|
||||
|
||||
public <T> T getService(Class<T> businessInterface, String serviceName, URI domainURI) throws NoSuchServiceException, NoSuchDomainException {
|
||||
return getService(businessInterface, serviceName);
|
||||
}
|
||||
|
||||
private static void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
|
||||
if (monitor != null) {
|
||||
Problem problem = monitor.createProblem(NodeImpl.class.getName(), "workspace-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
|
||||
monitor.problem(problem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,9 @@ public class NodeUtil {
|
|||
* @return
|
||||
*/
|
||||
static URI createURI(String uri) {
|
||||
if (uri == null) {
|
||||
return null;
|
||||
}
|
||||
int index = uri.indexOf(':');
|
||||
String scheme = null;
|
||||
String ssp = uri;
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
org.apache.tuscany.sca.node.impl.NodeFactoryImpl
|
||||
# under the License.
|
||||
org.apache.tuscany.sca.node.impl.NodeFactoryImpl
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
* 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.
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.client.impl;
|
||||
|
@ -29,7 +29,11 @@ import org.oasisopen.sca.client.SCAClient;
|
|||
|
||||
public class SCAClientImpl implements SCAClient {
|
||||
|
||||
public <T> T getService(Class<T> serviceInterface, String serviceName, URI domainURI) throws NoSuchServiceException, NoSuchDomainException {
|
||||
public <T> T getService(Class<T> serviceInterface, String serviceName, URI domainURI)
|
||||
throws NoSuchServiceException, NoSuchDomainException {
|
||||
if (domainURI == null) {
|
||||
domainURI = URI.create(Node.DEFAULT_DOMAIN_URI);
|
||||
}
|
||||
Node node = NodeFinder.getNode(domainURI);
|
||||
if (node == null) {
|
||||
throw new NoSuchDomainException(domainURI.toString());
|
||||
|
|
Loading…
Add table
Reference in a new issue