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

List of all members.

Classes

class  AGREE_Method
class  BEGIN_Method
class  CANCEL_FAILURE_Method
class  CANCEL_INFORM_Method
class  CANCEL_Method
class  FAILURE_Method
class  FINAL_Method
class  INFORM_Method
class  RECEIVE_SUBSCRIBE_Method
class  REFUSE_Method

Public Member Functions

 Jason_Fipa_Subscribe_Participant (String sagName, TransitionSystem ts)
ConvCFactory newFactory (String name, MessageFilter filter, int availableConversations, ConvJasonAgent myAgent)

Protected Member Functions

void doBegin (ConvCProcessor myProcessor, ACLMessage messageToSend)
String doReceiveSubscribe (ConvCProcessor myProcessor, ACLMessage subscribe)
void doRefuse (ConvCProcessor myProcessor, ACLMessage messageToSend)
void doAgree (ConvCProcessor myProcessor, ACLMessage messageToSend)
String doInform (ConvCProcessor myProcessor, ACLMessage messagereceived)
void doFailure (ConvCProcessor myProcessor, ACLMessage messageToSend)
String doCancel (ConvCProcessor myProcessor, ACLMessage messagereceived)
void doCancelInform (ConvCProcessor myProcessor, ACLMessage response)
void doCancelFailure (ConvCProcessor myProcessor, ACLMessage response)
void doFinal (ConvCProcessor myProcessor, ACLMessage messageToSend)

Protected Attributes

TransitionSystem Ts

Detailed Description

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

Author:
Bexy Alfonso Espinosa

Definition at line 36 of file Jason_Fipa_Subscribe_Participant.java.


Constructor & Destructor Documentation


Member Function Documentation

Sets the agree message

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendagree message

Definition at line 148 of file Jason_Fipa_Subscribe_Participant.java.

                                                  {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                messageToSend.setProtocol("fipa-subscribe");
                messageToSend.setPerformative(ACLMessage.AGREE);
                messageToSend.setInReplyTo(ACLMessage.getPerformative(ACLMessage.SUBSCRIBE));
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
                messageToSend.setReceiver(conv.initiator);

                //Precond: not necessarily but there sould be at least an object in 
                //conv.objects with result values
                Iterator<Entry<String, String>> objIt = conv.objects.entrySet().iterator();
                List<Literal> allperc = new ArrayList<Literal>();
                String percept;
                while (objIt.hasNext()) {
                        Entry<String, String> obj =  objIt.next();
                        String key = obj.getKey();
                        percept = "subscribe("+conv.initiator.name+","+key+","+conv.jasonConvID+")[source(self)]";
                        allperc.add(Literal.parseLiteral(percept));
                }
                ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allperc);
        }

Method executed at the beginning of the conversation

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

Definition at line 51 of file Jason_Fipa_Subscribe_Participant.java.

                                                  {
                myProcessor.getInternalData().put("InitialMessage", messageToSend);

        }

Cancels the conversation

Parameters:
myProcessorthe CProcessor managing the conversation
messagereceivedcancel message

Definition at line 255 of file Jason_Fipa_Subscribe_Participant.java.

                                                                                         {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                //To add a perception
                List<Literal> allperc = new ArrayList<Literal>();
                String percept = "conversationcanceledbyinitiator("+conv.jasonConvID+")[source(self)]";
                allperc.add(Literal.parseLiteral(percept));
                ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allperc);
                conv.aquire_semaphore();
                //Precond: conv.conversationCanceled must say if the conversation was right canceled 
                String result ;
                if (conv.conversationCanceled){result = "CANCEL_INFORM";}
                else {result = "CANCEL_FAILURE";}
                return result;
        }

Sets the failure message in response to the cancel request

Parameters:
myProcessorthe CProcessor managing the conversation
responsefailure message.

Definition at line 304 of file Jason_Fipa_Subscribe_Participant.java.

                                                                                       {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                response.setProtocol("fipa-subscribe");
                response.setPerformative(ACLMessage.FAILURE);
                response.setInReplyTo(ACLMessage.getPerformative(ACLMessage.CANCEL));
                response.setReceiver(conv.initiator);
                response.setSender(myProcessor.getMyAgent().getAid());
                response.setContent("Cancel failed!.");
        }

Sets the inform message in response the cancel request

Parameters:
myProcessorthe CProcessor managing the conversation
responseinform message.

Definition at line 282 of file Jason_Fipa_Subscribe_Participant.java.

                                                                                      {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                response.setProtocol("fipa-subscribe");
                response.setPerformative(ACLMessage.INFORM);
                response.setInReplyTo(ACLMessage.getPerformative(ACLMessage.CANCEL));
                response.setReceiver(conv.initiator);
                response.setSender(myProcessor.getMyAgent().getAid());
                response.setContent("Cancel done!.");
        }

Sets the failure message

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendfailure message

Definition at line 232 of file Jason_Fipa_Subscribe_Participant.java.

                                                  {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                messageToSend.setProtocol("fipa-subscribe");
                messageToSend.setPerformative(ACLMessage.FAILURE);
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
                messageToSend.setReceiver(conv.initiator);

        }

Method executed when the conversation ends

Parameters:
myProcessorthe CProcessor managing the conversation
messageToSendfinal message

Definition at line 326 of file Jason_Fipa_Subscribe_Participant.java.

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

Sets the inform message

Parameters:
myProcessorthe CProcessor managing the conversation
responseinform message. The values of conv.objects will be checked searching the first object with result values...

Definition at line 186 of file Jason_Fipa_Subscribe_Participant.java.

                                                                                         {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                ACLMessage informmsg = new ACLMessage();
                informmsg.setSender(myProcessor.getMyAgent().getAid());
                informmsg.setReceiver(conv.initiator);
                informmsg.setProtocol("fipa-subscribe");
                informmsg.setPerformative(ACLMessage.INFORM);
                informmsg.setContent("Informing changes.");
                informmsg.setConversationId(myProcessor.getConversationID());
                Literal headerkeyLit ;
                Literal objkey ;
                Iterator<Entry<String, String>> headIt = messagereceived.getHeaders().entrySet().iterator();
                while (headIt.hasNext()){
                        Entry<String, String> headerkey =  headIt.next();
                        headerkeyLit = new LiteralImpl(Literal.parseLiteral(headerkey.getKey()));

                        //Precond: message must have a header with the object as key and the changes as value 
                        Iterator<Entry<String, String>> objIt = conv.objects.entrySet().iterator();
                        while (objIt.hasNext()) {
                                Entry<String, String> obj =  objIt.next();
                                objkey = new LiteralImpl(Literal.parseLiteral(obj.getKey()));
                                if (objkey.compareTo(headerkeyLit)==0){
                                        obj.setValue(headerkey.getValue());
                                        informmsg.setHeader(headerkey.getKey(), headerkey.getValue());
                                }
                        }

                }
                myProcessor.getMyAgent().send(informmsg);


                return "WAIT_FOR_CANCEL";
        }

Method executed when the initiator receives the subscribe request

Parameters:
myProcessorthe CProcessor managing the conversation
subscribesubscribe message. It must have as many headers as objects that the sender is interested in
Returns:

Definition at line 72 of file Jason_Fipa_Subscribe_Participant.java.

                                             {
                String jasonID = subscribe.getHeaderValue("jasonID");
                Conversation conv =  myProcessor.getConversation();
                String factName = conv.factoryName;
                conv.jasonConvID = jasonID;
                conv.initiator = subscribe.getSender();
                FSConversation newConv = new FSConversation(conv.jasonConvID,conv.internalConvID,myProcessor.getMyAgent().getAid(),
                                "",conv.initiator,factName);
                ((ConvCFactory)myProcessor.getMyFactory()).UpdateConv(newConv, myProcessor);

                //Precond: subscribe message must have as many headers as objects 
                //that the initiator is interested in
                newConv.objects = subscribe.getHeaders();
                newConv.objects.remove("factoryname");
                newConv.objects.remove("jasonID"); 
                List<Literal> allperc = new ArrayList<Literal>();
                String percept = "subscriberequest("+newConv.initiator.name+",[";
                Iterator objIt = newConv.objects.entrySet().iterator();
                while (objIt.hasNext()) {
                        Entry<String, String> obj = (Entry<String, String>) objIt.next();
                        String key = obj.getKey();
                        percept = percept + key+",";
                }
                percept = percept.substring(0, percept.length()-1);
                percept = percept+"],"+newConv.jasonConvID+")[source(self)]";
                allperc.add(Literal.parseLiteral(percept));
                ((ConvMagentixAgArch)Ts.getUserAgArch()).setPerception(allperc);

                newConv.aquire_semaphore();

                //Precond: newConv.firstResult must have Refuse or agree values
                String result = null; 
                if (newConv.firstResult.compareTo(ACLMessage.getPerformative(ACLMessage.REFUSE))==0){
                        result = "REFUSE";
                }else 
                        if (newConv.firstResult.compareTo(ACLMessage.getPerformative(ACLMessage.AGREE))==0){
                                result = "AGREE";
                        }
                return result;
        }

Sets the refuse message

Parameters:
myProcessor
messageToSend

Definition at line 125 of file Jason_Fipa_Subscribe_Participant.java.

                                                  {
                FSConversation conv = (FSConversation) myProcessor.getConversation();
                messageToSend.setProtocol("fipa-subscribe");
                messageToSend.setPerformative(ACLMessage.REFUSE);
                messageToSend.setInReplyTo(ACLMessage.getPerformative(ACLMessage.SUBSCRIBE));
                messageToSend.setSender(myProcessor.getMyAgent().getAid());
                messageToSend.setReceiver(conv.initiator);
        }

Definition at line 338 of file Jason_Fipa_Subscribe_Participant.java.

                                                                           {

                //MessageFilter filter;
                ACLMessage template = new ACLMessage();

                // Create factory
                if (filter == null) {
                        filter = new MessageFilter("protocol = fipa-subscribe");
                }

                ConvCFactory theFactory = new ConvCFactory(name, filter,
                                availableConversations, myAgent);

                // Processor template setup
                ConvCProcessor processor = theFactory.cProcessorTemplate();

                //BEGIN 
                BeginState BEGIN = (BeginState) processor.getState("BEGIN");
                BEGIN.setMethod(new BEGIN_Method());

                //WAIT_SUBSCRIBE_INITIATOR
                processor.registerState(new WaitState("WAIT_SUBSCRIBE_INITIATOR", 30000));
                processor.addTransition("BEGIN","WAIT_SUBSCRIBE_INITIATOR");

                //RECEIVE_SUBSCRIBE
                ReceiveState RECEIVE_SUBSCRIBE = new ReceiveState("RECEIVE_SUBSCRIBE");
                RECEIVE_SUBSCRIBE.setMethod(new RECEIVE_SUBSCRIBE_Method());
                filter = new MessageFilter("protocol = fipa-subscribe AND performative = "+ACLMessage.getPerformative(ACLMessage.SUBSCRIBE));
                RECEIVE_SUBSCRIBE.setAcceptFilter(filter);
                processor.registerState(RECEIVE_SUBSCRIBE);
                processor.addTransition("WAIT_SUBSCRIBE_INITIATOR","RECEIVE_SUBSCRIBE");

                //REFUSE
                SendState REFUSE = new SendState("REFUSE");
                REFUSE.setMethod(new REFUSE_Method());
                template.setProtocol("fipa-subscribe");
                template.setPerformative(ACLMessage.REFUSE);
                REFUSE.setMessageTemplate(template);
                processor.registerState(REFUSE);
                processor.addTransition("RECEIVE_SUBSCRIBE","REFUSE");

                //AGREE
                SendState AGREE = new SendState("AGREE");
                AGREE.setMethod(new AGREE_Method());
                template.setProtocol("fipa-subscribe");
                template.setPerformative(ACLMessage.AGREE);
                AGREE.setMessageTemplate(template);
                processor.registerState(AGREE);
                processor.addTransition("RECEIVE_SUBSCRIBE","AGREE");


                //INFORM
                ReceiveState INFORM = new ReceiveState("INFORM");
                INFORM.setMethod(new INFORM_Method());
                filter = new MessageFilter("protocol = fipa-subscribe AND performative = "+ACLMessage.getPerformative(ACLMessage.INFORM));
                INFORM.setAcceptFilter(filter);
                processor.registerState(INFORM);
                //processor.addTransition("AGREE","INFORM");

                //FAILURE
                SendState FAILURE = new SendState("FAILURE");
                FAILURE.setMethod(new FAILURE_Method());
                template.setProtocol("fipa-subscribe");
                template.setPerformative(ACLMessage.FAILURE);
                FAILURE.setMessageTemplate(template);
                processor.registerState(FAILURE);


                //WAIT_FOR_CHANGES
                processor.registerState(new WaitState("WAIT_FOR_CANCEL", 0));
                processor.addTransition("AGREE","WAIT_FOR_CANCEL");
                processor.addTransition("WAIT_FOR_CANCEL","INFORM");
                processor.addTransition("INFORM","WAIT_FOR_CANCEL");
                processor.addTransition("WAIT_FOR_CANCEL","FAILURE");


                //RECEIVE_CANCEL
                ReceiveState RECEIVE_CANCEL = new ReceiveState("CANCEL_STATE");
                RECEIVE_CANCEL.setMethod(new CANCEL_Method());
                filter = new MessageFilter("protocol = fipa-subscribe AND performative = "+ACLMessage.getPerformative(ACLMessage.CANCEL));
                RECEIVE_CANCEL.setAcceptFilter(filter);
                processor.registerState(RECEIVE_CANCEL);
                processor.addTransition("WAIT_FOR_CANCEL","CANCEL_STATE");

                //CANCEL_INFORM
                SendState CANCEL_INFORM = new SendState("CANCEL_INFORM");
                CANCEL_INFORM.setMethod(new CANCEL_INFORM_Method());
                template.setProtocol("fipa-subscribe");
                template.setPerformative(ACLMessage.INFORM);
                CANCEL_INFORM.setMessageTemplate(template);
                processor.registerState(CANCEL_INFORM);
                processor.addTransition("CANCEL_STATE","CANCEL_INFORM");

                //CANCEL_FAILURE
                SendState CANCEL_FAILURE = new SendState("CANCEL_FAILURE");
                CANCEL_FAILURE.setMethod(new CANCEL_FAILURE_Method());
                template.setProtocol("fipa-subscribe");
                template.setPerformative(ACLMessage.FAILURE);
                CANCEL_FAILURE.setMessageTemplate(template);
                processor.registerState(CANCEL_FAILURE);
                processor.addTransition("CANCEL_STATE","CANCEL_FAILURE");

                FinalState FINAL = new FinalState("FINAL");
                FINAL.setMethod(new FINAL_Method());

                processor.registerState(FINAL);
                processor.addTransition(REFUSE,FINAL);
                processor.addTransition(FAILURE,FINAL);
                processor.addTransition(CANCEL_INFORM,FINAL);
                processor.addTransition(CANCEL_FAILURE,FINAL);

                return theFactory;


        }

Member Data Documentation


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