jade.proto
Class FipaRequestInitiatorBehaviour

java.lang.Object
  |
  +--jade.core.behaviours.Behaviour
        |
        +--jade.core.behaviours.SimpleBehaviour
              |
              +--jade.proto.FipaRequestInitiatorBehaviour
Direct Known Subclasses:
RequestFIPAServiceBehaviour

public abstract class FipaRequestInitiatorBehaviour
extends SimpleBehaviour

Behaviour class for fipa-request Initiator role.This abstract behaviour implements the fipa-request interaction protocol from the point of view of the agent initiating the protocol, that is the agent that sends the request message to an agent. In order to use correctly this behaviour, the programmer shoud do the following:

The behaviour can be hot reset, calling one of the following method in one of the handle methods other than from handleAgree:

The programmer can override the method public handleOtherMessages(ACLMessage reply) in order to handle replies different from those stated by the protocol. The method public long handleTimeOut() can be override to handle the expiration of the timeout.

Author:
Tiziana Trucco - CSELT S.p.A.
See Also:
FipaRequestResponderBehaviour, Serialized Form

Inner classes inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
 
Field Summary
protected  boolean finished
          Use this protected variable to block the protocol in whatever state.
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent
 
Constructor Summary
FipaRequestInitiatorBehaviour(Agent client, ACLMessage request)
          Constructor for this behaviour.
FipaRequestInitiatorBehaviour(Agent client, ACLMessage request, MessageTemplate template)
          Public constructor for this behaviour.
 
Method Summary
 void action()
           
 boolean done()
           
protected  ACLMessage getRequest()
          This method gives access to the request ACL message, originally set by the class constructor.
protected abstract  void handleAgree(ACLMessage reply)
          Abstract method to handle agree replies.
protected abstract  void handleFailure(ACLMessage reply)
          Abstract method to handle failure replies.
protected abstract  void handleInform(ACLMessage reply)
          Abstract method to handle inform replies.
protected abstract  void handleNotUnderstood(ACLMessage reply)
          Abstract method to handle not-understood replies.
protected  void handleOtherMessages(ACLMessage reply)
          This method can be override to handle other received messages different from those stated by the protocol.
protected abstract  void handleRefuse(ACLMessage reply)
          Abstract method to handle refuse replies.
 long handleTimeout()
          This method is called by the action method when the timeout set in the request message is expired.
 void reset()
          This method resets this behaviour so that it restarts from the initial state of the protocol with the same request message.
 void reset(ACLMessage request)
          This method resets this behaviour so that it restarts the protocol with another request message.
 void reset(ACLMessage request, MessageTemplate template)
          This method resets this behaviour so that it restarts the protocol with other request message and MessageTemplate
 
Methods inherited from class jade.core.behaviours.Behaviour
block, block, handle, isRunnable, restart, root
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

finished

protected boolean finished
Use this protected variable to block the protocol in whatever state.
Constructor Detail

FipaRequestInitiatorBehaviour

public FipaRequestInitiatorBehaviour(Agent client,
                                     ACLMessage request,
                                     MessageTemplate template)
Public constructor for this behaviour. Creates a Behaviour object that sends a request ACL message and calls user-defined methods to handle the different kinds of reply expected whithin a fipa-request interaction.
Parameters:
client - The agent this behaviour belongs to, that embodies Initiator role in this fipa-request interaction.
request - The ACLMessage object to be sent. When passed to this constructor, the message type is set to request and the :protocol slot is set to fipa-request, so there's no need to set them before calling the constructor. If present, :conversation-id and :reply-with slots are used for interaction labelling. Application programmer must ensure the following properties of request parameter when calling this constructor:
  1. request has a valid :receiver slot value.
  2. request has a valid :content slot value.
  3. request has a valid :language slot value.
  4. request has a valid :ontology slot value.
However, only :receiver slot is actually used by this behaviour to send the message to the destination agent (only one receiver is supported by fipa-request protocol).
template - A MessageTemplate object used to match incoming replies. This behaviour automatically matches replies according to message type and :protocol slot value; also, :conversation-id and :reply-to slot values are matched when corresponding slot values are present in request parameter. This constructor argument can be used to match additional fields, such as :language and :ontology slots.

FipaRequestInitiatorBehaviour

public FipaRequestInitiatorBehaviour(Agent client,
                                     ACLMessage request)
Constructor for this behaviour. In this case the MessageTemplate is the default one.
Method Detail

reset

public void reset()
This method resets this behaviour so that it restarts from the initial state of the protocol with the same request message.
Overrides:
reset in class SimpleBehaviour

reset

public void reset(ACLMessage request)
This method resets this behaviour so that it restarts the protocol with another request message.
Parameters:
request - updates request message to be sent.

reset

public void reset(ACLMessage request,
                  MessageTemplate template)
This method resets this behaviour so that it restarts the protocol with other request message and MessageTemplate
Parameters:
request - update request message to be sent.
template - a new MessageTemplate.

getRequest

protected ACLMessage getRequest()
This method gives access to the request ACL message, originally set by the class constructor.
Returns:
The ACL request message sent by this behaviour.

done

public boolean done()
Overrides:
done in class Behaviour

action

public void action()
Overrides:
action in class Behaviour

handleNotUnderstood

protected abstract void handleNotUnderstood(ACLMessage reply)
Abstract method to handle not-understood replies. This method must be implemented by FipaRequestInitiatorBehaviour subclasses to react to not-understood messages from the peer agent.
Parameters:
reply - The actual ACL message received. It is of not-understood type and matches the conversation template.

handleRefuse

protected abstract void handleRefuse(ACLMessage reply)
Abstract method to handle refuse replies. This method must be implemented by FipaRequestInitiatorBehaviour subclasses to react to refuse messages from the peer agent.
Parameters:
reply - The actual ACL message received. It is of refuse type and matches the conversation template.

handleAgree

protected abstract void handleAgree(ACLMessage reply)
Abstract method to handle agree replies. This method must be implemented by FipaRequestInitiatorBehaviour subclasses to react to agree messages from the peer agent.
Parameters:
reply - The actual ACL message received. It is of agree type and matches the conversation template.

handleFailure

protected abstract void handleFailure(ACLMessage reply)
Abstract method to handle failure replies. This method must be implemented by FipaRequestInitiatorBehaviour subclasses to react to failure messages from the peer agent.
Parameters:
reply - The actual ACL message received. It is of failure type and matches the conversation template.

handleInform

protected abstract void handleInform(ACLMessage reply)
Abstract method to handle inform replies. This method must be implemented by FipaRequestInitiatorBehaviour subclasses to react to inform messages from the peer agent.
Parameters:
reply - The actual ACL message received. It is of inform type and matches the conversation template.

handleOtherMessages

protected void handleOtherMessages(ACLMessage reply)
This method can be override to handle other received messages different from those stated by the protocol. By default it prints a warning message.

handleTimeout

public long handleTimeout()
This method is called by the action method when the timeout set in the request message is expired. By default it returns -1 so that the agent will wait for an infinite timeout. It can be override by the programmer to:
  • update his own data base;
  • call the reset to restart the protocol with different message or template;
  • stop the protocol, setting finished = true;
  • return an additional timeout;