Author: doogie
Date: Wed Jun 29 23:10:01 2011 New Revision: 1141318 URL: http://svn.apache.org/viewvc?rev=1141318&view=rev Log: FEATURE: Load each configured catalina web context in parallel. Modified: ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java Modified: ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java?rev=1141318&r1=1141317&r2=1141318&view=diff ============================================================================== --- ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java (original) +++ ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java Wed Jun 29 23:10:01 2011 @@ -25,6 +25,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -60,6 +63,7 @@ import org.apache.catalina.valves.Reques import org.apache.coyote.ProtocolHandler; import org.apache.coyote.http11.Http11Protocol; import org.ofbiz.base.component.ComponentConfig; +import org.ofbiz.base.concurrent.ExecutionPool; import org.ofbiz.base.container.ClassLoaderContainer; import org.ofbiz.base.container.Container; import org.ofbiz.base.container.ContainerConfig; @@ -136,6 +140,7 @@ public class CatalinaContainer implement public static final String J2EE_APP = "OFBiz"; public static final String module = CatalinaContainer.class.getName(); protected static Map<String, String> mimeTypes = new HashMap<String, String>(); + private static final ThreadGroup CATALINA_THREAD_GROUP = new ThreadGroup("CatalinaContainer"); // load the JSSE propertes (set the trust store) static { @@ -361,13 +366,15 @@ public class CatalinaContainer implement } protected Host createHost(Engine engine, String hostName) throws ContainerException { + Debug.logInfo("createHost(" + engine + ", " + hostName + ")", module); if (embedded == null) { throw new ContainerException("Cannot create Host without Embedded instance!"); } Host host = embedded.createHost(hostName, CATALINA_HOSTS_HOME); - host.setDeployOnStartup(true); - host.setAutoDeploy(true); + host.setDeployOnStartup(false); + host.setBackgroundProcessorDelay(5); + host.setAutoDeploy(false); host.setRealm(engine.getRealm()); engine.addChild(host); hosts.put(engine.getName() + hostName, host); @@ -499,14 +506,15 @@ public class CatalinaContainer implement return connector; } - protected Context createContext(ComponentConfig.WebappInfo appInfo) throws ContainerException { - Engine engine = engines.get(appInfo.server); + protected Callable<Context> createContext(final ComponentConfig.WebappInfo appInfo) throws ContainerException { + Debug.logInfo("createContext(" + appInfo + ")", module); + final Engine engine = engines.get(appInfo.server); if (engine == null) { Debug.logWarning("Server with name [" + appInfo.server + "] not found; not mounting [" + appInfo.name + "]", module); return null; } List<String> virtualHosts = appInfo.getVirtualHosts(); - Host host; + final Host host; if (UtilValidate.isEmpty(virtualHosts)) { host = hosts.get(engine.getName() + "._DEFAULT"); } else { @@ -515,8 +523,9 @@ public class CatalinaContainer implement String hostName = vhi.next(); boolean newHost = false; - host = hosts.get(engine.getName() + "." + hostName); - if (host == null) { + if (hosts.containsKey(engine.getName() + "." + hostName)) { + host = hosts.get(engine.getName() + "." + hostName); + } else { host = createHost(engine, hostName); newHost = true; } @@ -529,10 +538,17 @@ public class CatalinaContainer implement } } - return configureContext(engine, host, appInfo); + return new Callable<Context>() { + public Context call() throws ContainerException, LifecycleException { + StandardContext context = configureContext(engine, host, appInfo); + context.setParent(host); + context.start(); + return context; + } + }; } - private Context configureContext(Engine engine, Host host, ComponentConfig.WebappInfo appInfo) throws ContainerException { + private StandardContext configureContext(Engine engine, Host host, ComponentConfig.WebappInfo appInfo) throws ContainerException { // webapp settings Map<String, String> initParameters = appInfo.getInitParameters(); @@ -566,6 +582,9 @@ public class CatalinaContainer implement // create the web application context StandardContext context = (StandardContext) embedded.createContext(mount, location); + Debug.logInfo("host[" + host + "].addChild(" + context + ")", module); + //context.setDeployOnStartup(false); + //context.setBackgroundProcessorDelay(5); context.setJ2EEApplication(J2EE_APP); context.setJ2EEServer(J2EE_SERVER); context.setLoader(embedded.createLoader(ClassLoaderContainer.getClassLoader())); @@ -631,7 +650,14 @@ public class CatalinaContainer implement // load the applications List<ComponentConfig.WebappInfo> webResourceInfos = ComponentConfig.getAllWebappResourceInfos(); List<String> loadedMounts = FastList.newInstance(); - if (webResourceInfos != null) { + if (webResourceInfos == null) { + return; + } + + ScheduledExecutorService executor = ExecutionPool.getExecutor(CATALINA_THREAD_GROUP, "catalina-startup", -1, true); + try { + List<Future<Context>> futures = FastList.newInstance(); + for (int i = webResourceInfos.size(); i > 0; i--) { ComponentConfig.WebappInfo appInfo = webResourceInfos.get(i - 1); String engineName = appInfo.server; @@ -650,7 +676,7 @@ public class CatalinaContainer implement // means there are no existing loaded entries that overlap // with the new set if (appInfo.location != null) { - createContext(appInfo); + futures.add(executor.submit(createContext(appInfo))); } loadedMounts.addAll(keys); } else { @@ -658,6 +684,9 @@ public class CatalinaContainer implement Debug.logInfo("Duplicate webapp mount; not loading : " + appInfo.getName() + " / " + appInfo.getLocation(), module); } } + ExecutionPool.getAllFutures(futures); + } finally { + executor.shutdown(); } } |
Free forum by Nabble | Edit this page |