|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.lars.communication.Message
Message object for the communication between the agents.
Note, that the Message object is not synchronized!
Standard for naming message services:
Field Summary | |
static String |
ADDRESS_CONFIG
used as sender address, if this message was read from a config file |
static String |
ADDRESS_LARS_INTERNAL
used as receiver or sender address, if this message is used only lars internal |
static short |
EXPIRE_HOPS_DEFAULT
default value: how many hops a Message is allowed to do, before it expires |
static String |
MESSAGE_TYPE_GROUP
identifies a SingleMessage in a Map- or XML-representation of the message |
static String |
MESSAGE_TYPE_MULTICAST
identifies a SingleMessage in a Map- or XML-representation of the message |
static String |
MESSAGE_TYPE_SERVICE_BROADCAST
identifies a ServiceBroadcastMessage in a Map- or XML-representation of the message |
static String |
MESSAGE_TYPE_SERVICE_SINGLE
identifies a ServiceSingleMessage in a Map- or XML-representation of the message |
static String |
MESSAGE_TYPE_SINGLE
identifies a SingleMessage in a Map- or XML-representation of the message |
static short |
PRIORITY_HIGH
maximum priority for a message |
static short |
PRIORITY_LOW
lowest priority for a message |
static short |
PRIORITY_NORMAL
normal (default) priority for a message |
static short |
PRIORITY_SYSTEM
system priority: DO NOT USE THIS for agents! |
static String |
PRIORITY_TEXT_HIGH
identifies a high message priority |
static String |
PRIORITY_TEXT_LOW
identifies a low message priority |
static String |
PRIORITY_TEXT_NORMAL
identifies a normal message priority |
static String |
SERVICE_UNKNOWN
used as service, if this message's service is unset |
static String |
TAG_CONTENT
string that represent the "content" |
static String |
TAG_CURRENT_HOPS
string that represent the "currentHops" |
static String |
TAG_EXPIRE_HOPS
string that represent the "expireHops" |
static String |
TAG_FORWARDED_BY
string that represent the "forwardedBy" |
static String |
TAG_IN_REPLY_TO
string that represent the "inReplyTo" |
static String |
TAG_MESSAGE
string that represent the "mesage" |
static String |
TAG_PRIORITY
string that represent the "priority" |
static String |
TAG_QUALITY_OF_SERVICE
string that represent the "qualityOfService" |
static String |
TAG_REPLY_COUNTER
string that represent the "replyCounter" |
static String |
TAG_REPLY_WITH
string that represent the "replyWith" |
static String |
TAG_SENDER
string that represent the "sender" |
static String |
TAG_SENT_TIME
string that represent the "sentTime" |
static String |
TAG_SERVICE
string that represent the "service" |
static String |
TAG_TYPE
string that represent the "type" |
Constructor Summary | |
protected |
Message(Map messageHash)
Creates a message object from a Map. |
protected |
Message(String service,
Object content)
sets all fields of a message including the content object |
Method Summary | |
Object |
clone()
Returns a new message that is the clone of this message. |
int |
compareTo(Object other)
Compares this message to another Object. |
protected static Message |
createMessage(Map messageMap)
Creates a message object from a Map by calling different constructors depending on the specified message type. |
SingleMessage |
createReply(String service,
Object content)
Creates a new SingleMessage object, which is a reply to the message from which is invoked.
|
Object |
getContent()
Returns the content of this message. |
short |
getCurrentHops()
returns the number of hops this message already did |
short |
getExpireHops()
returns the number of hops this message is allowed to do before it expires |
List |
getForwardedBy()
returns an unmodifiable list of all forwarders or null, if the message wasn't forwarded |
String |
getInReplyTo()
returns the inReplyTo field of this message |
short |
getPriority()
returns the priority of this message |
int |
getQualityOfService()
returns the qualityOfService field of this message |
String |
getReplyWith()
returns the replyWith field of this message |
String |
getSender()
returns the name of this sender agent |
long |
getSentTime()
returns the time, when this message was sent (in ms since 01.01.1970) |
String |
getService()
returns the service of this message |
boolean |
hasInvalidSender()
Rudimentary checks this message, if it contains an invalid sender address. |
void |
hop()
Counts a message hop. |
void |
increasePriority()
Increases the priority of this message to avoid starvation. |
protected abstract Map |
inheritorToMap()
returns a new map containing the message-inheritor specific fields (usually the type and the recipient, which is a group or an agent name or ...) |
protected abstract String |
inheritorToString()
returns a well formatted string containing the message-inheritor specific fields (usually the type and the recipient, which is a group or an agent name or ...) |
boolean |
isExpired()
checks expiration of this message regarding the number of hops (Messengers, the Message passed on it's way) compared to the number of allowed hops |
boolean |
isSent()
checks, if thie message was already sent |
void |
setExpireHops(short expireHops)
sets the number of hops this message is allowed to do before it expires |
void |
setInReplyTo(String inReplyTo)
Sets a inReplyTo for this request message. |
void |
setPriority(short priority)
sets a new priority for this message |
void |
setPriority(String priority)
Sets a new priority for this message. |
void |
setQualityOfService(int qualityOfService)
Sets the qualityOfService tag of this message. |
void |
setQualityOfService(String qualityOfService)
Sets the qualityOfService tag of this message. |
void |
setReplyWith(String replyWith)
sets a replyWith for this request message |
void |
setSystemPriority()
Do not use this method for sending Messages between agents - this method sets the highest available priority a message can obtain and is reserved for lars-internal Messages only. |
Map |
toMap()
returns the complete message as a Map |
String |
toString()
Returns a well formatted string of this message. |
String |
toStringWithContent()
Returns a well formatted string of this message including (if existent) the content. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String TAG_MESSAGE
public static final String TAG_SERVICE
public static final String TAG_TYPE
public static final String TAG_SENDER
public static final String TAG_FORWARDED_BY
public static final String TAG_REPLY_WITH
public static final String TAG_IN_REPLY_TO
public static final String TAG_REPLY_COUNTER
public static final String TAG_PRIORITY
public static final String TAG_QUALITY_OF_SERVICE
public static final String TAG_SENT_TIME
public static final String TAG_CURRENT_HOPS
public static final String TAG_EXPIRE_HOPS
public static final String TAG_CONTENT
public static final short PRIORITY_SYSTEM
public static final short PRIORITY_HIGH
public static final short PRIORITY_NORMAL
public static final short PRIORITY_LOW
public static final String PRIORITY_TEXT_HIGH
public static final String PRIORITY_TEXT_NORMAL
public static final String PRIORITY_TEXT_LOW
public static final short EXPIRE_HOPS_DEFAULT
public static final String MESSAGE_TYPE_SINGLE
public static final String MESSAGE_TYPE_SERVICE_SINGLE
public static final String MESSAGE_TYPE_SERVICE_BROADCAST
public static final String MESSAGE_TYPE_GROUP
public static final String MESSAGE_TYPE_MULTICAST
public static final String ADDRESS_CONFIG
public static final String ADDRESS_LARS_INTERNAL
public static final String SERVICE_UNKNOWN
Constructor Detail |
protected Message(String service, Object content) throws InvalidArgumentException
service
- service of the messagecontent
- content of the message as a hashInvalidArgumentException
- if given service is null or empty or contains only whitespace charactersprotected Message(Map messageHash) throws InvalidArgumentException
messageHash
- a map with (at least) service, sender and content key.InvalidArgumentException
- if given messageHash is null or if any of the required values do not
fulfill the needs of a message
(e.g. the service/content/sender is not specified)Method Detail |
protected static Message createMessage(Map messageMap) throws InvalidArgumentException
messageMap
- A map with (at least) type, service and sender key.
If there is no priority specified, the default priority will be set.InvalidArgumentException
- if given messageMap is null or if any of the required values do not
fulfill the needs of the specific message type
(e.g. the service/sender is not specified)public Object clone()
Warning: If the content is an instance of Collection
, the content of the new message
is exactly the same Object as the source message's content. Therefore modifying one message's content will
result in a modification of the copied content.
clone
in class Object
Object.clone()
public final String getService()
public final String getSender()
public List getForwardedBy()
public final void setReplyWith(String replyWith) throws InvalidArgumentException, ProgrammingException
replyWith
- reply ID to use when answering to this messageInvalidArgumentException
- if given replyId is null or empty or contains only whitespace charactersProgrammingException
- if this message was already sentpublic final String getReplyWith()
public final void setInReplyTo(String inReplyTo) throws ProgrammingException
inReplyTo
- reply ID to use for this message (answer), may be nullProgrammingException
- if this message was already sentpublic final String getInReplyTo()
public void setQualityOfService(int qualityOfService) throws ProgrammingException
qualityOfService
- specifies, in which cases the systems needs to send a reply to this messageProgrammingException
- if this message was already sentQualityOfService
public void setQualityOfService(String qualityOfService)
Integer.parseInt(qualityOfService)
.qualityOfService
- specifies, in which cases the systems needs to send a reply to this messageQualityOfService
public final int getQualityOfService()
public final void setPriority(short priority) throws InvalidArgumentException
priority
- new priority for this message, e.g. PRIORITY_LOWInvalidArgumentException
- if given priority is negativePRIORITY_LOW
,
PRIORITY_NORMAL
,
PRIORITY_HIGH
public final void setSystemPriority()
public final void setPriority(String priority) throws InvalidArgumentException
priority
- new priority for this messageInvalidArgumentException
- if given priority is neither parseable to a short nor PRIORITY_HIGH
nor PRIORITY_NORMAL
nor PRIORITY_LOW
nor nullPRIORITY_TEXT_LOW
,
PRIORITY_TEXT_NORMAL
,
PRIORITY_TEXT_HIGH
,
PRIORITY_LOW
,
PRIORITY_NORMAL
,
PRIORITY_HIGH
public final short getPriority()
public final long getSentTime()
public final short getCurrentHops()
public final void setExpireHops(short expireHops) throws ProgrammingException
expireHops
- number of hops this message is allowed to doProgrammingException
- if this message was already sentpublic final short getExpireHops()
public final Object getContent()
try {
contentMap = (Map) message.getContent();
} catch (ClassCastException ccex) {
... [ do whatever needed ] ...
}
public final SingleMessage createReply(String service, Object content) throws InvalidArgumentException, ProgrammingException
SingleMessage
object, which is a reply to the message from which is invoked.
Therefore it sets the sender of this message as receiver of the new message, sets the inReplyTo field of the
new message to this.replyWith and increasees the reply counter of this message by 1.service
- specifies the new servicecontent
- body of the messageInvalidArgumentException
- if given service is null or empty or contains only whitespace charactersProgrammingException
- if this message was not yet sentpublic final boolean hasInvalidSender()
public final void hop() throws MessageException
MessageException
- if this message has passed too many messengers (hop counter is expired)isExpired()
public final void increasePriority()
protected abstract Map inheritorToMap()
public Map toMap()
public final boolean isExpired()
public final boolean isSent()
public final int compareTo(Object other) throws ClassCastException
Note: This comparision is not consistent with the equals method - it is possible, that two messages that are not equal (in the way Message.equals() determines equality) may get a return value of 0, if their priority is the same and their sentTime (in milliseconds since 01.01.1970) is the same, too (though this case is very unlikely to happen ;-).
compareTo
in interface Comparable
other
- object to this should be compared toClassCastException
- if the given object is not a message, because messages are
only comparable to other messagesprotected abstract String inheritorToString()
public final String toString()
toString
in class Object
SystemLogger
public final String toStringWithContent()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |