From 5559ef5edbf8d3616f7a4b497b2a459b0ee4082b Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:07:07 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835122 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/node/impl/ComponentInfoImpl.java | 47 -- .../sca/node/impl/ComponentManagerServiceImpl.java | 111 ----- .../sca/node/impl/ContributionManagerImpl.java | 332 ------------- .../sca/node/impl/DomainManagerServiceImpl.java | 85 ---- .../tuscany/sca/node/impl/NodeFactoryImpl.java | 48 -- .../sca/node/impl/NodeManagerServiceImpl.java | 84 ---- .../sca/node/impl/SCADomainServiceImpl.java | 158 ------ .../apache/tuscany/sca/node/impl/SCANodeImpl.java | 551 --------------------- .../apache/tuscany/sca/node/impl/SCANodeUtil.java | 456 ----------------- 9 files changed, 1872 deletions(-) delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentInfoImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ContributionManagerImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCADomainServiceImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java delete mode 100644 branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java (limited to 'branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node') diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentInfoImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentInfoImpl.java deleted file mode 100644 index 5e38c6bb81..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentInfoImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.io.Serializable; - -import org.apache.tuscany.sca.node.ComponentInfo; - -public class ComponentInfoImpl implements ComponentInfo, Serializable { - - private String name; - private boolean started; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public boolean isStarted() { - return started; - } - - public void setStarted(boolean started) { - this.started = started; - } - -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java deleted file mode 100644 index 6e2c4c69cf..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl; -import org.apache.tuscany.sca.node.ComponentListener; -import org.apache.tuscany.sca.node.ComponentManager; -import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime; - -public class ComponentManagerServiceImpl implements ComponentManager { - - protected List listeners = new CopyOnWriteArrayList(); - protected String domainURI; - protected String nodeName; - protected Composite nodeComposite; - protected ReallySmallRuntime nodeRuntime; - - public ComponentManagerServiceImpl(String domainURI, String nodeName, Composite nodeComposite, ReallySmallRuntime nodeRuntime) { - this.domainURI = domainURI; - this.nodeName = nodeName; - this.nodeComposite = nodeComposite; - this.nodeRuntime = nodeRuntime; - } - - public void addComponentListener(ComponentListener listener) { - this.listeners.add(listener); - } - - public void removeComponentListener(ComponentListener listener) { - this.listeners.remove(listener); - } - - public Component getComponent(String componentName) { - for (Composite composite: nodeComposite.getIncludes()) { - for (Component component: composite.getComponents()) { - if (component.getName().equals(componentName)) { - return component; - } - } - } - return null; - } - - public List getComponents() { - List components = new ArrayList(); - for (Composite composite: nodeComposite.getIncludes()) { - components.addAll(composite.getComponents()); - } - return components; - } - - public void startComponent(Component component) throws ActivationException { - nodeRuntime.getCompositeActivator().start(component); - notifyComponentStarted(component); - } - - public void stopComponent(Component component) throws ActivationException { - nodeRuntime.getCompositeActivator().stop(component); - notifyComponentStopped(component); - } - - public void notifyComponentStarted(Component component) { - for (ComponentListener listener : listeners) { - try { - listener.componentStarted(component); - } catch (Exception e) { - e.printStackTrace(); // TODO: log - } - } - } - - public void notifyComponentStopped(Component component) { - for (ComponentListener listener : listeners) { - try { - listener.componentStopped(component); - } catch (Exception e) { - e.printStackTrace(); // TODO: log - } - } - } - - public boolean isComponentStarted(Component component) { - RuntimeComponentImpl runtimeComponent = (RuntimeComponentImpl)component; - return runtimeComponent.isStarted(); - } - -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ContributionManagerImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ContributionManagerImpl.java deleted file mode 100644 index 45d5c6f854..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ContributionManagerImpl.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.DeployedArtifact; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.service.ContributionException; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.node.CompositeManager; -import org.apache.tuscany.sca.node.ContributionManager; -import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime; -import org.osoa.sca.ServiceRuntimeException; - -public class ContributionManagerImpl implements ContributionManager, CompositeManager { - - protected String domainURI; - protected String nodeName; - protected Composite nodeComposite; - protected ReallySmallRuntime nodeRuntime; - private ClassLoader classLoader; - - private ModelResolver modelResolver; - - private Map compositeArtifacts = new HashMap(); - private Map contributions = new HashMap(); - - public ContributionManagerImpl(String domainURI, String nodeName, Composite nodeComposite, ReallySmallRuntime nodeRuntime, ClassLoader classLoader, ModelResolver modelResolver) { - this.domainURI = domainURI; - this.nodeName = nodeName; - this.nodeComposite = nodeComposite; - this.nodeRuntime = nodeRuntime; - this.classLoader = classLoader; - this.modelResolver = modelResolver; - } - - public void addContribution(URL contributionURL) - throws ActivationException, ContributionException, IOException, CompositeBuilderException { - - if (contributionURL != null) { - // Get ready to add contributions to the domain - ContributionService contributionService = nodeRuntime.getContributionService(); - - // Contribute the SCA application - Contribution contribution = contributionService.contribute(contributionURL.toExternalForm(), - contributionURL, - modelResolver, - false); - - contributions.put(contributionURL, contribution); - - for (DeployedArtifact artifact : contribution.getArtifacts()) { - if (artifact.getModel() instanceof Composite) { - compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel()); - } - } - - } else { - throw new ActivationException("Contribution " + contributionURL + " not found"); - } - } - - /** - * Add all composite in a contribution - * - * @param contributionURL - */ - public void addAllComposites(URL contributionURL) - throws ActivationException, ContributionException, IOException, CompositeBuilderException { - Contribution contribution = contributions.get(contributionURL); - - if ( contribution != null) { - // Add the composites to the top level domain - for(Composite composite: contribution.getDeployables()) { - nodeComposite.getIncludes().add(composite); - nodeRuntime.getCompositeBuilder().build(composite); - } - - // activate all of the composites just loaded - for(Composite composite: contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().activate(composite); - } - } else { - throw new ActivationException("Contribution " + contributionURL + " not found"); - } - } - - /** - * adds a named composite - * - * @param compositeName the name of the composite to be added - */ - public void addComposite(QName compositeName){ - //TODO - } - - /** - * adds a named composite - * - * @param compositePath the path to the composite to be added - */ - public void addComposite(String compositePath) - throws ActivationException, ContributionException, IOException, CompositeBuilderException { - - Composite composite = compositeArtifacts.get(compositePath); - - if (composite == null) { - throw new ServiceRuntimeException("Composite not found: " + compositePath); - } - - nodeComposite.getIncludes().add(composite); - nodeRuntime.getCompositeBuilder().build(composite); - nodeRuntime.getCompositeActivator().activate(composite); - } - - /** - * Starts all composites in a contribution - * - * @param contributionURL - */ - public void startAllComposites(URL contributionURL) - throws ActivationException { - Contribution contribution = contributions.get(contributionURL); - - if (contribution != null) { - for(Composite composite: contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().start(composite); - } - } else { - throw new ActivationException("Contribution " + contributionURL+ " not started"); - } - } - - /** - * Starts a named composite - * - * @param compositeName the name of the composite to be started - */ - public void startComposite(QName compositeName){ - - } - - /** - * Starts a named composite - * - * @param compositePath the path to the composite to be started - */ - public void startComposite(String compositePath) - throws ActivationException { - Composite composite = compositeArtifacts.get(compositePath); - - if (composite == null) { - throw new ServiceRuntimeException("Composite not found: " + compositePath); - } - - nodeRuntime.getCompositeActivator().start(composite); - } - - /** - * Stops a all composites in a contribution - * - * @param compositeURL - */ - public void stopAllComposites(URL contributionURL) - throws ActivationException { - Contribution contribution = contributions.get(contributionURL); - - if (contribution != null) { - for(Composite composite: contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().stop(composite); - } - } else { - throw new ActivationException("Contribution " + contributionURL+ " not stopped"); - } - } - - /** - * Stops a named composite - * - * @param compositeName the name of the composite to be stopped - */ - public void stopComposite(QName compositeName){ - - } - - /** - * Stops a named composite - * - * @param compositeName the name of the composite to be stopped - */ - public void stopComposite(String compositePath){ - - } - - - public void removeContribution(URL contributionURL) - throws ActivationException, ContributionException { - - // Remove contribution - nodeRuntime.getContributionService().remove(contributionURL.toExternalForm()); - } - - /** - * Removes all composites - * - * @param compositeName the name of the composite to be added - */ - public void removeAllComposites(URL contributionURL) - throws ActivationException { - Contribution contribution = contributions.get(contributionURL); - - stopAllComposites(contributionURL); - - // Deactivate the composites - for(Composite composite: contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().deactivate(composite); - } - - // Remove the composites - for(Composite composite: contribution.getDeployables()) { - nodeComposite.getIncludes().remove(composite); - } - - contributions.remove(contributionURL); - } - - /** - * Removes a named composite - * - * @param compositeName the name of the composite to be added - */ - public void removeComposite(QName compositeName){ - - } - - /** - * Removes a named composite - * - * @param compositeName the name of the composite to be added - */ - public void removeComposite(String compositePath){ - - } - - - /** - * Stop and remove everything - */ - public void stop() - throws ActivationException, ContributionException { - for (URL contributionURL : contributions.keySet()){ - stopAllComposites(contributionURL); - removeContribution(contributionURL); - } - } - -/* - public void addContributionJAR(URL contributionJar) throws CompositeBuilderException, ActivationException { - - ContributionService contributionService = nodeRuntime.getContributionService(); - - Contribution contribution = contributeJAR(contributionJar, contributionService); - - // Add the composites to the top level domain - for (Composite composite : contribution.getDeployables()) { - nodeComposite.getIncludes().add(composite); - nodeRuntime.getCompositeBuilder().build(composite); - } - - // activate all of the composites just loaded - for (Composite composite : contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().activate(composite); - } - - // start all the composites just loaded - for (Composite composite : contribution.getDeployables()) { - nodeRuntime.getCompositeActivator().start(composite); - } - } - - protected Contribution contributeJAR(URL contributionJar, ContributionService contributionService) throws ActivationException { - InputStream is; - try { - is = contributionJar.openStream(); - } catch (IOException e) { - throw new ActivationException(e); - } - Contribution contribution; - try { - contribution = contributionService.contribute(contributionJar.toString(), contributionJar, is, modelResolver); - } catch (Exception e) { - throw new ActivationException(e); - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - throw new ActivationException(e); - } - } - return contribution; - } - */ -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java deleted file mode 100644 index 5f33ba0191..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.lang.reflect.UndeclaredThrowableException; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.domain.DomainManagerService; -import org.apache.tuscany.sca.domain.NodeInfo; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Scope; - - -/** - * Stores details of services exposed and retrieves details of remote services - * - * @version $Rev: 552343 $ $Date: 2007-09-07 12:41:52 +0100 (Fri, 07 Sep 2007) $ - */ -@Scope("COMPOSITE") -public class DomainManagerServiceImpl implements DomainManagerService{ - - private final static Logger logger = Logger.getLogger(DomainManagerServiceImpl.class.getName()); - - @Property - protected int retryCount = 100; - - @Property - protected int retryInterval = 5000; //ms - - @Reference - protected DomainManagerService domainManager; - - public String registerNode(String domainUri, String nodeUri) { - - String returnValue = null; - - for (int i =0; i < retryCount; i++){ - try { - returnValue = domainManager.registerNode(domainUri, nodeUri); - break; - } catch(UndeclaredThrowableException ex) { - logger.log(Level.INFO, "Trying to regsiter node " + - nodeUri + - " with domain " + - domainUri); - - } - - try { - Thread.sleep(retryInterval); - } catch(InterruptedException ex) { - } - } - - return returnValue; - } - - public String removeNode(String domainUri, String nodeUri) { - return domainManager.removeNode(domainUri, nodeUri); - } - - public List getNodeInfo(){ - return domainManager.getNodeInfo(); - } -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java deleted file mode 100644 index 14ba5fa1f9..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import org.apache.tuscany.sca.node.NodeFactory; -import org.apache.tuscany.sca.node.SCANode; - - -/** - * A factory that always returns the same domain object - * - * @version $Rev: 556897 $ $Date: 2007-09-07 12:41:52 +0100 (Fri, 07 Sep 2007) $ - */ -public class NodeFactoryImpl implements NodeFactory { - - SCANode node = null; - - public NodeFactoryImpl(SCANode node){ - this.node = node; - } - - /** - * Returns the domain object - * - * @return the domain - */ - public SCANode getNode(){ - return node; - } - -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java deleted file mode 100644 index 41de823845..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.node.ComponentInfo; -import org.apache.tuscany.sca.node.ComponentManagerService; -import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.NodeManagerInitService; -import org.apache.tuscany.sca.node.NodeManagerService; -import org.osoa.sca.annotations.Scope; -import org.osoa.sca.annotations.Service; - -/** - * Stores details of services exposed and retrieves details of remote services - * - * @version $Rev: 552343 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $ - */ -@Scope("COMPOSITE") -@Service(interfaces = {NodeManagerService.class, NodeManagerInitService.class, ComponentManagerService.class}) -public class NodeManagerServiceImpl implements NodeManagerService, NodeManagerInitService, ComponentManagerService { - - private SCANode node; - - public String getNodeUri() { - return node.getNodeURI(); - } - - // NodeManagerInitService - public void setNode(SCANode node) { - this.node = node; - } - - // ComponentManagerService - public List getComponentInfos() { - List componentInfos = new ArrayList(); - for (Component component : node.getComponentManager().getComponents()) { - ComponentInfo componentInfo = new ComponentInfoImpl(); - componentInfo.setName(component.getName()); - componentInfo.setStarted(node.getComponentManager().isComponentStarted(component)); - componentInfos.add(componentInfo); - } - return componentInfos; - } - - public ComponentInfo getComponentInfo(String componentName) { - Component component = node.getComponentManager().getComponent(componentName); - ComponentInfo componentInfo = new ComponentInfoImpl(); - componentInfo.setName(component.getName()); - componentInfo.setStarted(node.getComponentManager().isComponentStarted(component)); - return componentInfo; - } - - public void startComponent(String componentName) throws ActivationException { - node.getComponentManager().startComponent(node.getComponentManager().getComponent(componentName)); - } - - public void stopComponent(String componentName) throws ActivationException { - node.getComponentManager().stopComponent(node.getComponentManager().getComponent(componentName)); - } - - // TODO - ContributionManagerService -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCADomainServiceImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCADomainServiceImpl.java deleted file mode 100644 index 328d18c5d7..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCADomainServiceImpl.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.lang.reflect.UndeclaredThrowableException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.domain.SCADomainService; -import org.apache.tuscany.sca.domain.ServiceInfo; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; - - -/** - * Stores details of services exposed and retrieves details of remote services - * - * @version $Rev: 552343 $ $Date: 2007-09-09 23:54:46 +0100 (Sun, 09 Sep 2007) $ - */ -public class SCADomainServiceImpl implements SCADomainService{ - - private final static Logger logger = Logger.getLogger(SCADomainServiceImpl.class.getName()); - - @Property - protected int retryCount = 100; - - @Property - protected int retryInterval = 5000; //ms - - - @Reference - protected SCADomainService scaDomainService; - - /** - * Accepts information about a service endpoint and holds onto it - * - * @param domainUri the string uri for the distributed domain - * @param nodeUri the string uri for the current node - * @param serviceName the name of the service that is exposed and the provided endpoint - * @param bindingName the remote binding that is providing the endpoint - * @param url the endpoint url - * @return dummy values just so that we don't have a void return which doesn't work - */ - public String registerServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName, String URL){ - - String dummy = null; - - for (int i =0; i < retryCount; i++){ - try { - dummy = scaDomainService.registerServiceEndpoint(domainUri, nodeUri, serviceName, bindingName, URL); - break; - } catch(UndeclaredThrowableException ex) { - logger.log(Level.INFO, "Trying to connect to domain " + - domainUri + - " to register service " + - serviceName); - - } - - try { - Thread.sleep(retryInterval); - } catch(InterruptedException ex) { - } - } - - return dummy; - } - - /** - * Removes information about a service endpoint - * - * @param domainUri the string uri for the distributed domain - * @param nodeUri the string uri for the current node - * @param serviceName the name of the service that is exposed and the provided endpoint - * @param bindingName the remote binding that is providing the endpoint - * @return dummy values just so that we don't have a void return which doesn't work - */ - public String removeServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName){ - - String dummy = null; - - for (int i =0; i < retryCount; i++){ - try { - dummy = scaDomainService.removeServiceEndpoint(domainUri, nodeUri, serviceName, bindingName); - break; - } catch(UndeclaredThrowableException ex) { - logger.log(Level.INFO, "Trying to connect to domain " + - domainUri + - " to remove service " + - serviceName); - - } - - try { - Thread.sleep(retryInterval); - } catch(InterruptedException ex) { - } - } - - return dummy; - } - - /** - * Locates information about a service endpoint - * - * @param domainUri the string uri for the distributed domain - * @param serviceName the name of the service that is exposed and the provided endpoint - * @param bindingName the remote binding that we want to find an endpoint for - * @return url the endpoint url - */ - public String findServiceEndpoint(String domainUri, String serviceName, String bindingName){ - - - String url = null; - - for (int i =0; i < retryCount; i++){ - try { - url = scaDomainService.findServiceEndpoint(domainUri, serviceName, bindingName); - break; - } catch(UndeclaredThrowableException ex) { - logger.log(Level.INFO, "Trying to connect to domain " + - domainUri + - " to find service " + - serviceName); - - } - - try { - Thread.sleep(retryInterval); - } catch(InterruptedException ex) { - } - } - - return url; - } - - public ServiceInfo getServiceInfo(){ - return scaDomainService.getServiceInfo(); - } - -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java deleted file mode 100644 index 30ab7e3ad2..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java +++ /dev/null @@ -1,551 +0,0 @@ - /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.URI; -import java.net.URL; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -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.SCABinding; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; -import org.apache.tuscany.sca.node.ComponentManager; -import org.apache.tuscany.sca.node.ContributionManager; -import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.NodeManagerInitService; -import org.apache.tuscany.sca.domain.SCADomain; -import org.apache.tuscany.sca.domain.DomainManagerService; -import org.apache.tuscany.sca.domain.SCADomainService; -import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain; -import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentContext; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.osoa.sca.CallableReference; -import org.osoa.sca.ServiceReference; -import org.osoa.sca.ServiceRuntimeException; - -/** - * A local representation of the sca domain running on a single node - * - * @version $Rev: 552343 $ $Date: 2007-09-09 23:54:46 +0100 (Sun, 09 Sep 2007) $ - */ -public class SCANodeImpl extends SCADomain implements SCANode { - - private final static Logger logger = Logger.getLogger(SCANodeImpl.class.getName()); - - public final static String LOCAL_DOMAIN_URI = "standalonedomain"; - public final static String LOCAL_NODE_URI = "standalonenode"; - - private boolean isStandalone = false; - - // the domain used by the node to talk to the rest of the domain - private EmbeddedSCADomain managementRuntime; - - // class loader used to get the runtime going - private ClassLoader domainClassLoader; - - // class loader used to get application resources - private ClassLoader applicationClassLoader; - - // representation of the private state of the node that the domain is running on - private String domainUri; - private URL domainUrl; - private String nodeUri; - private URL nodeUrl; - private ReallySmallRuntime nodeRuntime; - private Composite nodeComposite; - - // the managers used to control the domain node - private ComponentManagerServiceImpl componentManager; - private ContributionManagerImpl contributionManager; - - // the proxies to the domain - private SCADomainService scaDomain; - private DomainManagerService domainManager; - private NodeManagerInitService nodeManagerInit; - - // methods defined on the implementation only - - /** - * Default constructor creates a standalone node with no connectivity to a wider - * domain and no local web page. - */ - public SCANodeImpl() - throws ActivationException { - this.domainUri = LOCAL_DOMAIN_URI ; - this.nodeUri = LOCAL_NODE_URI; - this.domainClassLoader = SCANodeImpl.class.getClassLoader(); - this.applicationClassLoader = Thread.currentThread().getContextClassLoader(); - this.isStandalone = true; - init(); - } - - /** - * Creates a node connected to a wider domain. To find its place in the domain - * node and domain identifiers must be provided. - * - * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081 - * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082 - * @throws ActivationException - */ - public SCANodeImpl(String domainUri, String nodeUri) - throws ActivationException { - this.domainUri = domainUri; - this.nodeUri = nodeUri; - this.domainClassLoader = SCANodeImpl.class.getClassLoader(); - this.applicationClassLoader = Thread.currentThread().getContextClassLoader(); - this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri); - init(); - } - - /** - * Creates a node connected to a wider domain and allows a classpath to be specified. - * To find its place in the domain node and domain identifiers must be provided. - * - * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081 - * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082 - * @param cl - the ClassLoader to use for loading system resources for the node - * @throws ActivationException - */ - public SCANodeImpl(String domainUri, String nodeUri, ClassLoader cl) - throws ActivationException { - this.domainUri = domainUri; - this.nodeUri = nodeUri; - this.domainClassLoader = cl; - this.applicationClassLoader = Thread.currentThread().getContextClassLoader(); - this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri); - init(); - } - - /** - * Creates a node connected to a wider domain and allows a classpath to be specified. - * To find its place in the domain node and domain identifiers must be provided. - * - * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081 - * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082 - * @param cl - the ClassLoader to use for loading system resources for the node - * @param applicationCl - the ClassLoader to use for loading application resources for the node - * @throws ActivationException - */ - public SCANodeImpl(String domainUri, String nodeUri, ClassLoader cl, ClassLoader applicationCl, String contributionPath, String[] composites) - throws ActivationException { - this.domainUri = domainUri; - this.nodeUri = nodeUri; - this.domainClassLoader = cl; - this.applicationClassLoader = applicationCl; - this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri); - init(); - start(); - - try { - URL contributionURL = SCANodeUtil.findContributionURLFromCompositeNameOrPath(applicationClassLoader, contributionPath, composites); - - contributionManager.addContribution(contributionURL); - - if (composites.length > 0 ){ - for(int i = 0; i < composites.length; i++) { - contributionManager.addComposite(composites[i]); - contributionManager.startComposite(composites[i]); - } - } else { - contributionManager.addAllComposites(contributionURL); - contributionManager.startAllComposites(contributionURL); - } - - } catch(Exception ex) { - throw new ActivationException(ex); - } - - } - - /** - * Work out if we are representing a domain in memory or can go out to the network to - * get domain information. This all depends on whether there is a management - * composite on the classpath - */ - private void init() - throws ActivationException { - try { - - // create a node runtime for the domain contributions to run on - nodeRuntime = new ReallySmallRuntime(domainClassLoader); - - // Check if node has been given a domain name to connect to - if (isStandalone) { - logger.log(Level.INFO, "Domain node will be started stand-alone as node and domain URIs are not provided"); - managementRuntime = null; - scaDomain = null; - } else { - // check where domain and node uris are urls, they will be used to configure various - // endpoints if they are - URI tmpURI; - try { - tmpURI = new URI(domainUri); - if (tmpURI.isAbsolute()){ - domainUrl = tmpURI.toURL(); - } - } catch(Exception ex) { - throw new ActivationException("domain uri " + - domainUri + - "must be a valid url"); - } - - try { - tmpURI = new URI(nodeUri); - if (tmpURI.isAbsolute()){ - nodeUrl = tmpURI.toURL(); - } - } catch(Exception ex) { - nodeUrl = null; - } - - createManagementNode(); - } - } catch(ActivationException ex) { - throw ex; - } catch(Exception ex) { - throw new ActivationException(ex); - } - } - - private void createManagementNode() - throws ActivationException { - try { - // create a runtime for components to run on that will be used for talking to the - // rest of the domain. The components are defined in the node.composite file - String nodeCompositeName = "node.composite"; - URL contributionURL = SCANodeUtil.findContributionURLFromCompositeNameOrPath(domainClassLoader, null, new String[]{nodeCompositeName} ); - - if ( contributionURL != null ){ - logger.log(Level.INFO, "Node management configured from " + contributionURL); - - // start a local domain in order to talk to the logical domain - managementRuntime = new EmbeddedSCADomain(domainClassLoader, "node"); - managementRuntime.start(); - - // add node composite to the management domain - ContributionService contributionService = managementRuntime.getContributionService(); - Contribution contribution = null; - - contribution = contributionService.contribute(nodeUri, - contributionURL, - false); - - if (contribution.getDeployables().size() != 0) { - Composite composite = contribution.getDeployables().get(0); - - managementRuntime.getDomainComposite().getIncludes().add(composite); - managementRuntime.getCompositeBuilder().build(composite); - - // deal with the special case of registering the node manager service - // in service discovery. It's not on an SCA binding. - // TODO - really want to be able to hand out service references but they - // don't serialize out over web services yet. - SCANodeUtil.fixUpNodeServiceUrls(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents(), nodeUrl); - SCANodeUtil.fixUpNodeReferenceUrls(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents(), domainUrl); - - managementRuntime.getCompositeActivator().activate(composite); - managementRuntime.getCompositeActivator().start(composite); - - // get the management components out of the domain so that they - // can be configured/used. - scaDomain = managementRuntime.getService(SCADomainService.class, "SCADomainComponent"); - domainManager = managementRuntime.getService(DomainManagerService.class, "DomainManagerComponent"); - nodeManagerInit = managementRuntime.getService(NodeManagerInitService.class, "NodeManagerComponent/NodeManagerInitService"); - - // Now get the uri back out of the component now it has been built and started - // TODO - this doesn't pick up the url from external hosting environments - String nodeManagerUrl = SCANodeUtil.getNodeManagerServiceUrl(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents()); - - if (nodeManagerUrl != null) { - if (isStandalone == false){ - try { - - scaDomain.registerServiceEndpoint(domainUri, - nodeUri, - nodeUri + "NodeManagerService", - "", - nodeManagerUrl); - - } catch(Exception ex) { - logger.log(Level.SEVERE, - "Can't connect to domain manager at: " + - domainUrl); - throw new ActivationException(ex); - } - } - } - - } else { - throw new ActivationException("Node management contribution " + - contributionURL + - " found but could not be loaded"); - } - } else { - throw new ActivationException("Node management contribution " + - nodeCompositeName + - " not found on the classpath"); - } - } catch(ActivationException ex) { - throw ex; - } catch(Exception ex) { - throw new ActivationException(ex); - } - } - - - // methods that implement interfaces - - public void start() throws ActivationException { - // Start the runtime - nodeRuntime.start(); - - // Create an in-memory domain level composite - AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory(); - nodeComposite = assemblyFactory.createComposite(); - nodeComposite.setName(new QName(Constants.SCA10_NS, "domain")); - nodeComposite.setURI(domainUri); - - // add the top level composite into the composite activator - nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite); - - // make the domain available to the model. - // TODO - No sure how this should be done properly. As a nod to this though - // I have a domain factory which always returns the same domain - // object. I.e. this node - ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class); - NodeFactoryImpl domainFactory = new NodeFactoryImpl(this); - factories.addFactory(domainFactory); - - // create the domain node managers - componentManager = new ComponentManagerServiceImpl(domainUri, nodeUri, nodeComposite, nodeRuntime); - contributionManager = new ContributionManagerImpl(domainUri, nodeUri, nodeComposite, nodeRuntime, applicationClassLoader, null); - - if (isStandalone == false){ - // pass this object into the node manager - nodeManagerInit.setNode((SCANode)this); - - try { - // go out and add this node to the wider domain - domainManager.registerNode(domainUri, nodeUri); - } catch(Exception ex) { - logger.log(Level.SEVERE, - "Can't connect to domain manager at: " + - domainUrl); - throw new ActivationException(ex); - } - } - } - - @Override - public void close() { - try { - stop(); - } catch (Exception ex) { - throw new ServiceRuntimeException(ex); - } - } - - public void stop() throws ActivationException { - // stop the components - - // remove contributions - - // Stop the node - nodeRuntime.stop(); - - // Cleanup the top level composite - nodeComposite = null; - - // remove the manager objects - - // go out and remove this node from the wider domain - if (isStandalone == false){ - try { - domainManager.removeNode(domainUri, nodeUri); - } catch(Exception ex) { - logger.log(Level.SEVERE, - "Can't connect to domain manager at: " + - domainUrl); - throw new ActivationException(ex); - } - } - } - - public String getURI(){ - return domainUri; - } - - public String getDomainURI(){ - return domainUri; - } - - public String getNodeURI(){ - return nodeUri; - } - - public URL getDomainURL(){ - return domainUrl; - } - - public URL getNodeURL(){ - return nodeUrl; - } - - public ComponentManager getComponentManager() { - return componentManager; - } - - public ContributionManager getContributionManager() { - return contributionManager; - } - - - /** - * Return an interface for registering local services and for - * finding remote services - * - * @return The service discovery interface - */ - public SCADomainService getDomainService(){ - return scaDomain; - } - - public > R cast(B target) throws IllegalArgumentException { - return (R)nodeRuntime.getProxyFactory().cast(target); - } - - public B getService(Class businessInterface, String serviceName) { - ServiceReference serviceReference = getServiceReference(businessInterface, serviceName); - if (serviceReference == null) { - throw new ServiceRuntimeException("Service not found: " + serviceName); - } - return serviceReference.getService(); - } - - private ServiceReference createServiceReference(Class businessInterface, String targetURI) { - try { - AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory(); - Composite composite = assemblyFactory.createComposite(); - composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default")); - RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent(); - component.setName("default"); - component.setURI("default"); - nodeRuntime.getCompositeActivator().configureComponentContext(component); - composite.getComponents().add(component); - RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference(); - reference.setName("default"); - ModelFactoryExtensionPoint factories = - nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class); - JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); - InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); - interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface)); - reference.setInterfaceContract(interfaceContract); - component.getReferences().add(reference); - reference.setComponent(component); - SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class); - SCABinding binding = scaBindingFactory.createSCABinding(); - binding.setURI(targetURI); - reference.getBindings().add(binding); - return new ServiceReferenceImpl(businessInterface, component, reference, binding, nodeRuntime - .getProxyFactory(), nodeRuntime.getCompositeActivator()); - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } - } - - public ServiceReference getServiceReference(Class 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 in the domain - Component component = componentManager.getComponent(componentName); - if (component == null) { - // The component is not local in the partition, try to create a remote service ref - return createServiceReference(businessInterface, name); - } - 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$." + serviceName; - } - componentContext = - ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext(); - return componentContext.createSelfReference(businessInterface, compositeService - .getPromotedService()); - } - break; - } - } - // No matching service is 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); - } - } - } - -} diff --git a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java b/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java deleted file mode 100644 index 84bdd465c4..0000000000 --- a/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.ServerSocket; -import java.net.URI; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.service.util.FileHelper; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.domain.SCADomainService; -import org.apache.tuscany.sca.node.NodeFactory; -import org.apache.tuscany.sca.domain.SCADomain; -import org.osoa.sca.CallableReference; -import org.osoa.sca.ServiceReference; - - -/** - * Some utility methods for the Node implementation - * - * @version $Rev: 556897 $ $Date: 2007-09-07 12:41:52 +0100 (Fri, 07 Sep 2007) $ - */ -public class SCANodeUtil { - private final static Logger logger = Logger.getLogger(SCANodeUtil.class.getName()); - - /** - * Given a contribution path an array of composite names or neither this method finds - * a suitable contribution to load - * - * @param classLoader - * @param compositePath - * @param composites - * @return the contribution URL - * @throws MalformedURLException - */ -/* original version - public static URL findContributionURLFromCompositeNameOrPath(ClassLoader classLoader, String contributionPath, String[] composites) - throws MalformedURLException { - if (contributionPath != null && contributionPath.length() > 0) { - //encode spaces as they would cause URISyntaxException - contributionPath = contributionPath.replace(" ", "%20"); - URI contributionURI = URI.create(contributionPath); - if (contributionURI.isAbsolute() || composites.length == 0) { - return new URL(contributionPath); - } - } - - String contributionArtifactPath = null; - URL contributionArtifactURL = null; - if (composites != null && composites.length > 0 && composites[0].length() > 0) { - - // Here the SCADomain was started with a reference to a composite file - contributionArtifactPath = composites[0]; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath); - } - } else { - - // Here the SCANode was started without any reference to a composite file - // We are going to look for an sca-contribution.xml or sca-contribution-generated.xml - - // Look for META-INF/sca-contribution.xml - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - - // Look for META-INF/sca-contribution-generated.xml - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - } - - // Look for META-INF/sca-deployables directory - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - } - } - - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("Can't determine contribution deployables. Either specify a composite file, or use an sca-contribution.xml file to specify the deployables."); - } - - URL contributionURL = null; - // "jar:file://....../something.jar!/a/b/c/app.composite" - try { - String url = contributionArtifactURL.toExternalForm(); - String protocol = contributionArtifactURL.getProtocol(); - if ("file".equals(protocol)) { - // directory contribution - if (url.endsWith(contributionArtifactPath)) { - String location = url.substring(0, url.lastIndexOf(contributionArtifactPath)); - // workaround from evil url/uri form maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - } - - } else if ("jar".equals(protocol)) { - // jar contribution - String location = url.substring(4, url.lastIndexOf("!/")); - // workaround for evil url/uri from maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - } - } catch (MalformedURLException mfe) { - throw new IllegalArgumentException(mfe); - } - - return contributionURL; - } - */ - public static URL findContributionURLFromCompositeNameOrPath(ClassLoader classLoader, String contributionPath, String[] composites) - throws MalformedURLException { - - String contributionArtifactPath = null; - URL contributionArtifactURL = null; - - - if (contributionPath != null && contributionPath.length() > 0) { - - //encode spaces as they would cause URISyntaxException - contributionPath = contributionPath.replace(" ", "%20"); - URI contributionURI = URI.create(contributionPath); - if (contributionURI.isAbsolute() || composites.length == 0) { - return new URL(contributionPath); - } else { - // contributionArtifactURL = classLoader.getResource(contributionPath); - // if (contributionArtifactURL == null) { - // throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath); - // } - } - } - - if ( contributionArtifactURL == null){ - if (composites != null && composites.length > 0 && composites[0].length() > 0) { - - // Here the SCADomain was started with a reference to a composite file - contributionArtifactPath = composites[0]; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath); - } - } else { - - // Here the SCANode was started without any reference to a composite file - // We are going to look for an sca-contribution.xml or sca-contribution-generated.xml - - // Look for META-INF/sca-contribution.xml - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - - // Look for META-INF/sca-contribution-generated.xml - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - } - - // Look for META-INF/sca-deployables directory - if (contributionArtifactURL == null) { - contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES; - contributionArtifactURL = classLoader.getResource(contributionArtifactPath); - } - } - } - - if (contributionArtifactURL == null) { - throw new IllegalArgumentException("Can't determine contribution deployables. Either specify a composite file, or use an sca-contribution.xml file to specify the deployables."); - } - - URL contributionURL = null; - // "jar:file://....../something.jar!/a/b/c/app.composite" - try { - String url = contributionArtifactURL.toExternalForm(); - String protocol = contributionArtifactURL.getProtocol(); - if ("file".equals(protocol)) { - // directory contribution - if (url.endsWith(contributionArtifactPath)) { - String location = url.substring(0, url.lastIndexOf(contributionArtifactPath)); - // workaround from evil url/uri form maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - } - - } else if ("jar".equals(protocol)) { - // jar contribution - String location = url.substring(4, url.lastIndexOf("!/")); - // workaround for evil url/uri from maven - contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL(); - } - } catch (MalformedURLException mfe) { - throw new IllegalArgumentException(mfe); - } - - return contributionURL; - } - - /** - * Given the name of a composite this method finds the contribution that it belongs to - * this could be either a local directory of a jar file. - * - * @param classLoader - * @param compositeString - * @return the contribution URL - * @throws MalformedURLException - */ -/* - public static URL findContributionFromComposite(ClassLoader classLoader, String compositeString) - throws MalformedURLException { - - URL contributionURL = classLoader.getResource(compositeString); - - if ( contributionURL != null ){ - String contributionString = contributionURL.toExternalForm(); - int jarPosition = contributionString.indexOf(".jar"); - - if (jarPosition> -1){ - // if the node dir is in a jar just contribute the name of the jar file - // rather the name of the directory in the jar file. - // changing - // jar:file:/myjarfile.jar!/contributiondir - // to - // file:/myjarfile.jar - contributionString = contributionString.substring(0, jarPosition + 4); - contributionString = contributionString.substring(4); - contributionURL = new URL(contributionString); - } else { - // Assume the node.composite file is in a directory so find the directory name - // changing - // file:/mydir/node.composite - // to - // file:/mydir - int compositePosition = contributionString.indexOf(compositeString); - contributionString = contributionString.substring(0, compositePosition); - contributionURL = new URL(contributionString); - } - } - - return contributionURL; - } -*/ - - /** - * A rather ugly method to find and fix the url of the service, assuming that there - * is one. - * - * we can't get is out of a service reference - * the component itself doesn't know how to get it - * the binding can't to do it automatically as it's not the sca binding - * - * TODO - This would be better done by passing out a serializable reference to service discovery - * but this doesn't work yet - * - * @return node manager url - */ - public static void fixUpNodeServiceUrls(List nodeComponents, URL nodeUrlString) - throws MalformedURLException, UnknownHostException { - - for(Component component : nodeComponents){ - for (ComponentService service : component.getServices() ){ - for (Binding binding : service.getBindings() ) { - fixUpNodeServiceBindingUrl(binding, nodeUrlString); - } - } - } - } - - /** - * Find and return the URL of the NodeManagerService - * - * @param nodeComponents - * @return - */ - public static String getNodeManagerServiceUrl(List nodeComponents){ - String nodeManagerUrl = null; - - for(Component component : nodeComponents){ - for (ComponentService service : component.getServices() ){ - - if ( service.getName().equals("NodeManagerService")) { - nodeManagerUrl = service.getBindings().get(0).getURI(); - } - } - } - - return nodeManagerUrl; - } - - /** - * For node management services that use the http(s) protocol then use the node url as the enpoint - * if it has been specified otherwise find a port that isn't in use and make sure the domain name - * is the real domain name - * - * @param binding - * @param nodeURL the URL provided as the identifier of the node - */ - public static void fixUpNodeServiceBindingUrl(Binding binding, URL manualUrl) - throws MalformedURLException, UnknownHostException{ - - String urlString = binding.getURI(); - - // only going to fiddle with bindings that use HTTP protocol - if( (urlString == null) || - ((urlString.startsWith("http") != true ) && - (urlString.startsWith("https") != true )) || - (binding instanceof SCABinding)) { - return; - } - - URL bindingUrl = new URL(urlString); - String originalHost = bindingUrl.getHost(); - String newHost = null; - int originalPort = bindingUrl.getPort(); - int newPort = 0; - - if (manualUrl != null) { - // the required url has been specified manually - newHost = manualUrl.getHost(); - newPort = manualUrl.getPort(); - - if ( newHost.equals("localhost")){ - newHost = InetAddress.getLocalHost().getHostName(); - } - } else { - // discover the host and port information - newHost = InetAddress.getLocalHost().getHostName(); - newPort = findFreePort(originalPort); - } - - // replace the old with the new - urlString = urlString.replace(String.valueOf(originalPort), String.valueOf(newPort)); - urlString = urlString.replace(originalHost, newHost); - - // set the address back into the NodeManager binding. - binding.setURI(urlString); - } - - /** - * Find a port on this machine that isn't in use. - * - * @param startPort - * @return - */ - public static int findFreePort(int startPort) - { - boolean portIsBusy = true; - int freePort = startPort; - - do { - try { - ServerSocket socket = new ServerSocket(freePort); - portIsBusy = false; - socket.close(); - break; - } - catch (IOException ex) { - // the port is busy - freePort = freePort + 1; - } - } while (portIsBusy || freePort > 9999); - - return freePort; - } - - /** - * For node services that have to talk to the domain fix up the reference URL using the - * provided domain url if it has been provided - * - * @param nodeComponents - * @param domainUrlString - * @throws MalformedURLException - * @throws UnknownHostException - */ - public static void fixUpNodeReferenceUrls(List nodeComponents, URL domainUrl) - throws MalformedURLException, UnknownHostException, ActivationException{ - - for(Component component : nodeComponents){ - for (ComponentReference reference : component.getReferences() ){ - if ( reference.getName().equals("domainManager") || - reference.getName().equals("scaDomainService")) { - for (Binding binding : reference.getBindings() ) { - fixUpNodeReferenceBindingUrl(binding, domainUrl); - } - } - } - } - } - - /** - * For node management references to the domain fix up the binding URLs so that they point - * to the endpoint described in the domainURL - * - * @param binding - * @param nodeURL the URL provided as the identifier of the node - */ - public static void fixUpNodeReferenceBindingUrl(Binding binding, URL manualUrl) - throws MalformedURLException, UnknownHostException, ActivationException{ - - String urlString = binding.getURI(); - - // only going to fiddle with bindings that use HTTP protocol - if( (urlString == null) || - ((urlString.startsWith("http") != true ) && - (urlString.startsWith("https") != true )) || - (binding instanceof SCABinding) ) { - return; - } - - URL bindingUrl = new URL(urlString); - String originalHost = bindingUrl.getHost(); - String newHost = null; - int originalPort = bindingUrl.getPort(); - int newPort = 0; - - if (manualUrl != null) { - // the required url has been specified manually - newHost = manualUrl.getHost(); - newPort = manualUrl.getPort(); - } else { - throw new ActivationException("domain uri can't be null"); - } - - // replace the old with the new - urlString = urlString.replace(String.valueOf(originalPort), String.valueOf(newPort)); - urlString = urlString.replace(originalHost, newHost); - - // set the address back into the NodeManager binding. - binding.setURI(urlString); - } -} -- cgit v1.2.3