Magentix2
2.1.1
|
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_FCN_Initiator | fcnp = null |
ACLMessage | msg = new ACLMessage(ACLMessage.CFP) |
This class represents the internal action to be used when adding a conversation to a Jason agent under the Fipa Contract Net Protocol as initiator
Definition at line 28 of file ia_FCN_Initiator.java.
void jason.stdlib.ia_FCN_Initiator.checkArguments | ( | Term[] | args | ) | throws JasonException |
Definition at line 43 of file ia_FCN_Initiator.java.
{ super.checkArguments(args); boolean result = false; if ( (((Term)args[args.length-1]).isAtom())|| (((Term)args[args.length-1]).isString())|| (((Term)args[args.length-1]).isLiteral())|| (((Term)args[args.length-1]).isNumeric())){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.isNumeric()); break; case 2:result = (result&&t.isNumeric()); break; case 3:result = (result&&t.isList()); break; } cont++; } } if (protocolSteep.compareTo(Protocol_Template.PROPOSALS_EVALUATED_STEP)==0) { int cont = 0; for (Term t:args){ switch (cont){ case 1: result = (result&&t.isList()); break; case 2: result = (result&&t.isList()); break; } cont++; } } if (!result) { throw JasonException.createWrongArgument(this,"Parameters must be in correct format."); } }
Object jason.stdlib.ia_FCN_Initiator.execute | ( | TransitionSystem | ts, |
Unifier | un, | ||
Term[] | args | ||
) | throws Exception |
Definition at line 92 of file ia_FCN_Initiator.java.
{ protocolSteep = getTermAsString(args[0]); checkArguments(args); agName = ts.getUserAgArch().getAgName(); ConvJasonAgent myag = ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent(); agentConversationID = getTermAsString(args[args.length-1]); if (((Term)args[args.length-1]).isString()){ agentConversationID = "\""+agentConversationID+"\""; } if (ts.getSettings().verbose()>1) ts.getAg().getLogger().info("CALLING INTERNAL ACTION WITH STEEP: '"+protocolSteep+"'"+" CID: "+agentConversationID); //the first state in the conversation if (protocolSteep.compareTo(Protocol_Template.START_STEP)==0){ //TODO: It's necessary to document that this is the time for waiting for the inform timeOut = getTermAsInt(args[1]); //TODO: It's necessary to document that this is the deadLine for waiting for proposals. Also in the Jason code examples long deadLineTime = getTermAslong(args[2]); Term participants = args[3]; Term proposal = args[4]; //TODO: Document: The initial participants are going to be the same in the rest of instantiations of the protocol int participantsNumber = 0; for (Term t: (ListTerm)participants) { String rec = getTermAsString(t); msg.addReceiver(new AgentID(rec)); participantsNumber++; } msg.setContent(getTermAsString(proposal)); msg.setProtocol("fipa-contract-net"); String factName = getFactoryName(agentConversationID,"FCN",true); String prevFactory = ""; if (Protocol_Factory!=null) prevFactory = Protocol_Factory.getName(); fcnp = new Jason_FCN_Initiator(agName, ts) ; if (prevFactory.compareTo(factName)!=0) // if it is a new conversation a create a new one. This verification is not strictly //necessary because it supposed that this condition will be always truth. This must be improved but, //as the participants can not distinguish between conversation of the same factory also one factory per conversation //is created with the initiator factory name as a filter. This implies one factory per conversation in the initiator too { Protocol_Factory = fcnp.newFactory("CNPFACTORY", null, msg, 1, ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent() , participantsNumber, deadLineTime,timeOut); ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().addFactoryAsInitiator(Protocol_Factory); } /* finally the new conversation starts an asynchronous conversation.*/ myag.lock(); String ConvID = myag.newConvID(); FCNConversation conv = new FCNConversation(agentConversationID, ConvID,"Starting new FCN conversation", ((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); conv.solicitude = getTermAsString(proposal); convPprocessor.setConversation(conv); myag.unlock(); conversationsList.put(agentConversationID, conv); } else if (protocolSteep.compareTo(Protocol_Template.PROPOSALS_EVALUATED_STEP)==0){ //the agent finished the evaluations of proposals Term PropAccepted = args[1]; Term PropRejected = args[2]; ((FCNConversation)conversationsList.get(agentConversationID)).myAcceptances =getTermAsString(PropAccepted); ((FCNConversation)conversationsList.get(agentConversationID)).myRejections =getTermAsString(PropRejected); /* * Releases the semaphore, and if there is a process waiting, it will go on */ conversationsList.get(agentConversationID).release_semaphore(); } else if (protocolSteep.compareTo(Protocol_Template.RESULTS_PROCESSED_STEP)==0){ //the agent finished to process the results /* * Releases the semaphore, and if there is a process waiting, it will take * it again */ conversationsList.get(agentConversationID).release_semaphore(); } // everything ok, so returns true return true; }
Definition at line 40 of file ia_FCN_Initiator.java.
{ return 7; };
Definition at line 39 of file ia_FCN_Initiator.java.
{ return 2; };
Jason_FCN_Initiator jason.stdlib.ia_FCN_Initiator.fcnp = null [package] |
Definition at line 34 of file ia_FCN_Initiator.java.
ACLMessage jason.stdlib.ia_FCN_Initiator.msg = new ACLMessage(ACLMessage.CFP) [package] |
Definition at line 35 of file ia_FCN_Initiator.java.