You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/01/03 00:13:28 UTC

svn commit: r1054488 - /directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/

Author: elecharny
Date: Sun Jan  2 23:13:27 2011
New Revision: 1054488

URL: http://svn.apache.org/viewvc?rev=1054488&view=rev
Log:
o Merged the DN and UUID to Subentry cache into a single cache
o The SubentryCN is now an AttributeType
o Added some values into the AdministrativeRoleEnum


Modified:
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AccessControlSubentry.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AdministrativeRoleEnum.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/CollectiveAttributeSubentry.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubSchemaSubentry.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/Subentry.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/TriggerExecutionSubentry.java

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AccessControlSubentry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AccessControlSubentry.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AccessControlSubentry.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AccessControlSubentry.java Sun Jan  2 23:13:27 2011
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.directory.shared.ldap.aci.ACIItem;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 
 
@@ -39,7 +40,7 @@ public class AccessControlSubentry exten
     /**
      * Create an instance of the AccessControlSubentry class
      */
-    public AccessControlSubentry( String cn, SubtreeSpecification ss, String uuid )
+    public AccessControlSubentry( EntryAttribute cn, SubtreeSpecification ss, String uuid )
     {
         super( cn, ss, uuid );
         aciItems = new ArrayList<ACIItem>();

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AdministrativeRoleEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AdministrativeRoleEnum.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AdministrativeRoleEnum.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/AdministrativeRoleEnum.java Sun Jan  2 23:13:27 2011
@@ -26,8 +26,28 @@ package org.apache.directory.server.core
  */
 public enum AdministrativeRoleEnum
 {
-    AccessControl,
-    CollectiveAttribute,
-    TriggerExecution,
-    SubSchema
+    AccessControl(0),
+    CollectiveAttribute(1),
+    TriggerExecution(2),
+    SubSchema(3);
+    
+    /** The integer value */
+    private int value;
+    
+    /**
+     * A private constructor to associate a value to each element
+     */
+    private AdministrativeRoleEnum( int value )
+    {
+        this.value = value;
+    }
+    
+    
+    /**
+     * @return The internal value
+     */
+    public int getValue()
+    {
+        return value;
+    }
 }

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/CollectiveAttributeSubentry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/CollectiveAttributeSubentry.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/CollectiveAttributeSubentry.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/CollectiveAttributeSubentry.java Sun Jan  2 23:13:27 2011
@@ -46,7 +46,7 @@ public class CollectiveAttributeSubentry
     /**
      * Create an instance of the CollectiveAttributeSubentry class
      */
-    public CollectiveAttributeSubentry( String cn, SubtreeSpecification ss, String uuid, List<EntryAttribute> collectiveAttributes )
+    public CollectiveAttributeSubentry( EntryAttribute cn, SubtreeSpecification ss, String uuid, List<EntryAttribute> collectiveAttributes )
     {
         super( cn, ss, uuid );
         this.collectiveAttributes = collectiveAttributes;

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubSchemaSubentry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubSchemaSubentry.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubSchemaSubentry.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubSchemaSubentry.java Sun Jan  2 23:13:27 2011
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.administrative;
 
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 
 
@@ -32,7 +33,7 @@ public class SubSchemaSubentry extends S
     /**
      * Create an instance of the SubSchemaSubentry class
      */
-    public SubSchemaSubentry( String cn, SubtreeSpecification ss, String uuid )
+    public SubSchemaSubentry( EntryAttribute cn, SubtreeSpecification ss, String uuid )
     {
         super( cn, ss, uuid );
     }

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/Subentry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/Subentry.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/Subentry.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/Subentry.java Sun Jan  2 23:13:27 2011
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.administrative;
 
 
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 
 
@@ -39,8 +40,8 @@ public abstract class Subentry
     /** The subentry UUID */
     private String uuid;
     
-    /** The subentry CN */
-    private String cn;
+    /** The subentry CN (normalized) */
+    private EntryAttribute cn;
     
     /**
      * Creates a new instance of a Subentry
@@ -53,7 +54,7 @@ public abstract class Subentry
     /**
      * Creates a new instance of a Subentry
      */
-    protected Subentry( String cn, SubtreeSpecification ss, String uuid )
+    protected Subentry( EntryAttribute cn, SubtreeSpecification ss, String uuid )
     {
         this.cn = cn;
         this.ss = ss;
@@ -144,7 +145,7 @@ public abstract class Subentry
     /**
      * @return the cn
      */
-    public String getCn()
+    public  EntryAttribute getCn()
     {
         return cn;
     }
@@ -153,10 +154,36 @@ public abstract class Subentry
     /**
      * @param cn the cn to set
      */
-    public void setCn( String cn )
+    public void setCn( EntryAttribute cn )
     {
         this.cn = cn;
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals( Object o )
+    {
+        if ( o == null )
+        {
+            return false;
+        }
+        
+        if ( !(o instanceof Subentry ) )
+        {
+            return false;
+        }
+        
+        Subentry that = (Subentry)o;
+        
+        if ( cn == null )
+        {
+            return that.cn == null;
+        }
+        
+        return ( cn.equals( that.cn ) );
+    }
 
 
     /**
@@ -165,8 +192,8 @@ public abstract class Subentry
     public String toString()
     {
         StringBuilder sb = new StringBuilder();
-        sb.append( "Subentry name : " ).append( cn ).append( '\n' );
-        sb.append( "UUID          : " ).append( uuid ).append( '\n' );
+        sb.append( cn );
+        sb.append( "    UUID : " ).append( uuid ).append( '\n' );
         
         return sb.toString();
     }

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java Sun Jan  2 23:13:27 2011
@@ -20,61 +20,126 @@
 package org.apache.directory.server.core.administrative;
 
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.util.tree.DnNode;
 
 
 /**
- * A cache for subtree specifications. It associates a Subentry with its entryUUID<br>
+ * A cache for subentries. It associates a set of Subentry with its entryUUID or
+ * with its DN<br>
+ * This cache is thread safe.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class SubentryCache implements Iterable<String>
 {
-    /** The Subentry cache */
-    private final Map<String, Subentry> cache;
+    /** The Subentry UUID cache */
+    private final Map<String, Subentry[]> uuidCache;
+    
+    /** The Subentry DN cache */
+    private final DnNode<Subentry[]> dnCache;
     
     /**
      * Creates a new instance of SubentryCache with a default maximum size.
      */
     public SubentryCache()
     {
-        cache = new ConcurrentHashMap<String, Subentry>();
+        uuidCache = new HashMap<String, Subentry[]>();
+        dnCache = new DnNode<Subentry[]>();
     }
     
     
     /**
-     * Creates a new instance of SubentryCache with a specific maximum size.
+     * Retrieve a Subentry given an UUID and its role. If there is none, null will be returned.
+     *
+     * @param uuid The UUID we want to get the Subentry for 
+     * @param role The subentry Role
+     * @return The found Subentry, or null
      */
-    public SubentryCache( int maxSize )
+    public final Subentry getSubentry( String uuid, AdministrativeRoleEnum role )
     {
-        cache = new ConcurrentHashMap<String, Subentry>();
+        Subentry[] subentries = uuidCache.get( uuid );
+        Subentry subentry = subentries[role.getValue()];
+        
+        return subentry;
     }
     
     
     /**
-     * Retrieve a Subentry given an UUID. If there is none, null will be returned.
+     * Retrieve the Subentries for given an UUID
      *
-     * @param uuid The UUID we want to get the Subentry for 
+     * @param uuid The UUID we want to get the Subentries for 
+     * @return The found Subentries, or null
+     */
+    public final Subentry[] getSubentries( String uuid )
+    {
+        Subentry[] subentries = uuidCache.get( uuid );
+        
+        return subentries;
+    }
+    
+    
+    /**
+     * Retrieve a Subentry given an DN and its role. If there is none, null will be returned.
+     *
+     * @param dn The DN we want to get the Subentry for 
+     * @param role The subentry Role
      * @return The found Subentry, or null
      */
-    public final Subentry getSubentry( String uuid )
+    public final Subentry getSubentry( DN dn, AdministrativeRoleEnum role )
     {
-        return cache.get( uuid );
+        Subentry[] subentries = dnCache.getElement( dn );
+        Subentry subentry = subentries[role.getValue()];
+        
+        return subentry;
     }
     
     
     /**
-     * Remove a Subentry for a given UUID 
+     * Retrieve the Subentries for given a DN
+     *
+     * @param dn The DN we want to get the Subentries for 
+     * @return The found Subentries, or null
+     */
+    public final Subentry[] getSubentries( DN dn )
+    {
+        Subentry[] subentries = dnCache.getElement( dn );
+        
+        return subentries;
+    }
+    
+    
+    /**
+     * Remove the Subentries for a given UUID and role
      *
      * @param uuid The UUID for which we want to remove the 
-     * associated Subentry
-     * @return The removed Subentry, if any
+     * associated Subentries
+     * @return The removed Subentries, if any
      */
-    public final Subentry removeSubentry( String uuid )
+    public final Subentry[] removeSubentry( String uuid )
     {
-        Subentry oldSubentry = cache.remove( uuid );
+        Subentry[] oldSubentry = uuidCache.remove( uuid );
+        
+        return oldSubentry;
+    }
+    
+    
+    /**
+     * Remove the Subentries for a given UUID and role
+     *
+     * @param uuid The DN for which we want to remove the 
+     * associated Subentries
+     * @return The removed Subentries, if any
+     */
+    public final Subentry[] removeSubentry( DN dn ) throws LdapException
+    {
+        Subentry[] oldSubentry = dnCache.getElement( dn );
+        dnCache.remove( dn );
         
         return oldSubentry;
     }
@@ -83,12 +148,22 @@ public class SubentryCache implements It
     /**
      * Stores a new Subentry into the cache, associated with a DN
      *
+     * @param dn, the subentry DN
      * @param subentry The Subentry
-     * @return The old Subentry, if any
+     * @return The old Subentries, if any
      */
-    public Subentry addSubentry( Subentry subentry )
+    public Subentry[] addSubentry( DN dn, Subentry subentry ) throws LdapException
     {
-        Subentry oldSubentry = cache.put( subentry.getUuid(), subentry );
+        Subentry[] subentries = uuidCache.get( subentry.getUuid() );
+        
+        if ( subentries == null )
+        {
+            subentries = new Subentry[4];
+        }
+        
+        subentries[subentry.getAdministrativeRole().getValue()] = subentry;
+        Subentry[] oldSubentry = uuidCache.put( subentry.getUuid(), subentries );
+        dnCache.add( dn, subentries );
         
         return oldSubentry;
     }
@@ -101,7 +176,61 @@ public class SubentryCache implements It
      */
     public boolean hasSubentry( String uuid )
     {
-        return cache.containsKey( uuid );
+        return uuidCache.containsKey( uuid );
+    }
+    
+    
+    /**
+     * Tells if there is a Subentry associated with a DN
+     * @param dn The DN
+     * @return True if a Subentry is found
+     */
+    public boolean hasSubentry( DN dn )
+    {
+        return dnCache.hasElement( dn );
+    }
+    
+    
+    /**
+     * Tells if there is a Subentry associated with an UUID and a role
+     * 
+     * @param uuid The UUID
+     * @param role The role
+     * @return True if a Subentry is found
+     */
+    public boolean hasSubentry( String uuid, AdministrativeRoleEnum role )
+    {
+        Subentry[] subentries = uuidCache.get( uuid );
+        
+        if ( subentries == null )
+        {
+            return false;
+        }
+        else
+        {
+            return subentries[ role.getValue() ] != null;
+        }
+    }
+    
+    
+    /**
+     * Tells if there is a Subentry associated with a DN and a role
+     * @param dn The DN
+     * @param role The role
+     * @return True if a Subentry is found
+     */
+    public boolean hasSubentry( DN dn, AdministrativeRoleEnum role )
+    {
+        Subentry[] subentries = dnCache.getElement( dn );
+        
+        if ( subentries == null )
+        {
+            return false;
+        }
+        else
+        {
+            return subentries[ role.getValue() ] != null;
+        }
     }
     
     
@@ -110,6 +239,6 @@ public class SubentryCache implements It
      */
     public Iterator<String> iterator()
     {
-        return cache.keySet().iterator();
+        return uuidCache.keySet().iterator();
     }
 }

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/TriggerExecutionSubentry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/TriggerExecutionSubentry.java?rev=1054488&r1=1054487&r2=1054488&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/TriggerExecutionSubentry.java (original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/TriggerExecutionSubentry.java Sun Jan  2 23:13:27 2011
@@ -22,6 +22,7 @@ package org.apache.directory.server.core
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 import org.apache.directory.shared.ldap.trigger.TriggerSpecification;
 
@@ -39,7 +40,7 @@ public class TriggerExecutionSubentry ex
     /**
      * Create an instance of the TriggerExecutionSubentry class
      */
-    public TriggerExecutionSubentry( String cn, SubtreeSpecification ss, String uuid )
+    public TriggerExecutionSubentry( EntryAttribute cn, SubtreeSpecification ss, String uuid )
     {
         super( cn, ss, uuid );
         triggerSpecifications = new ArrayList<TriggerSpecification>();