Magentix2  2.1.1
es.upv.dsic.gti_ia.jason.conversationsFactory.participant.Jason_FCN_Participant Class Reference
Collaboration diagram for es.upv.dsic.gti_ia.jason.conversationsFactory.participant.Jason_FCN_Participant:

List of all members.

Classes

class  BEGIN_Method
class  DO_TASK_Method
class  FINAL_Method
class  RECEIVE_ACCEPT_Method
class  RECEIVE_REJECT_Method
class  RECEIVE_SOLICIT_Method
class  SEND_FAILURE_Method
class  SEND_INFO_Method
class  SEND_NOT_UNDERSTOOD_Method
class  SEND_PROPOSAL_Method
class  SEND_REFUSE_Method

Public Member Functions

 Jason_FCN_Participant (String agName2, TransitionSystem ts2)
ConvCFactory newFactory (String name, MessageFilter filter, ACLMessage template, int availableConversations, ConvJasonAgent myAgent, int timeout)

Protected Member Functions

void doBegin (CProcessor myProcessor, ACLMessage msg)
String doReceiveSolicit (ConvCProcessor myProcessor, ACLMessage msg)
void doSendProposal (ConvCProcessor myProcessor, ACLMessage messageToSend)
void doSendRefuse (CProcessor myProcessor, ACLMessage messageToSend)
void doSendNotUnderstood (CProcessor myProcessor, ACLMessage messageToSend)
void doReceiveAccept (CProcessor myProcessor, ACLMessage msg)
void doReceiveReject (CProcessor myProcessor, ACLMessage msg)
String doTask (ConvCProcessor myProcessor, ACLMessage solicitMessage)
void doSendFailure (CProcessor myProcessor, ACLMessage messageToSend)
void doSendInfo (ConvCProcessor myProcessor, ACLMessage messageToSend)
void doFinal (ConvCProcessor myProcessor, ACLMessage messageToSend)

Protected Attributes

TransitionSystem Ts

Detailed Description

This class represents a template for a Fipa Contract Net Protocol from the participant perspective for being used in the Conversations Factory from Jason agents.

Author:
Bexy Alfonso Espinosa

Definition at line 38 of file Jason_FCN_Participant.java.


Constructor & Destructor Documentation

Definition at line 42 of file Jason_FCN_Participant.java.

                                                                           {
                Ts = ts2;
        }

Member Function Documentation

Method executed at the beginning of the conversation

Parameters:
myProcessorthe CProcessor managing the conversation
msgfirst message assigned to this conversation

Definition at line 51 of file Jason_FCN_Participant.java.

                                                                       {
                myProcessor.getInternalData().put("InitialMessage", msg);
        }

Method executed when the conversation ends

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendfinal message

Definition at line 283 of file Jason_FCN_Participant.java.

                                                                                     {
                FCNConversation conv = (FCNConversation)myProcessor.getConversation();
                myProcessor.getMyAgent().removeFactory(conv.factoryName);
                messageToSend = myProcessor.getLastSentMessage();
        }

Method executed when the initiator accepts participant's proposal

Parameters:
myProcessorthe CProcessor managing the conversation
msgaccept message

Definition at line 179 of file Jason_FCN_Participant.java.

                                                                              {
        }

Method executed when the initiator rejects participant's proposal

Parameters:
myProcessorthe CProcessor managing the conversation
msgreject message

Definition at line 194 of file Jason_FCN_Participant.java.

                                                                              {
        }

Method executed when the participant receives a call for proposals

Parameters:
myProcessorthe CProcessor managing the conversation
msgcall for proposals message
Returns:
next state of this conversation

Definition at line 68 of file Jason_FCN_Participant.java.

                                                                                     {
                // accept all the solicits
                String jasonConvID = msg.getHeaderValue("jasonID");
                
                Conversation conv = myProcessor.getConversation();
                String factName = conv.factoryName;
                //At this point the conversation associated to the CProcessor has no value
                //for the internal conversation ID so it is updated
                conv.jasonConvID = jasonConvID;
                conv.initiator = msg.getSender();
                FCNConversation newConv = new FCNConversation(conv.jasonConvID, conv.internalConvID, "", conv.initiator,factName);
                ((ConvCFactory)myProcessor.getMyFactory()).UpdateConv(newConv, myProcessor);
                String result = "";
                AgentID Sender = myProcessor.getLastReceivedMessage().getSender();
                String newMsgContent = "callforproposal"+"("+Sender.name+","+msg.getContent()+","+conv.jasonConvID+")[source(self)]";
                List<Literal> allpercep = new ArrayList<Literal>();
                allpercep.add(Literal.parseLiteral(newMsgContent));
                ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allpercep);
                
                newConv.aquire_semaphore();
                
                if (newConv.kindOfAnswer =="propose"){
                        result = "SEND_PROPOSAL";
                }else if (newConv.kindOfAnswer=="refuse"){
                        result = "SEND_REFUSE";
                }else if (newConv.kindOfAnswer=="notUnderstood"){
                        result = "SEND_NOT_UNDERSTOOD";
                }
                return result;
        }

Method executed when the task failed

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendfail message

Definition at line 238 of file Jason_FCN_Participant.java.

                                                 {
                ACLMessage aux = (ACLMessage) myProcessor.getInternalData().get(
                "InitialMessage");
                messageToSend.copyFromAsTemplate(aux);
                messageToSend.setProtocol("fipa-contract-net");
                messageToSend.setPerformative(ACLMessage.FAILURE);
                messageToSend.setReceiver(myProcessor.getLastReceivedMessage().getSender());
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
        }

Method executed when the task succeeded

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendinform message

Definition at line 261 of file Jason_FCN_Participant.java.

                                                 {
                FCNConversation conv = (FCNConversation)myProcessor.getConversation();
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
                messageToSend.setReceiver(myProcessor.getLastReceivedMessage().getSender());
                messageToSend.setContent("I'm "+myProcessor.getMyAgent().getAid().name+": "+conv.infoToSend);
                messageToSend.setPerformative(ACLMessage.INFORM);
                messageToSend.setProtocol("fipa-contract-net"); 
        }

Method executed when the participant sends a not-understood

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendnot-understood message

Definition at line 157 of file Jason_FCN_Participant.java.

                                                 {
                ACLMessage aux = (ACLMessage) myProcessor.getInternalData().get(
                "InitialMessage");
                messageToSend.copyFromAsTemplate(aux);
                messageToSend.setProtocol("fipa-contract-net");
                messageToSend.setPerformative(ACLMessage.NOT_UNDERSTOOD);
                messageToSend.setReceiver(myProcessor.getLastReceivedMessage().getSender());
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
        }

Method executed when the participant sends a proposal

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendproposal message

Definition at line 111 of file Jason_FCN_Participant.java.

                                                 {
                FCNConversation conv = (FCNConversation)myProcessor.getConversation();
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
                messageToSend.setReceiver(conv.initiator);
                messageToSend.setContent(conv.proposal);
                messageToSend.setPerformative(ACLMessage.PROPOSE);
                messageToSend.setProtocol("fipa-contract-net");
        }

Method executed when the participant sends a refuse

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendrefuse message

Definition at line 134 of file Jason_FCN_Participant.java.

                                                 {
                ACLMessage aux = (ACLMessage) myProcessor.getInternalData().get(
                "InitialMessage");
                messageToSend.copyFromAsTemplate(aux);
                messageToSend.setProtocol("fipa-contract-net");
                messageToSend.setPerformative(ACLMessage.REFUSE);
                messageToSend.setReceiver(myProcessor.getLastReceivedMessage().getSender());
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
        }

Perform the proposal's task

Parameters:
myProcessorthe CProcessor managing the conversation
solicitMessagethe first message assigned to this conversation containing the solicit of the initiator agent
Returns:
next conversation state

Definition at line 210 of file Jason_FCN_Participant.java.

                                                                                      {
                String result = ""; 
                FCNConversation conv = (FCNConversation)myProcessor.getConversation();
                List<Literal> allpercep = new ArrayList<Literal>();
                allpercep.add(Literal.parseLiteral("timetodotask("+conv.initiator.name+","+conv.jasonConvID+")[source(self)]"));
                ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allpercep);

                conv.aquire_semaphore();
                
                if (conv.taskDone){ 
                        result = "SEND_INFORM";}
                else {
                        result = "SEND_FAILURE";}
                return result;
        }
ConvCFactory es.upv.dsic.gti_ia.jason.conversationsFactory.participant.Jason_FCN_Participant.newFactory ( String  name,
MessageFilter  filter,
ACLMessage  template,
int  availableConversations,
ConvJasonAgent  myAgent,
int  timeout 
)

Creates a new contract-net participant CFactory

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

Definition at line 307 of file Jason_FCN_Participant.java.

                                                                                                              {

                // Create factory

                if (filter == null) {
                        filter = new MessageFilter("performative = CFP"); // falta AND
                                                                                                                                        // protocol
                                                                                                                                        // =
                                                                                                                                        // fipa-contract-net;
                }
                
                if (template == null){
                        template = new ACLMessage(ACLMessage.PROPOSE);
                }
                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_SOLICIT State
                WaitState WAIT_FOR_SOLICIT = new WaitState("WAIT_FOR_SOLICIT", timeout);
                processor.registerState(WAIT_FOR_SOLICIT);
                processor.addTransition(BEGIN, WAIT_FOR_SOLICIT);
                
                // RECEIVE_SOLICIT State

                ReceiveState RECEIVE_SOLICIT = new ReceiveState(
                                "RECEIVE_SOLICIT");
                RECEIVE_SOLICIT.setMethod(new RECEIVE_SOLICIT_Method());
                filter = new MessageFilter("performative = CFP");
                RECEIVE_SOLICIT.setAcceptFilter(filter);
                processor.registerState(RECEIVE_SOLICIT);
                processor.addTransition(WAIT_FOR_SOLICIT,
                                RECEIVE_SOLICIT);

                // SEND_PROPOSAL State

                SendState SEND_PROPOSAL = new SendState("SEND_PROPOSAL");

                SEND_PROPOSAL.setMethod(new SEND_PROPOSAL_Method());
                template.setProtocol("fipa-contract-net");
                template.setPerformative(ACLMessage.PROPOSE);
                SEND_PROPOSAL.setMessageTemplate(template);
                processor.registerState(SEND_PROPOSAL);
                processor.addTransition(RECEIVE_SOLICIT, SEND_PROPOSAL);
                
                // SEND_REFUSE State

                SendState SEND_REFUSE = new SendState("SEND_REFUSE");

                SEND_REFUSE.setMethod(new SEND_REFUSE_Method());
                template.setProtocol("fipa-contract-net");
                template.setPerformative(ACLMessage.REFUSE);
                SEND_REFUSE.setMessageTemplate(template);
                processor.registerState(SEND_REFUSE);
                processor.addTransition(RECEIVE_SOLICIT, SEND_REFUSE);
                
                // SEND_NOT_UNDERSTOOD State

                SendState SEND_NOT_UNDERSTOOD = new SendState("SEND_NOT_UNDERSTOOD");

                SEND_NOT_UNDERSTOOD.setMethod(new SEND_NOT_UNDERSTOOD_Method());
                template.setProtocol("fipa-contract-net");
                template.setPerformative(ACLMessage.NOT_UNDERSTOOD);
                SEND_NOT_UNDERSTOOD.setMessageTemplate(template);
                processor.registerState(SEND_NOT_UNDERSTOOD);
                processor.addTransition(RECEIVE_SOLICIT, SEND_NOT_UNDERSTOOD);

                // WAIT_FOR_ACCEPT State
                WaitState WAIT_FOR_ACCEPT = new WaitState("WAIT_FOR_ACCEPT", timeout);
                processor.registerState(WAIT_FOR_ACCEPT);
                processor.addTransition(SEND_PROPOSAL, WAIT_FOR_ACCEPT);

                // RECEIVE_ACCEPT State

                ReceiveState RECEIVE_ACCEPT = new ReceiveState(
                                "RECEIVE_ACCEPT");
                RECEIVE_ACCEPT.setMethod(new RECEIVE_ACCEPT_Method());
                filter = new MessageFilter("performative = ACCEPT-PROPOSAL");
                RECEIVE_ACCEPT.setAcceptFilter(filter);
                processor.registerState(RECEIVE_ACCEPT);
                processor.addTransition(WAIT_FOR_ACCEPT,
                                RECEIVE_ACCEPT);

                // RECEIVE_REJECT State

                ReceiveState RECEIVE_REJECT = new ReceiveState("RECEIVE_REJECT");
                RECEIVE_REJECT.setMethod(new RECEIVE_REJECT_Method());
                filter = new MessageFilter("performative = REJECT-PROPOSAL");
                RECEIVE_REJECT.setAcceptFilter(filter);
                processor.registerState(RECEIVE_REJECT);
                processor.addTransition(WAIT_FOR_ACCEPT,
                                RECEIVE_REJECT);

                // DO_TASK State

                ActionState DO_TASK = new ActionState("DO_TASK");
                DO_TASK.setMethod(new DO_TASK_Method());
                processor.registerState(DO_TASK);
                processor.addTransition(RECEIVE_ACCEPT, DO_TASK);
                
                // SEND_INFO State

                SendState SEND_INFO = new SendState("SEND_INFORM");

                SEND_INFO.setMethod(new SEND_INFO_Method());
                template.setProtocol("fipa-contract-net");
                template.setPerformative(ACLMessage.INFORM);
                SEND_INFO.setMessageTemplate(template);
                processor.registerState(SEND_INFO);
                processor.addTransition(DO_TASK, SEND_INFO);
                
                // SEND_INFO State

                SendState SEND_FAILURE = new SendState("SEND_FAILURE");

                SEND_FAILURE.setMethod(new SEND_FAILURE_Method());
                template.setProtocol("fipa-contract-net");
                template.setPerformative(ACLMessage.FAILURE);
                SEND_FAILURE.setMessageTemplate(template);
                processor.registerState(SEND_FAILURE);
                processor.addTransition(DO_TASK, SEND_FAILURE);         

                // FINAL State

                FinalState FINAL = new FinalState("FINAL");

                FINAL.setMethod(new FINAL_Method());

                processor.registerState(FINAL);
                processor.addTransition(SEND_FAILURE, FINAL);                   
                processor.addTransition(SEND_INFO, FINAL);
                processor.addTransition(RECEIVE_REJECT, FINAL);
                processor.addTransition(SEND_NOT_UNDERSTOOD, FINAL);
                processor.addTransition(SEND_REFUSE, FINAL);
                return theFactory;
        } 

Member Data Documentation


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