Magentix2  2.1.1
es.upv.dsic.gti_ia.jason.conversationsFactory.initiator.Jason_Fipa_Request_Initiator Class Reference
Collaboration diagram for es.upv.dsic.gti_ia.jason.conversationsFactory.initiator.Jason_Fipa_Request_Initiator:

List of all members.

Classes

class  AGREE_Method
class  BEGIN_Method
class  FAILURE_Method
class  FINAL_Method
class  INFORM_Method
class  NOT_UNDERSTOOD_Method
class  RECEIVE_CANCEL_WAIT_Method
class  REFUSE_Method
class  REQUEST_Method
class  TIMEOUT_Method

Public Member Functions

 Jason_Fipa_Request_Initiator (String sagName, TransitionSystem ts)
ConvCFactory newFactory (String name, MessageFilter filter, ACLMessage requestMessage, int availableConversations, ConvJasonAgent myAgent, long timeout)

Protected Member Functions

void doBegin (ConvCProcessor myProcessor, ACLMessage messageToSend)
void doRequest (ConvCProcessor myProcessor, ACLMessage messageToSend)
void doNotUnderstood (ConvCProcessor myProcessor, ACLMessage msg)
void doRefuse (ConvCProcessor myProcessor, ACLMessage msg)
void doAgree (ConvCProcessor myProcessor, ACLMessage msg)
void doTimeout (ConvCProcessor myProcessor, ACLMessage msg)
void doFailure (ConvCProcessor myProcessor, ACLMessage msg)
void doInform (ConvCProcessor myProcessor, ACLMessage msg)
void doFinal (ConvCProcessor myProcessor, ACLMessage messageToSend)

Protected Attributes

TransitionSystem Ts

Detailed Description

This class represents a template for a Fipa Request Protocol from the initiator perspective for being used in the Conversations Factory from Jason agents.

Author:
Bexy Alfonso Espinosa

Definition at line 35 of file Jason_Fipa_Request_Initiator.java.


Constructor & Destructor Documentation


Member Function Documentation

Method to execute when the initiator receives an agree message

Parameters:
myProcessorthe CProcessor managing the conversation
msgagree message

Definition at line 151 of file Jason_Fipa_Request_Initiator.java.

                                                                  {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        conv.FinalResult = '"'+ACLMessage.getPerformative(ACLMessage.AGREE)+'"';
}

Method to execute at the beginning of the conversation

Parameters:
myProcessorthe CProcessor managing the conversation
msgfirst message to send

Definition at line 51 of file Jason_Fipa_Request_Initiator.java.

                                          {
        FRConversation conv =  (FRConversation) myProcessor.getConversation();
        messageToSend.setContent(conv.initialMessage);
        myProcessor.getInternalData().put("InitialMessage", messageToSend);

}

Method to execute when the initiator receives a failure message

Parameters:
myProcessorthe CProcessor managing the conversation
msgfailure message

Definition at line 186 of file Jason_Fipa_Request_Initiator.java.

                                                                    {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        conv.FinalResult = '"'+ACLMessage.getPerformative(ACLMessage.FAILURE)+'"';

}

Method to execute when the initiator ends the conversation

Parameters:
myProcessor
messageToSend

Definition at line 232 of file Jason_Fipa_Request_Initiator.java.

                                                                            {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        List<Literal> allperc = new ArrayList<Literal>();
        String percept = "conversationended("+conv.jasonConvID+","+conv.FinalResult+")[source(self)]";
        allperc.add(Literal.parseLiteral(percept));
        ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allperc);
        messageToSend = myProcessor.getLastSentMessage();
        messageToSend.setProtocol("fipa-request");
        messageToSend.setPerformative(ACLMessage.REQUEST);
        
        myProcessor.getMyAgent().removeFactory(conv.factoryName);
}

Method to execute when the initiator receives an inform message

Parameters:
myProcessor
msg

Definition at line 204 of file Jason_Fipa_Request_Initiator.java.

                                                                    {

        FRConversation conv = (FRConversation) myProcessor.getConversation();
        conv.TaskResult = msg.getContent();
        List<Literal> allperc = new ArrayList<Literal>();
        String percept = "taskdonesuccessfully("+conv.Participant +","+conv.TaskResult+","+conv.jasonConvID+")[source(self)]";
        allperc.add(Literal.parseLiteral(percept));
        ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allperc);

        conv.aquire_semaphore();
        
        msg.setProtocol("fipa-request");
        msg.setPerformative(ACLMessage.REQUEST);
        conv.FinalResult = '"'+ACLMessage.getPerformative(ACLMessage.INFORM)+'"';
}

Method to execute when the initiator receives a not-understood message

Parameters:
myProcessorthe CProcessor managing the conversation
msgnot-understood message

Definition at line 117 of file Jason_Fipa_Request_Initiator.java.

                                                                          {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        conv.FinalResult = '"'+ACLMessage.getPerformative(ACLMessage.NOT_UNDERSTOOD)+'"';
}

Method to execute when the initiator receives a failure message

Parameters:
myProcessorthe CProcessor managing the conversation
msgfailure message

Definition at line 134 of file Jason_Fipa_Request_Initiator.java.

                                                                   {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        conv.FinalResult = '"'+ACLMessage.getPerformative(ACLMessage.REFUSE)+'"';
}

Sets the request message

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendrequest message

Definition at line 89 of file Jason_Fipa_Request_Initiator.java.

                                          {
        FRConversation conv = (FRConversation) myProcessor.getConversation();

        conv.aquire_semaphore();
        
        messageToSend.setContent(conv.frMessage);
        messageToSend.setProtocol("fipa-request");
        messageToSend.setPerformative(ACLMessage.REQUEST);
        messageToSend.setReceiver(new AgentID(conv.Participant));  
        messageToSend.setSender(myProcessor.getMyAgent().getAid() );
        messageToSend.setHeader("jasonID", conv.jasonConvID);
        messageToSend.setHeader("data", conv.frData);
        messageToSend.setHeader("factoryname", conv.factoryName);
}

Method executed when the timeout is reached while the initiator was waiting for the acceptance of the request

Parameters:
myProcessorthe CProcessor managing the conversation
msgtimeout message

Definition at line 169 of file Jason_Fipa_Request_Initiator.java.

                                                                     {
        FRConversation conv = (FRConversation)myProcessor.getConversation();
        conv.FinalResult = '"'+"Timeout"+'"';
}
ConvCFactory es.upv.dsic.gti_ia.jason.conversationsFactory.initiator.Jason_Fipa_Request_Initiator.newFactory ( String  name,
MessageFilter  filter,
ACLMessage  requestMessage,
int  availableConversations,
ConvJasonAgent  myAgent,
long  timeout 
)

Creates a new initiator fipa request cfactory

Parameters:
namefactory's name
filtermessage filter
requestMessagefirst message to send
availableConversationsmaximum number of conversation this CFactory can manage simultaneously
myAgentagent owner of this CFactory
timeoutfor waiting after sending the request message
Returns:
a new fipa request initiator factory

Definition at line 260 of file Jason_Fipa_Request_Initiator.java.

                                                                                          {

                // Create factory

                if (filter == null) {
                        filter = new MessageFilter("performative = REQUEST"); //falta AND protocol = fipa-request;
                }
                ConvCFactory theFactory = new ConvCFactory(name, filter,
                                availableConversations, myAgent);

                // Processor template setup

                ConvCProcessor processor = theFactory.cProcessorTemplate();

                // BEGIN State

                BeginState BEGIN = (BeginState) processor.getState("BEGIN");
                BEGIN.setMethod(new BEGIN_Method());
                
                // WAIT_FOR_PARTICIPANT_TO_JOIN state
                WaitState WAIT_FOR_PARTICIPANT_TO_JOIN = new WaitState("WAIT_FOR_PARTICIPANT_TO_JOIN", 500);
                processor.registerState(WAIT_FOR_PARTICIPANT_TO_JOIN);
                processor.addTransition(BEGIN, WAIT_FOR_PARTICIPANT_TO_JOIN);
                
                // RECEIVE_CANCEL_WAIT State
                //Header: purpose Value: waitMessage
                ReceiveState RECEIVE_CANCEL_WAIT = new ReceiveState("RECEIVE_CANCEL_WAIT");
                RECEIVE_CANCEL_WAIT.setMethod(new RECEIVE_CANCEL_WAIT_Method());
                filter = new MessageFilter("purpose = waitMessage");  
                RECEIVE_CANCEL_WAIT.setAcceptFilter(filter);
                processor.registerState(RECEIVE_CANCEL_WAIT);
                processor.addTransition(WAIT_FOR_PARTICIPANT_TO_JOIN,
                                RECEIVE_CANCEL_WAIT);
                
                // REQUEST State

                SendState REQUEST = new SendState("REQUEST_REQUEST_INITIATOR");

                REQUEST.setMethod(new REQUEST_Method());
                //requestMessage = new ACLMessage(ACLMessage.REQUEST);
                //requestMessage.setProtocol("REQUEST");                
                REQUEST.setMessageTemplate(requestMessage);
                processor.registerState(REQUEST);
                processor.addTransition("RECEIVE_CANCEL_WAIT", "REQUEST_REQUEST_INITIATOR");

                // FIRST_WAIT State

                processor.registerState(new WaitState("FIRST_WAIT_REQUEST_INITIATOR", timeout));
                processor.addTransition("REQUEST_REQUEST_INITIATOR", "FIRST_WAIT_REQUEST_INITIATOR");
                
                // NOT_UNDERSTOOD State
                
                ReceiveState NOT_UNDERSTOOD = new ReceiveState("NOT_UNDERSTOOD_REQUEST_INITIATOR");
                NOT_UNDERSTOOD.setMethod(new NOT_UNDERSTOOD_Method());
                filter = new MessageFilter("performative = "+ACLMessage.getPerformative(ACLMessage.NOT_UNDERSTOOD));
                NOT_UNDERSTOOD.setAcceptFilter(filter);
                processor.registerState(NOT_UNDERSTOOD);
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "NOT_UNDERSTOOD_REQUEST_INITIATOR");
                
                // REFUSE State
                
                ReceiveState REFUSE = new ReceiveState("REFUSE_REQUEST_INITIATOR");
                REFUSE.setMethod(new REFUSE_Method());
                filter = new MessageFilter("performative = REFUSE");
                REFUSE.setAcceptFilter(filter);
                processor.registerState(REFUSE);
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "REFUSE_REQUEST_INITIATOR");
                
                // AGREE State
                
                ReceiveState AGREE = new ReceiveState("AGREE_REQUEST_INITIATOR");
                AGREE.setMethod(new AGREE_Method());
                filter = new MessageFilter("performative = AGREE");
                AGREE.setAcceptFilter(filter);
                processor.registerState(AGREE);
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "AGREE_REQUEST_INITIATOR");
                

                // TIMEOUT State

                ReceiveState TIMEOUT = new ReceiveState("TIMEOUT");
                TIMEOUT.setMethod(new TIMEOUT_Method());
                filter = new MessageFilter("performative = INFORM AND purpose = waitMessage");
                TIMEOUT.setAcceptFilter(filter);
                processor.registerState(TIMEOUT);
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "TIMEOUT");
                
                // SECOND_WAIT State

                processor.registerState(new WaitState("SECOND_WAIT_REQUEST_INITIATOR", timeout));
                processor.addTransition("AGREE_REQUEST_INITIATOR", "SECOND_WAIT_REQUEST_INITIATOR");
                
                // FAILURE State

                ReceiveState FAILURE = new ReceiveState("FAILURE_REQUEST_INITIATOR");
                FAILURE.setMethod(new FAILURE_Method());
                filter = new MessageFilter("performative = FAILURE");
                FAILURE.setAcceptFilter(filter);
                processor.registerState(FAILURE);
                processor.addTransition("SECOND_WAIT_REQUEST_INITIATOR", "FAILURE_REQUEST_INITIATOR");
                
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "FAILURE_REQUEST_INITIATOR");
                
                // INFORM State

                ReceiveState INFORM = new ReceiveState("INFORM_REQUEST_INITIATOR");
                INFORM.setMethod(new INFORM_Method());
                filter = new MessageFilter("performative = INFORM AND in-reply-to = request");
                INFORM.setAcceptFilter(filter);
                processor.registerState(INFORM);
                processor.addTransition("SECOND_WAIT_REQUEST_INITIATOR", "INFORM_REQUEST_INITIATOR");
                
                processor.addTransition("FIRST_WAIT_REQUEST_INITIATOR", "INFORM_REQUEST_INITIATOR");

                processor.addTransition("SECOND_WAIT_REQUEST_INITIATOR", "TIMEOUT");
                // FINAL State

                FinalState FINAL = new FinalState("FINAL_REQUEST_INITIATOR");

                FINAL.setMethod(new FINAL_Method());

                processor.registerState(FINAL);
                processor.addTransition("TIMEOUT","FINAL_REQUEST_INITIATOR");
                processor.addTransition("INFORM_REQUEST_INITIATOR", "FINAL_REQUEST_INITIATOR");
                processor.addTransition("FAILURE_REQUEST_INITIATOR", "FINAL_REQUEST_INITIATOR");
                processor.addTransition("NOT_UNDERSTOOD_REQUEST_INITIATOR", "FINAL_REQUEST_INITIATOR");
                processor.addTransition("REFUSE_REQUEST_INITIATOR", "FINAL_REQUEST_INITIATOR");
                return theFactory;
        }

Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables