sg.edu.nus.protocol
Class Message

java.lang.Object
  extended by sg.edu.nus.protocol.Message
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Message
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Implement a message to be communicated between peers. Each message includes two parts: a head and a body.

Version:
1.0 2006-1-4
Author:
Xu Linhao
See Also:
Serialized Form

Constructor Summary
Message(Head head)
          Construct a confirm message with head only.
Message(Head head, Body body)
          Construct a message with specified head and body.
 
Method Summary
 java.lang.Object clone()
          Clone self.
static Message deserialize(java.io.ObjectInputStream ois)
          Deserialize ObjectInputStream to reconstruct an instance of the Message.
 Body getBody()
          Get the body of the message.
 Head getHead()
          Get the head of the message.
 void serialize(java.io.ObjectOutputStream oos)
          Serialize the message by ObjectOutputStream.
 void setBody(Body body)
          Change the body of the message, if necessary.
 void setHead(Head head)
          Change the head of the message, if necessary.
 java.lang.String toString()
          Override toString() function of java.lang.Object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Message

public Message(Head head,
               Body body)
Construct a message with specified head and body.

Parameters:
head - The head of the message.
body - The body of the message.

Message

public Message(Head head)
Construct a confirm message with head only.

Parameters:
head - The head of the message.
Method Detail

clone

public java.lang.Object clone()
Clone self.

Overrides:
clone in class java.lang.Object
Returns:
The instance of Message.

getHead

public Head getHead()
Get the head of the message.

Returns:
The head of the message.

setHead

public void setHead(Head head)
Change the head of the message, if necessary.

Parameters:
head - The head of the message.

getBody

public Body getBody()
Get the body of the message.

Returns:
The body of the message.

setBody

public void setBody(Body body)
Change the body of the message, if necessary.

Parameters:
body - The body of the message.

serialize

public void serialize(java.io.ObjectOutputStream oos)
Serialize the message by ObjectOutputStream.

Parameters:
oos - the output stream

deserialize

public static Message deserialize(java.io.ObjectInputStream ois)
Deserialize ObjectInputStream to reconstruct an instance of the Message.

Returns:
The Message object.

toString

public java.lang.String toString()
Override toString() function of java.lang.Object.

Overrides:
toString in class java.lang.Object
Returns:
A string that describes the content of the body.