From bdcbee41067e1f439a8ebe7fd0a9dd01799b593a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 11 Jul 2014 09:17:59 +0000
Subject: [PATCH] Code cleanups.

---
 opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java |   59 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java b/opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java
index f98fd81..9171191 100644
--- a/opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java
+++ b/opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java
@@ -292,31 +292,11 @@
            *           restart as usual
            *   load this change on the delayList
            */
-          DBCursor<UpdateMsg> cursor = null;
-          try
-          {
-            // fill the lateQueue
-            cursor = replicationServerDomain.getCursorFrom(serverState);
-            while (cursor.next() && isLateQueueBelowThreshold())
-            {
-              lateQueue.add(cursor.getRecord());
-            }
-          }
-          catch (ChangelogException e)
-          {
-            logger.traceException(e);
-          }
-          finally
-          {
-            close(cursor);
-          }
-
-          /*
-           * If the late queue is empty then we could not find any messages in
-           * the replication log so the remote server is not late anymore.
-           */
+          fillLateQueue();
           if (lateQueue.isEmpty())
           {
+            // we could not find any messages in the changelog
+            // so the remote server is not late anymore.
             synchronized (msgQueue)
             {
               // Ensure we are below threshold so this server will follow the
@@ -330,8 +310,8 @@
           else
           {
             /*
-             * if the first change in the lateQueue is also on the regular
-             * queue, we can resume the processing from the regular queue
+             * if the first change in the lateQueue is also on the regular queue,
+             * we can resume the processing from the regular queue
              * -> set following to true and empty the lateQueue.
              */
             UpdateMsg msg = lateQueue.first();
@@ -353,7 +333,7 @@
         {
           // get the next change from the lateQueue
           UpdateMsg msg;
-          synchronized (msgQueue)
+          synchronized (msgQueue) // TODO JNR why synchronize(msgQueue) here?
           {
             msg = lateQueue.removeFirst();
           }
@@ -406,6 +386,27 @@
     return null;
   }
 
+  private void fillLateQueue()
+  {
+    DBCursor<UpdateMsg> cursor = null;
+    try
+    {
+      cursor = replicationServerDomain.getCursorFrom(serverState);
+      while (cursor.next() && isLateQueueBelowThreshold())
+      {
+        lateQueue.add(cursor.getRecord());
+      }
+    }
+    catch (ChangelogException e)
+    {
+      logger.traceException(e);
+    }
+    finally
+    {
+      close(cursor);
+    }
+  }
+
   private boolean isLateQueueBelowThreshold()
   {
     return lateQueue.count() < 100 && lateQueue.bytesCount() < 50000;
@@ -425,16 +426,14 @@
       {
         if (!msgQueue.isEmpty())
         {
-          UpdateMsg msg = msgQueue.first();
-          result = msg.getCSN();
+          result = msgQueue.first().getCSN();
         }
       }
       else
       {
         if (!lateQueue.isEmpty())
         {
-          UpdateMsg msg = lateQueue.first();
-          result = msg.getCSN();
+          result = lateQueue.first().getCSN();
         }
         else
         {

--
Gitblit v1.10.0