moses.message
Class Message

java.lang.Object
  |
  +--moses.message.Message
All Implemented Interfaces:
java.lang.Cloneable

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

This class represents in a single object all the messages that can possibly circulate between agent-controller, controller-controller and controller-external_member.

The class only offers two methods concerned with serialization and deserialization of a message to and from a DataInput(Output)Stream (Java default serialization mechanism is not an efficient alternative).

The class has a polymorphic behavior. It declares a pool of variable, representing all the possible fields in all the possible messages, and a number of indicator flags (int). Depending on the value of the flags, only certain variables in the pool actually store values (the rest are null).

All the messages start with an integer value, indicating the number of bytes that follow in the message (body length). It follows a byte value indicating the type of message (all types are defined in moses.util.Const class), followed by an int value indicating the message unique sequence number. The subsequent values depend on the type of the message.
A list of all messages and their serial layout is presented bellow:

agent-controller communication:
-------------------------------------------------------------------------
send
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|...
SND| SPLD| |S:s_payload|
OPLD| |O:o_payload|
BPLD| |I:plen |B[]:b_payload|
send_exp
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|...
SNDE| SPLD| |S:s_payload|S:s_lname|
OPLD| |O:o_payload|S:s_lname|
BPLD| |I:plen |B[]:b_payload|S:s_lname|
send_ack
|I:b-size|B:type|I:seq_no|
ACK
send_cert
|I:b-size|B:type|I:seq_no|S:source|O:cert|
CERT
send_self_cert
|I:b-size|B:type|I:seq_no|S:source|O:cert||I:plen |B[]:sign |
SCERT
adopt
// |I:b-size|B:type|I:seq_no|B:a_type|B:l_type|S:source|S:pwd|S:law|S:arg1|S:arg2| |I:b-size|B:type|I:seq_no|B:l_type|S:source|S:pwd|S:law|S:arg1|S:arg2|B[]:sign ("sign" saves the certifeid list see CertVerifierList) |
ADOPT
reconnect
|I:b-size|B:type|I:seq_no|S:source|S:pwd|
RECON
test
|I:b-size|B:type|I:seq_no|S:source|S:arg1|S:arg2|
TEST
change_password
|I:b-size|B:type|I:seq_no|S:pwd|S:opwd|
CHPWD
change_password_answer
|I:b-size|B:type|I:seq_no|B:status|
CHPWDA
adopt_answer
|I:b-size|B:type|I:seq_no|B:status|
ADANS
adopt_answer_certified
|I:b-size|B:type|I:seq_no|O:cert||I:plen |B[]:sign |
ADANSC


controller-controller communication:
-------------------------------------------------------------------------
forward
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|
FWD| SPLD| |S:s_payload |S:s_hash|S:s_lname|S:d_hash|
OPLD| |O:o_payload |S:s_hash|S:s_lname|S:d_hash|
BPLD| |I:plen|B[]:b_payload|S:s_hash|S:s_lname|S:d_hash|
controller
|I:b-size|B:type|I:seq_no|
CNTR

controller_cert
|I:b-size|B:type|I:seq_no|S:source|O:cert||I:plen |B[]:sign |
CNTRCERT

create
// |I:b-size|B:type|I:seq_no|B:a_type|B:l_type|S:dest|S:pwd|S:law|S:arg1|S:arg2|S:source|S:s_lname|S:s_hash|
|I:b-size|B:type|I:seq_no|B:l_type|S:dest|S:pwd|S:law|S:arg1|S:arg2|S:source|S:s_lname|S:s_hash|
CRT

exception
|I:b-size|B:type|I:seq_no|B:ex_po|...
EXC|
FWD|B:p_type|S:source|S:dest|...
SPLD| |S:s_payload |S:d_hash|S:fcause|
OPLD| |O:o_payload |S:d_hash|S:fcause|
BPLD| |I:plen|B[]:b_payload|S:d_hash|S:fcause|
//ADOPT|B:a_type|B:l_type|S:source|S:pwd|S:law|S:arg1|S:arg2|S:fcause| // CRT|B:a_type|B:l_type|S:dest|S:pwd|S:law|S:arg1|S:arg2|S:source|S:s_lname|S:s_hash|S:fcause| CRT|B:l_type|S:dest|S:pwd|S:law|S:arg1|S:arg2|S:source|S:s_lname|S:s_hash|S:fcause|

controller-external_member communication:
-------------------------------------------------------------------------

submit
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|I:sport|...
SBMT| SPLD| |S:s_payload|
OPLD| |O:o_payload|
BPLD| |I:plen |B[]:b_payload|
submitp
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|I:sport|...
SBMTP| SPLD| |S:s_payload|S:pwd|
OPLD| |O:o_payload|S:pwd|
BPLD| |I:plen |B[]:b_payload|S:pwd|
submitc
|I:b-size|B:type|I:seq_no|B:p_type|S:source|S:dest|I:sport|...
SBMTC| SPLD| |S:s_payload|O:cert|
OPLD| |O:o_payload|O:cert|
BPLD| |I:plen |B[]:b_payload|O:cert|I:plen |B[]:sign |

error_message
|I:b-size|B:type|I:seq_no|I:status|
ERR

exmember
|I:b-size|B:type|I:seq_no|S:dest||I:sport|
EXM


Field Summary
 java.lang.String arg1
          Holds the adoption argument supplied by the actor.
 java.lang.String arg2
          Holds an extra adoption argument; not used at present time.
 byte[] b_payload
          Holds the byte array payload of this message according to the type of the message; null otherwise.
 moses.security.LGICert cert
          Holds the LGI certificate when such a certificate is exchanged during a particular message.
 java.lang.String d_hash
          The hash of the destination law.
static int DEFAULT_AS
          Minimum default size of a message; it represents the preallocated space for a ByteArrayOutputStream
static int DEFAULT_MAXS
          The maximum size allowed for a message.
 java.lang.String dest
          Holds the moses name of the destination of this message.
 int ex_po
          This field contains the type of the payload of the original message reported during an exception message.
 java.lang.String fcause
          Holds the failure cause during an exception message.
 int l_type
          Holds the type of the law referenced in this message; it is either Const.IMM or Const.URL.
 java.lang.String law
          Holds the law URL
 java.lang.Object o_payload
          Holds the Object payload of this message according to the type of the message; null otherwise.
 java.lang.String opwd
          Holds the old reconnection password during changing the password.
 int p_type
          Maintains the payload type: String, Object and byte array.
 java.lang.String pwd
          Holds the reconnection password of the actor.
 java.lang.String s_hash
          This field contains the hash of the law of the source of the message.
 java.lang.String s_lname
          The name of the law of the source of the message; necessary only as a suggestion, when the destination is not in the portal.
 java.lang.String s_payload
          Holds the String payload of this message according to the type of the message; null otherwise.
 int seq_no
          Maintains the message sequence number.
 byte[] sign
          Holds the signature of a self-certificate when such a certificate is exchanged during a particular message.
 java.lang.String source
          Holds the moses name of the source of this message.
 int sport
          Sender port for a submitted message.
 int status
          Status answer the controller reports to the actor.
 int type
          Variable maintaining the type of the message being sent.
 
Constructor Summary
Message()
          The default constructor, allocates and initializes all necessary structures for a message.
 
Method Summary
 moses.message.Message copy()
          Copy itself into a new Message object.
static void main(java.lang.String[] args)
           
 void read(java.io.DataInput dis)
          Read (deserializing) method: Considering the layout presented in the description of this class, first read the first Integer coming from the DataInputStream argument.
 void write_cached(java.io.DataOutput dos)
          Version of write method where data to serialized is assumed to have been previously cached in the "recv" byte array (perhaps from a previous read).
 void write(java.io.DataOutput dos)
          Write(serializing) method: initially resets a ByteArrayOutputStream object then proceeds in writing all the data into the byte array, according to the message layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

public int type
Variable maintaining the type of the message being sent.


seq_no

public int seq_no
Maintains the message sequence number.


p_type

public int p_type
Maintains the payload type: String, Object and byte array.


source

public java.lang.String source
Holds the moses name of the source of this message.


dest

public java.lang.String dest
Holds the moses name of the destination of this message.


s_payload

public java.lang.String s_payload
Holds the String payload of this message according to the type of the message; null otherwise.


o_payload

public java.lang.Object o_payload
Holds the Object payload of this message according to the type of the message; null otherwise.


b_payload

public byte[] b_payload
Holds the byte array payload of this message according to the type of the message; null otherwise.


cert

public moses.security.LGICert cert
Holds the LGI certificate when such a certificate is exchanged during a particular message.


sign

public byte[] sign
Holds the signature of a self-certificate when such a certificate is exchanged during a particular message.


l_type

public int l_type
Holds the type of the law referenced in this message; it is either Const.IMM or Const.URL.


pwd

public java.lang.String pwd
Holds the reconnection password of the actor.


opwd

public java.lang.String opwd
Holds the old reconnection password during changing the password.


law

public java.lang.String law
Holds the law URL


arg1

public java.lang.String arg1
Holds the adoption argument supplied by the actor.


arg2

public java.lang.String arg2
Holds an extra adoption argument; not used at present time.


status

public int status
Status answer the controller reports to the actor.


s_hash

public java.lang.String s_hash
This field contains the hash of the law of the source of the message.


s_lname

public java.lang.String s_lname
The name of the law of the source of the message; necessary only as a suggestion, when the destination is not in the portal.


d_hash

public java.lang.String d_hash
The hash of the destination law.


ex_po

public int ex_po
This field contains the type of the payload of the original message reported during an exception message.


fcause

public java.lang.String fcause
Holds the failure cause during an exception message.


sport

public int sport
Sender port for a submitted message.


DEFAULT_AS

public static final int DEFAULT_AS
Minimum default size of a message; it represents the preallocated space for a ByteArrayOutputStream

See Also:
Constant Field Values

DEFAULT_MAXS

public static final int DEFAULT_MAXS
The maximum size allowed for a message.

See Also:
Constant Field Values
Constructor Detail

Message

public Message()
The default constructor, allocates and initializes all necessary structures for a message. It should be used called to using a message object.

Method Detail

write

public void write(java.io.DataOutput dos)
           throws java.io.IOException
Write(serializing) method: initially resets a ByteArrayOutputStream object then proceeds in writing all the data into the byte array, according to the message layout. After the message has been written and flushed, retrieve the byte array out of ByteArrayOutputStream, then rewrite the first 4 bytes with the length of byte array - 4. Finally, send the byte array into the DataOutputStream argument.

Parameters:
dos - argument specifies the DataOutputStream where to write the message to.
java.io.IOException

read

public void read(java.io.DataInput dis)
          throws java.lang.Exception
Read (deserializing) method: Considering the layout presented in the description of this class, first read the first Integer coming from the DataInputStream argument. Then allocate a new byte array the size of that length and read the remaining data into that byte array. Once the byte array is available, transform it into a ByteArrayInputStream, then int a DataInputStream and read the remaining fields, according to the layout schema. This method maintains the original byte array buffer into a object field, such that a message that has been read can be written back into the connection without expensive serialization (caching functionality). In order to do that, the actual byte array allocated for reading is readInt()+4, and the initial 4 bytes would store the length of data to come.

Parameters:
dis - argument specifies the DataInputStream where to read the message from.
java.lang.Exception

write_cached

public void write_cached(java.io.DataOutput dos)
                  throws java.io.IOException
Version of write method where data to serialized is assumed to have been previously cached in the "recv" byte array (perhaps from a previous read).

It may be useful for forwarding unmodified messages carrying objects .

java.io.IOException

copy

public moses.message.Message copy()
Copy itself into a new Message object. This method is similar in fuctionality to a (deep) clone method.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
java.lang.Exception