ist.palcom.mal
Class Message

java.lang.Object
  extended by ist.palcom.mal.Message
Direct Known Subclasses:
AbstractRoutingMessage, IRMessageWrapper, MultiPartMessage, SimpleMessage

public class Message
extends java.lang.Object

Message implement the common message format.


Field Summary
static byte TYPE_MULTIPART
           
static byte TYPE_NONE
          Special value used when there is no data
static byte TYPE_SINGLE
           
 
Constructor Summary
Message()
           
Message(byte dataType)
           
Message(byte[] data)
          Create a message of TYPE_SINGLE with the given data.
Message(byte[] data, int offset, int dataLength)
          Create a message of TYPE_SINGLE with the given data.
Message(byte dataType, byte[] data)
           
Message(byte dataType, byte[] data, int offset, int dataLength)
           
Message(MessageHeaderNode node)
          Create a message of type TYPE_NONE containing only a message header node.
Message(MessageHeaderNode node, byte[] rawData)
          Create a message of type TYPE_NONE containing a message header node and a byte array with all the data unhandled.
 
Method Summary
 void addPart(Message part)
           
 Message getCopy()
           
 byte[] getData()
           
 int getDataLength()
          Returns the length of the data in the message (zero if there is no data).
 LinkedList getHeaderNodes()
           
 int getHeaderNodesLength()
          Get the length of all the current header nodes in the message.
 int getNodeAndDataLength()
          Returns the length of the data including the header part in the message.
 int getNumberOfParts()
           
 Message getPart(int index)
           
 byte[] getRawData()
           
 java.lang.String getReceiverDeviceID()
          Returns the receiver deviceID.
 Selector getReceiverSelector()
          Returns the receiver selector.
 URL getReceiverURL()
          Returns the receiver URL (protocol-specific URL), or null if it has not been set.
 java.lang.String getSenderDeviceID()
          Returns the sender deviceID.
 Selector getSenderSelector()
          Returns the sender selector.
 URL getSenderURL()
          Returns the sender URL (protocol-specific URL), or null if it has not been set.
 int getTotalLength()
          Returns the total length of the message, including the length of the header with length and type.
 byte getType()
          Returns the data type of the message.
 void insertHeaderNodeAfter(MessageHeaderNode newNode, MessageHeaderNode linkedNode)
          Insert a message header node after the specified node into the linked list with nodes related to this message.
 void insertHeaderNodeFirst(MessageHeaderNode hNode)
          Insert a message header node first in the linked list with nodes related to this message.
 void insertHeaderNodeLast(MessageHeaderNode hNode)
          Insert a message header node last in the linked list with nodes related to this message.
static Message parse(byte[] buffer, int offset, int length)
          Factory method for parsing a Message from a byte array.
 void removePart(Message part)
           
 void setData(byte[] data)
          Sets the data of the message (used when the data type is of TYPE_SINGLE).
 void setHeaderNodes(LinkedList headerNodes)
          Set the linked list with message header nodes to the specified list.
 void setReceiverDeviceID(java.lang.String deviceID)
          Sets the receiver deviceID of this message.
 void setReceiverSelector(Selector selector)
          Sets the receiver selector.
 void setReceiverURL(URL url)
          Sets the receiver URL of this message (protocol-specific URL, set when a message has been received over the network).
 void setSenderDeviceID(java.lang.String deviceID)
          Sets the sender deviceID of this message.
 void setSenderSelector(Selector selector)
          Sets the sender selector of this message.
 void setSenderURL(URL url)
          Sets the sender URL of this message (protocol-specific URL, set when a message has been received over the network).
 int write(byte[] buffer, int offset)
          Write the message to a buffer, starting at index offset.
protected  int writeData(byte[] buffer, int offset)
          Write the data of the message to buffer, starting at index offset in buffer.
 int writeDataNodeToBuffer(byte[] buffer, int offset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_NONE

public static final byte TYPE_NONE
Special value used when there is no data

See Also:
Constant Field Values

TYPE_SINGLE

public static final byte TYPE_SINGLE
See Also:
Constant Field Values

TYPE_MULTIPART

public static final byte TYPE_MULTIPART
See Also:
Constant Field Values
Constructor Detail

Message

public Message()

Message

public Message(MessageHeaderNode node,
               byte[] rawData)
Create a message of type TYPE_NONE containing a message header node and a byte array with all the data unhandled.


Message

public Message(MessageHeaderNode node)
Create a message of type TYPE_NONE containing only a message header node.


Message

public Message(byte[] data)
Create a message of TYPE_SINGLE with the given data.


Message

public Message(byte[] data,
               int offset,
               int dataLength)
Create a message of TYPE_SINGLE with the given data.


Message

public Message(byte dataType)

Message

public Message(byte dataType,
               byte[] data)

Message

public Message(byte dataType,
               byte[] data,
               int offset,
               int dataLength)
Method Detail

getDataLength

public int getDataLength()
Returns the length of the data in the message (zero if there is no data).


getNodeAndDataLength

public int getNodeAndDataLength()
Returns the length of the data including the header part in the message.


getTotalLength

public int getTotalLength()
Returns the total length of the message, including the length of the header with length and type.


getHeaderNodesLength

public int getHeaderNodesLength()
Get the length of all the current header nodes in the message. This is the same as the offset on the array with raw data that has been handled.


getType

public byte getType()
Returns the data type of the message.


getData

public byte[] getData()
Returns:
The data of the message (null if the data type is not of TYPE_SINGLE).

setData

public void setData(byte[] data)
Sets the data of the message (used when the data type is of TYPE_SINGLE).


getRawData

public byte[] getRawData()
Returns:
The entire raw data array with all the information.

getNumberOfParts

public int getNumberOfParts()

getPart

public Message getPart(int index)

addPart

public void addPart(Message part)

removePart

public void removePart(Message part)

setHeaderNodes

public void setHeaderNodes(LinkedList headerNodes)
Set the linked list with message header nodes to the specified list.

Parameters:
headerNodes - LinkedList to set

insertHeaderNodeLast

public void insertHeaderNodeLast(MessageHeaderNode hNode)
Insert a message header node last in the linked list with nodes related to this message.

Parameters:
hNode - MessageHeaderNode to insert

insertHeaderNodeAfter

public void insertHeaderNodeAfter(MessageHeaderNode newNode,
                                  MessageHeaderNode linkedNode)
Insert a message header node after the specified node into the linked list with nodes related to this message.

Parameters:
newNode - MessageHeaderNode to insert
linkedNode - MessageHeaderNode to insert after

insertHeaderNodeFirst

public void insertHeaderNodeFirst(MessageHeaderNode hNode)
Insert a message header node first in the linked list with nodes related to this message.

Parameters:
hNode - MessageHeaderNode to insert

getHeaderNodes

public LinkedList getHeaderNodes()
Returns:
a LinkedList with all the message header nodes.

getSenderDeviceID

public java.lang.String getSenderDeviceID()
Returns the sender deviceID.


setSenderDeviceID

public void setSenderDeviceID(java.lang.String deviceID)
Sets the sender deviceID of this message.


getSenderSelector

public Selector getSenderSelector()
Returns the sender selector.


setSenderSelector

public void setSenderSelector(Selector selector)
Sets the sender selector of this message.


getReceiverDeviceID

public java.lang.String getReceiverDeviceID()
Returns the receiver deviceID.


setReceiverDeviceID

public void setReceiverDeviceID(java.lang.String deviceID)
Sets the receiver deviceID of this message.


getReceiverSelector

public Selector getReceiverSelector()
Returns the receiver selector.


setReceiverSelector

public void setReceiverSelector(Selector selector)
Sets the receiver selector.


getSenderURL

public URL getSenderURL()
Returns the sender URL (protocol-specific URL), or null if it has not been set.


setSenderURL

public void setSenderURL(URL url)
Sets the sender URL of this message (protocol-specific URL, set when a message has been received over the network).


getReceiverURL

public URL getReceiverURL()
Returns the receiver URL (protocol-specific URL), or null if it has not been set.


setReceiverURL

public void setReceiverURL(URL url)
Sets the receiver URL of this message (protocol-specific URL, set when a message has been received over the network).


write

public int write(byte[] buffer,
                 int offset)
Write the message to a buffer, starting at index offset.

Returns:
The number of bytes written.
Throws:
java.lang.IndexOutOfBoundsException - if the buffer is too small.

writeDataNodeToBuffer

public int writeDataNodeToBuffer(byte[] buffer,
                                 int offset)
Returns:
The number of bytes written.

writeData

protected int writeData(byte[] buffer,
                        int offset)
Write the data of the message to buffer, starting at index offset in buffer.

Returns:
The number of bytes written.

getCopy

public Message getCopy()
Returns:
A copy of the message, with the same data in new buffer(s).

parse

public static Message parse(byte[] buffer,
                            int offset,
                            int length)
Factory method for parsing a Message from a byte array. The parsing starts at offset and parses to the end of a message, or at most length bytes.

Returns:
The message read, or null if no message could be read.