From dfbe880eb338a1d752ce790f689b5133761d7079 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

---
 opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java b/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
index e433e83..6194c85 100644
--- a/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
@@ -30,6 +30,9 @@
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
 
+import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
+
 /**
  * This message is part of the replication protocol.
  * This message is sent by a server to one or several servers as the
@@ -37,15 +40,16 @@
  */
 public class InitializeTargetMsg extends RoutableMsg
 {
-  private String baseDN = null;
+  private DN baseDN;
 
-  // Specifies the number of entries expected to be exported.
+  /** Specifies the number of entries expected to be exported. */
   private long entryCount;
 
-  // Specifies the serverID of the server that requested this export
-  // to happen. It allows a server that previously sent an
-  // InitializeRequestMessage to know that the current message
-  // is related to its own request.
+  /**
+   * Specifies the serverID of the server that requested this export to happen.
+   * It allows a server that previously sent an InitializeRequestMessage to know
+   * that the current message is related to its own request.
+   */
   private int requestorID;
 
   private int initWindow;
@@ -55,16 +59,16 @@
    *
    * @param baseDN     The base DN for which the InitializeMessage is created.
    * @param serverID   The serverID of the server that sends this message.
-   * @param target     The destination of this message.
-   * @param target2    The server that initiates this export.
+   * @param destination     The destination of this message.
+   * @param requestorID    The server that initiates this export.
    * @param entryCount The count of entries that will be sent.
    * @param initWindow the initialization window.
    */
-  public InitializeTargetMsg(String baseDN, int serverID,
-      int target, int target2, long entryCount, int initWindow)
+  public InitializeTargetMsg(DN baseDN, int serverID,
+      int destination, int requestorID, long entryCount, int initWindow)
   {
-    super(serverID, target);
-    this.requestorID = target2;
+    super(serverID, destination);
+    this.requestorID = requestorID;
     this.baseDN = baseDN;
     this.entryCount = entryCount;
     this.initWindow = initWindow; // V4
@@ -95,9 +99,9 @@
       this.destination = Integer.valueOf(destinationString);
       pos += length +1;
 
-      // baseDn
+      // baseDN
       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;
 
       // sender
@@ -131,6 +135,10 @@
     {
       throw new DataFormatException("UTF-8 is not supported by this jvm.");
     }
+    catch (DirectoryException e)
+    {
+      throw new DataFormatException(e.getLocalizedMessage());
+    }
   }
 
   /**
@@ -159,7 +167,7 @@
    *
    * @return the base DN
    */
-  public String getBaseDN()
+  public DN getBaseDN()
   {
     return this.baseDN;
   }
@@ -188,7 +196,7 @@
     try
     {
       byte[] byteDestination = String.valueOf(destination).getBytes("UTF-8");
-      byte[] byteDn = baseDN.getBytes("UTF-8");
+      byte[] byteDn = baseDN.toString().getBytes("UTF-8");
       byte[] byteSender = String.valueOf(senderID).getBytes("UTF-8");
       byte[] byteRequestor = String.valueOf(requestorID).getBytes("UTF-8");
       byte[] byteEntryCount = String.valueOf(entryCount).getBytes("UTF-8");

--
Gitblit v1.10.0