You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by go...@apache.org on 2012/01/27 15:38:43 UTC

svn commit: r1236696 - in /directory/shared/branches/shared-osgi/ldap/schema/data: pom.xml src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java

Author: gokturk
Date: Fri Jan 27 14:38:42 2012
New Revision: 1236696

URL: http://svn.apache.org/viewvc?rev=1236696&view=rev
Log:
Loading every schema element as IPojo in OSGI is slowing down the SchemaManager creation process. 

Changed the semantic to try to:
classload them everytime, if it fails and it is in OSGI then use IPojo to load it.

Modified:
    directory/shared/branches/shared-osgi/ldap/schema/data/pom.xml
    directory/shared/branches/shared-osgi/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java

Modified: directory/shared/branches/shared-osgi/ldap/schema/data/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ldap/schema/data/pom.xml?rev=1236696&r1=1236695&r2=1236696&view=diff
==============================================================================
--- directory/shared/branches/shared-osgi/ldap/schema/data/pom.xml (original)
+++ directory/shared/branches/shared-osgi/ldap/schema/data/pom.xml Fri Jan 27 14:38:42 2012
@@ -150,6 +150,11 @@
           <manifestLocation>META-INF</manifestLocation>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.ldap.schema</Bundle-SymbolicName>
+            <Import-Package>
+                org.apache.directory.shared.ldap.model.schema.comparators;resolution:=optional,
+                org.apache.directory.shared.ldap.model.schema.syntaxCheckers;resolution:=optional,
+                *
+            </Import-Package>
             <Export-Package>
                 {local-packages};version=${project.version};-noimport:=true,
                 org.apache.directory.shared.ldap.schemaextractor.impl;version="${project.version}";-noimport:=true,

Modified: directory/shared/branches/shared-osgi/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java?rev=1236696&r1=1236695&r2=1236696&view=diff
==============================================================================
--- directory/shared/branches/shared-osgi/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java (original)
+++ directory/shared/branches/shared-osgi/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java Fri Jan 27 14:38:42 2012
@@ -20,6 +20,7 @@
 package org.apache.directory.shared.ldap.schemaloader;
 
 
+import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -53,12 +54,14 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.SchemaObject;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.model.schema.UsageEnum;
+import org.apache.directory.shared.ldap.model.schema.comparators.BooleanComparator;
 import org.apache.directory.shared.ldap.model.schema.parsers.LdapComparatorDescription;
 import org.apache.directory.shared.ldap.model.schema.parsers.NormalizerDescription;
 import org.apache.directory.shared.ldap.model.schema.parsers.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.model.schema.registries.DefaultSchema;
 import org.apache.directory.shared.ldap.model.schema.registries.Registries;
 import org.apache.directory.shared.ldap.model.schema.registries.Schema;
+import org.apache.directory.shared.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker;
 import org.apache.directory.shared.util.Base64;
 import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
@@ -271,14 +274,10 @@ public class SchemaEntityFactory impleme
         SyntaxChecker syntaxChecker = null;
         String byteCodeStr = StringConstants.EMPTY;
 
-        // Check if we're in OSGI context and byteCode is null 
-        if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
-        {
-            // That is the only case we have to OSGI load the class,
-            // The other cases are the monolithic load cases.
-            syntaxChecker = schemaElements.getSyntaxChecker( className );
-        }
-        else
+        // In OSGI and in normal JRE execution, we first try to load the element through 'Class.forName()'
+        // This is for speed. There are so much schema elements and letting IPojo manage every one of them 
+        // is not viable for server start-up time.
+        try
         {
             if ( byteCode == null )
             {
@@ -294,6 +293,26 @@ public class SchemaEntityFactory impleme
             // Create the syntaxChecker instance
             syntaxChecker = ( SyntaxChecker ) clazz.newInstance();
         }
+        catch ( ClassNotFoundException e )
+        {
+            // Check if we're in OSGI context and byteCode is null 
+            if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
+            {
+                // That is the only case we have to OSGI load the class,
+                // The other cases are the monolithic load cases.
+                syntaxChecker = schemaElements.getSyntaxChecker( className );
+
+                if ( syntaxChecker == null )
+                {
+                    // We couldn't load the syntax checker using IPojo too.
+                    throw e;
+                }
+            }
+            else
+            {
+                throw e;
+            }
+        }
 
         // Update the common fields
         syntaxChecker.setBytecode( byteCodeStr );
@@ -413,15 +432,10 @@ public class SchemaEntityFactory impleme
         Class<?> clazz = null;
         String byteCodeStr = StringConstants.EMPTY;
 
-        // Check if we're in OSGI context and byteCode is null 
-        if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
-        {
-            // That is the only case we have to OSGI load the class,
-            // The other cases are the monolithic load cases.
-            // Comparators are also oid bound classes, so we send it too.
-            comparator = schemaElements.getLdapComparator( className, oid );
-        }
-        else
+        // In OSGI and in normal JRE execution, we first try to load the element through 'Class.forName()'
+        // This is for speed. There are so much schema elements and letting IPojo manage every one of them 
+        // is not viable for server start-up time.
+        try
         {
             if ( byteCode == null )
             {
@@ -458,6 +472,27 @@ public class SchemaEntityFactory impleme
                 }
             }
         }
+        catch ( ClassNotFoundException e )
+        {
+            // Check if we're in OSGI context and byteCode is null 
+            if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
+            {
+                // That is the only case we have to OSGI load the class,
+                // The other cases are the monolithic load cases.
+                // Comparators are also oid bound classes, so we send it too.
+                comparator = schemaElements.getLdapComparator( className, oid );
+
+                if ( comparator == null )
+                {
+                    // We couldn't load the comparator using IPojo too.
+                    throw e;
+                }
+            }
+            else
+            {
+                throw e;
+            }
+        }
 
         // Update the loadable fields
         comparator.setBytecode( byteCodeStr );
@@ -575,14 +610,10 @@ public class SchemaEntityFactory impleme
         Normalizer normalizer = null;
         String byteCodeStr = StringConstants.EMPTY;
 
-        // Check if we're in OSGI context and byteCode is null 
-        if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
-        {
-            // That is the only case we have to OSGI load the class,
-            // The other cases are the monolithic load cases.
-            normalizer = schemaElements.getNormalizer( className );
-        }
-        else
+        // In OSGI and in normal JRE execution, we first try to load the element through 'Class.forName()'
+        // This is for speed. There are so much schema elements and letting IPojo manage every one of them 
+        // is not viable for server start-up time.
+        try
         {
             if ( byteCode == null )
             {
@@ -598,6 +629,26 @@ public class SchemaEntityFactory impleme
             // Create the normalizer instance
             normalizer = ( Normalizer ) clazz.newInstance();
         }
+        catch ( ClassNotFoundException e )
+        {
+            // Check if we're in OSGI context and byteCode is null 
+            if ( OSGIHelper.isAPIInOSGIContainer() && byteCode == null )
+            {
+                // That is the only case we have to OSGI load the class,
+                // The other cases are the monolithic load cases.
+                normalizer = schemaElements.getNormalizer( className );
+
+                if ( normalizer == null )
+                {
+                    // We couldn't load the normalizer using IPojo too.
+                    throw e;
+                }
+            }
+            else
+            {
+                throw e;
+            }
+        }
 
         // Update the common fields
         normalizer.setBytecode( byteCodeStr );