Package jade.lang.acl
Class MessageTemplate
- java.lang.Object
-
- jade.lang.acl.MessageTemplate
-
- All Implemented Interfaces:
Serializable,Serializable
public class MessageTemplate extends Object implements Serializable
A pattern for matching incoming ACL messages. This class allows to build complex slot patterns to select ACL messages. These patterns can then be used inreceive()operations. This class provide one method for each attribute of an ACLMessage, that can be combined using the logic operators to create more complex patterns. A user can also create an application-specific pattern. In this case he has to implement the MatchExpression interface, writing the application specificmatch()method. Then an instance of that class can be used as parameter of the MessageTemplate constructor to define the application specific MessageTemaplate.- Version:
- $Date$ $Revision$
- Author:
- Giovanni Rimassa - Universita' di Parma, Tiziana Trucco - Telecom Italia Lab S.p.A.
- See Also:
Agent.receive(MessageTemplate mt), Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMessageTemplate.MatchExpressionThis interface must be overriden in order to define an application specific MessageTemplate.
-
Constructor Summary
Constructors Constructor Description MessageTemplate(MessageTemplate.MatchExpression e)Public constructor to use when the user needs to define an application specific pattern.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MessageTemplateand(MessageTemplate op1, MessageTemplate op2)Logical and between twoMessageTemplateobjects.booleanequals(Object obj)StringgetID()inthashCode()booleanmatch(ACLMessage msg)Matches an ACL message against thisMessageTemplateobject.static MessageTemplateMatchAll()This Factory Method returns a message template that matches any message.static MessageTemplateMatchContent(String value)This Factory Method returns a message template that matches any message with a given:contentslot.static MessageTemplateMatchConversationId(String value)This Factory Method returns a message template that matches any message with a given:conversation-idslot.static MessageTemplateMatchCustom(ACLMessage msg, boolean matchPerformative)This Factory Method returns a message template that matches ACL messages against a given one, passed as parameter.static MessageTemplateMatchEncoding(String value)This Factory Method returns a message template that matches any message with a given:encodingslot.static MessageTemplateMatchInReplyTo(String value)This Factory Method returns a message template that matches any message with a given:in-reply-toslot.static MessageTemplateMatchLanguage(String value)This Factory Method returns a message template that matches any message with a given:languageslot.static MessageTemplateMatchOntology(String value)This Factory Method returns a message template that matches any message with a given:ontologyslot.static MessageTemplateMatchPerformative(int value)This Factory Method returns a message template that matches any message with a given performative.static MessageTemplateMatchProtocol(String value)This Factory Method returns a message template that matches any message with a given:protocolslot.static MessageTemplateMatchReceiver(AID[] values)This Factory Method returns a message template that matches any message with a given:receiverslot.static MessageTemplateMatchReplyByDate(Date value)This Factory Method returns a message template that matches any message with a given:reply-byslot.static MessageTemplateMatchReplyTo(AID[] values)This Factory Method returns a message template that matches any message with a given:reply-toslot.static MessageTemplateMatchReplyWith(String value)This Factory Method returns a message template that matches any message with a given:reply-withslot.static MessageTemplateMatchSender(AID value)This Factory Method returns a message template that matches any message with a given:senderslot.static MessageTemplateMatchTopic(AID topic)This Factory Method returns a message template that matches any message about a given topic.static MessageTemplatenot(MessageTemplate op)Logical not of aMessageTemplateobject.static MessageTemplateor(MessageTemplate op1, MessageTemplate op2)Logical or between twoMessageTemplateobjects.voidsetID(String id)StringtoString()Retrieve a string representation of this message template.
-
-
-
Constructor Detail
-
MessageTemplate
public MessageTemplate(MessageTemplate.MatchExpression e)
Public constructor to use when the user needs to define an application specific pattern.
-
-
Method Detail
-
MatchAll
public static MessageTemplate MatchAll()
This Factory Method returns a message template that matches any message.- Returns:
- A new
MessageTemplatematching any given value.
-
MatchSender
public static MessageTemplate MatchSender(AID value)
This Factory Method returns a message template that matches any message with a given:senderslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchReceiver
public static MessageTemplate MatchReceiver(AID[] values)
This Factory Method returns a message template that matches any message with a given:receiverslot.- Parameters:
values- An array of Agent IDs against which the value of the message slot will be matched.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchTopic
public static MessageTemplate MatchTopic(AID topic)
This Factory Method returns a message template that matches any message about a given topic.- Parameters:
topic- An AID representing the topic to be matched- Returns:
- A new
MessageTemplatematching messages about the given topic
-
MatchContent
public static MessageTemplate MatchContent(String value)
This Factory Method returns a message template that matches any message with a given:contentslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchReplyWith
public static MessageTemplate MatchReplyWith(String value)
This Factory Method returns a message template that matches any message with a given:reply-withslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchInReplyTo
public static MessageTemplate MatchInReplyTo(String value)
This Factory Method returns a message template that matches any message with a given:in-reply-toslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchReplyTo
public static MessageTemplate MatchReplyTo(AID[] values)
This Factory Method returns a message template that matches any message with a given:reply-toslot.- Parameters:
values- An array of Agent IDs against which the value of the message slot will be matched.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchLanguage
public static MessageTemplate MatchLanguage(String value)
This Factory Method returns a message template that matches any message with a given:languageslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchEncoding
public static MessageTemplate MatchEncoding(String value)
This Factory Method returns a message template that matches any message with a given:encodingslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchOntology
public static MessageTemplate MatchOntology(String value)
This Factory Method returns a message template that matches any message with a given:ontologyslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchReplyByDate
public static MessageTemplate MatchReplyByDate(Date value)
This Factory Method returns a message template that matches any message with a given:reply-byslot.- Parameters:
value- TheDatethe message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchProtocol
public static MessageTemplate MatchProtocol(String value)
This Factory Method returns a message template that matches any message with a given:protocolslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchConversationId
public static MessageTemplate MatchConversationId(String value)
This Factory Method returns a message template that matches any message with a given:conversation-idslot.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTemplatematching the given value.
-
MatchPerformative
public static MessageTemplate MatchPerformative(int value)
This Factory Method returns a message template that matches any message with a given performative.- Parameters:
value- The value the message slot will be matched against.- Returns:
- A new
MessageTenplatematching the given value.
-
MatchCustom
public static MessageTemplate MatchCustom(ACLMessage msg, boolean matchPerformative)
This Factory Method returns a message template that matches ACL messages against a given one, passed as parameter. The following algorithm is used: When the givenACLMessagehas a nonnullslot, subsequent messages must have the same slot value in that slot to have a match. When the givenACLMessagehas anullslot, subsequent messages can have any value for that slot and still match the template. In short, anullvalue for a slot means don't care.- Parameters:
msg- TheACLMessageused to build a custom message template.matchPerformative- aboolvalue. Whentrue, the performative of themsgwill be considered as a part of the template (i.e. the message template will match only ACL messages with the same performativa asmsg). When, the performative of msgis ignored and the resulting message template will not consider it when matching messages.- Returns:
- A new
MessageTemplate, matching the given message according to the above algorithm.
-
and
public static MessageTemplate and(MessageTemplate op1, MessageTemplate op2)
Logical and between twoMessageTemplateobjects. This method creates a new message template that is matched by those ACL messages matching both message templates given as operands.- Parameters:
op1- The first and operand.op2- The second and operand.- Returns:
- A new
MessageTemplateobject. - See Also:
or(MessageTemplate op1, MessageTemplate op2)
-
or
public static MessageTemplate or(MessageTemplate op1, MessageTemplate op2)
Logical or between twoMessageTemplateobjects. This method creates a new message template that is matched by those ACL messages matching any of the two message templates given as operands.- Parameters:
op1- The first or operand.op2- The second or operand.- Returns:
- A new
MessageTemplateobject. - See Also:
and(MessageTemplate op1, MessageTemplate op2)
-
not
public static MessageTemplate not(MessageTemplate op)
Logical not of aMessageTemplateobject. This method creates a new message template that is matched by those ACL messages not matching the message template given as operand.- Parameters:
op- The not operand.- Returns:
- A new
MessageTemplateobject.
-
match
public boolean match(ACLMessage msg)
Matches an ACL message against thisMessageTemplateobject.- Parameters:
msg- TheACLMessageto check for matching.- Returns:
trueif the ACL message matches this template,falseotherwise.
-
setID
public void setID(String id)
-
getID
public String getID()
-
toString
public String toString()
Retrieve a string representation of this message template.
-
-