directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r471971 - in /directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis: operation/AddEntryOperation.java operation/OperationFactory.java service/ReplicationService.java
Date Tue, 07 Nov 2006 02:43:01 GMT
Author: akarasulu
Date: Mon Nov  6 18:43:00 2006
New Revision: 471971

URL: http://svn.apache.org/viewvc?view=rev&rev=471971
Log:
fixing issue with adding entry that was already deleted: DIRSERVER-774; also added socket
reuse for config to get rid of bind exceptions

Modified:
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java

Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java?view=diff&rev=471971&r1=471970&r2=471971
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
(original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
Mon Nov  6 18:43:00 2006
@@ -20,11 +20,8 @@
 package org.apache.directory.mitosis.operation;
 
 
-import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
 
 import org.apache.directory.mitosis.common.CSN;
 import org.apache.directory.mitosis.operation.support.EntryUtil;
@@ -82,42 +79,15 @@
         Attributes oldEntry = nexus.lookup( normalizedName );
         if ( oldEntry != null )
         {
-            // Find the attributes that new entry doesn't have.
-            Attributes attrsToRemove = ( Attributes ) oldEntry.clone();
-            NamingEnumeration e = oldEntry.getAll();
-            while ( e.hasMore() )
-            {
-                Attribute attr = ( Attribute ) e.next();
-                String attrID = attr.getID();
-                if ( entry.get( attrID ) != null )
-                {
-                    attrsToRemove.remove( attrID );
-                }
-            }
-
-            // Don't let RN attribute be removed
-            String rnAttrID = NamespaceTools.getRdnAttribute( normalizedName.get( normalizedName.size()
- 1 ) );
-            attrsToRemove.remove( rnAttrID );
-
-            // Delete the attributes.
-            nexus.modify( normalizedName, DirContext.REMOVE_ATTRIBUTE, entry );
-
-            // Remove RN attribute from new entry because it should be the same
-            // with the old one.
-            entry.remove( rnAttrID );
-
-            // Now replace old entries with the new attributes
-            nexus.modify( normalizedName, DirContext.REPLACE_ATTRIBUTE, entry );
-        }
-        else
-        {
-            String rdn = normalizedName.get( normalizedName.size() - 1 );
-            // Remove the attribute first in case we're using a buggy 
-            // LockableAttributesImpl which doesn't replace old attributes
-            // when we put a new one.
-            entry.remove( NamespaceTools.getRdnAttribute( rdn ) );
-            entry.put( NamespaceTools.getRdnAttribute( rdn ), NamespaceTools.getRdnValue(
rdn ) );
-            nexus.add( normalizedName, entry );
+            nexus.delete( normalizedName );
         }
+
+        String rdn = normalizedName.get( normalizedName.size() - 1 );
+        // Remove the attribute first in case we're using a buggy 
+        // LockableAttributesImpl which doesn't replace old attributes
+        // when we put a new one.
+        entry.remove( NamespaceTools.getRdnAttribute( rdn ) );
+        entry.put( NamespaceTools.getRdnAttribute( rdn ), NamespaceTools.getRdnValue( rdn
) );
+        nexus.add( normalizedName, entry );
     }
 }

Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java?view=diff&rev=471971&r1=471970&r2=471971
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
(original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
Mon Nov  6 18:43:00 2006
@@ -243,6 +243,20 @@
     {
         if ( nexus.hasEntry( newEntryName ) )
         {
+            Attributes entry = nexus.lookup( newEntryName );
+            Attribute deleted = entry.get( Constants.ENTRY_DELETED );
+            Object value = deleted == null ? null : deleted.get();
+
+            /*
+             * Check first if the entry has been marked as deleted before
+             * throwing an exception and delete the entry if so and return
+             * without throwing an exception.
+             */
+            if ( value != null && "true".equalsIgnoreCase( value.toString() ) )
+            {
+                return;
+            }
+
             throw new NameAlreadyBoundException( newEntryName.toString() + " already exists."
);
         }
     }

Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java?view=diff&rev=471971&r1=471970&r2=471971
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java
(original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java
Mon Nov  6 18:43:00 2006
@@ -61,7 +61,6 @@
 import org.apache.directory.shared.ldap.filter.FilterParserImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.filter.LoggingFilter;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
@@ -150,7 +149,8 @@
     private void startNetworking() throws Exception
     {
         registry = new SocketAcceptor();
-        IoServiceConfig config = new SocketAcceptorConfig();
+        SocketAcceptorConfig config = new SocketAcceptorConfig();
+        config.setReuseAddress( true );
 
         config.getFilterChain().addLast( "protocol",
             new ProtocolCodecFilter( new ReplicationServerProtocolCodecFactory() ) );



Mime
View raw message