Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 55462 invoked from network); 21 May 2009 15:08:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 May 2009 15:08:11 -0000 Received: (qmail 26689 invoked by uid 500); 21 May 2009 15:08:24 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 26627 invoked by uid 500); 21 May 2009 15:08:24 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 26618 invoked by uid 99); 21 May 2009 15:08:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2009 15:08:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2009 15:08:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 84D01238889D; Thu, 21 May 2009 15:08:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r777147 - in /directory/apacheds/trunk: schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ schema-registries/src/main/java/org/apache/directory/server/schema/registries/ Date: Thu, 21 May 2009 15:08:01 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090521150801.84D01238889D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Thu May 21 15:08:00 2009 New Revision: 777147 URL: http://svn.apache.org/viewvc?rev=777147&view=rev Log: Review of the AttributeTypeRegistry : o Replaced the HashMap by a ConcurrentHashmap o Initialized the oidNormalizer map at startup o Added some logs o Removed the useless getBinaryAttributes() and list() methods o Simplified the getDescendant method o Updated the Javadoc o A few other minor improvements Modified: directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java Modified: directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java?rev=777147&r1=777146&r2=777147&view=diff ============================================================================== --- directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java (original) +++ directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java Thu May 21 15:08:00 2009 @@ -301,9 +301,7 @@ ( ( BootstrapAttributeType ) attributeType ).setSchema( schema.getSchemaName() ); } - AttributeTypeRegistry attributeTypeRegistry; - attributeTypeRegistry = registries.getAttributeTypeRegistry(); - attributeTypeRegistry.register( attributeType ); + registries.getAttributeTypeRegistry().register( attributeType ); break; case OBJECT_CLASS_PRODUCER : Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java?rev=777147&r1=777146&r2=777147&view=diff ============================================================================== --- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java (original) +++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java Thu May 21 15:08:00 2009 @@ -26,7 +26,6 @@ import javax.naming.NamingException; import java.util.Iterator; import java.util.Map; -import java.util.Set; /** @@ -48,17 +47,6 @@ /** - * Gets a set of Strings representing the aliases, and numeric identifiers of - * all binary attributes. The set will contain all the aliases for a binary - * attributeType (one whose syntax is not human readible) along with its numeric - * identifier. - * - * @return set of aliases and numeric ids for binary attributeTypes - * @throws NamingException if there are issues resolving type information - */ - Set getBinaryAttributes() throws NamingException; - - /** * Looks up an AttributeType by its unique Object Identifier or by its * unique name. * Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java?rev=777147&r1=777146&r2=777147&view=diff ============================================================================== --- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java (original) +++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java Thu May 21 15:08:00 2009 @@ -21,21 +21,19 @@ import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import javax.naming.NamingException; import javax.naming.directory.NoSuchAttributeException; -import org.apache.directory.shared.ldap.constants.SchemaConstants; import org.apache.directory.shared.ldap.schema.AttributeType; import org.apache.directory.shared.ldap.schema.MatchingRule; import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer; import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer; -import org.apache.directory.shared.ldap.util.StringTools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,20 +54,21 @@ private static final boolean IS_DEBUG = LOG.isDebugEnabled(); /** maps an OID to an AttributeType */ - private final Map byOid; + private final Map byOidAT; + /** maps OIDs to a Set of descendants for that OID */ private final Map> oidToDescendantSet; - /** the registry used to resolve names to OIDs */ + + /** the Registry used to resolve names to OIDs */ private final OidRegistry oidRegistry; - /** cached normalizer mapping */ - private transient Map mapping; + + /** cached Oid/normalizer mapping */ + private transient Map oidNormalizerMap; // ------------------------------------------------------------------------ // C O N S T R U C T O R S // ------------------------------------------------------------------------ - - /** * Creates an empty DefaultAttributeTypeRegistry. * @@ -78,8 +77,9 @@ */ public DefaultAttributeTypeRegistry( OidRegistry oidRegistry ) { - this.byOid = new HashMap(); - this.oidToDescendantSet= new HashMap>(); + byOidAT = new ConcurrentHashMap(); + oidToDescendantSet= new ConcurrentHashMap>(); + oidNormalizerMap = new ConcurrentHashMap(); this.oidRegistry = oidRegistry; } @@ -87,71 +87,55 @@ // ------------------------------------------------------------------------ // Service Methods // ------------------------------------------------------------------------ - - + /** + * {@inheritDoc} + */ public void register( AttributeType attributeType ) throws NamingException { - if ( byOid.containsKey( attributeType.getOid() ) ) + if ( byOidAT.containsKey( attributeType.getOid() ) ) { - throw new NamingException( "attributeType w/ OID " + attributeType.getOid() - + " has already been registered!" ); + String msg = "attributeType " + attributeType.getName() + " w/ OID " + attributeType.getOid() + + " has already been registered!"; + LOG.error( msg ); + throw new NamingException( msg ); } + // First, register the AttributeType names and oid in the global + // OidRegistry String[] names = attributeType.getNamesRef(); + for ( String name : names ) { oidRegistry.register( name, attributeType.getOid() ); } + oidRegistry.register( attributeType.getOid(), attributeType.getOid() ); - if ( mapping != null ) - { - addMappingFor( attributeType ); - } + // Inject the attributeType into the oid/normalizer map + addMappingFor( attributeType ); + // Register this AttributeType into the Descendant map registerDescendants( attributeType ); - byOid.put( attributeType.getOid(), attributeType ); + + // Internally associate the OID to the registered AttributeType + byOidAT.put( attributeType.getOid(), attributeType ); if ( IS_DEBUG ) { - LOG.debug( "registed attributeType: " + attributeType ); + LOG.debug( "registred attributeType: {}", attributeType ); } } - public Set getBinaryAttributes() throws NamingException - { - Set binaries = new HashSet(); - Iterator list = iterator(); - while ( list.hasNext() ) - { - AttributeType type = list.next(); - - if ( ! type.getSyntax().isHumanReadable() ) - { - // add the OID for the attributeType - binaries.add( type.getOid() ); - - // add the lowercased name for the names for the attributeType - String[] names = type.getNamesRef(); - - for ( String name : names ) - { - // @TODO do we really need to lowercase strings here? - binaries.add( StringTools.lowerCaseAscii( StringTools.trim( name ) ) ); - } - } - } - - return binaries; - } - - + /** + * Store the AttributeType into a map associating an AttributeType to its + * descendants. + * + * @param attributeType The attributeType to register + * @throws NamingException If something went wrong + */ public void registerDescendants( AttributeType attributeType ) throws NamingException { - // add/create the descendent set for this attribute - oidToDescendantSet.put( attributeType.getOid(), new HashSet( 5 ) ); - // add this attribute to descendant list of other attributes in superior chain onRegisterAddToAncestorDescendants( attributeType, attributeType.getSuperior() ); } @@ -162,7 +146,7 @@ * until top is reached. Top will not have the new type added. * * @param newType the new attributeType being added - * @param ancestor some anscestor from superior up to and including top + * @param ancestor some ancestor from superior up to and including top * @throws NamingException if there are resolution failures */ protected void onRegisterAddToAncestorDescendants( AttributeType newType, AttributeType ancestor ) @@ -173,80 +157,92 @@ return; } - if ( ancestor.getName() != null && ancestor.getName().equals( SchemaConstants.TOP_OC ) ) - { - return; - } - + // Get the ancestor's descendant, if any Set descendants = oidToDescendantSet.get( ancestor.getOid() ); + + // Initialize the descendant Set to store the descendants for the attributeType if ( descendants == null ) { - descendants = new HashSet( 5 ); + descendants = new HashSet( 1 ); oidToDescendantSet.put( ancestor.getOid(), descendants ); } + + // Add the current type as a descendant descendants.add( newType ); + + // And recurse until we reach the top of the hierarchy onRegisterAddToAncestorDescendants( newType, ancestor.getSuperior() ); } + /** + * {@inheritDoc} + */ public AttributeType lookup( String id ) throws NamingException { String oid = oidRegistry.getOid( id ); + AttributeType attributeType = byOidAT.get( oid ); - if ( !byOid.containsKey( oid ) ) + if ( attributeType == null ) { - throw new NoSuchAttributeException( "attributeType w/ OID " + oid + " not registered!" ); + String msg = "attributeType w/ OID " + oid + " not registered!"; + LOG.error( msg ); + throw new NoSuchAttributeException( msg ); } - AttributeType attributeType = byOid.get( oid ); - if ( IS_DEBUG ) { - LOG.debug( "lookup with id" + oid + "' of attributeType: " + attributeType ); + LOG.debug( "lookup with id '{}' for attributeType: {}", oid, attributeType ); } return attributeType; } + /** + * {@inheritDoc} + */ public boolean hasAttributeType( String id ) { - if ( oidRegistry.hasOid( id ) ) + try { - try - { - return byOid.containsKey( oidRegistry.getOid( id ) ); - } - catch ( NamingException e ) - { - return false; - } + String oid = oidRegistry.getOid( id ); + + if ( oid != null ) + { + return byOidAT.containsKey( oid ); + } + + return false; + } + catch ( NamingException e ) + { + return false; } - - return false; } + /** + * {@inheritDoc} + */ public String getSchemaName( String id ) throws NamingException { - id = oidRegistry.getOid( id ); - AttributeType at = byOid.get( id ); + AttributeType at = byOidAT.get( oidRegistry.getOid( id ) ); if ( at != null ) { return at.getSchema(); } - throw new NamingException( "OID " + id + " not found in oid to " + "AttributeType map!" ); - } - - - public Iterator list() - { - return byOid.values().iterator(); + String msg = "OID " + id + " not found in oid to " + "AttributeType map!"; + LOG.debug( msg ); + throw new NamingException( msg ); } + /** + * Remove the AttributeType normalizer from the OidNormalizer map + */ private void removeMappingFor( AttributeType type ) throws NamingException { if ( type == null ) @@ -254,97 +250,111 @@ return; } - MatchingRule matchingRule = type.getEquality(); - mapping.remove( type.getOid() ); + oidNormalizerMap.remove( type.getOid() ); + + // We also have to remove all the short names for this attribute String[] aliases = type.getNamesRef(); + for ( String aliase : aliases ) { - mapping.remove( aliase ); - mapping.remove( aliase.toLowerCase() ); + oidNormalizerMap.remove( aliase ); + oidNormalizerMap.remove( aliase.toLowerCase() ); } } + /** + * Add a new Oid/Normalizer couple in the OidNormalizer map + */ private void addMappingFor( AttributeType type ) throws NamingException { MatchingRule matchingRule = type.getEquality(); OidNormalizer oidNormalizer; + String oid = type.getOid(); if ( matchingRule == null ) { - LOG.debug( "Attribute " + type.getName() + " does not have normalizer : using NoopNormalizer" ); - oidNormalizer = new OidNormalizer( type.getOid(), new NoOpNormalizer() ); + LOG.debug( "Attribute {} does not have normalizer : using NoopNormalizer", type.getName() ); + oidNormalizer = new OidNormalizer( oid, new NoOpNormalizer() ); } else { - oidNormalizer = new OidNormalizer( type.getOid(), matchingRule.getNormalizer() ); + oidNormalizer = new OidNormalizer( oid, matchingRule.getNormalizer() ); } - mapping.put( type.getOid(), oidNormalizer ); + oidNormalizerMap.put( oid, oidNormalizer ); + + // Also inject the attributeType's short nampes in the map String[] aliases = type.getNamesRef(); + for ( String aliase : aliases ) { - mapping.put( aliase, oidNormalizer ); - mapping.put( aliase.toLowerCase(), oidNormalizer ); + oidNormalizerMap.put( aliase, oidNormalizer ); + oidNormalizerMap.put( aliase.toLowerCase(), oidNormalizer ); } } + /** + * {@inheritDoc} + */ public Map getNormalizerMapping() throws NamingException { - if ( mapping == null ) - { - mapping = new HashMap( byOid.size() << 1 ); - for ( AttributeType type : byOid.values() ) - { - addMappingFor( type ); - } - } - - return Collections.unmodifiableMap( mapping ); + return Collections.unmodifiableMap( oidNormalizerMap ); } + /** + * {@inheritDoc} + */ public Iterator descendants( String ancestorId ) throws NamingException { String oid = oidRegistry.getOid( ancestorId ); Set descendants = oidToDescendantSet.get( oid ); + if ( descendants == null ) { - //noinspection unchecked return Collections.EMPTY_SET.iterator(); } + return descendants.iterator(); } + /** + * {@inheritDoc} + */ public boolean hasDescendants( String ancestorId ) throws NamingException { String oid = oidRegistry.getOid( ancestorId ); - Set descendants = oidToDescendantSet.get( oid ); - return descendants != null && !descendants.isEmpty(); + Set descendants = oidToDescendantSet.get( oid ); + return (descendants != null) && !descendants.isEmpty(); } + /** + * {@inheritDoc} + */ public Iterator iterator() { - return byOid.values().iterator(); + return byOidAT.values().iterator(); } + /** + * {@inheritDoc} + */ public void unregister( String numericOid ) throws NamingException { if ( ! Character.isDigit( numericOid.charAt( 0 ) ) ) { - throw new NamingException( "Looks like the arg is not a numeric OID" ); - } - - if ( mapping != null ) - { - removeMappingFor( byOid.get( numericOid )); + String msg = "Looks like the arg (" + numericOid + ") is not a numeric OID"; + LOG.error(msg ); + throw new NamingException( msg ); } - byOid.remove( numericOid ); + removeMappingFor( byOidAT.get( numericOid )); + byOidAT.remove( numericOid ); oidToDescendantSet.remove( numericOid ); } } Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java?rev=777147&r1=777146&r2=777147&view=diff ============================================================================== --- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java (original) +++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java Thu May 21 15:08:00 2009 @@ -178,14 +178,14 @@ { ArrayList errors = new ArrayList(); - Iterator list = objectClassRegistry.iterator(); + Iterator list = objectClassRegistry.iterator(); while ( list.hasNext() ) { ObjectClass oc = ( ObjectClass ) list.next(); resolve( oc, errors ); } - list = attributeTypeRegistry.list(); + list = attributeTypeRegistry.iterator(); while ( list.hasNext() ) { AttributeType at = ( AttributeType ) list.next();