com.mindtree.techworks.insight.remoteprotocol.spi
Class PacketHeader

java.lang.Object
  extended by com.mindtree.techworks.insight.remoteprotocol.spi.PacketHeader
All Implemented Interfaces:
java.io.Serializable

public class PacketHeader
extends java.lang.Object
implements java.io.Serializable

This is the common Header for all DataPackets. The format of the Packet Header is as follows

      0               8              16              24              32
      | . . . . . . . | . . . . . . . | . . . . . . . | . . . . . . . |
      
      +---------------+---------------+-------------------------------+
      |  IDENTIFIER   |    VERSION    |      PHL      |  MESSAGE TYPE |
      +---------------+---------------+-------------------------------+
      |     FLAGS     |      0xFF     |       HEADER CHECKSUM         |
      +-------------------------------+-------------------------------+
      |      SOURCE IDENTIFIER        |      MESSAGE SEQUENCE         |
      +-------------------------------+-------------------------------+
      |                          DATA LENGTH                          |
      +---------------------------------------------------------------+
      |             DATA AND PADDING (Multiples of 8 bits)            |
     <                                                               <
      >                                                               >
      |                                                               |
      +---------------------------------------------------------------+
      
      | . . . . . . . | . . . . . . . | . . . . . . . | . . . . . . . |
      0               8              16              24              32
      
      IDENTIFIER:               A constant (01001001 / 0x49) identifying that the 
                                        packet is an Insight packet. (The number is the 
                                        ASCII for 'I')
      
      VERSION:                  The version of the packet. Currently 0x01
      
      PHL:                              Packet Header Length. Basically identifies the start
                                        of the data content
      
      MESSAGE TYPE:             The identifier for the message. Currently the 
                                        following will be used:
        0x01    Startup         The content in the Data field will contain the 
                                                format specified.
        0x02    Log Data        The content will be data from the log event.
        0x03    Shutdown        The content will be empty.
      
      FLAGS:                            Currently Unused
      
      HEADER CHECKSUM:  The checksum of the header with the checksum fields  
                                        set to 0xFF.
      
      SOURCE IDENTIFIER:        This will uniquely identify a source for a message.  
                                        This field will be generated by the source (sender)  
                                        and Insight will cache it on receipt of the first  
                                        message from the source. All messages from the same  
                                        source will be associated.
      
      MESSAGE SEQUENCE:         The sequence number of the message. Ideally the  
                                        Startup message will have the sequence number 0x00,  
                                        and it will roll over after 0xFF.
      
      DATA LENGTH:              Number of bytes in the data part.
 

For details on the different supported message types, see the static fields in the MessageType class.

The format of the data content for the different message types are:

Version:
$Revision: 1.1 $ $Date: 2005/08/03 14:39:18 $
Author:
Bindul Bhowmik
See Also:
DataPacket, Serialized Form

Field Summary
static byte INSIGHT_PACKET_IDENTIFIER
          The identifier for an Insight Packet.
static byte PACKET_HEADER_LENGTH
          The packet header length for this version.
 
Constructor Summary
PacketHeader()
          Creates an instance of the packet header
PacketHeader(byte[] packetData)
          Creates an instance of the header from the byte array passed in.
 
Method Summary
 int getDataLength()
          Returns the dataLength
 byte getFlags()
          Returns the flags
 short getHeaderChecksum()
          Returns the headerChecksum
 short getMessageSequence()
          Returns the messageSequence
 MessageType getMessageType()
          Returns the messageType
 byte[] getPacketHeaderAsByteArray()
          Gets the packet Header as a byte array
 byte getPacketHeaderLength()
          Returns the packetHeaderLength
 short getSourceIdentifier()
          Returns the sourceIdentifier
 byte getVersion()
          Returns the version
 void recalculateHeader(PacketDataContent content)
          Recalculates the Header for this packet using the PacketDataContent field passed in.
 void setDataLength(int dataLength)
          Sets the dataLength
 void setFlags(byte flags)
          Sets the flags
 void setMessageSequence(short messageSequence)
          Sets the messageSequence
 void setMessageType(MessageType messageType)
          Sets the messageType
 void setSourceIdentifier(short sourceIdentifier)
          Sets the sourceIdentifier
 void setVersion(byte version)
          Sets the version
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSIGHT_PACKET_IDENTIFIER

public static final byte INSIGHT_PACKET_IDENTIFIER
The identifier for an Insight Packet. Always ASCII - I

See Also:
Constant Field Values

PACKET_HEADER_LENGTH

public static final byte PACKET_HEADER_LENGTH
The packet header length for this version.

See Also:
Constant Field Values
Constructor Detail

PacketHeader

public PacketHeader()
Creates an instance of the packet header


PacketHeader

public PacketHeader(byte[] packetData)
             throws RemoteProtocolException
Creates an instance of the header from the byte array passed in.

Parameters:
packetData - The byte array representing the header
Throws:
RemoteProtocolException - If the header is not well formatted.
Method Detail

getDataLength

public int getDataLength()
Returns the dataLength

Returns:
Returns the dataLength.

setDataLength

public void setDataLength(int dataLength)
Sets the dataLength

Parameters:
dataLength - The dataLength to set.

getFlags

public byte getFlags()
Returns the flags

Returns:
Returns the flags.

setFlags

public void setFlags(byte flags)
Sets the flags

Parameters:
flags - The flags to set.

getMessageSequence

public short getMessageSequence()
Returns the messageSequence

Returns:
Returns the messageSequence.

setMessageSequence

public void setMessageSequence(short messageSequence)
Sets the messageSequence

Parameters:
messageSequence - The messageSequence to set.

getMessageType

public MessageType getMessageType()
Returns the messageType

Returns:
Returns the messageType.

setMessageType

public void setMessageType(MessageType messageType)
Sets the messageType

Parameters:
messageType - The messageType to set.

getSourceIdentifier

public short getSourceIdentifier()
Returns the sourceIdentifier

Returns:
Returns the sourceIdentifier.

setSourceIdentifier

public void setSourceIdentifier(short sourceIdentifier)
Sets the sourceIdentifier

Parameters:
sourceIdentifier - The sourceIdentifier to set.

getVersion

public byte getVersion()
Returns the version

Returns:
Returns the version.

setVersion

public void setVersion(byte version)
Sets the version

Parameters:
version - The version to set.

getHeaderChecksum

public short getHeaderChecksum()
Returns the headerChecksum

Returns:
Returns the headerChecksum.

getPacketHeaderLength

public byte getPacketHeaderLength()
Returns the packetHeaderLength

Returns:
Returns the packetHeaderLength.

getPacketHeaderAsByteArray

public byte[] getPacketHeaderAsByteArray()
Gets the packet Header as a byte array

Returns:
A byte array containing the data from the header.

recalculateHeader

public void recalculateHeader(PacketDataContent content)
Recalculates the Header for this packet using the PacketDataContent field passed in. The only field in the header directly dependent on the content of the packet is the DATA LENGTH field. However changing this field changes the HEADER CHECKSUM, hence this method changes the checksum too. In later versions of the DataPacket if variable length headers are allowed, then the PHL field would also be set in this method.

Parameters:
content - The data content accompanying this packet header


Copyright © 2003-2008 MindTree Consulting Ltd.. All Rights Reserved.