From bd724fad0c954f1e607a0a90cbca3eb41d1f2460 Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Mon, 17 Sep 2007 08:00:37 +0000
Subject: [PATCH] Fixes repl init and total update #2253 #845 #1733
---
opends/src/server/org/opends/server/replication/protocol/ResetGenerationId.java | 62 ++++++++++++++++++++++++++-----
1 files changed, 52 insertions(+), 10 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationId.java b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationId.java
index 0945377..ace1403 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationId.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationId.java
@@ -26,7 +26,10 @@
*/
package org.opends.server.replication.protocol;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
@@ -38,13 +41,15 @@
Serializable
{
private static final long serialVersionUID = 7657049716115572226L;
-
+ private long generationId;
/**
* Creates a new message.
+ * @param generationId The new reference value of the generationID.
*/
- public ResetGenerationId()
+ public ResetGenerationId(long generationId)
{
+ this.generationId = generationId;
}
/**
@@ -57,9 +62,24 @@
*/
public ResetGenerationId(byte[] in) throws DataFormatException
{
- if (in[0] != MSG_TYPE_RESET_GENERATION_ID)
- throw new
- DataFormatException("input is not a valid GenerationId Message");
+ try
+ {
+ if (in[0] != MSG_TYPE_RESET_GENERATION_ID)
+ throw new
+ DataFormatException("input is not a valid GenerationId Message");
+
+ int pos = 1;
+
+ /* read the generationId */
+ int length = getNextLength(in, pos);
+ generationId = Long.valueOf(new String(in, pos, length,
+ "UTF-8"));
+ pos += length +1;
+ } catch (UnsupportedEncodingException e)
+ {
+ throw new DataFormatException("UTF-8 is not supported by this jvm.");
+ }
+
}
/**
@@ -68,11 +88,33 @@
@Override
public byte[] getBytes()
{
- int length = 1;
- byte[] resultByteArray = new byte[length];
+ try
+ {
+ ByteArrayOutputStream oStream = new ByteArrayOutputStream();
- /* put the type of the operation */
- resultByteArray[0] = MSG_TYPE_RESET_GENERATION_ID;
- return resultByteArray;
+ /* Put the message type */
+ oStream.write(MSG_TYPE_RESET_GENERATION_ID);
+
+ // Put the generationId
+ oStream.write(String.valueOf(generationId).getBytes("UTF-8"));
+ oStream.write(0);
+
+ return oStream.toByteArray();
+ }
+ catch (IOException e)
+ {
+ // never happens
+ return null;
+ }
+ }
+
+ /**
+ * Returns the generation Id set in this message.
+ * @return the value of the generation ID.
+ *
+ */
+ public long getGenerationId()
+ {
+ return this.generationId;
}
}
--
Gitblit v1.10.0