Magentix2  2.1.1
jason.stdlib.ia_fipa_requestw_Initiator Class Reference
Inheritance diagram for jason.stdlib.ia_fipa_requestw_Initiator:
Collaboration diagram for jason.stdlib.ia_fipa_requestw_Initiator:

List of all members.

Public Member Functions

int getMinArgs ()
int getMaxArgs ()
void checkArguments (Term[] args) throws JasonException
Object execute (TransitionSystem ts, Unifier un, Term[] args) throws Exception

Package Attributes

Jason_Fipa_RequestW_Initiator fri = null

Detailed Description

This class represents the internal action to be used when adding a conversation to a Jason agent under the Fipa Request When Protocol as initiator

Author:
Bexy Alfonso Espinosa

Definition at line 24 of file ia_fipa_requestw_Initiator.java.


Member Function Documentation

void jason.stdlib.ia_fipa_requestw_Initiator.checkArguments ( Term[]  args) throws JasonException

Definition at line 39 of file ia_fipa_requestw_Initiator.java.

        {
                super.checkArguments(args);
                boolean result = false;

                if (((Term)args[args.length-1]).isLiteral()){result=true;}

                result = (result && (((Term)args[0]).isString()) );

                if ( protocolSteep.compareTo(Protocol_Template.START_STEP)==0)
                {
                        int cont = 0; 
                        for (Term t:args){
                                switch (cont){
                                case 1:result = (result&&t.isAtom());   
                                break;
                                case 2:result = (result&&t.isNumeric());
                                break;
                                case 3:result = (result&&t.isString());
                                break;
                                }
                                cont++;
                        }
                }
                if ((protocolSteep.compareTo(Protocol_Template.REQUEST_STEP)==0)||
                                (protocolSteep.compareTo(Protocol_Template.TASK_DONE_STEP)==0))
                {
                        result = (result && (((Term)args[1]).isLiteral()) ); //Condition
                }
                if (protocolSteep.compareTo(Protocol_Template.REQUEST_STEP)==0)
                {
                        result = (result && (((Term)args[2]).isAtom()) );
                }
                
                if (!result)
                {
                        throw JasonException.createWrongArgument(this,"Parameters must be in correct format.");
                }

        }
Object jason.stdlib.ia_fipa_requestw_Initiator.execute ( TransitionSystem  ts,
Unifier  un,
Term[]  args 
) throws Exception

Definition at line 82 of file ia_fipa_requestw_Initiator.java.

                                                                                             {

                protocolSteep = getTermAsString(args[0]);

                checkArguments(args);
                
                agentConversationID = getAtomAsString(args[args.length-1]);

                agName  = ts.getUserAgArch().getAgName();

                ConvJasonAgent myag = ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent();
                
                ts.getAg().getLogger().info("CALLING INTERNAL ACTION WITH STEEP: '"+protocolSteep+"'"+" CID: "+agentConversationID);

                /*
                 * When a FR Protocol is taking place*/
                if (protocolSteep.compareTo(Protocol_Template.START_STEP)==0){

                        String participant = getAtomAsString(args[1]);

                        timeOut = getTermAsInt(args[2]);                        

                        String initialInfo = getTermAsString(args[4]);

                        //This time allows participants to join the conversation
                        int wait = 0;
            while(wait<=100000){
                wait++;
            }
                        
                        //building message template
                        ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
                        msg.setProtocol("request-when");

                        msg.setContent(agName+","+initialInfo+","+agentConversationID);
                        String factName = "Web_Protocol_Factory";
                        if (fri == null){
                                fri = new Jason_Fipa_RequestW_Initiator(agName, ts);


                                Protocol_Factory = fri.newFactory(factName, null, 
                                                msg, 1, ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent(),timeOut);

                                ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().addFactoryAsInitiator(Protocol_Factory);
                                
                        }

                        /* finally the new conversation starts an asynchronous conversation.*/
                        
                        myag.lock();
                        String ConvID = myag.newConvID();
                        FRWConversation conv = new FRWConversation(agentConversationID,ConvID,timeOut,participant,initialInfo,
                                        ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().getAid(),factName); //the internal id is unknown yet
                        ConvCProcessor processorTemplate = ((ConvCFactory)Protocol_Factory).cProcessorTemplate();
                        processorTemplate.setConversation(conv);
                        msg.setConversationId(ConvID);
                        
                        ConvCProcessor convPprocessor =  myag.newConversation(msg, processorTemplate, false, Protocol_Factory);
                        convPprocessor.setConversation(conv);
                        myag.unlock();

                        conversationsList.put(agentConversationID, conv);

                        
                }else
                        if(protocolSteep.compareTo(Protocol_Template.REQUEST_STEP)==0){

                                ((FRWConversation)conversationsList.get(agentConversationID)).frMessage=getTermAsString(args[1]);
                                
                                ACLMessage requestmsg = new ACLMessage();
                                requestmsg.setSender(myag.getAid());
                                requestmsg.setReceiver(myag.getAid());
                                requestmsg.setProtocol("request-when");
                                requestmsg.setPerformative(ACLMessage.INFORM);
                                requestmsg.setContent("Do the request");
                                requestmsg.setConversationId(((FRWConversation)conversationsList.get(agentConversationID)).internalConvID);
                                //Message for getting out of the WAIT_FOR_CONDITION state
                                myag.send(requestmsg);

                        }else
                                if(protocolSteep.compareTo(Protocol_Template.TASK_DONE_STEP)==0){

                                        conversationsList.get(agentConversationID).release_semaphore();
                                        
                                        conversationsList.remove(agentConversationID);
                                }

                return true;

        }

Member Data Documentation


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