From 88cfe5045d77d433ce02b0ef10ee84c9d4fb15e2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 23 May 2014 15:17:15 +0000
Subject: [PATCH] (CR-3599) Convert all protocols message to use ByteArrayBuilder + ByteArrayScanner

---
 opends/src/server/org/opends/server/replication/protocol/ChangeStatusMsg.java |   53 +++++++++++++++++++----------------------------------
 1 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/protocol/ChangeStatusMsg.java b/opends/src/server/org/opends/server/replication/protocol/ChangeStatusMsg.java
index f0a3b5c..3e55c30 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ChangeStatusMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ChangeStatusMsg.java
@@ -22,11 +22,12 @@
  *
  *
  *      Copyright 2008 Sun Microsystems, Inc.
- *      Portions copyright 2013 ForgeRock AS.
+ *      Portions copyright 2013-2014 ForgeRock AS.
  */
 package org.opends.server.replication.protocol;
 
 import java.util.zip.DataFormatException;
+
 import org.opends.server.replication.common.ServerStatus;
 
 /**
@@ -36,10 +37,10 @@
  */
 public class ChangeStatusMsg extends ReplicationMsg
 {
-  // The status we want the DS to enter (used when from RS to DS)
-  private ServerStatus requestedStatus = ServerStatus.INVALID_STATUS;
-  // The new status the DS just entered (used when from DS to RS)
-  private ServerStatus newStatus = ServerStatus.INVALID_STATUS;
+  /** The status we want the DS to enter (used when from RS to DS) */
+  private final ServerStatus requestedStatus;
+  /** The new status the DS just entered (used when from DS to RS) */
+  private ServerStatus newStatus;
 
   /**
    * Create a new ChangeStatusMsg.
@@ -61,25 +62,19 @@
    * @throws DataFormatException If the byte array does not contain a valid
    *                             encoded form of the ChangeStatusMsg.
    */
-  public ChangeStatusMsg(byte[] encodedMsg) throws DataFormatException
+  ChangeStatusMsg(byte[] encodedMsg) throws DataFormatException
   {
     /*
      * The message is stored in the form:
      * <message type><requested status><new status>
      */
-
-    /* First byte is the type */
-    if (encodedMsg[0] != ReplicationMsg.MSG_TYPE_CHANGE_STATUS)
-    {
-      throw new DataFormatException("byte[] is not a valid msg");
-    }
-
     try
     {
-      /* Then the requested status */
+      if (encodedMsg[0] != ReplicationMsg.MSG_TYPE_CHANGE_STATUS)
+      {
+        throw new DataFormatException("byte[] is not a valid msg");
+      }
       requestedStatus = ServerStatus.valueOf(encodedMsg[1]);
-
-      /* Then the new status */
       newStatus = ServerStatus.valueOf(encodedMsg[2]);
     } catch (IllegalArgumentException e)
     {
@@ -87,9 +82,7 @@
     }
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public byte[] getBytes(short protocolVersion)
   {
@@ -97,18 +90,12 @@
      * The message is stored in the form:
      * <message type><requested status><new status>
      */
-    byte[] encodedMsg = new byte[3];
-
-    /* Put the type of the operation */
-    encodedMsg[0] = ReplicationMsg.MSG_TYPE_CHANGE_STATUS;
-
-    /* Put the requested status */
-    encodedMsg[1] = requestedStatus.getValue();
-
-    /* Put the requested status */
-    encodedMsg[2] = newStatus.getValue();
-
-    return encodedMsg;
+    return new byte[]
+    {
+      ReplicationMsg.MSG_TYPE_CHANGE_STATUS,
+      requestedStatus.getValue(),
+      newStatus.getValue()
+    };
   }
 
   /**
@@ -129,9 +116,7 @@
     return newStatus;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public String toString()
   {

--
Gitblit v1.10.0