* @throws DataFormatException If the byte array does not contain a valid
* encoded form of the ServerStartMessage.
*/
public MonitorMsg(byte[] in, short version) throws DataFormatException
{
ByteSequenceReader reader = ByteString.wrap(in).asReader();
if (version == ProtocolVersion.REPLICATION_PROTOCOL_V1)
{
try
{
/* first byte is the type */
if (in[0] != MSG_TYPE_REPL_SERVER_MONITOR)
throw new DataFormatException("input is not a valid " +
this.getClass().getCanonicalName());
int pos = 1;
// sender
int length = getNextLength(in, pos);
String senderIDString = new String(in, pos, length, "UTF-8");
this.senderID = Integer.valueOf(senderIDString);
pos += length +1;
// destination
length = getNextLength(in, pos);
String destinationString = new String(in, pos, length, "UTF-8");
this.destination = Integer.valueOf(destinationString);
pos += length +1;
reader.position(pos);
}
catch (UnsupportedEncodingException e)
{
throw new DataFormatException("UTF-8 is not supported by this jvm.");
}
}
else
{
if (reader.get() != MSG_TYPE_REPL_SERVER_MONITOR)
throw new DataFormatException("input is not a valid " +
this.getClass().getCanonicalName());
/*
* V4 and above uses integers for its serverIds while V2 and V3
* use shorts.
*/
if (version <= ProtocolVersion.REPLICATION_PROTOCOL_V3)
{
// sender
this.senderID = reader.getShort();
// destination
this.destination = reader.getShort();
}
else
{
// sender
this.senderID = reader.getInt();
// destination
this.destination = reader.getInt();
}
}
ASN1Reader asn1Reader = ASN1.getReader(reader);