public byte[] getBytes(short protocolVersion)
throws UnsupportedEncodingException
{
try
{
ByteStringBuilder byteBuilder = new ByteStringBuilder();
ASN1Writer writer = ASN1.getWriter(byteBuilder);
if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
{
/* put the type of the operation */
byteBuilder.append(MSG_TYPE_REPL_SERVER_MONITOR);
/*
* V4 and above uses integers for its serverIds while V2 and V3
* use shorts.
*/
if (protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
{
byteBuilder.append(senderID);
byteBuilder.append(destination);
}
else
{
byteBuilder.append((short)senderID);
byteBuilder.append((short)destination);
}
}
/* Put the serverStates ... */
writer.writeStartSequence();
/* first put the Replication Server state */
writer.writeStartSequence();
ArrayList<ByteString> cnOctetList =
data.replServerDbState.toASN1ArrayList();
for (ByteString soci : cnOctetList)
{
writer.writeOctetString(soci);
}
writer.writeEndSequence();
// then the LDAP server datas
Set<Integer> servers = data.ldapStates.keySet();
for (Integer sid : servers)
{
ServerState statei = data.ldapStates.get(sid).state;
Long outime = data.ldapStates.get(sid).approxFirstMissingDate;
// retrieves the change numbers as an arrayList of ANSN1OctetString
cnOctetList = statei.toASN1ArrayList();
writer.writeStartSequence();
// a fake changenumber helps storing the LDAP server ID
ChangeNumber cn = new ChangeNumber(outime,1,sid);
writer.writeOctetString(cn.toString());
// the changenumbers that make the state
for (ByteString soci : cnOctetList)
{
writer.writeOctetString(soci);
}
writer.writeEndSequence();
}
// then the RS server datas
servers = data.rsStates.keySet();
for (Integer sid : servers)
{
ServerState statei = data.rsStates.get(sid).state;
Long outime = data.rsStates.get(sid).approxFirstMissingDate;
// retrieves the change numbers as an arrayList of ANSN1OctetString
cnOctetList = statei.toASN1ArrayList();
writer.writeStartSequence();
// a fake changenumber helps storing the LDAP server ID
ChangeNumber cn = new ChangeNumber(outime,0,sid);
writer.writeOctetString(cn.toString());
// the changenumbers that make the state
for (ByteString soci : cnOctetList)
{
writer.writeOctetString(soci);
}
writer.writeEndSequence();
}
writer.writeEndSequence();
if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
{
return byteBuilder.toByteArray();
}
else
{
byte[] temp = byteBuilder.toByteArray();
byte[] senderBytes = String.valueOf(senderID).getBytes("UTF-8");
byte[] destinationBytes = String.valueOf(destination).getBytes("UTF-8");
int length = 1 + 1 + senderBytes.length +