tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1239405 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config: AnnotationDeployer.java OutputGeneratedDescriptors.java
Date Wed, 01 Feb 2012 23:36:34 GMT
Author: rmannibucau
Date: Wed Feb  1 23:36:33 2012
New Revision: 1239405

URL: http://svn.apache.org/viewvc?rev=1239405&view=rev
Log:
trying to dump descriptors then use them instead of scanning - to enhance a lot

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/OutputGeneratedDescriptors.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1239405&r1=1239404&r2=1239405&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Wed Feb  1 23:36:33 2012
@@ -62,6 +62,7 @@ import org.apache.openejb.jee.Intercepto
 import org.apache.openejb.jee.InterceptorBinding;
 import org.apache.openejb.jee.Invokable;
 import org.apache.openejb.jee.IsolationLevel;
+import org.apache.openejb.jee.JaxbJavaee;
 import org.apache.openejb.jee.JndiConsumer;
 import org.apache.openejb.jee.JndiReference;
 import org.apache.openejb.jee.License;
@@ -111,6 +112,7 @@ import org.apache.openejb.jee.Transactio
 import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.jee.WebserviceDescription;
 import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.AnnotationUtil;
 import org.apache.openejb.util.Join;
@@ -202,6 +204,7 @@ import java.beans.BeanInfo;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -237,6 +240,25 @@ public class AnnotationDeployer implemen
     public static final Logger startupLogger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG,
"org.apache.openejb.util.resources");
     private static final ThreadLocal<DeploymentModule> currentModule = new ThreadLocal<DeploymentModule>();
     private static final Set<String> lookupMissing = new HashSet<String>(2);
+    public static final String OPENEJB_USE_DESCRIPTOR_GENERATED = "openejb.use.descriptor.generated";
+    public static final String OPENEJB_DUMPED_DD_PATH = "openejb.dumped.dd.path";
+    private static final String DUMPED_DD_BASE;
+
+    static {
+        String dumpedBase = System.getProperty(OPENEJB_DUMPED_DD_PATH, "temp");
+        File file = new File(SystemInstance.get().getBase().getDirectory(), dumpedBase);
+        if (!file.exists()) {
+            file = new File(dumpedBase);
+            if (!file.exists()) { // ignore this
+                System.setProperty(OPENEJB_USE_DESCRIPTOR_GENERATED, "false");
+            } else {
+                dumpedBase = file.getAbsolutePath();
+            }
+        } else {
+            dumpedBase = file.getAbsolutePath();
+        }
+        DUMPED_DD_BASE = dumpedBase;
+    }
 
     public static final Set<String> knownResourceEnvTypes = new TreeSet<String>(asList(
             "javax.ejb.EJBContext",
@@ -306,6 +328,7 @@ public class AnnotationDeployer implemen
 
     public WebModule deploy(WebModule webModule) throws OpenEJBException {
         setModule(webModule);
+
         try {
             webModule = discoverAnnotatedBeans.deploy(webModule);
             webModule = envEntriesPropertiesDeployer.deploy(webModule);
@@ -963,7 +986,26 @@ public class AnnotationDeployer implemen
 
         public WebModule deploy(WebModule webModule) throws OpenEJBException {
             WebApp webApp = webModule.getWebApp();
-            if (webApp != null && (webApp.isMetadataComplete())) return webModule;
+            if (webApp != null && (webApp.isMetadataComplete())) {
+                return webModule;
+            }
+
+            if (readDumpedDD()) {
+                final File dumpedWeb = getDumpWeb(webModule.getModuleId());
+                if (!dumpedWeb.exists()) {
+                    FileOutputStream fos = null;
+                    try {
+                        webModule.setWebApp(ReadDescriptors.readWebApp(dumpedWeb.toURI().toURL()));
+                        webModule.getWebApp().setMetadataComplete(true);
+                        logger.info("read web.xml for module " + webModule.getModuleId()
+ " at " + dumpedWeb.getAbsolutePath());
+                        return webModule;
+                    } catch (Exception ignored) {
+                        logger.warning("can't read web.xml");
+                    } finally {
+                        IO.close(fos);
+                    }
+                }
+            }
 
             try {
                 if (webModule.getFinder() == null) {
@@ -1038,7 +1080,22 @@ public class AnnotationDeployer implemen
         }
 
         public EjbModule deploy(EjbModule ejbModule) throws OpenEJBException {
-            if (ejbModule.getEjbJar() != null && ejbModule.getEjbJar().isMetadataComplete())
return ejbModule;
+            if (ejbModule.getEjbJar() != null && ejbModule.getEjbJar().isMetadataComplete())
{
+                return ejbModule;
+            }
+            if (readDumpedDD()) {
+                final File dumpedEjbJar = getDumpEjbJar(ejbModule.getModuleId());
+                if (dumpedEjbJar.exists()) {
+                    try {
+                        ejbModule.setEjbJar(ReadDescriptors.readEjbJar(dumpedEjbJar.toURI().toURL()));
+                        ejbModule.getEjbJar().setMetadataComplete(true);
+                        logger.info("using ejb-jar " + dumpedEjbJar.getAbsolutePath() + "
for module " + ejbModule.getModuleId());
+                        return ejbModule;
+                    } catch (MalformedURLException ignored) {
+                        logger.warning("can't read dumped ejb-jar");
+                    }
+                }
+            }
 
 
             try {
@@ -1870,6 +1927,22 @@ public class AnnotationDeployer implemen
 
             processWebServiceClientHandlers(webApp, classLoader);
 
+            if (readDumpedDD()) {
+                final File dumpedWeb = getDumpWeb(webModule.getModuleId());
+                if (!dumpedWeb.exists()) {
+                    FileOutputStream fos = null;
+                    try {
+                        fos = new FileOutputStream(dumpedWeb);
+                        JaxbJavaee.marshal(WebApp.class, webModule.getWebApp(), fos);
+                        logger.info("dumped web.xml for module " + webModule.getModuleId()
+ " at " + dumpedWeb.getAbsolutePath());
+                    } catch (Exception e) {
+                        logger.warning("can't dump web.xml", e);
+                    } finally {
+                        IO.close(fos);
+                    }
+                }
+            }
+
             return webModule;
         }
 
@@ -2375,6 +2448,22 @@ public class AnnotationDeployer implemen
                 }
             }
 
+            if (readDumpedDD()) {
+                final File dumpedEjbJar = getDumpEjbJar(ejbModule.getModuleId());
+                if (!dumpedEjbJar.exists()) {
+                    FileOutputStream fos = null;
+                    try {
+                        fos = new FileOutputStream(dumpedEjbJar);
+                        JaxbJavaee.marshal(EjbJar.class, ejbModule.getEjbJar(), fos);
+                        logger.info("dumped ejb-jar for module " + ejbModule.getModuleId()
+ " at " + dumpedEjbJar.getAbsolutePath());
+                    } catch (Exception e) {
+                        logger.warning("can't dump ejb-jar", e);
+                    } finally {
+                        IO.close(fos);
+                    }
+                }
+            }
+
             return ejbModule;
         }
 
@@ -4889,4 +4978,16 @@ public class AnnotationDeployer implemen
         }
         return rawClassName;
     }
+
+    private static boolean readDumpedDD() {
+        return Boolean.getBoolean(OPENEJB_USE_DESCRIPTOR_GENERATED);
+    }
+
+    private static File getDumpEjbJar(final String moduleId) {
+        return new File(DUMPED_DD_BASE, "ejb-jar-" + Math.abs(moduleId.hashCode()) + ".xml");
+    }
+
+    private static File getDumpWeb(final String moduleId) {
+        return new File(DUMPED_DD_BASE, "web-" + Math.abs(moduleId.hashCode()) + ".xml");
+    }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/OutputGeneratedDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/OutputGeneratedDescriptors.java?rev=1239405&r1=1239404&r2=1239405&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/OutputGeneratedDescriptors.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/OutputGeneratedDescriptors.java
Wed Feb  1 23:36:33 2012
@@ -173,18 +173,28 @@ public class OutputGeneratedDescriptors 
 
     private void writeEjbJar(EjbModule ejbModule) {
         try {
+            final File tempFile = tempFile("ejb-jar-", ejbModule.getModuleId() + ".xml");
+            writeEjbJar(tempFile, ejbModule);
+            logger.info("Dumping Generated ejb-jar.xml to: " + tempFile.getAbsolutePath());
+        } catch (IOException e) {
+            // no-op
+        }
+    }
+
+    public static void writeEjbJar(final File output, final EjbModule ejbModule) {
+        try {
             EjbJar ejbJar = ejbModule.getEjbJar();
-            File tempFile = tempFile("ejb-jar-", ejbModule.getModuleId() + ".xml");
-            FileOutputStream fout = new FileOutputStream(tempFile);
+            FileOutputStream fout = new FileOutputStream(output);
             BufferedOutputStream out = new BufferedOutputStream(fout);
             try {
                 JaxbJavaee.marshal(EjbJar.class, ejbJar, out);
-                logger.info("Dumping Generated ejb-jar.xml to: " + tempFile.getAbsolutePath());
-            } catch (JAXBException e) {
+            } catch (JAXBException ignored) {
+                // no-op
             } finally {
                 out.close();
             }
         } catch (Exception e) {
+            // no-op
         }
     }
 }



Mime
View raw message