directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1416995 - in /directory/apacheds/trunk: protocol-ldap/src/main/java/org/apache/directory/server/ldap/ protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ server-integ/src/test/java/org/apache/directory/server...
Date Tue, 04 Dec 2012 15:32:58 GMT
Author: elecharny
Date: Tue Dec  4 15:32:56 2012
New Revision: 1416995

URL: http://svn.apache.org/viewvc?rev=1416995&view=rev
Log:
o Improved the ReplicationStatusEnum usage, by removing some useless states
o Simplified the consumer creation loop in LdapServer

Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationStatusEnum.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java?rev=1416995&r1=1416994&r2=1416995&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
Tue Dec  4 15:32:56 2012
@@ -696,9 +696,7 @@ public class LdapServer extends Director
                     {
                         try
                         {
-                            boolean stopped = false;
-                            
-                            while ( !stopped )
+                            while ( true )
                             {
                                 LOG.info( "starting the replication consumer with {}", consumer
);
                                 CONSUMER_LOG.info( "starting the replication consumer with
{}", consumer );
@@ -713,18 +711,10 @@ public class LdapServer extends Director
                                         status = consumer.startSync();
                                     } while ( status == ReplicationStatusEnum.REFRESH_REQUIRED
);
                                     
-                                    switch ( status )
+                                    if ( status == ReplicationStatusEnum.STOPPED )
                                     {
-                                        case STOPPED :
-                                            stopped = true;
-                                            break;
-                                            
-                                        case CANCELLED :
-                                        case DISCONNECTED :
-                                        case INTERRUPTED :
-                                        case UNKOWN_ERROR :
-                                            // Loop on connect
-                                            break;
+                                        // Exit the loop
+                                        break;
                                     }
                                 }
                             }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java?rev=1416995&r1=1416994&r2=1416995&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java
Tue Dec  4 15:32:56 2012
@@ -46,7 +46,6 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.ldap.LdapProtocolUtils;
 import org.apache.directory.server.ldap.replication.ReplicationConsumerConfig;
 import org.apache.directory.server.ldap.replication.SyncReplConfiguration;
-import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.ldap.codec.controls.manageDsaIT.ManageDsaITDecorator;
 import org.apache.directory.shared.ldap.extras.controls.SyncDoneValue;
 import org.apache.directory.shared.ldap.extras.controls.SyncInfoValue;
@@ -129,7 +128,7 @@ public class ReplicationConsumerImpl imp
     /** flag to indicate whether the consumer was disconnected */
     private boolean disconnected;
 
-    /** A field used to tell the thread it should stop */
+    /** A field used to tell the RefreshOnly method it should stop */
     private volatile boolean stop = false;
 
     /** the core session */
@@ -298,7 +297,7 @@ public class ReplicationConsumerImpl imp
     }
 
 
-    private ResultCodeEnum handleSearchRseultDone( SearchResultDone searchDone )
+    private ResultCodeEnum handleSearchResultDone( SearchResultDone searchDone )
     {
         LOG.debug( "///////////////// handleSearchDone //////////////////" );
 
@@ -529,6 +528,28 @@ public class ReplicationConsumerImpl imp
     {
         CONSUMER_LOG.debug( "Consumer {} session with {} has been closed ", config.getReplicaId(),
config.getProducer() );
         
+        // Cleanup
+        disconnected = true;
+
+        try
+        {
+            stopRefreshing();
+
+            connection = null;
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to close the connection", e );
+        }
+        finally
+        {
+            // persist the cookie
+            storeCookie();
+            
+            // reset the cookie
+            syncCookie = null;
+        }
+        
         return;
     }
 
@@ -554,7 +575,7 @@ public class ReplicationConsumerImpl imp
             catch ( Exception e )
             {
                 LOG.error( "Failed to sync with refreshAndPersist mode", e );
-                return ReplicationStatusEnum.UNKOWN_ERROR;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
         }
         else
@@ -582,12 +603,13 @@ public class ReplicationConsumerImpl imp
             catch ( InterruptedException ie )
             {
                 LOG.warn( "refresher thread interrupted" );
-                return ReplicationStatusEnum.INTERRUPTED;
+                
+                return ReplicationStatusEnum.DISCONNECTED;
             }
             catch ( Exception e )
             {
                 LOG.error( "Failed to sync with refresh only mode", e );
-                return ReplicationStatusEnum.UNKOWN_ERROR;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
         }
 
@@ -733,7 +755,7 @@ public class ReplicationConsumerImpl imp
             
             CONSUMER_LOG.debug( "Search sync on {} has been canceled ", config.getProducer(),
sf.getCause() );
             
-            return ReplicationStatusEnum.CANCELLED;
+            return ReplicationStatusEnum.DISCONNECTED;
         }
         else if ( disconnected )
         {
@@ -743,7 +765,7 @@ public class ReplicationConsumerImpl imp
         }
         else
         {
-            ResultCodeEnum resultCode = handleSearchRseultDone( ( SearchResultDone ) resp
);
+            ResultCodeEnum resultCode = handleSearchResultDone( ( SearchResultDone ) resp
);
     
             CONSUMER_LOG.debug( "Response from {} : {}", config.getProducer(), resultCode
);
             LOG.debug( "sync operation returned result code {}", resultCode );
@@ -788,7 +810,7 @@ public class ReplicationConsumerImpl imp
             else
             {
                 CONSUMER_LOG.debug( "Got result code {} from producer {}. Replication stopped",
resultCode, config.getProducer() );
-                return ReplicationStatusEnum.UNKOWN_ERROR;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
         }
     }
@@ -1267,7 +1289,10 @@ public class ReplicationConsumerImpl imp
 
 
 
-    public void stopRefreshing()
+    /**
+     * Stop the refresh operation
+     */
+    private void stopRefreshing()
     {
         stop = true;
     }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationStatusEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationStatusEnum.java?rev=1416995&r1=1416994&r2=1416995&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationStatusEnum.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationStatusEnum.java
Tue Dec  4 15:32:56 2012
@@ -32,15 +32,6 @@ public enum ReplicationStatusEnum
     /** A full refresh should be done */
     REFRESH_REQUIRED,
     
-    /** The replication loop has been interrupted */
-    INTERRUPTED,
-    
     /** The replication has been stopped */
-    STOPPED,
-    
-    /** The replication has been cancelled */
-    CANCELLED,
-    
-    /** We have got an unknown error */
-    UNKOWN_ERROR;
+    STOPPED
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java?rev=1416995&r1=1416994&r2=1416995&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
Tue Dec  4 15:32:56 2012
@@ -483,7 +483,7 @@ public class MockSyncReplConsumer implem
             catch ( Exception e )
             {
                 LOG.error( "Failed to sync with refreshAndPersist mode", e );
-                return ReplicationStatusEnum.UNKOWN_ERROR;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
         }
         else
@@ -510,12 +510,12 @@ public class MockSyncReplConsumer implem
             catch ( InterruptedException ie )
             {
                 LOG.warn( "refresher thread interrupted" );
-                return ReplicationStatusEnum.INTERRUPTED;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
             catch ( Exception e )
             {
                 LOG.error( "Failed to sync with refresh only mode", e );
-                return ReplicationStatusEnum.UNKOWN_ERROR;
+                return ReplicationStatusEnum.DISCONNECTED;
             }
         }
 
@@ -666,7 +666,7 @@ public class MockSyncReplConsumer implem
         } 
         else
         {
-            return ReplicationStatusEnum.UNKOWN_ERROR;
+            return ReplicationStatusEnum.DISCONNECTED;
         }
     }
 



Mime
View raw message