tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1178185 - in /openejb/trunk/openejb: assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/ assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/ assembly/o...
Date Sun, 02 Oct 2011 12:59:01 GMT
Author: dblevins
Date: Sun Oct  2 12:59:00 2011
New Revision: 1178185

URL: http://svn.apache.org/viewvc?rev=1178185&view=rev
Log:
OPENEJB-1693: Embedded TomEE speed improvements
Reworked the embedded container support so that it uses the Tomcat embedded code.. and wow!
 Excellent results when combined with our already light code.

Modified:
    openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatLoader.java
    openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
    openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/EmbeddedJarScanner.java
    openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java
    openejb/trunk/openejb/assembly/openejb-tomcat/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

Modified: openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatLoader.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatLoader.java
(original)
+++ openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatLoader.java
Sun Oct  2 12:59:00 2011
@@ -114,16 +114,23 @@ public class TomcatLoader implements Loa
     public void init(Properties properties) throws Exception {
 
         // Enable System EJBs like the MEJB and DeployerEJB
+        initDefaults(properties);
+
+        // Loader maybe the first thing executed in a new classloader
+        // so we must attempt to initialize the system instance.
+        SystemInstance.init(properties);
+        initialize(properties);
+    }
+
+    public void initDefaults(Properties properties) {
         setIfNull(properties, "openejb.deployments.classpath", "true");
         setIfNull(properties, "openejb.deployments.classpath.filter.systemapps", "false");
 
         //Sets default service provider
         setIfNull(properties, "openejb.provider.default", "org.apache.openejb." + platform);
+    }
 
-        // Loader maybe the first thing executed in a new classloader
-        // so we must attempt to initialize the system instance.
-        SystemInstance.init(properties);
-
+    public void initialize(Properties properties) throws Exception {
         //Install Log
         OptionsLog.install();
 

Modified: openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
(original)
+++ openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
Sun Oct  2 12:59:00 2011
@@ -18,6 +18,7 @@ package org.apache.openejb.tomcat.catali
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Service;
@@ -128,6 +129,7 @@ public class TomcatWebAppBuilder impleme
      */
     //Key is the host name
     private final Map<String, HostConfig> deployers = new TreeMap<String, HostConfig>();
+    private final Map<String, Host> hosts = new TreeMap<String, Host>();
     /**
      * Deployed web applications
      */
@@ -168,6 +170,7 @@ public class TomcatWebAppBuilder impleme
                 for (Container engineChild : engine.findChildren()) {
                     if (engineChild instanceof StandardHost) {
                         StandardHost host = (StandardHost) engineChild;
+                        hosts.put(host.getName(), host);
                         for (LifecycleListener listener : host.findLifecycleListeners())
{
                             if (listener instanceof HostConfig) {
                                 HostConfig hostConfig = (HostConfig) listener;
@@ -226,13 +229,21 @@ public class TomcatWebAppBuilder impleme
                 }
                 
                 // TODO: instead of storing deployers, we could just lookup the right hostconfig
for the server.
-                HostConfig deployer = deployers.get(host);
+                final HostConfig deployer = deployers.get(host);
                 if (deployer != null) {
                     // host isn't set until we call deployer.manageApp, so pass it
                     ContextInfo contextInfo = addContextInfo(host, standardContext);
                     contextInfo.appInfo = appInfo;
                     contextInfo.deployer = deployer;
                     deployer.manageApp(standardContext);
+                } else if (hosts.containsKey(host)){
+                    Host theHost = hosts.get(host);
+
+                    ContextInfo contextInfo = addContextInfo(host, standardContext);
+                    contextInfo.appInfo = appInfo;
+                    contextInfo.host = theHost;
+
+                    theHost.addChild(standardContext);
                 }
             }
         }
@@ -285,10 +296,16 @@ public class TomcatWebAppBuilder impleme
     public void undeployWebApps(AppInfo appInfo) throws Exception {
         for (WebAppInfo webApp : appInfo.webApps) {
             ContextInfo contextInfo = getContextInfo(webApp);
+
             if (contextInfo != null && contextInfo.deployer != null) {
                 StandardContext standardContext = contextInfo.standardContext;
                 HostConfig deployer = contextInfo.deployer;
-                deployer.unmanageApp(standardContext.getPath());
+
+                if (deployer != null) {
+                    deployer.unmanageApp(standardContext.getPath());
+                } else if (contextInfo.host != null) {
+                    contextInfo.host.removeChild(standardContext);
+                }
                 deleteDir(new File(standardContext.getServletContext().getRealPath("")));
                 removeContextInfo(standardContext);
             }
@@ -1073,6 +1090,7 @@ public class TomcatWebAppBuilder impleme
         public AppInfo appInfo;
         public StandardContext standardContext;
         public HostConfig deployer;
+        public Host host;
         public LinkResolver<EntityManagerFactory> emfLinkResolver;
     }
 

Modified: openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/EmbeddedJarScanner.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/EmbeddedJarScanner.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/EmbeddedJarScanner.java
(original)
+++ openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/EmbeddedJarScanner.java
Sun Oct  2 12:59:00 2011
@@ -69,8 +69,15 @@ public class EmbeddedJarScanner implemen
             final UrlSet classpath = new UrlSet(classloader);
 
             UrlSet excluded = classpath.exclude(".*/WEB-INF/lib/.*");
-            excluded = excluded.exclude(".*myfaces-impl-.*");
-            excluded = excluded.exclude(".*openejb-jsf-.*");
+
+            // TODO Commenting out these two lines can have an impact on JSF
+            // There's something that gets pulled from the classpath here
+            // lets figure out what it is so we can optimize it as the effect
+            // of adding myfaces here is that the entire jar is scanned, which
+            // is really slow.
+
+//            excluded = excluded.exclude(".*myfaces-impl-.*");
+//            excluded = excluded.exclude(".*openejb-jsf-.*");
 
             final UrlSet scan = classpath.exclude(excluded);
 

Modified: openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java
(original)
+++ openejb/trunk/openejb/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java
Sun Oct  2 12:59:00 2011
@@ -29,6 +29,7 @@ import org.apache.catalina.Realm;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.core.StandardServer;
+import org.apache.openejb.loader.SystemInstance;
 
 public class TomcatHelper {
 
@@ -44,8 +45,11 @@ public class TomcatHelper {
 
 	public static StandardServer getServer() {
 		StandardServer server = null;
-		
-		// first try to use Tomcat's ServerFactory class to give us a reference to the server
+
+        server = SystemInstance.get().getComponent(StandardServer.class);
+        if (server != null) return server;
+
+        // first try to use Tomcat's ServerFactory class to give us a reference to the server
 		
 		try {
 			Class<?> tomcatServerFactory = Class.forName("org.apache.catalina.ServerFactory");

Modified: openejb/trunk/openejb/assembly/openejb-tomcat/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/openejb-tomcat/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/openejb-tomcat/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
(original)
+++ openejb/trunk/openejb/assembly/openejb-tomcat/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
Sun Oct  2 12:59:00 2011
@@ -16,7 +16,16 @@
  */
 package org.apache.tomee.embedded;
 
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.session.StandardManager;
 import org.apache.catalina.startup.Bootstrap;
+import org.apache.catalina.startup.CatalinaProperties;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.coyote.http11.Http11Protocol;
 import org.apache.openejb.NoSuchApplicationException;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.UndeployException;
@@ -47,12 +56,17 @@ import java.util.Properties;
  */
 public class Container {
 
+    static {
+        // org.apache.naming
+        Assembler.installNaming("org.apache.naming");
+    }
     private Bootstrap bootstrap;
     protected Configuration configuration;
-    private File catalinaDirectory;
+    private File base;
     private Map<String, String> moduleIds = new HashMap<String, String>();
     private ConfigurationFactory configurationFactory;
     private Assembler assembler;
+    private final Tomcat tomcat;
 
     public Container() {
         final Configuration configuration = new Configuration();
@@ -60,6 +74,7 @@ public class Container {
         configuration.setStopPort(23881);
         setup(configuration);
         final Class<Bootstrap> bootstrapClass = Bootstrap.class;
+        tomcat = new TomcatWithFastSessionIDs();
     }
 
     public void setup(Configuration configuration) {
@@ -69,21 +84,51 @@ public class Container {
     public void start() throws Exception {
         final String dir = getBaseDir();
 
-        catalinaDirectory = new File(dir);
-        if (catalinaDirectory.exists()) {
-            catalinaDirectory.delete();
+        base = new File(dir);
+        if (base.exists()) {
+            base.delete();
         }
 
-        catalinaDirectory.mkdirs();
-        catalinaDirectory.deleteOnExit();
-
-        createTomcatDirectories(catalinaDirectory);
-        copyConfigs(catalinaDirectory);
+        base.mkdirs();
+        // TODO: this delete on exit won't actually work
+        base.deleteOnExit();
+
+        final File conf = createDirectory(base, "conf");
+        final File lib = createDirectory(base, "lib");
+        final File logs = createDirectory(base, "logs");
+        final File webapps = createDirectory(base, "webapps");
+        final File temp = createDirectory(base, "temp");
+        final File work = createDirectory(base, "work");
+
+        copyFileTo(conf, "catalina.policy");
+        copyTemplateTo(conf, "catalina.properties");
+        copyFileTo(conf, "context.xml");
+        copyFileTo(conf, "logging.properties");
+        copyFileTo(conf, "openejb.xml");
+        copyFileTo(conf, "server.xml");
+        copyFileTo(conf, "tomcat-users.xml");
+        copyFileTo(conf, "web.xml");
+
+        // Need to use JULI so log messages from the tests are visible
+        System.setProperty("java.util.logging.manager", "org.apache.juli.ClassLoaderLogManager");
+        System.setProperty("java.util.logging.config.file", new File(conf, "logging.properties").toString());
+        System.setProperty("catalina.base", base.getAbsolutePath());
+
+        // Trigger loading of catalina.properties
+        CatalinaProperties.getProperty("foo");
+
+        Connector connector = new Connector(Http11Protocol.class.getName());
+        connector.setPort(configuration.getHttpPort());
+        connector.setAttribute("connectionTimeout", "3000");
+        tomcat.getService().addConnector(connector);
+        tomcat.setConnector(connector);
+        tomcat.setBaseDir(base.getAbsolutePath());
+        tomcat.getHost().setAppBase(webapps.getAbsolutePath());
 
         // Bootstrap Tomcat
-        System.out.println("Starting TomEE from: " + catalinaDirectory.getAbsolutePath());
+        System.out.println("Starting TomEE from: " + base.getAbsolutePath());
 
-        String catalinaBase = catalinaDirectory.getAbsolutePath();
+        String catalinaBase = base.getAbsolutePath();
         System.setProperty("openejb.logging.embedded", "true");
         System.setProperty("openejb.deployments.classpath", "false");
         System.setProperty("catalina.home", catalinaBase);
@@ -92,8 +137,11 @@ public class Container {
         System.setProperty("openejb.base", catalinaBase);
         System.setProperty("openejb.servicemanager.enabled", "false");
 
-        bootstrap = new Bootstrap();
-        bootstrap.start();
+        tomcat.start();
+
+
+//        bootstrap = new Bootstrap();
+//        bootstrap.start();
 
         // Bootstrap OpenEJB
         Properties properties = new Properties();
@@ -128,7 +176,13 @@ public class Container {
         } catch (Throwable e) {
         }
 
-        new TomcatLoader().init(properties);
+        SystemInstance.init(System.getProperties());
+        SystemInstance.get().setComponent(StandardServer.class, (StandardServer) tomcat.getServer());
+
+        TomcatLoader loader = new TomcatLoader();
+        loader.initDefaults(properties);
+        loader.initialize(properties);
+
 
         assembler = SystemInstance.get().getComponent(Assembler.class);
         configurationFactory = new ConfigurationFactory();
@@ -146,8 +200,8 @@ public class Container {
     }
 
     public void stop() throws Exception {
-        bootstrap.stopServer();
-        deleteTree(catalinaDirectory);
+        tomcat.stop();
+        deleteTree(base);
     }
 
     public void deploy(String name, File file) throws OpenEJBException, IOException, NamingException
{
@@ -188,18 +242,6 @@ public class Container {
         }
     }
 
-    private void copyConfigs(File directory) throws Exception {
-        File confDir = new File(directory, "conf");
-        copyFileTo(confDir, "catalina.policy");
-        copyTemplateTo(confDir, "catalina.properties");
-        copyFileTo(confDir, "context.xml");
-        copyFileTo(confDir, "logging.properties");
-        copyFileTo(confDir, "openejb.xml");
-        copyFileTo(confDir, "server.xml");
-        copyFileTo(confDir, "tomcat-users.xml");
-        copyFileTo(confDir, "web.xml");
-    }
-
     private void copyTemplateTo(File targetDir, String filename) throws Exception {
         Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new Log4JLogChute());
         Velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
@@ -245,7 +287,37 @@ public class Container {
         createDirectory(directory, "work");
     }
 
-    private void createDirectory(File parent, String directory) {
-        new File(parent, directory).mkdirs();
+    private File createDirectory(File parent, String directory) {
+        File dir = new File(parent, directory);
+        if (!dir.exists() && !dir.mkdirs()) {
+            throw new IllegalStateException("Unable to make dir " + dir.getAbsolutePath());
+        }
+
+        return dir;
+    }
+
+    private static class TomcatWithFastSessionIDs extends Tomcat {
+
+        @Override
+        public void start() throws LifecycleException {
+            // Use fast, insecure session ID generation for all tests
+            Server server = getServer();
+            for (Service service : server.findServices()) {
+                org.apache.catalina.Container e = service.getContainer();
+                for (org.apache.catalina.Container h : e.findChildren()) {
+                    for (org.apache.catalina.Container c : h.findChildren()) {
+                        StandardManager m = (StandardManager) c.getManager();
+                        if (m == null) {
+                            m = new StandardManager();
+                            m.setSecureRandomClass(
+                                    "org.apache.catalina.startup.FastNonSecureRandom");
+                            c.setManager(m);
+                        }
+                    }
+                }
+            }
+            super.start();
+        }
     }
+
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1178185&r1=1178184&r2=1178185&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
Sun Oct  2 12:59:00 2011
@@ -273,10 +273,15 @@ public class Assembler extends Assembler
         if (SystemInstance.get().hasProperty("openejb.geronimo")) return;
 
         /* Add IntraVM JNDI service /////////////////////*/
+        installNaming(OPENEJB_URL_PKG_PREFIX);
+        /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
+    }
+
+    public static void installNaming(String prefix) {
         Properties systemProperties = System.getProperties();
         synchronized (systemProperties) {
             String str = systemProperties.getProperty(Context.URL_PKG_PREFIXES);
-            String naming = OPENEJB_URL_PKG_PREFIX;
+            String naming = prefix;
             if (str == null) {
                 str = naming;
             } else if (str.indexOf(naming) == -1) {
@@ -284,7 +289,6 @@ public class Assembler extends Assembler
             }
             systemProperties.setProperty(Context.URL_PKG_PREFIXES, str);
         }
-        /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
     }
 
     private static ThreadLocal<Map<String, Object>> context = new ThreadLocal<Map<String,
Object>>();



Mime
View raw message