utilities
Class Message

java.lang.Object
  |
  +--utilities.Message
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
KQMLMessage, LengthPrefixMessage

public class Message
extends java.lang.Object
implements java.lang.Cloneable

Base inter-agent (or whatever..) message class.


Constructor Summary
Message()
          Constructor, dosen't do anything.
Message(java.lang.Object c)
          Constructor
Message(java.lang.Object c, java.lang.String da, int dp)
          Constructor
Message(java.lang.Object c, java.lang.String sa, int sp, java.lang.String da, int dp)
          Constructor
 
Method Summary
 java.lang.Object clone()
          Clone
 java.lang.String contentData()
          Returns the string after the first word in the content (used to get the supposed data out of the content).
 java.lang.String contentData(java.lang.String str)
          Returns the string after the first word in the string.
 java.lang.String contentWord()
          Returns the first word in the content (used to determine the type of content).
 java.lang.String contentWord(java.lang.String str)
          Returns the first word in the string.
 Connection getConnection()
           
 java.lang.Object getContent()
          Accessor functions
 java.lang.String getData()
           
 java.lang.String getDestAddr()
           
 int getDestPort()
           
 int getReceiveTime()
           
 int getSendTime()
           
 java.lang.String getSourceAddr()
           
 int getSourcePort()
           
static java.lang.String receive(java.io.BufferedReader b)
          Same as above, but uses MSG_DELIM as the delimiter.
static java.lang.String receive(java.io.BufferedReader b, int length)
          Recieves a message (string) from a stream.
static java.lang.String receive(java.io.BufferedReader b, java.lang.String d)
          Recieves a message (string) from a stream.
 boolean send(java.io.BufferedWriter b)
          Same as above, but uses MSG_DELIM as the delimiter.
 boolean send(java.io.BufferedWriter b, java.lang.String d)
          Sends the message across a stream
 void setConnection(Connection c)
           
 void setContent(java.lang.Object c)
           
 void setData(java.lang.String d)
           
 void setDestAddr(java.lang.String da)
           
 void setDestPort(int dp)
           
 void setReceiveTime(int t)
           
 void setSendTime(int t)
           
 void setSourceAddr(java.lang.String sa)
           
 void setSourcePort(int sp)
           
 java.lang.String toString()
          Stringify's the message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Message

public Message()
Constructor, dosen't do anything.

Message

public Message(java.lang.Object c)
Constructor
Parameters:
c - The message to send

Message

public Message(java.lang.Object c,
               java.lang.String da,
               int dp)
Constructor
Parameters:
c - The message to send
da - The destination address
dp - The destination port

Message

public Message(java.lang.Object c,
               java.lang.String sa,
               int sp,
               java.lang.String da,
               int dp)
Constructor
Parameters:
c - The message to send
sa - The source address
sp - The source port
da - The destination address
dp - The destination port
Method Detail

getContent

public java.lang.Object getContent()
Accessor functions

setContent

public void setContent(java.lang.Object c)

getData

public java.lang.String getData()

setData

public void setData(java.lang.String d)

getConnection

public Connection getConnection()

setConnection

public void setConnection(Connection c)

getSourceAddr

public java.lang.String getSourceAddr()

setSourceAddr

public void setSourceAddr(java.lang.String sa)

getSourcePort

public int getSourcePort()

setSourcePort

public void setSourcePort(int sp)

getDestAddr

public java.lang.String getDestAddr()

setDestAddr

public void setDestAddr(java.lang.String da)

getDestPort

public int getDestPort()

setDestPort

public void setDestPort(int dp)

getSendTime

public int getSendTime()

setSendTime

public void setSendTime(int t)

getReceiveTime

public int getReceiveTime()

setReceiveTime

public void setReceiveTime(int t)

contentWord

public java.lang.String contentWord()
Returns the first word in the content (used to determine the type of content).
Returns:
The word, or an empty string if none found

contentWord

public java.lang.String contentWord(java.lang.String str)
Returns the first word in the string. Uses whitespace as the delimeter.
Parameters:
str - The string to examine
Returns:
The word, or an empty string if none found

contentData

public java.lang.String contentData()
Returns the string after the first word in the content (used to get the supposed data out of the content).
Returns:
The data, or an empty string if none found

contentData

public java.lang.String contentData(java.lang.String str)
Returns the string after the first word in the string. Uses whitespace as the delimeter.
Parameters:
str - The string to examine
Returns:
The data, or an empty string if none found

send

public boolean send(java.io.BufferedWriter b)
Same as above, but uses MSG_DELIM as the delimiter. This method retained for compatibility. Sends the message across a stream
Parameters:
b - The writer to use to send the message

send

public boolean send(java.io.BufferedWriter b,
                    java.lang.String d)
Sends the message across a stream
Parameters:
b - The writer to use to send the message
d - The message delimiter

receive

public static java.lang.String receive(java.io.BufferedReader b,
                                       java.lang.String d)
Recieves a message (string) from a stream. Typically this should be called to fill in the data parameter of the Message constructor. This is a blocking receive, use the ready() function of BufferedReader to determine beforehand if a message is available.
Parameters:
b - The reader used to get the message
d - The message delimiter
Returns:
The message, or null if error occurs

receive

public static java.lang.String receive(java.io.BufferedReader b)
Same as above, but uses MSG_DELIM as the delimiter. This method retained for compatibility.
Parameters:
b - The reader used to get the message
Returns:
The message, or null if error occurs

receive

public static java.lang.String receive(java.io.BufferedReader b,
                                       int length)
Recieves a message (string) from a stream. Typically this should be called to fill in the data parameter of the Message constructor. This is a blocking receive, use the ready() function of BufferedReader to determine beforehand if a message is available.
Parameters:
b - The reader used to get the message
length - The length of the data to read
Returns:
The message, or null if error occurs

clone

public java.lang.Object clone()
Clone

toString

public java.lang.String toString()
Stringify's the message. For logging, not transfer.
Overrides:
toString in class java.lang.Object