org.opennms.protocols.icmpd
Class MessageHeader

java.lang.Object
  |
  +--org.opennms.protocols.icmpd.MessageHeader
Direct Known Subclasses:
CtrlCloseMessage, CtrlFilterMessage, CtrlResponseMessage, CtrlResumeMessage, CtrlSuspendMessage, DataRecvMessage, DataSendMessage

public class MessageHeader
extends Object

The base message class for communications with the icmp daemon. The basic message begins with an eight byte header. The header consist of a type, code, sequence number, length, and reserved field

 +--------+--------+----------------+
 | Type   |  Code  |   Sequence #   |
 +--------+--------+----------------+
 |    Length       |   Reserved     |
 +-----------------+----------------+
 


Field Summary
protected  byte m_code
          The class code
protected  short m_length
          The total length of the message.
protected  short m_reserved
          Reserved for use by different messages.
protected  short m_sequence
          The class sequence
protected  byte m_type
          The class type
private static short sm_seq
           
static byte TYPE_CONTROL
           
static byte TYPE_DATA
           
 
Constructor Summary
(package private) MessageHeader()
          Creates a default message header
(package private) MessageHeader(MessageHeader hdr)
          Creates a duplicate of the passed header.
 
Method Summary
static int align4(int sz)
          Aligns the number by making sure the number is divisable by four.
 byte getCode()
          Returns the code for the object.
 int getLength()
          returns the current length of the entire message.
 short getSequence()
          Returns the current sequence of the object.
 byte getType()
          Returns the type for the object.
static int makeInt(byte a, byte b, byte c, byte d)
          Converts the four passed bytes into a single 32-bit value.
static short makeShort(byte a, byte b)
          Converts two eight bit bytes to a sixteen bit short.
static short nextSequenceId()
          Returns the next sequence identitifer for the class.
(package private)  void read(InputStream istream)
          Reads in the first 8 bytes of the message.
 short setSequence(short seq)
          sets the current sequence of the object
(package private)  void write(OutputStream ostream)
          Write the header to the output stream, effectively seralizing the object for the icmp daemon.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_type

protected byte m_type
The class type

m_code

protected byte m_code
The class code

m_sequence

protected short m_sequence
The class sequence

m_length

protected short m_length
The total length of the message.

m_reserved

protected short m_reserved
Reserved for use by different messages.

sm_seq

private static short sm_seq

TYPE_CONTROL

public static final byte TYPE_CONTROL

TYPE_DATA

public static final byte TYPE_DATA
Constructor Detail

MessageHeader

MessageHeader()
Creates a default message header

MessageHeader

MessageHeader(MessageHeader hdr)
Creates a duplicate of the passed header.
Parameters:
hdr - The header object to duplicate.
Method Detail

nextSequenceId

public static short nextSequenceId()
Returns the next sequence identitifer for the class.
Returns:
The next unique sequence identifier.

align4

public static int align4(int sz)
Aligns the number by making sure the number is divisable by four. If the number is not divisiable by four then the number is rouned up to the next boundry number.
Parameters:
sz - The number to align
Returns:
The aligned value

makeShort

public static short makeShort(byte a,
                              byte b)
Converts two eight bit bytes to a sixteen bit short. The first byte becomes the high order byte and the second byte becomes the lower order byte.
Parameters:
a - The high order byte.
b - The lo order byte.
Returns:
The converted 16-bit number.

makeInt

public static int makeInt(byte a,
                          byte b,
                          byte c,
                          byte d)
Converts the four passed bytes into a single 32-bit value. The bytes are converted with the first parameter becomming the hi order byte and the last parameter becoming the lo order byte.
Parameters:
a - The high order byte, bit position 31-24
b - Bit positions 23-16.
c - Bit positions 15-8.
d - The lo order byte, bit position 7-0.
Returns:
The built 32-bit value.

write

void write(OutputStream ostream)
     throws IOException
Write the header to the output stream, effectively seralizing the object for the icmp daemon.
Parameters:
ostream - The output stream
Throws:
IOException - Thrown if an error occurs with ostream.

read

void read(InputStream istream)
    throws IOException
Reads in the first 8 bytes of the message. This is then converted to the member fields of the object. If an error occurs then an excetpion is thown.
Parameters:
istream - The input stream contain the "seralized" object.
Throws:
IOException - Thrown if an error occurs with ostream.

getType

public byte getType()
Returns the type for the object.

getCode

public byte getCode()
Returns the code for the object.

getSequence

public short getSequence()
Returns the current sequence of the object.

setSequence

public short setSequence(short seq)
sets the current sequence of the object

getLength

public int getLength()
returns the current length of the entire message. This would be the number of bytes seralized to the icmp daemon if a message were sent.