jade.proto
Class FipaRequestResponderBehaviour

java.lang.Object
  |
  +--jade.core.behaviours.Behaviour
        |
        +--jade.core.behaviours.SimpleBehaviour
              |
              +--jade.core.behaviours.CyclicBehaviour
                    |
                    +--jade.proto.FipaRequestResponderBehaviour

public class FipaRequestResponderBehaviour
extends CyclicBehaviour

This behaviour plays the Responder role in fipa-request protocol. This is an abstract class, defining an abstract method for each message type expected from a fipa-request interaction. This behaviour works as a dispatcher, reading the :content slot of received request messages and spawning different behaviours according to the action requested. To be able to handle requests, user defined behaviours must extend Action inner class; when a request message arrives, an implementation of Factory inner interface is retrieved from registered action factories, using the action name as key. Then an Action is created and spawned with Agent.addBehaviour(); this new action object will handle the specific request. Therefore, three steps must be accomplished to add a new action to a FipaRequestResponderBehaviour object:

  1. Write a suitable handler for the new action extending Action inner class.
  2. Write an implementation of Factory inner interface to create handler behaviours on demand.
  3. Register your Factory object calling registerFactory() and use the name of the action you want to handle as key.

Author:
Giovanni Rimassa - Universita` di Parma
See Also:
FipaRequestInitiatorBehaviour, Serialized Form

Inner Class Summary
static class FipaRequestResponderBehaviour.ActionHandler
          This class must be extended by users to handle a specific request action.
static interface FipaRequestResponderBehaviour.Factory
          This interface must be implemented by users to create on demand a new instance of a suitable Action according to the action name.
 
Inner classes inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent
 
Constructor Summary
FipaRequestResponderBehaviour(Agent a)
          Public constructor for this behaviour.
FipaRequestResponderBehaviour(Agent a, MessageTemplate match)
          This constructor allows to specify a message pattern to be matched by the received message.
 
Method Summary
 void action()
           
protected  java.lang.String getActionName(ACLMessage msg)
          This method is used to get the right behaviour from the Factory.
 void registerFactory(java.lang.String actionName, FipaRequestResponderBehaviour.Factory f)
          Associate a Factory object with an action name.
 void unregisterFactory(java.lang.String actionName)
          Remove a action name - Factory object association.
 
Methods inherited from class jade.core.behaviours.CyclicBehaviour
done
 
Methods inherited from class jade.core.behaviours.SimpleBehaviour
reset
 
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
 

Constructor Detail

FipaRequestResponderBehaviour

public FipaRequestResponderBehaviour(Agent a)
Public constructor for this behaviour.
Parameters:
a - The agent this behaviour belongs to.

FipaRequestResponderBehaviour

public FipaRequestResponderBehaviour(Agent a,
                                     MessageTemplate match)
This constructor allows to specify a message pattern to be matched by the received message.
Parameters:
a - the agent that adds the behaviour
match - the MessageTemplate to be matched
Method Detail

getActionName

protected java.lang.String getActionName(ACLMessage msg)
                                  throws NotUnderstoodException,
                                         RefuseException
This method is used to get the right behaviour from the Factory. It must return the name of the action that is then used to look-up in the factory with the list of registered actions. A default implementation is provided that is case-sensitive. So, the case of the returned String and that of the String passed as a parameter to registerFactory must be the same.
Parameters:
a - An Action ontological object, that holds the content of a received request ACL message.
Returns:
the name of the action. If some problem occurs, it throws an Exception.
See Also:
registerFactory(String actionName, FipaRequestResponderBehaviour.Factory f)

action

public void action()
Overrides:
action in class Behaviour

registerFactory

public void registerFactory(java.lang.String actionName,
                            FipaRequestResponderBehaviour.Factory f)
Associate a Factory object with an action name. This method registers an object to be used to create behaviours to handle the specified action when some request for it is received. In order to implement a case-insensitive match, all action names are converted to uppercase before registration.
Parameters:
actionName - The name of the action the Factory creates handlers for.
f - The actual Factory object; it will be used to create action handlers on demand.

unregisterFactory

public void unregisterFactory(java.lang.String actionName)
Remove a action name - Factory object association. This method deregisters a Factory object with the dispatcher. It can be used to suspend service for a specific action for a while; during that time, the agent will answer with not-understood messages to requests for the suspended action. In order to implement a case-insensitive match, all action names are converted to uppercase before deregistration.
Parameters:
actionName - The name of the action to remove from supported actions.