Author: antelder
Date: Tue Nov 27 07:13:59 2007
New Revision: 598666
URL: http://svn.apache.org/viewvc?rev=598666&view=rev
Log:
Add files missing from last commit
Added:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
(with props)
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
(with props)
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
(with props)
Removed:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/webapp/
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/sample-calculator-nodeB.jar
Modified:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/WEB-INF/web.xml
Added:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java?rev=598666&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
(added)
+++
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
Tue Nov 27 07:13:59 2007
@@ -0,0 +1,332 @@
+/*
+ * 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.runtime.war;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.domain.DomainException;
+import org.apache.tuscany.sca.node.NodeException;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+
+/**
+ */
+public class Launcher {
+ private final static Logger logger =
Logger.getLogger(Launcher.class.getName());
+
+ protected File repository;
+
+ protected String nodeName;
+ protected String domainName;
+ protected long hotDeployInterval; // miliseconds, 0 = no hot deploy
+
+ protected SCANode node;
+
+ protected Thread hotDeployThread;
+ protected boolean stopHotDeployThread;
+
+ protected HashMap<URL, Long> existingContributions; // value is last
modified time
+
+ public Launcher(File repository) {
+ this(repository, null, null, false, 0);
+ }
+
+ public Launcher(File repository, String nodeName, String domainName,
boolean startManager, long hotDeployInterval) {
+ this.repository = repository;
+ this.nodeName = nodeName;
+ this.domainName = domainName;
+ this.hotDeployInterval = hotDeployInterval;
+ }
+
+ public void start() throws NodeException, URISyntaxException,
InterruptedException, DomainException, MalformedURLException {
+ logger.log(Level.INFO, "SCA runtime starting");
+
+ initFromPropertyFile();
+
+ logger.info("nodeName: " + nodeName);
+ logger.info("domainName: " + domainName);
+ logger.info("hotDeployInterval: " + hotDeployInterval);
+
+ node = startNode(nodeName, domainName);
+
+ initHotDeploy(repository);
+
+ logger.log(Level.INFO, "SCA runtime started");
+ }
+
+ public void stop() {
+ logger.log(Level.INFO, "SCA runtime stopping");
+ stopHotDeployThread = true;
+
+ if (node != null) {
+ stopNode(node);
+ }
+ logger.log(Level.INFO, "SCA runtime stopped");
+ }
+
+ protected SCANode startNode(String nodeName, String domainName) throws
NodeException, URISyntaxException, MalformedURLException {
+ logger.log(Level.INFO, "starting node " + nodeName);
+
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ SCANode scaNode = nodeFactory.createSCANode(nodeName, domainName);
+
+ initNode(scaNode);
+ logger.log(Level.INFO, "started node " + nodeName);
+
+ return scaNode;
+ }
+
+ protected void stopNode(SCANode node) {
+ logger.log(Level.INFO, "stopping node " + node.getURI());
+ try {
+ node.stop();
+ logger.log(Level.INFO, "stopped node " + node.getURI());
+ } catch (NodeException e) {
+ logger.log(Level.SEVERE, "exception stopping node " +
node.getURI(), e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void initNode(SCANode scaNode) throws NodeException,
URISyntaxException, MalformedURLException {
+ URL[] contributions = getContributionJarURLs(repository);
+ if (contributions.length > 0) {
+ existingContributions = new HashMap<URL, Long>();
+ for (URL contribution : contributions) {
+ scaNode.addContribution(contribution.toString(), contribution);
+ existingContributions.put(contribution, new Long(new
File(contribution.toURI()).lastModified()));
+ logger.log(Level.INFO, "Added contribution: " + contribution);
+ }
+ } else {
+ scaNode.addContribution(repository.toString(), repository.toURL());
+ logger.log(Level.INFO, "Added contribution folder: " + repository);
+ }
+
+ scaNode.addToDomainLevelComposite((QName)null);
+ scaNode.start();
+ }
+
+ protected void restartNode(SCANode scaNode) {
+ stopNode(scaNode);
+ for (URL contributionURL : existingContributions.keySet()) {
+ try {
+ scaNode.removeContribution(contributionURL.toString());
+ } catch (NodeException e) {
+ logger.log(Level.SEVERE, "exception removing contribution from
node: " + contributionURL, e);
+ }
+ }
+ try {
+ initNode(scaNode);
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, "exception restarting node " +
scaNode.getURI(), e);
+ }
+ }
+
+ protected URL[] getContributionJarURLs(File repositoryDir) {
+
+ String[] jarNames = repositoryDir.list(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".jar");
+ }});
+
+ List<URL> contributionJars = new ArrayList<URL>();
+ if (jarNames != null) {
+ for (String jar : jarNames) {
+ try {
+ contributionJars.add(new File(repositoryDir, jar).toURL());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ return contributionJars.toArray(new URL[contributionJars.size()]);
+ }
+
+ protected void initHotDeploy(final File repository) {
+
+ if (hotDeployInterval == 0) {
+ return; // hotUpdateInterval of 0 disables hotupdate
+ }
+
+ Runnable runable = new Runnable() {
+
+ public void run() {
+ logger.info("Contribution hot deploy activated");
+ while (!stopHotDeployThread) {
+ try {
+ Thread.sleep(hotDeployInterval);
+ } catch (InterruptedException e) {
+ }
+ if (!stopHotDeployThread) {
+ checkForUpdates(repository);
+ }
+ }
+ logger.info("contribution hot deploy stopped");
+ }
+ };
+ hotDeployThread = new Thread(runable, "TuscanyHotDeploy");
+ stopHotDeployThread = false;
+ hotDeployThread.start();
+ }
+
+ protected void checkForUpdates(File repository) {
+ URL[] currentContributions = getContributionJarURLs(repository);
+ if (areContributionsAltered(currentContributions)) {
+ restartNode(node);
+ }
+ }
+
+ protected boolean areContributionsAltered(URL[] currentContrabutions) {
+ try {
+
+ List addedContributions =
getAddedContributions(currentContrabutions);
+ List removedContributions =
getRemovedContributions(currentContrabutions);
+ List updatedContributions =
getUpdatedContributions(currentContrabutions);
+
+ return (addedContributions.size() > 0 ||
removedContributions.size() > 0 || updatedContributions.size() > 0);
+
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected List<URL> getAddedContributions(URL[] currentContrabutions) {
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : currentContrabutions) {
+ if (!existingContributions.containsKey(url)) {
+ urls.add(url);
+ }
+ }
+ return urls;
+ }
+
+ protected List<URL> getUpdatedContributions(URL[] currentContrabutions)
throws URISyntaxException {
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : currentContrabutions) {
+ if (existingContributions.containsKey(url)) {
+ File curentFile = new File(url.toURI());
+ if (curentFile.lastModified() !=
existingContributions.get(url)) {
+ urls.add(url);
+ logger.info("updated contribution: " +
curentFile.getName());
+ }
+ }
+ }
+ return urls;
+ }
+
+ protected List getRemovedContributions(URL[] currentContrabutions) throws
URISyntaxException {
+ List<URL> currentUrls = Arrays.asList(currentContrabutions);
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : existingContributions.keySet()) {
+ if (!currentUrls.contains(url)) {
+ urls.add(url);
+ }
+ }
+ for (URL url : urls) {
+ logger.info("removed contributions: " + new
File(url.toURI()).getName());
+ }
+ return urls;
+ }
+
+ protected void initFromPropertyFile() {
+ File file = new File(repository, "tuscany.properties");
+ if (!file.exists()) {
+ return;
+ }
+ logger.info("using config properties at: " + file);
+
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileInputStream(file));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ if (properties.getProperty("nodeName") != null) {
+ this.nodeName = properties.getProperty("nodeName");
+ }
+ if (properties.getProperty("domainName") != null) {
+ this.domainName = properties.getProperty("domainName");
+ }
+ if (properties.getProperty("hotDeployInterval") != null) {
+ this.hotDeployInterval =
Long.parseLong(properties.getProperty("hotDeployInterval"));
+ }
+ }
+
+ protected void copyFiles(File origin, File destination) throws IOException
{
+ if (origin.isDirectory()) {
+ if (!destination.exists()) {
+ destination.mkdir();
+ }
+ for (String file : origin.list()) {
+ copyFiles(new File(origin, file), new File(destination, file));
+ }
+ } else {
+ InputStream in = new FileInputStream(origin);
+ OutputStream out = new FileOutputStream(destination);
+ try {
+ byte[] buf = new byte[4096];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ } finally {
+ in.close();
+ out.close();
+ }
+ }
+ }
+}
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/Launcher.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java?rev=598666&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
(added)
+++
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
Tue Nov 27 07:13:59 2007
@@ -0,0 +1,71 @@
+/*
+ * 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.runtime.war;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class WarContextListener implements ServletContextListener {
+
+ private static final Logger logger =
Logger.getLogger(WarContextListener.class.getName());
+
+ protected Launcher launcher;
+
+ protected static final String DEFAULT_REPOSITORY_FOLDER =
"sca-contributions";
+
+ public void contextInitialized(ServletContextEvent event) {
+ try {
+ launcher = new Launcher(getRepositoryFolder(event));
+ launcher.start();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ logger.log(Level.SEVERE, "exception starting SCA runtime", e);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ if (launcher != null)
+ try {
+ launcher.stop();
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, "exception stopping SCA runtime", e);
+ }
+ }
+
+ protected File getRepositoryFolder(ServletContextEvent event) {
+ ServletContext servletContext = event.getServletContext();
+
+ File repositoryFolder;
+ if (servletContext.getInitParameter("repositoryFolder") != null) {
+ repositoryFolder = new
File(servletContext.getInitParameter("repositoryFolder"));
+ } else {
+ repositoryFolder = new
File(servletContext.getRealPath("sca-contributions"));
+ }
+
+ logger.info((new StringBuilder()).append("Contribution Repository ->
").append(repositoryFolder).toString());
+ return repositoryFolder;
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/java/org/apache/tuscany/sca/runtime/war/WarContextListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/WEB-INF/web.xml?rev=598666&r1=598665&r2=598666&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/WEB-INF/web.xml
(original)
+++
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/WEB-INF/web.xml
Tue Nov 27 07:13:59 2007
@@ -28,10 +28,10 @@
<listener-class>org.apache.tuscany.sca.runtime.war.WarContextListener</listener-class>
</listener>
- <context-param>
+ <!-- context-param>
<param-name>repositoryFolder</param-name>
- <param-value>/TuscanyRepository</param-value>
- </context-param>
+ <param-value>/sca-contributions</param-value>
+ </context-param -->
<filter>
<filter-name>tuscany</filter-name>
Added:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties?rev=598666&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
(added)
+++
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
Tue Nov 27 07:13:59 2007
@@ -0,0 +1,4 @@
+nodeName=http://myNode
+#nodeName=http://localhost:8080/tuscany/myNode/
+#domainName=http://localhost:9876/tuscany/domainManager
+hotDeployInterval=10000
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/tuscany/java/sca/modules/runtime-war/src/main/webapp/sca-contributions/tuscany.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]