es.upv.dsic.gti_ia.core
Class ACLMessage

java.lang.Object
  extended by es.upv.dsic.gti_ia.core.ACLMessage
All Implemented Interfaces:
Serializable, Cloneable

public class ACLMessage
extends Object
implements Serializable, Cloneable

This class represents a message sent between agents.

Author:
Ricard Lopez Fogues, Luis Burdalo (Added toString and fromString methods)
See Also:
Serialized Form

Field Summary
static int ACCEPT_PROPOSAL
          constant identifying the FIPA performative
static int AGREE
          constant identifying the FIPA performative
static int CANCEL
          constant identifying the FIPA performative
static int CFP
          constant identifying the FIPA performative
static int CONFIRM
          constant identifying the FIPA performative
static int DISCONFIRM
          constant identifying the FIPA performative
static int FAILURE
          constant identifying the FIPA performative
static int INFORM
          constant identifying the FIPA performative
static int INFORM_IF
          constant identifying the FIPA performative
static int INFORM_REF
          constant identifying the FIPA performative
static int NOT_UNDERSTOOD
          constant identifying the FIPA performative
static int PROPAGATE
          constant identifying the FIPA performative
static int PROPOSE
          constant identifying the FIPA performative
static int PROXY
          constant identifying the FIPA performative
static int QUERY_IF
          constant identifying the FIPA performative
static int QUERY_REF
          constant identifying the FIPA performative
static int REFUSE
          constant identifying the FIPA performative
static int REJECT_PROPOSAL
          constant identifying the FIPA performative
static int REQUEST
          constant identifying the FIPA performative
static int REQUEST_WHEN
          constant identifying the FIPA performative
static int REQUEST_WHENEVER
          constant identifying the FIPA performative
static int SUBSCRIBE
          constant identifying the FIPA performative
static int UNKNOWN
          constant identifying an unknown performative
 
Constructor Summary
ACLMessage()
          Empty constructor.
ACLMessage(int performative)
          Constructor for the class.
 
Method Summary
 int addReceiver(AgentID r)
          Adds a receiver to the receivers list
 void clearAllReceiver()
          Clears receivers list
 ACLMessage clone()
          Clones Message
 void copyFromAsTemplate(ACLMessage msg)
          Copies the fields of the message to this one, when those fields have a correct value.
 ACLMessage createReply()
          Creates an ACLMessage that is a reply to this one
static ACLMessage fromString(String strMsg)
          Parses the message given as a String and creates an object of type ACLMessage.
 byte[] getByteSequenceContent()
          Reads :content slot.
 String getContent()
          Gets the content of this message.
 Object getContentObject()
          This method returns the content of this ACLMessage when they have been written via the method setContentObject.
 String getConversationId()
          Gets the conversationID of this message.
 String getEncoding()
          Get the encoding for this message.
 String getExchangeHeader(String key)
           
 Map<String,String> getExchangeHeaders()
           
 Map<String,String> getHeaders()
          Obtains the whole set of headers in this message.
 String getHeaderValue(String key)
          Gets the value of a header for this message.
 String getInReplyTo()
          Gets the inReplyTo field of this message.
 String getLanguage()
          Gets the language field.
 String getOntology()
          Get the ontology for the message
 String getPerformative()
           
static String getPerformative(int perf)
          Returns the string corresponding to the integer for the performative
static int getPerformative(String perf)
          Returns the integer corresponding to the performative
 int getPerformativeInt()
           
 String getProtocol()
          Gets the protocol for the message
 AgentID getReceiver()
          Obtains the AgentID of the first receiver of the (possibly many) receivers of this message.
 AgentID getReceiver(int index)
          Returns receiver in index position in receivers list
 ArrayList<AgentID> getReceiverList()
          Returns the whole list of the AgentID of the receivers.
 String getReplyBy()
          Gets the replyBy field.
 Date getReplyByDate()
          Gets the replyByDate field for this message.
 AgentID getReplyTo()
          Gets the ReplyTo field
 String getReplyWith()
          Gets the replyWith field of this message.
 AgentID getSender()
          Returns the sender of this message.
 int getTotalReceivers()
          Gets the count of receivers of this message.
 void putExchangeHeader(String key, String value)
           
 void setByteSequenceContent(byte[] content)
          Sets the value of byte sequence content
 void setContent(String cont)
          Sets content field.
 void setContentObject(Serializable s)
          Sets the value of byte sequence content
 void setConversationId(String id)
          Sets the conversationID of this message.
 void setEncoding(String encoding)
          Set encoding of the message
 void setHeader(String key, String value)
          Sets the value of a header for this message.
 void setInReplyTo(String irt)
          Sets the inReplyTo field of this message.
 void setLanguage(String lang)
          Sets language field
 void setOntology(String ontology)
          Set ontology of the message
 void setPerformative(int performative)
          Sets performative type
 void setPerformative(String performative)
          Sets the performative field in the message.
 void setProtocol(String protocol)
          Sets the protocol for the message
 void setReceiver(AgentID receiver)
          Sets the receiver.
 void setReplyByDate(Date date)
          Sets the replyByDate field for this message.
 void setReplyTo(AgentID reply)
          Sets ReplyTo field
 void setReplyWith(String rw)
          Sets the replyWith field of this message.
 void setSender(AgentID sender)
          Set sender
 String toString()
          Serializes this message to a String, using all the fields in the message.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACCEPT_PROPOSAL

public static final int ACCEPT_PROPOSAL
constant identifying the FIPA performative

See Also:
Constant Field Values

AGREE

public static final int AGREE
constant identifying the FIPA performative

See Also:
Constant Field Values

CANCEL

public static final int CANCEL
constant identifying the FIPA performative

See Also:
Constant Field Values

CFP

public static final int CFP
constant identifying the FIPA performative

See Also:
Constant Field Values

CONFIRM

public static final int CONFIRM
constant identifying the FIPA performative

See Also:
Constant Field Values

DISCONFIRM

public static final int DISCONFIRM
constant identifying the FIPA performative

See Also:
Constant Field Values

FAILURE

public static final int FAILURE
constant identifying the FIPA performative

See Also:
Constant Field Values

INFORM

public static final int INFORM
constant identifying the FIPA performative

See Also:
Constant Field Values

INFORM_IF

public static final int INFORM_IF
constant identifying the FIPA performative

See Also:
Constant Field Values

INFORM_REF

public static final int INFORM_REF
constant identifying the FIPA performative

See Also:
Constant Field Values

NOT_UNDERSTOOD

public static final int NOT_UNDERSTOOD
constant identifying the FIPA performative

See Also:
Constant Field Values

PROPOSE

public static final int PROPOSE
constant identifying the FIPA performative

See Also:
Constant Field Values

QUERY_IF

public static final int QUERY_IF
constant identifying the FIPA performative

See Also:
Constant Field Values

QUERY_REF

public static final int QUERY_REF
constant identifying the FIPA performative

See Also:
Constant Field Values

REFUSE

public static final int REFUSE
constant identifying the FIPA performative

See Also:
Constant Field Values

REJECT_PROPOSAL

public static final int REJECT_PROPOSAL
constant identifying the FIPA performative

See Also:
Constant Field Values

REQUEST

public static final int REQUEST
constant identifying the FIPA performative

See Also:
Constant Field Values

REQUEST_WHEN

public static final int REQUEST_WHEN
constant identifying the FIPA performative

See Also:
Constant Field Values

REQUEST_WHENEVER

public static final int REQUEST_WHENEVER
constant identifying the FIPA performative

See Also:
Constant Field Values

SUBSCRIBE

public static final int SUBSCRIBE
constant identifying the FIPA performative

See Also:
Constant Field Values

PROXY

public static final int PROXY
constant identifying the FIPA performative

See Also:
Constant Field Values

PROPAGATE

public static final int PROPAGATE
constant identifying the FIPA performative

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
constant identifying an unknown performative

See Also:
Constant Field Values
Constructor Detail

ACLMessage

public ACLMessage()
Empty constructor. The performative is set to UNKNOWN

See Also:
setPerformative

ACLMessage

public ACLMessage(int performative)
Constructor for the class. Only sets the performative.

Parameters:
performative - The performative to be used in this message.
See Also:
setPerformative
Method Detail

setPerformative

public void setPerformative(int performative)
Sets performative type

Parameters:
performative -

getPerformative

public String getPerformative()
Returns:
Performative type as a String

getPerformativeInt

public int getPerformativeInt()
Returns:
Performative type as an integer

setSender

public void setSender(AgentID sender)
Set sender

Parameters:
sender - The AgentID of the sender of this message.
See Also:
AgentID

getSender

public AgentID getSender()
Returns the sender of this message.

Returns:
sender The AgentID of the sender of this message.
See Also:
AgentID

setReceiver

public void setReceiver(AgentID receiver)
Sets the receiver. It deletes the receivers list and creates a new one with the new receiver

Parameters:
receiver -

getReceiver

public AgentID getReceiver()
Obtains the AgentID of the first receiver of the (possibly many) receivers of this message.

Returns:
First receiver in receivers list
See Also:
AgentID

getReceiver

public AgentID getReceiver(int index)
Returns receiver in index position in receivers list

Parameters:
index -
Returns:
receiver

setReplyTo

public void setReplyTo(AgentID reply)
Sets ReplyTo field

Parameters:
reply -

getReplyTo

public AgentID getReplyTo()
Gets the ReplyTo field

Returns:
AgentID of ReplyTo field

setContent

public void setContent(String cont)
Sets content field.

Parameters:
cont -

getContent

public String getContent()
Gets the content of this message.

Returns:
Content of content field as a String

setLanguage

public void setLanguage(String lang)
Sets language field

Parameters:
lang -

getLanguage

public String getLanguage()
Gets the language field.

Returns:
content of language field

setEncoding

public void setEncoding(String encoding)
Set encoding of the message

Parameters:
encoding -

getEncoding

public String getEncoding()
Get the encoding for this message.

Returns:
encoding

setOntology

public void setOntology(String ontology)
Set ontology of the message

Parameters:
ontology -

getOntology

public String getOntology()
Get the ontology for the message

Returns:
ontology

setProtocol

public void setProtocol(String protocol)
Sets the protocol for the message

Parameters:
protocol -

getProtocol

public String getProtocol()
Gets the protocol for the message

Returns:
protocol

setConversationId

public void setConversationId(String id)
Sets the conversationID of this message.

Parameters:
id - A String containing the conversationID to be set.

getConversationId

public String getConversationId()
Gets the conversationID of this message.

Returns:
conversation id

setReplyWith

public void setReplyWith(String rw)
Sets the replyWith field of this message.

Parameters:
replyWith -

getReplyWith

public String getReplyWith()
Gets the replyWith field of this message.

Returns:
reply with

setInReplyTo

public void setInReplyTo(String irt)
Sets the inReplyTo field of this message.

Parameters:
inReplyTo -

getInReplyTo

public String getInReplyTo()
Gets the inReplyTo field of this message.

Returns:
in reply to

setReplyByDate

public void setReplyByDate(Date date)
Sets the replyByDate field for this message.

Parameters:
date - If the date is null, the current time and date is used.

getReplyByDate

public Date getReplyByDate()
Gets the replyByDate field for this message.

Returns:
reply by time in date format

getReplyBy

public String getReplyBy()
Gets the replyBy field.

Returns:
reply by time in string format

setPerformative

public void setPerformative(String performative)
Sets the performative field in the message.

Parameters:
performative - Must contain a valid performative (e.g. INFORM) in order to be set. See the performatives in this class to notice which ones are valid.
See Also:
ACLMessage

clearAllReceiver

public void clearAllReceiver()
Clears receivers list


addReceiver

public int addReceiver(AgentID r)
Adds a receiver to the receivers list

Parameters:
receiver - AgentID of the receiver to be added.
Returns:
-1 if the agent already exists in the list, 1 otherwise

getReceiverList

public ArrayList<AgentID> getReceiverList()
Returns the whole list of the AgentID of the receivers.

Returns:
receivers list
See Also:
AgentID

getTotalReceivers

public int getTotalReceivers()
Gets the count of receivers of this message.

Returns:
total number of receivers

clone

public ACLMessage clone()
Clones Message

Overrides:
clone in class Object
Returns:
Another ACLMessage that is a clone from this one

createReply

public ACLMessage createReply()
Creates an ACLMessage that is a reply to this one

Returns:
ACLMessage that is a reply to this one

copyFromAsTemplate

public void copyFromAsTemplate(ACLMessage msg)
Copies the fields of the message to this one, when those fields have a correct value. If they don't, they are not copied.

Parameters:
msg - From which the fields are to be copied.

setHeader

public void setHeader(String key,
                      String value)
Sets the value of a header for this message.

Parameters:
key - The name of the header
value - The content for the header

getHeaderValue

public String getHeaderValue(String key)
Gets the value of a header for this message.

Parameters:
key - The name of the header
Returns:
The value of the header specified

getHeaders

public Map<String,String> getHeaders()
Obtains the whole set of headers in this message.

Returns:
A Map containing all the headers (and its contents) in this message

setContentObject

public void setContentObject(Serializable s)
                      throws IOException
Sets the value of byte sequence content

Parameters:
serializable - object to store
Throws:
IOException

setByteSequenceContent

public void setByteSequenceContent(byte[] content)
Sets the value of byte sequence content

Parameters:
byte - array to store

getPerformative

public static int getPerformative(String perf)
Returns the integer corresponding to the performative

Returns:
the integer corresponding to the performative; -1 otherwise

getPerformative

public static String getPerformative(int perf)
Returns the string corresponding to the integer for the performative

Returns:
the string corresponding to the integer for the performative; "NOT-UNDERSTOOD" if the integer is out of range.

getByteSequenceContent

public byte[] getByteSequenceContent()
Reads :content slot.

Returns:
The value of :content slot.

getContentObject

public Object getContentObject()
This method returns the content of this ACLMessage when they have been written via the method setContentObject.

Returns:
the object read from the content of this ACLMessage

toString

public String toString()
Serializes this message to a String, using all the fields in the message. The fields are separated using the char '#'

Overrides:
toString in class Object

fromString

public static ACLMessage fromString(String strMsg)
Parses the message given as a String and creates an object of type ACLMessage.

Parameters:
strMsg - String containing a serialization of an ACLMessage
Returns:
An object of type ACLMessage created from the given String
See Also:
toString()

getExchangeHeaders

public Map<String,String> getExchangeHeaders()

putExchangeHeader

public void putExchangeHeader(String key,
                              String value)

getExchangeHeader

public String getExchangeHeader(String key)


Copyright © 2012 GTI-IA. All Rights Reserved.