From 597a315998e4d59414a967a7268cf1e7f8006b8c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 26 Sep 2013 07:35:55 +0000
Subject: [PATCH] OPENDJ-1116 Introduce abstraction for the changelog DB

---
 opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
index 2018214..a4c50a6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
@@ -31,6 +31,8 @@
 import java.util.zip.DataFormatException;
 
 import org.opends.server.replication.common.ServerState;
+import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
 
 /**
  * Message sent by a replication server to a directory server in reply to the
@@ -40,7 +42,7 @@
 {
   private int serverId;
   private String serverURL;
-  private String baseDn = null;
+  private DN baseDN;
   private int windowSize;
   private ServerState serverState;
 
@@ -72,9 +74,9 @@
    *
    * @param serverId replication server id
    * @param serverURL replication server URL
-   * @param baseDn base DN for which the ReplServerStartDSMsg is created.
+   * @param baseDN base DN for which the ReplServerStartDSMsg is created.
    * @param windowSize The window size.
-   * @param serverState our ServerState for this baseDn.
+   * @param serverState our ServerState for this baseDN.
    * @param generationId The generationId for this server.
    * @param sslEncryption Whether to continue using SSL to encrypt messages
    *                      after the start messages have been exchanged.
@@ -84,7 +86,7 @@
    * @param connectedDSNumber Number of currently connected DS to the
    *        replication server.
    */
-  public ReplServerStartDSMsg(int serverId, String serverURL, String baseDn,
+  public ReplServerStartDSMsg(int serverId, String serverURL, DN baseDN,
                                int windowSize,
                                ServerState serverState,
                                long generationId,
@@ -97,10 +99,7 @@
     super((short) -1 /* version set when sending */, generationId);
     this.serverId = serverId;
     this.serverURL = serverURL;
-    if (baseDn != null)
-      this.baseDn = baseDn;
-    else
-      this.baseDn = null;
+    this.baseDN = baseDN;
     this.windowSize = windowSize;
     this.serverState = serverState;
     this.sslEncryption = sslEncryption;
@@ -126,7 +125,7 @@
     try
     {
       /* The ReplServerStartDSMsg payload is stored in the form :
-       * <baseDn><serverId><serverURL><windowSize><sslEncryption>
+       * <baseDN><serverId><serverURL><windowSize><sslEncryption>
        * <degradedStatusThreshold><weight><connectedDSNumber>
        * <serverState>
        */
@@ -138,7 +137,7 @@
        * first calculate the length then construct the string
        */
       int length = getNextLength(in, pos);
-      baseDn = new String(in, pos, length, "UTF-8");
+      baseDN = DN.decode(new String(in, pos, length, "UTF-8"));
       pos += length +1;
 
       /*
@@ -202,10 +201,15 @@
       // the ServerState to be the last. This should be changed and we want to
       // have more than one ServerState field.
       serverState = new ServerState(in, pos, in.length - 1);
-    } catch (UnsupportedEncodingException e)
+    }
+    catch (UnsupportedEncodingException e)
     {
       throw new DataFormatException("UTF-8 is not supported by this jvm.");
     }
+    catch (DirectoryException e)
+    {
+      throw new DataFormatException(e.getLocalizedMessage());
+    }
   }
 
   /**
@@ -231,9 +235,9 @@
    *
    * @return the base DN from this ReplServerStartDSMsg.
    */
-  public String getBaseDn()
+  public DN getBaseDN()
   {
-    return baseDn;
+    return baseDN;
   }
 
   /**
@@ -253,11 +257,11 @@
      throws UnsupportedEncodingException
   {
     /* The ReplServerStartDSMsg is stored in the form :
-     * <operation type><baseDn><serverId><serverURL><windowSize><sslEncryption>
+     * <operation type><baseDN><serverId><serverURL><windowSize><sslEncryption>
      * <degradedStatusThreshold><weight><connectedDSNumber>
      * <serverState>
      */
-    byte[] byteDn = baseDn.getBytes("UTF-8");
+    byte[] byteDn = baseDN.toString().getBytes("UTF-8");
     byte[] byteServerId = String.valueOf(serverId).getBytes("UTF-8");
     byte[] byteServerUrl = serverURL.getBytes("UTF-8");
     byte[] byteServerState = serverState.getBytes();
@@ -362,7 +366,7 @@
     return "ReplServerStartDSMsg content: " +
       "\nprotocolVersion: " + protocolVersion +
       "\ngenerationId: " + generationId +
-      "\nbaseDn: " + baseDn +
+      "\nbaseDN: " + baseDN +
       "\ngroupId: " + groupId +
       "\nserverId: " + serverId +
       "\nserverState: " + serverState +

--
Gitblit v1.10.0