You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/06/20 16:58:09 UTC

svn commit: r191479 - in /directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server: configuration/ partition/ partition/store/impl/btree/

Author: trustin
Date: Mon Jun 20 07:58:08 2005
New Revision: 191479

URL: http://svn.apache.org/viewcvs?rev=191479&view=rev
Log:
* Modified ContextPartition.init() to let it self-configure.
* RootNexus now self configures using StartupConfiguration.

Modified:
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartitionNexus.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/RootNexus.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/store/impl/btree/BTreeContextPartition.java

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java?rev=191479&r1=191478&r2=191479&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java Mon Jun 20 07:58:08 2005
@@ -23,9 +23,12 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.naming.Name;
+import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
 
+import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.server.partition.ContextPartition;
 
 
@@ -39,6 +42,7 @@
 {
     private String name;
     private String suffix;
+    private Name normalizedSuffix;
     private Set indexedAttributes = new HashSet(); // Set<String>
     private Attributes contextEntry = new BasicAttributes();
     private ContextPartition contextPartition;
@@ -86,9 +90,6 @@
         return contextPartition;
     }
     
-    /**
-     * Set this to null if you want to use {@link org.apache.ldap.server.partition.ApplicationPartition}.
-     */
     protected void setContextPartition( ContextPartition partition )
     {
         this.contextPartition = partition;
@@ -109,10 +110,23 @@
         return suffix;
     }
     
+    public Name getNormalizedSuffix()
+    {
+        return normalizedSuffix;
+    }
+    
     protected void setSuffix( String suffix )
     {
         // TODO Suffix should be normalized before being set
         this.suffix = suffix.trim();
+        try
+        {
+            this.normalizedSuffix = new LdapName( suffix );
+        }
+        catch( NamingException e )
+        {
+            throw new ConfigurationException( "Failed to normalized the suffix: " + suffix );
+        }
     }
     
     
@@ -131,6 +145,11 @@
         if( getSuffix() == null )
         {
             throw new ConfigurationException( "Suffix is not specified." );
+        }
+        
+        if( getContextPartition() == null )
+        {
+            throw new ConfigurationException( "Context partition is not specifiec." );
         }
     }
 }

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java?rev=191479&r1=191478&r2=191479&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java Mon Jun 20 07:58:08 2005
@@ -25,8 +25,11 @@
 import javax.naming.directory.Attributes;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
+import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
 
 
 /**
@@ -51,7 +54,7 @@
     /**
      * Initializes this partition.
      */
-    void init( Name userProvidedSuffix, Name normalizedSuffix ) throws NamingException;
+    void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException;
     
     
     /**
@@ -144,8 +147,7 @@
      * retrieval.
      *
      * @param base the base distinguished/absolute name for the search/listing
-     * @return a NamingEnumeration containing objects of type
-     * {@link org.apache.ldap.server.partition.store.impl.btree.jdbm.BTreeContextPartitionSearchResult}
+     * @return a NamingEnumeration containing objects of type {@link SearchResult}
      * @throws NamingException if there are any problems
      */
     NamingEnumeration list( Name base ) throws NamingException;

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartitionNexus.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartitionNexus.java?rev=191479&r1=191478&r2=191479&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartitionNexus.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartitionNexus.java Mon Jun 20 07:58:08 2005
@@ -93,32 +93,4 @@
      * @throws NamingException if there are any problems
      */
     Iterator listSuffixes( boolean normalized ) throws NamingException;
-
-    /**
-     * Registers an ContextPartition with this BackendManager.  Called by each
-     * ContextPartition implementation after it has started to register for
-     * backend operation calls.  This method effectively puts the 
-     * ContextPartition's naming context online.
-     *
-     * Operations against the naming context should result in an LDAP BUSY
-     * result code in the returnValue if the naming context is not online.
-     *
-     * @param partition ContextPartition component to register with this
-     * BackendNexus.
-     */
-    void register( ContextPartition partition );
-
-    /**
-     * Unregisters an ContextPartition with this BackendManager.  Called for each
-     * registered Backend right befor it is to be stopped.  This prevents
-     * protocol server requests from reaching the Backend and effectively puts
-     * the ContextPartition's naming context offline.
-     *
-     * Operations against the naming context should result in an LDAP BUSY
-     * result code in the returnValue if the naming context is not online.
-     *
-     * @param partition ContextPartition component to unregister with this
-     * BackendNexus.
-     */
-    void unregister( ContextPartition partition );
 }

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/RootNexus.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/RootNexus.java?rev=191479&r1=191478&r2=191479&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/RootNexus.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/RootNexus.java Mon Jun 20 07:58:08 2005
@@ -17,9 +17,11 @@
 package org.apache.ldap.server.partition;
 
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.naming.Name;
@@ -41,7 +43,10 @@
 import org.apache.ldap.common.message.LockableAttributeImpl;
 import org.apache.ldap.common.message.LockableAttributes;
 import org.apache.ldap.common.message.LockableAttributesImpl;
+import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.common.util.SingletonEnumeration;
+import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
+import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
 import org.apache.ldap.server.jndi.SystemPartition;
 
                                 
@@ -66,13 +71,13 @@
     private static final String NAMINGCTXS_ATTR = "namingContexts";
 
     /** the closed state of this partition */
-    private boolean open = true;
+    private boolean initialized;
 
     /** the system backend */
     private SystemPartition system;
 
     /** the backends keyed by normalized suffix strings */
-    private HashMap backends = new HashMap();
+    private HashMap partitions = new HashMap();
 
     /** the read only rootDSE attributes */
     private final Attributes rootDSE;
@@ -117,6 +122,155 @@
     }
 
 
+    public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException
+    {
+        // NOTE: We ignore ContextPartitionConfiguration parameter here.
+        
+        if( initialized )
+        {
+            return;
+        }
+        
+        Iterator i = factoryCfg.getConfiguration().getContextPartitionConfigurations().iterator();
+        List initializedPartitions = new ArrayList();
+        boolean success = false;
+        try
+        {
+            while( i.hasNext() )
+            {
+                cfg = ( ContextPartitionConfiguration ) i.next();
+                ContextPartition partition = cfg.getContextPartition();
+                partition.init( factoryCfg, cfg );
+                initializedPartitions.add( partition );
+                register( partition );
+            }
+            success = true;
+        }
+        finally
+        {
+            if( !success )
+            {
+                i = initializedPartitions.iterator();
+                while( i.hasNext() )
+                {
+                    ContextPartition partition = ( ContextPartition ) i.next();
+                    try
+                    {
+                        partition.destroy();
+                    }
+                    catch( Exception e )
+                    {
+                        e.printStackTrace();
+                    }
+                    finally
+                    {
+                        unregister( partition );
+                    }
+                }
+            }
+        }
+    }
+
+
+    public boolean isInitialized()
+    {
+        return initialized;
+    }
+
+
+    public synchronized void destroy() throws NamingException
+    {
+        if ( !initialized )
+        {
+            return;
+        }
+
+        MultiException error = null;
+
+        Iterator list = this.partitions.values().iterator();
+
+        // make sure this loop is not fail fast so all backing stores can
+        // have an attempt at closing down and synching their cached entries
+        while ( list.hasNext() )
+        {
+            ContextPartition partition = ( ContextPartition ) list.next();
+
+            try
+            {
+                partition.sync();
+                partition.destroy();
+            }
+            catch ( NamingException e )
+            {
+                e.printStackTrace();
+
+                if ( error == null )
+                {
+                    error = new MultiException( "Grouping many exceptions on root nexus close()" );
+                }
+
+                // @todo really need to send this info to a monitor
+                error.addThrowable( e );
+            }
+        }
+
+        initialized = false;
+
+        if ( error != null )
+        {
+            String msg = "Encountered failures while performing a close() operation on backing stores";
+
+            NamingException total = new NamingException( msg );
+
+            total.setRootCause( error );
+
+            throw total;
+        }
+    }
+
+
+    /**
+     * @see ContextPartition#sync()
+     */
+    public void sync() throws NamingException
+    {
+        MultiException error = null;
+
+        Iterator list = this.partitions.values().iterator();
+
+        while ( list.hasNext() )
+        {
+            ContextPartition store = ( ContextPartition ) list.next();
+
+            try
+            {
+                store.sync();
+            }
+            catch ( NamingException e )
+            {
+                e.printStackTrace();
+
+                if ( error == null )
+                {
+                    error = new MultiException( "Grouping many exceptions on root nexus sync()" );
+                }
+
+                // @todo really need to send this info to a monitor
+                error.addThrowable( e );
+            }
+        }
+
+        if ( error != null )
+        {
+            String msg = "Encountered failures while performing a sync() operation on backing stores";
+
+            NamingException total = new NamingException( msg );
+
+            total.setRootCause( error );
+        }
+    }
+
+
     // ------------------------------------------------------------------------
     // BackendNexus Interface Method Implementations
     // ------------------------------------------------------------------------
@@ -152,6 +306,12 @@
     }
 
 
+    public Name getSuffix( boolean normalized )
+    {
+        return new LdapName();
+    }
+
+
     /**
      * @see org.apache.ldap.server.partition.ContextPartitionNexus#getSuffix(javax.naming.Name, boolean)
      */
@@ -168,7 +328,7 @@
      */
     public Iterator listSuffixes( boolean normalized ) throws NamingException
     {
-        return Collections.unmodifiableSet( backends.keySet() ).iterator();
+        return Collections.unmodifiableSet( partitions.keySet() ).iterator();
     }
 
 
@@ -184,30 +344,42 @@
 
 
     /**
-     * @see org.apache.ldap.server.partition.ContextPartitionNexus#register(
-     * ContextPartition)
+     * Registers an ContextPartition with this BackendManager.  Called by each
+     * ContextPartition implementation after it has started to register for
+     * backend operation calls.  This method effectively puts the 
+     * ContextPartition's naming context online.
+     *
+     * Operations against the naming context should result in an LDAP BUSY
+     * result code in the returnValue if the naming context is not online.
+     *
+     * @param partition ContextPartition component to register with this
+     * BackendNexus.
      */
-    public void register( ContextPartition backend )
+    private void register( ContextPartition partition )
     {
         Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
-
-        namingContexts.add( backend.getSuffix( false ).toString() );
-
-        backends.put( backend.getSuffix( true ).toString(), backend );
+        namingContexts.add( partition.getSuffix( false ).toString() );
+        partitions.put( partition.getSuffix( true ).toString(), partition );
     }
 
 
     /**
-     * @see ContextPartitionNexus#unregister(
-     * ContextPartition)
+     * Unregisters an ContextPartition with this BackendManager.  Called for each
+     * registered Backend right befor it is to be stopped.  This prevents
+     * protocol server requests from reaching the Backend and effectively puts
+     * the ContextPartition's naming context offline.
+     *
+     * Operations against the naming context should result in an LDAP BUSY
+     * result code in the returnValue if the naming context is not online.
+     *
+     * @param partition ContextPartition component to unregister with this
+     * BackendNexus.
      */
-    public void unregister( ContextPartition backend )
+    private void unregister( ContextPartition partition )
     {
         Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
-
-        namingContexts.remove( backend.getSuffix( false ).toString() );
-
-        backends.remove( backend.getSuffix( true ).toString() );
+        namingContexts.remove( partition.getSuffix( false ).toString() );
+        partitions.remove( partition.getSuffix( true ).toString() );
     }
 
 
@@ -414,7 +586,7 @@
      */
     public boolean isSuffix( Name dn ) throws NamingException
     {
-        return backends.containsKey( dn.toString() );
+        return partitions.containsKey( dn.toString() );
     }
 
     
@@ -452,106 +624,7 @@
         backend.move( oldChildDn, newParentDn, newRdn, deleteOldRdn );
     }
 
-
-    /**
-     * @see ContextPartition#sync()
-     */
-    public void sync() throws NamingException
-    {
-        MultiException error = null;
-
-        Iterator list = this.backends.values().iterator();
-
-        while ( list.hasNext() )
-        {
-            ContextPartition store = ( ContextPartition ) list.next();
-
-            try
-            {
-                store.sync();
-            }
-            catch ( NamingException e )
-            {
-                e.printStackTrace();
-
-                if ( error == null )
-                {
-                    error = new MultiException( "Grouping many exceptions on root nexus sync()" );
-                }
-
-                // @todo really need to send this info to a monitor
-                error.addThrowable( e );
-            }
-        }
-
-        if ( error != null )
-        {
-            String msg = "Encountered failures while performing a sync() operation on backing stores";
-
-            NamingException total = new NamingException( msg );
-
-            total.setRootCause( error );
-        }
-    }
-
-
-    public boolean isInitialized()
-    {
-        return open;
-    }
-
-
-    public synchronized void destroy() throws NamingException
-    {
-        if ( !open )
-        {
-            return;
-        }
-
-        MultiException error = null;
-
-        Iterator list = this.backends.values().iterator();
-
-        // make sure this loop is not fail fast so all backing stores can
-        // have an attempt at closing down and synching their cached entries
-        while ( list.hasNext() )
-        {
-            ContextPartition store = ( ContextPartition ) list.next();
-
-            try
-            {
-                store.sync();
-                store.destroy();
-            }
-            catch ( NamingException e )
-            {
-                e.printStackTrace();
-
-                if ( error == null )
-                {
-                    error = new MultiException( "Grouping many exceptions on root nexus close()" );
-                }
-
-                // @todo really need to send this info to a monitor
-                error.addThrowable( e );
-            }
-        }
-
-        open = false;
-
-        if ( error != null )
-        {
-            String msg = "Encountered failures while performing a close() operation on backing stores";
-
-            NamingException total = new NamingException( msg );
-
-            total.setRootCause( error );
-
-            throw total;
-        }
-    }
-
-
+    
     // ------------------------------------------------------------------------
     // Private Methods
     // ------------------------------------------------------------------------
@@ -570,9 +643,9 @@
 
         while ( clonedDn.size() > 0 )
         {
-            if ( backends.containsKey( clonedDn.toString() ) )
+            if ( partitions.containsKey( clonedDn.toString() ) )
             {
-                return ( ContextPartition ) backends.get( clonedDn.toString() );
+                return ( ContextPartition ) partitions.get( clonedDn.toString() );
             }
             
             clonedDn.remove( clonedDn.size() - 1 );

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/store/impl/btree/BTreeContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/store/impl/btree/BTreeContextPartition.java?rev=191479&r1=191478&r2=191479&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/store/impl/btree/BTreeContextPartition.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/store/impl/btree/BTreeContextPartition.java Mon Jun 20 07:58:08 2005
@@ -36,8 +36,12 @@
 import org.apache.ldap.common.message.LockableAttributesImpl;
 import org.apache.ldap.common.schema.AttributeType;
 import org.apache.ldap.common.util.ArrayUtils;
+import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
+import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
 import org.apache.ldap.server.partition.ContextPartition;
 import org.apache.ldap.server.partition.store.impl.btree.gui.PartitionViewer;
+import org.apache.ldap.server.schema.AttributeTypeRegistry;
+import org.apache.ldap.server.schema.OidRegistry;
 
 
 /**
@@ -114,14 +118,20 @@
     // ------------------------------------------------------------------------
 
     /**
-     * Creates a context partition with a new database and a search engine.
-     *
-     * @param searchEngine the search engine for this backing store
+     * Creates a B-tree based context partition.
      */
-    public BTreeContextPartition( SearchEngine searchEngine, AttributeType[] indexedAttrs )
-        throws NamingException
+    protected BTreeContextPartition()
     {
-        this.searchEngine = searchEngine;
+    }
+    
+
+    public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException
+    {
+        AttributeTypeRegistry attributeTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+        OidRegistry oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
+        ExpressionEvaluator evaluator = new ExpressionEvaluator( this, oidRegistry, attributeTypeRegistry );
+        ExpressionEnumerator enumerator = new ExpressionEnumerator( this, attributeTypeRegistry, evaluator );
+        this.searchEngine = new DefaultSearchEngine( this, evaluator, enumerator );
 
         HashSet sysOidSet = new HashSet();
         sysOidSet.add( EXISTANCE_OID );
@@ -132,40 +142,44 @@
         sysOidSet.add( SUBALIAS_OID );
         sysOidSet.add( ALIAS_OID );
 
-        for ( int ii = 0; ii < indexedAttrs.length; ii ++ )
+        
+        Iterator i = cfg.getIndexedAttributes().iterator();
+        while( i.hasNext() )
         {
-            String oid = indexedAttrs[ii].getOid();
-
+            String name = ( String ) i.next();
+            String oid = oidRegistry.getOid( name );
+            AttributeType type = attributeTypeRegistry.lookup( oid );
+            
             // check if attribute is a system attribute
             if ( sysOidSet.contains( oid ) )
             {
                 if ( oid.equals( EXISTANCE_OID ) )
                 {
-                    setExistanceIndexOn( indexedAttrs[ii] );
+                    setExistanceIndexOn( type );
                 }
                 else if ( oid.equals( HIERARCHY_OID ) )
                 {
-                    setHierarchyIndexOn( indexedAttrs[ii] );
+                    setHierarchyIndexOn( type );
                 }
                 else if ( oid.equals( UPDN_OID ) )
                 {
-                    setUpdnIndexOn( indexedAttrs[ii] );
+                    setUpdnIndexOn( type );
                 }
                 else if ( oid.equals( NDN_OID ) )
                 {
-                    setNdnIndexOn( indexedAttrs[ii] );
+                    setNdnIndexOn( type );
                 }
                 else if ( oid.equals( ONEALIAS_OID ) )
                 {
-                    setOneAliasIndexOn( indexedAttrs[ii] );
+                    setOneAliasIndexOn( type );
                 }
                 else if ( oid.equals( SUBALIAS_OID ) )
                 {
-                    setSubAliasIndexOn( indexedAttrs[ii] );
+                    setSubAliasIndexOn( type );
                 }
                 else if ( oid.equals( ALIAS_OID ) )
                 {
-                    setAliasIndexOn( indexedAttrs[ii] );
+                    setAliasIndexOn( type );
                 }
                 else
                 {
@@ -175,12 +189,12 @@
             }
             else
             {
-                addIndexOn( indexedAttrs[ii] );
+                addIndexOn( type );
             }
         }
     }
 
-
+    
     // ------------------------------------------------------------------------
     // Public Accessors - not declared in any interfaces just for this class
     // ------------------------------------------------------------------------