directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r556176 - in /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition: ./ tree/
Date Fri, 13 Jul 2007 23:15:29 GMT
Author: akarasulu
Date: Fri Jul 13 16:15:28 2007
New Revision: 556176

URL: http://svn.apache.org/viewvc?view=rev&rev=556176
Log:
refactored the partition structure stuff so it is clear what and how it is being used: still
need more explainations on the data structure and how names are used in it

Added:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html
  (with props)
Removed:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/AbstractPartitionStructure.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionContainer.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionStructure.java
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?view=diff&rev=556176&r1=556175&r2=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
Fri Jul 13 16:15:28 2007
@@ -54,6 +54,8 @@
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.core.partition.tree.Node;
+import org.apache.directory.server.core.partition.tree.BranchNode;
 import org.apache.directory.server.ldap.constants.SupportedSASLMechanisms;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.schema.registries.OidRegistry;
@@ -124,7 +126,7 @@
     private Map<String, Partition> partitions = new HashMap<String, Partition>();
     
     /** A structure to hold all the partitions */
-    private PartitionStructure partitionList = new PartitionContainer();
+    private Node partitionList = new BranchNode();
     
     /** the read only rootDSE attributes */
     private final Attributes rootDSE;
@@ -400,7 +402,7 @@
         {
             partitions.put( key, system );
         
-            partitionList.buildPartitionStructure( partitionList, system.getSuffix(), 0,
system );
+            partitionList.buildNode( partitionList, system.getSuffix(), 0, system );
 
             Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
             namingContexts.add( system.getUpSuffix().getUpName() );
@@ -578,7 +580,7 @@
         {
             partitions.put( partition.getSuffix().toString(), partition );
             
-            partitionList.buildPartitionStructure( partitionList, partition.getSuffix(),
0, partition );
+            partitionList.buildNode( partitionList, partition.getSuffix(), 0, partition );
 
             Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
             namingContexts.add( partition.getUpSuffix().getUpName() );
@@ -607,11 +609,11 @@
         {
             partitions.remove( key );
         
-            partitionList = new PartitionContainer();
+            partitionList = new BranchNode();
             
             for ( Partition part:partitions.values() )
             {
-                partitionList.buildPartitionStructure( partitionList, part.getSuffix(), 0,
partition );
+                partitionList.buildNode( partitionList, part.getSuffix(), 0, partition );
             }
     
             partition.sync();
@@ -1034,7 +1036,7 @@
     private Partition getBackend( LdapDN dn ) throws NamingException
     {
         Enumeration<String> rdns = dn.getAll();
-        PartitionStructure currentPartition = partitionList;
+        Node currentPartition = partitionList;
         
         // This is synchronized so that we can't read the
         // partitionList when it is modified.
@@ -1047,9 +1049,9 @@
                 
                 if ( currentPartition.contains( rdn ) )
                 {
-                    currentPartition = currentPartition.getPartition( rdn );
+                    currentPartition = currentPartition.getChildOrThis( rdn );
     
-                    if ( currentPartition.isPartition() )
+                    if ( currentPartition.isLeaf() )
                     {
                         return currentPartition.getPartition();
                     }

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java?view=auto&rev=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java
Fri Jul 13 16:15:28 2007
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.tree;
+
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+/**
+ * This abstract class is just used to implement the utility method needed to build the
+ * global partition structue used by the getBackend method. 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+public abstract class AbstractNode implements Node
+{
+    /**
+     * @see Node#buildNode(Node, LdapDN, int, Partition)
+     */
+    public Node buildNode( Node current, LdapDN dn, int index, Partition partition )
+    {
+        if ( index == dn.size() - 1 )
+        {
+            return current.addNode( dn.getRdn( index ).toString(), new LeafNode( partition
) );
+        }
+        else
+        {
+            return current.addNode( dn.getRdn( index ).toString(), 
+                buildNode( new BranchNode(), dn, index + 1, partition ) );
+        }
+    }
+}

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java?view=auto&rev=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
Fri Jul 13 16:15:28 2007
@@ -0,0 +1,142 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.tree;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.server.core.partition.Partition;
+
+/**
+ * 
+ * The Partition Container holds entries which can be either Partitions or 
+ * Containers. 
+ * 
+ * We can see them as directories, where Partitions are the files.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BranchNode extends AbstractNode
+{
+    /** Stores the list of all the descendant partitions and containers */
+    private Map<String, Node> children;
+    
+    
+    /**
+     * Creates a new instance of PartitionContainer.
+     */
+    public BranchNode()
+    {
+        children = new HashMap<String, Node>();
+    }
+
+    
+    /**
+     * @see Node#isLeaf()
+     */
+    public boolean isLeaf()
+    {
+        return false;
+    }
+    
+    
+    /**
+     * @see Node#addNode( String, Node )
+     */
+    public Node addNode( String name, Node child )
+    {
+        children.put( name, child );
+        return this;
+    }
+    
+    
+    /**
+     * @see Node#contains( String )     
+     */
+    public boolean contains( String name )
+    {
+        return children.containsKey( name );
+    }
+    
+    
+    /**
+     * @see Node#getPartition()
+     * 
+     * As this is a container, we just return null;
+     */
+    public Partition getPartition()
+    {
+        return null;
+    }
+
+    
+    /**
+     * @see Node#getChildOrThis( String )
+     */
+    public Node getChildOrThis( String name )
+    {
+        if ( children.containsKey( name ) )
+        {
+            return children.get( name );
+        }
+        else
+        {
+            return null;
+        }
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( " { " );
+        
+        boolean isFirst = true;
+        
+        for ( Node child:children.values() )
+        {
+            if ( isFirst )
+            {
+                isFirst = false;
+            }
+            else
+            {
+                sb.append(  ", " );
+            }
+
+            if ( child instanceof BranchNode )
+            {
+                sb.append( "Branch:").append( child.toString() );
+            }
+            else
+            {
+                sb.append( "Leaf: " ).append( "'" ).append( child.toString() ).append( "'"
);
+            }
+        }
+
+        sb.append( " } " );
+        
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java?view=auto&rev=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
Fri Jul 13 16:15:28 2007
@@ -0,0 +1,130 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.tree;
+
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.partition.Partition;
+
+
+/**
+ * A leaf node which stores a Partition. These objects are stored in BranchNodes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LeafNode extends AbstractNode
+{
+    /** The stored partition */
+    private Partition partition;
+
+    
+    /**
+     * Creates a new instance of LeafNode.
+     *
+     * @param partition the partition to store
+     */
+    public LeafNode( Partition partition )
+    {
+        this.partition = partition;
+    }
+
+    
+    /**
+     * @see Node#isLeaf()
+     */
+    public boolean isLeaf()
+    {
+        return true;
+    }
+    
+    
+    /**
+     * @see Node#contains( String )
+     */
+    public boolean contains( String name )
+    {
+        try
+        {
+            return partition.getSuffix().getNormName().equals(  name  );
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+    
+
+    /**
+     * @see Node#addNode( String, Node )
+     */
+    public Node addNode( String name, Node partition )
+    {
+        return this;
+    }
+    
+    
+    /**
+     * @see Node#getPartition()
+     */
+    public Partition getPartition()
+    {
+        return partition;
+    }
+    
+
+    /**
+     * @see Node#getChildOrThis( String )
+     */
+    public Node getChildOrThis( String name )
+    {
+        try
+        {
+            if ( partition.getSuffix().getNormName().equals( name ) )
+            {
+                return this;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        catch ( NamingException ne )
+        {
+            return null;
+        }
+    }
+
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        try
+        {
+            return partition.getSuffix().getUpName();
+        }
+        catch ( NamingException ne )
+        {
+            return "Unkown partition";
+        }
+    }
+}

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java?view=auto&rev=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
Fri Jul 13 16:15:28 2007
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.tree;
+
+
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+
+/**
+ * An interface for nodes in a tree designed to quickly lookup partitions.
+ * Branch nodes in this tree contain other nodes.  Leaf nodes in the tree
+ * contain a referrence to a partition whose suffix is the path through the 
+ * nodes of the tree from the root.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface Node
+{
+    /**
+     * Tells if the implementation is a leaf node. If it's a branch node
+     * then false is returned.
+     *
+     * @return <code>true</code> if the class is a leaf node, false otherwise.
+     */
+    boolean isLeaf();
+    
+    /**
+     * Add a new Partition to the current container.
+     *
+     * @param name The partition name
+     * @param children The PartitionStructure object (it should be a PartitionHandler)
+     * @return The current PartitionStructure to which a Partition has been added.
+     */
+    Node addNode( String name, Node children );
+    
+    /**
+     * Tells if the current PartitionStructure contains the given partition.
+     * 
+     * If the PartitionStructure is an instance of PartitionHandler, returns true
+     * if the partition's name equals the given name.
+     *
+     * If the PartitionStructure is an instance of PartitionContainer, returns true
+     * if the container's children contains the given name.
+     *
+     * @param name The name we are looking for
+     * @return <code>true</code> if the PartitionStructure instance contains
this name
+     */
+    boolean contains( String name );
+    
+    /**
+     * Returns the Partition associated with this name, if any, or null if the name is not

+     * found
+     *
+     * @param name The name we are looking for 
+     * @return The associated PartitionHandler or PartitionContainer
+     */
+    Node getChildOrThis( String name );
+    
+    /**
+     * @return Get the partition if the object is an instance of PartitionHandler, null otherwise
+     */
+    Partition getPartition();
+    
+    /**
+     * Construct the global partition structure, assuming the DN passed as an argument is
a partition
+     * name.
+     * 
+     * This is a recursive method.
+     *
+     * @param current The current structure
+     * @param dn The DN associated with the partition
+     * @param index The current RDN being processed 
+     * @param partition The associated partition
+     * @return The modified global structure.
+     */
+    Node buildNode( Node current, LdapDN dn, int index, Partition partition );
+}

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html?view=auto&rev=556176
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html
Fri Jul 13 16:15:28 2007
@@ -0,0 +1,9 @@
+<body>
+<p>
+Set of classes and interfaces for a special data tree structure used to quickly
+find partitions corresponding to an entry by DN.  The data structure contains
+branch nodes which store other nodes as well as leaf nodes which referrence 
+partitions whose suffix is the path from the root of the tree down to the node.
+Each node contains an RDN used for it's position.
+</p>
+</body>

Propchange: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/package.html
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message