You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/04/03 09:36:15 UTC

svn commit: r644202 - in /incubator/tuscany/branches/sca-java-1.2: modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/ modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implement...

Author: jsdelfino
Date: Thu Apr  3 00:36:14 2008
New Revision: 644202

URL: http://svn.apache.org/viewvc?rev=644202&view=rev
Log:
Fixes for TUSCANY-2182, merged from trunk. Revert back to a parent-last classloading scheme as a portable classloading scheme for Tomcat, Geronimo and WebSphere. Make sure that the node classloader is set on the thread context after a node is started, as sample clients like calculator-distributed don't set it. Minor fixes to calculator-distributed to fix issues found during testing and bringup.

Modified:
    incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java
    incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
    incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
    incubator/tuscany/branches/sca-java-1.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
    incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
    incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
    incubator/tuscany/branches/sca-java-1.2/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainManagerLauncherBootstrap.java
    incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/build.xml
    incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java

Modified: incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java Thu Apr  3 00:36:14 2008
@@ -34,6 +34,7 @@
      * A node wrappering an instance of a node daemon.
      */
     public static class NodeFacade implements SCANode2 {
+        private ClassLoader threadContextClassLoader;
         private ClassLoader runtimeClassLoader;
         private SCADomain daemon;
         
@@ -42,22 +43,25 @@
         }
         
         public void start() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+            boolean started = false;
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 daemon = SCADomain.newInstance("NodeDaemon.composite");
+                started = true;
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                if (!started) {
+                    Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+                }
             }
         }
         
         public void stop() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 daemon.close();
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                Thread.currentThread().setContextClassLoader(threadContextClassLoader);
             }
         }
     }

Modified: incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java Thu Apr  3 00:36:14 2008
@@ -25,6 +25,7 @@
 import org.apache.tuscany.sca.node.SCANode2Factory.SCAContribution;
 import org.osoa.sca.CallableReference;
 import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
 
 /**
  * Bootstrap class for standalone SCA nodes.
@@ -39,6 +40,7 @@
      * A node facade.
      */
     public static class NodeFacade implements SCANode2, SCAClient {
+        private ClassLoader threadContextClassLoader;
         private ClassLoader runtimeClassLoader;
         private SCANode2 delegate;
         
@@ -48,22 +50,25 @@
         }
         
         public void start() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+            boolean started = false;
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 delegate.start();
+                started = true;
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                if (!started) {
+                    Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+                }
             }
         }
         
         public void stop() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 delegate.stop();
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                Thread.currentThread().setContextClassLoader(threadContextClassLoader);
             }
         }
 

Modified: incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java Thu Apr  3 00:36:14 2008
@@ -74,7 +74,7 @@
     }
 
     /**
-     * Returns the servlet host for the current Web app.
+     * Returns the Servlet host for the current Web app.
      * 
      * @return
      */
@@ -83,17 +83,17 @@
     }
 
     /**
-     * Initialize the servlet host.
+     * Initialize the Servlet host.
      * 
      * @param filterConfig
      * @throws ServletException
      */
     public void init(final FilterConfig filterConfig) throws ServletException {
         
-        // Create a servlet config wrappering the given filter config
+        // Create a Servlet config wrapping the given filter config
         ServletConfig servletConfig = servletConfig(filterConfig);
 
-        // Get the servlet context
+        // Get the Servlet context
         ServletContext servletContext = servletConfig.getServletContext();
 
         // Initialize the context path
@@ -115,18 +115,18 @@
         SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
         node = nodeFactory.createSCANode(nodeImage);
         
-        // Register the servlet host
+        // Register the Servlet host
         ServletHostExtensionPoint servletHosts = servletHosts(node);
         servletHosts.getServletHosts().clear();
         servletHosts.addServletHost(servletHost);
 
-        // Save the node in the servlet context 
+        // Save the node in the Servlet context 
         servletContext.setAttribute(SCAClient.class.getName(), node);
         
         // Start the node
         node.start();
 
-        // Initialize the registered servlets
+        // Initialize the registered Servlets
         for (Servlet servlet : servlets.values()) {
             servlet.init(servletConfig);
         }
@@ -179,7 +179,7 @@
             suri = contextPath + suri;
         }
 
-        // Get the servlet mapped to the given path
+        // Get the Servlet mapped to the given path
         Servlet servlet = servlets.get(suri);
         return servlet;
     }
@@ -233,7 +233,7 @@
 
         suri = contextPath + suri;
 
-        // Get the servlet mapped to the given path
+        // Get the Servlet mapped to the given path
         Servlet servlet = servlets.get(suri);
         if (servlet != null) {
             return new NodeWebAppRequestDispatcher(suri, servlet);
@@ -253,18 +253,18 @@
             }
         }
 
-        // No servlet found
+        // No Servlet found
         return null;
     }
 
     /**
-     * Destroy the servlet host.
+     * Destroy the Servlet host.
      * 
      * @throws ServletException
      */
     public void destroy() {
 
-        // Destroy the registered servlets
+        // Destroy the registered Servlets
         for (Servlet servlet : servlets.values()) {
             servlet.destroy();
         }
@@ -278,7 +278,7 @@
     public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
         throws IOException, ServletException {
 
-        // Get the servlet path
+        // Get the Servlet path
         HttpServletRequest httpRequest = (HttpServletRequest)request;
         String path = httpRequest.getPathInfo();
         if (path == null) {
@@ -288,11 +288,11 @@
             path = "/";
         }
 
-        // Get a request dispatcher for the servlet mapped to that path
+        // Get a request dispatcher for the Servlet mapped to that path
         RequestDispatcher dispatcher = getRequestDispatcher(path);
         if (dispatcher != null) {
 
-            // Let the dispatcher forward the request to the servlet
+            // Let the dispatcher forward the request to the Servlet
             dispatcher.forward(request, response);
 
         } else {
@@ -320,7 +320,7 @@
 
     /**
      * Initializes the contextPath
-     * The 2.5 Servlet API has a getter for this, for pre 2.5 servlet
+     * The 2.5 Servlet API has a getter for this, for pre 2.5 Servlet
      * containers use an init parameter.
      */
     private static String contextPath(ServletContext context) {
@@ -346,7 +346,7 @@
     }
 
     /**
-     * Returns the servlet host extension point used by the given node.
+     * Returns the Servlet host extension point used by the given node.
      * 
      * @return
      */
@@ -364,7 +364,7 @@
     }
 
     /**
-     * Returns a servlet config wrappering a filter config.
+     * Returns a Servlet config wrapping a filter config.
      * 
      * @param filterConfig
      * @return

Modified: incubator/tuscany/branches/sca-java-1.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java Thu Apr  3 00:36:14 2008
@@ -60,7 +60,7 @@
 import org.osoa.sca.ServiceRuntimeException;
 
 /**
- * A local representation of the sca domain running on a single node
+ * A local representation of the SCADomain running on a single node
  * 
  * @version $Rev$ $Date$
  */
@@ -71,7 +71,7 @@
     // The node configuration name, used for logging
     private String configurationName;
     
-    // The tuscany runtime that does the hard work
+    // The Tuscany runtime that does the hard work
     private ReallySmallRuntime runtime;
     private CompositeActivator compositeActivator;
     private XMLInputFactory inputFactory;
@@ -144,6 +144,7 @@
             Composite composite = assemblyFactory.createComposite();
             composite.setURI(compositeURI);
             composite.setUnresolved(true);
+            configuration.setComposite(composite);
             
             // Create contribution models
             ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
@@ -377,17 +378,20 @@
         
         // Collect JARs from the URLClassLoader's classpath
         if (cl instanceof URLClassLoader) {
-            for (URL jarURL: ((URLClassLoader)cl).getURLs()) {
-                String file =jarURL.getPath();
-                int i = file.lastIndexOf('/');
-                if (i != -1 && i < file.length() -1 ) {
-                    file = file.substring(i +1);
-                    urls.put(file, jarURL);
+            URL[] jarURLs = ((URLClassLoader)cl).getURLs();
+            if (jarURLs != null) {
+                for (URL jarURL: jarURLs) {
+                    String file =jarURL.getPath();
+                    int i = file.lastIndexOf('/');
+                    if (i != -1 && i < file.length() -1 ) {
+                        file = file.substring(i +1);
+                        urls.put(file, jarURL);
+                    }
                 }
             }
         }
         
-        // Collect JARs from the parent classloader
+        // Collect JARs from the parent ClassLoader
         collectJARs(urls, cl.getParent());
     }
 }

Modified: incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java Thu Apr  3 00:36:14 2008
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -29,6 +30,8 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -46,13 +49,38 @@
 
 
     /**
-     * Returns a classloader for the Tuscany runtime JARs.
+     * Returns a ClassLoader for the Tuscany runtime JARs for use in a standalone
+     * J2SE environment.
      * 
      * @param parentClassLoader
      * 
      * @return
      */
-    static ClassLoader runtimeClassLoader(ClassLoader parentClassLoader) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+    static ClassLoader standAloneRuntimeClassLoader(ClassLoader parentClassLoader) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+        return runtimeClassLoader(parentClassLoader, new StandAloneJARFileNameFilter());
+    }
+    
+    /**
+     * Returns a ClassLoader for the Tuscany runtime JARs for use in a Webapp
+     * environment.
+     * 
+     * @param parentClassLoader
+     * 
+     * @return
+     */
+    static ClassLoader webAppRuntimeClassLoader(ClassLoader parentClassLoader) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+        return runtimeClassLoader(parentClassLoader, new WebAppJARFileNameFilter());
+    }
+    
+    /**
+     * Returns a ClassLoader for the Tuscany runtime JARs.
+     * 
+     * @param parentClassLoader
+     * @param filter
+     * 
+     * @return
+     */
+    static private ClassLoader runtimeClassLoader(ClassLoader parentClassLoader, FilenameFilter filter) throws FileNotFoundException, URISyntaxException, MalformedURLException {
         
         // Build list of runtime JARs
         List<URL> jarURLs = new ArrayList<URL>();
@@ -84,7 +112,7 @@
 
                     // Collect JAR files from the directory containing the input JAR
                     // (e.g. the Tuscany modules directory)
-                    collectJARFiles(jarDirectory, jarURLs);
+                    collectJARFiles(jarDirectory, jarURLs, filter);
                     
                     File homeDirectory = jarDirectory.getParentFile();
                     if (homeDirectory != null && homeDirectory.exists()) {
@@ -92,13 +120,13 @@
                         // Collect JARs from the ../modules directory
                         File modulesDirectory = new File(homeDirectory, "modules");
                         if (modulesDirectory.exists() && !modulesDirectory.getAbsolutePath().equals(jarDirectory.getAbsolutePath())) {
-                            collectJARFiles(modulesDirectory, jarURLs);
+                            collectJARFiles(modulesDirectory, jarURLs, filter);
                         }
 
                         // Collect JARs from the ../lib directory
                         File libDirectory = new File(homeDirectory, "lib");
                         if (libDirectory.exists() && !libDirectory.getAbsolutePath().equals(jarDirectory.getAbsolutePath())) {
-                            collectJARFiles(libDirectory, jarURLs);
+                            collectJARFiles(libDirectory, jarURLs, filter);
                         }
 
                     }
@@ -119,18 +147,18 @@
             if (homeDirectory.exists()) {
                 
                 // Collect files under $TUSCANY_HOME
-                collectJARFiles(homeDirectory, jarURLs);
+                collectJARFiles(homeDirectory, jarURLs, filter);
                 
                 // Collect files under $TUSCANY_HOME/modules
                 File modulesDirectory = new File(homeDirectory, "modules");
                 if (modulesDirectory.exists()) {
-                    collectJARFiles(modulesDirectory, jarURLs);
+                    collectJARFiles(modulesDirectory, jarURLs, filter);
                 }
     
                 // Collect files under $TUSCANY_HOME/lib
                 File libDirectory = new File(homeDirectory, "lib");
                 if (libDirectory.exists()) {
-                    collectJARFiles(libDirectory, jarURLs);
+                    collectJARFiles(libDirectory, jarURLs, filter);
                 }
             }
         }
@@ -138,8 +166,8 @@
         // Return the runtime class loader
         if (!jarURLs.isEmpty()) {
             
-            // Return a classloader configured with the runtime JARs
-            ClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new URL[0]), parentClassLoader);
+            // Return a ClassLoader configured with the runtime JARs
+            ClassLoader classLoader = new RuntimeClassLoader(jarURLs.toArray(new URL[0]), parentClassLoader);
             return classLoader;
             
         } else {
@@ -151,41 +179,11 @@
      * Collect JAR files in the given directory
      * @param directory
      * @param urls
+     * @param filter
      * @throws MalformedURLException
      */
-    private static void collectJARFiles(File directory, List<URL> urls) throws MalformedURLException {
-        File[] files = directory.listFiles(new FilenameFilter() {
-    
-            public boolean accept(File dir, String name) {
-                name = name.toLowerCase(); 
-                
-                // Exclude tuscany-sca-all and tuscany-sca-manifest as they duplicate
-                // code in the individual runtime module JARs
-                if (name.startsWith("tuscany-sca-all")) {
-                    return false;
-                }
-                if (name.startsWith("tuscany-sca-manifest")) {
-                    return false;
-                }
-                
-                // Filter out the Jetty and Webapp hosts
-                if (name.startsWith("tuscany-host-jetty") ||
-                    name.startsWith("tuscany-host-webapp")) {
-                    //FIXME This is temporary
-                    return false;
-                }
-                
-                // Include JAR and MAR files
-                if (name.endsWith(".jar")) {
-                    return true;
-                }
-                if (name.endsWith(".mar")) {
-                    return true;
-                }
-                return false;
-            }
-        });
-    
+    private static void collectJARFiles(File directory, List<URL> urls, FilenameFilter filter) throws MalformedURLException {
+        File[] files = directory.listFiles(filter);
         if (files != null) {
             int count = 0;
             for (File file: files) {
@@ -205,6 +203,68 @@
     }
 
     /**
+     * A file name filter used to filter JAR files.
+     */
+    private static class StandAloneJARFileNameFilter implements FilenameFilter {
+        
+        public boolean accept(File dir, String name) {
+            name = name.toLowerCase(); 
+            
+            // Exclude tuscany-sca-all and tuscany-sca-manifest as they duplicate
+            // code in the individual runtime module JARs
+            if (name.startsWith("tuscany-sca-all")) {
+                return false;
+            }
+            if (name.startsWith("tuscany-sca-manifest")) {
+                return false;
+            }
+            
+            // Filter out the Jetty and Webapp hosts
+            if (name.startsWith("tuscany-host-jetty") ||
+                name.startsWith("tuscany-host-webapp")) {
+                //FIXME This is temporary
+                return false;
+            }
+            
+            // Include JAR and MAR files
+            if (name.endsWith(".jar")) {
+                return true;
+            }
+            if (name.endsWith(".mar")) {
+                return true;
+            }
+            return false;
+        }
+    }
+    
+    /**
+     * A file name filter used to filter JAR files.
+     */
+    private static class WebAppJARFileNameFilter extends StandAloneJARFileNameFilter {
+        
+        public boolean accept(File dir, String name) {
+            if (!super.accept(dir, name)) {
+                return false;
+            }
+            name = name.toLowerCase(); 
+            
+            // Exclude servlet-api JARs
+            if (name.startsWith("servlet-api")) {
+                return false;
+            }
+            
+            // Filter out the Tomcat host
+            if (name.startsWith("tuscany-host-tomcat")) {
+                //FIXME This is temporary
+                return false;
+            }
+            
+            return true;
+        }
+    }
+    
+    
+    /**
      * Creates a new node.
      * 
      * @param compositeURI
@@ -215,7 +275,8 @@
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         try {
             // Set up runtime ClassLoader
-            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader());
+            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+                                                                new StandAloneJARFileNameFilter());
             if (runtimeClassLoader != null) {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
             }
@@ -269,7 +330,8 @@
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         try {
             // Set up runtime ClassLoader
-            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader());
+            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+                                                                new StandAloneJARFileNameFilter());
             if (runtimeClassLoader != null) {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
             }
@@ -305,7 +367,8 @@
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         try {
             // Set up runtime ClassLoader
-            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader());
+            ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+                                                                new StandAloneJARFileNameFilter());
             if (runtimeClassLoader != null) {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
             }
@@ -332,4 +395,78 @@
         }
     }
 
+    /**
+     * Simple URL class loader for the runtime JARs
+     */
+    private static class RuntimeClassLoader extends URLClassLoader {
+        private final static ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+        private ClassLoader parent;
+        
+        /**
+         * Constructs a new class loader.
+         * @param urls
+         * @param parent
+         */
+        private RuntimeClassLoader(URL[] urls, ClassLoader parent) {
+            super(urls);
+            this.parent = parent;
+        }
+
+        @Override
+        public URL findResource(String name) {
+            URL url = super.findResource(name);
+            if (url == null) {
+                url = parent.getResource(name);
+            }
+            return url;
+        }
+
+        @Override
+        public Enumeration<URL> findResources(String name) throws IOException {
+            Enumeration<URL> resources = super.findResources(name);
+            Enumeration<URL> parentResources = parent.getResources(name);
+            List<URL> allResources = new ArrayList<URL>(); 
+            for (; resources.hasMoreElements(); ) {
+                allResources.add(resources.nextElement());
+            }
+            for (; parentResources.hasMoreElements(); ) {
+                allResources.add(parentResources.nextElement());
+            }
+            return Collections.enumeration(allResources);
+        }
+
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
+            Class<?> cl;
+
+            // First try to load the class using the parent classloader
+            try {
+                cl = parent.loadClass(name);
+                ClassLoader loadedBy = cl.getClassLoader();
+
+                // If the class was not loaded directly by the parent classloader
+                // or the system classloader try to load a local version of the class
+                // using our RuntimeClassloader instead
+                if (loadedBy != parent &&
+                    loadedBy != systemClassLoader &&
+                    loadedBy != null) {
+
+                    try {
+                        cl = super.findClass(name);
+                    } catch (ClassNotFoundException e) {
+                        // No class alternative was found in our RuntimeClassloader,
+                        // use the class found in the parent classloader hierarchy
+                    }
+                }
+            } catch (ClassNotFoundException e) {
+                
+                // The class was not found by the parent class loader, try
+                // to load it using our RuntimeClassloader
+                cl = super.findClass(name);
+            }
+
+            return cl;
+        }
+    }
+    
 }

Modified: incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java Thu Apr  3 00:36:14 2008
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.node.launcher;
 
+import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.webAppRuntimeClassLoader;
+
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -30,10 +32,10 @@
 import javax.servlet.ServletResponse;
 
 /**
- * A servlet filter that forwards service requests to the servlets registered with
+ * A Servlet filter that forwards service requests to the Servlets registered with
  * the Tuscany ServletHost.
  * 
- * @version $Rev$ $Date$
+ * @version $Rev: 639872 $ $Date: 2008-03-21 14:42:27 -0700 (Fri, 21 Mar 2008) $
  */
 public class NodeServletFilter implements Filter {
     private static final long serialVersionUID = 1L;
@@ -49,16 +51,16 @@
         logger.info("Apache Tuscany SCA WebApp Node starting...");
 
         try {
-            // Get the Tuscany runtime classloader
+            // Get the Tuscany runtime ClassLoader
             ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-            runtimeClassLoader = NodeLauncherUtil.runtimeClassLoader(getClass().getClassLoader());
+            runtimeClassLoader = webAppRuntimeClassLoader(getClass().getClassLoader());
             
             try {
                 if (runtimeClassLoader != null) {
                     Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 }
         
-                // Load the Tuscany WebApp servlet host and get the host instance
+                // Load the Tuscany WebApp Servlet host and get the host instance
                 // for the current webapp
                 String className = "org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost"; 
                 if (runtimeClassLoader != null) {
@@ -68,10 +70,10 @@
                 }
                 servletHost = servletHostClass.getMethod("servletHost").invoke(null);
         
-                // Initialize the servlet host
+                // Initialize the Servlet host
                 servletHostClass.getMethod("init", FilterConfig.class).invoke(servletHost, filterConfig);
     
-                // The servlet host also implements the filter interface 
+                // The Servlet host also implements the filter interface 
                 filter = (Filter)servletHost;
                 
             } finally {
@@ -109,7 +111,7 @@
     public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
         throws IOException, ServletException {
 
-        // Delegate to the servlet host filter
+        // Delegate to the Servlet host filter
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         try {
             if (runtimeClassLoader != null) {

Modified: incubator/tuscany/branches/sca-java-1.2/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainManagerLauncherBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainManagerLauncherBootstrap.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainManagerLauncherBootstrap.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainManagerLauncherBootstrap.java Thu Apr  3 00:36:14 2008
@@ -34,6 +34,7 @@
      * A node wrappering an instance of a domain manager.
      */
     public static class NodeFacade implements SCANode2 {
+        private ClassLoader threadContextClassLoader;
         private ClassLoader runtimeClassLoader;
         private SCADomain domainManager;
         
@@ -42,22 +43,25 @@
         }
         
         public void start() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+            boolean started = false;
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 domainManager = SCADomain.newInstance("DomainManager.composite");
+                started = true;
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                if (!started) {
+                    Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+                }
             }
         }
         
         public void stop() {
-            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
             try {
                 Thread.currentThread().setContextClassLoader(runtimeClassLoader);
                 domainManager.close();
             } finally {
-                Thread.currentThread().setContextClassLoader(tccl);
+                Thread.currentThread().setContextClassLoader(threadContextClassLoader);
             }
         }
     }

Modified: incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/build.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/build.xml?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/build.xml (original)
+++ incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/build.xml Thu Apr  3 00:36:14 2008
@@ -30,7 +30,9 @@
                source="1.5"
                target="1.5">
             <classpath>
-            	<pathelement location="../../lib/tuscany-sca-manifest.jar"/>
+            	<pathelement location="../../modules/tuscany-sca-api-1.2-incubating-SNAPSHOT.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-api-1.2-incubating-SNAPSHOT.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-launcher-1.2-incubating-SNAPSHOT.jar"/>
             </classpath>
         </javac> 
         <copy todir="target/classes">
@@ -50,7 +52,7 @@
             	<pathelement path="src/main/resources"/>
                 <pathelement path="target/classes"/>
             	<pathelement path="target/${test.jar}"/>
-            	<pathelement location="../../lib/tuscany-sca-manifest.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-launcher-1.2-incubating-SNAPSHOT.jar"/>
             </classpath>    	        	
         </java>
     </target>
@@ -62,7 +64,9 @@
             	<pathelement path="src/main/resources"/>
                 <pathelement path="target/classes"/>
             	<pathelement path="target/${test.jar}"/>
-            	<pathelement location="../../lib/tuscany-sca-manifest.jar"/>
+            	<pathelement location="../../modules/tuscany-sca-api-1.2-incubating-SNAPSHOT.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-api-1.2-incubating-SNAPSHOT.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-launcher-1.2-incubating-SNAPSHOT.jar"/>
             </classpath>     	        	
         </java>
     </target>
@@ -74,7 +78,7 @@
             	<pathelement path="src/main/resources"/>
                 <pathelement path="target/classes"/>
             	<pathelement path="target/${test.jar}"/>
-            	<pathelement location="../../lib/tuscany-sca-manifest.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-launcher-1.2-incubating-SNAPSHOT.jar"/>
             </classpath>      	
         </java>
     </target>	
@@ -86,7 +90,7 @@
             	<pathelement path="src/main/resources"/>
                 <pathelement path="target/classes"/>
             	<pathelement path="target/${test.jar}"/>
-            	<pathelement location="../../lib/tuscany-sca-manifest.jar"/>
+            	<pathelement location="../../modules/tuscany-node2-launcher-1.2-incubating-SNAPSHOT.jar"/>
             </classpath>      	
         </java>
     </target>	

Modified: incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java?rev=644202&r1=644201&r2=644202&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java Thu Apr  3 00:36:14 2008
@@ -21,7 +21,7 @@
 
 import org.apache.tuscany.sca.node.SCAClient;
 import org.apache.tuscany.sca.node.SCANode2;
-import org.apache.tuscany.sca.node.SCANode2Factory;
+import org.apache.tuscany.sca.node.launcher.NodeLauncher;
 import org.osoa.sca.ServiceRuntimeException;
 
 import calculator.CalculatorService;
@@ -32,8 +32,8 @@
         SCANode2 node = null;
         try {
             
-            SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
-            node = nodeFactory.createSCANode("http://localhost:9990/node-image/NodeA");
+            NodeLauncher nodeLauncher = NodeLauncher.newInstance();
+            node = nodeLauncher.createNode("http://localhost:9990/node-image/NodeA");
 
             node.start();
             



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org