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_Participant | fcnp |
This class represents the internal action to be used when adding a conversation to a Jason agent under the Fipa Contract Net Protocol as participant
Definition at line 23 of file ia_FCN_Participant.java.
void jason.stdlib.ia_FCN_Participant.checkArguments | ( | Term[] | args | ) | throws JasonException |
Definition at line 37 of file ia_FCN_Participant.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.TASK_DONE_STEP)==0)|| (protocolSteep.compareTo(Protocol_Template.TASK_NOT_DONE_STEP)==0)) { result = (result && (((Term)args[1]).isString()) ); } if (protocolSteep.compareTo(Protocol_Template.MAKE_PROPOSAL_STEP)==0) { result = (result && (((Term)args[1]).isNumeric()||((Term)args[1]).isNumeric()) ); } if (!result) { throw JasonException.createWrongArgument(this,"Parameters must be in correct format."); } }
Object jason.stdlib.ia_FCN_Participant.execute | ( | TransitionSystem | ts, |
Unifier | un, | ||
Term[] | args | ||
) | throws Exception |
Definition at line 65 of file ia_FCN_Participant.java.
{ agName = ts.getUserAgArch().getAgName(); Term protSteep = args[0]; agentConversationID = getTermAsString( args[args.length-1]); if (((Term)args[args.length-1]).isString()){ agentConversationID = "\""+agentConversationID+"\""; } protocolSteep = ((StringTerm)protSteep).getString(); checkArguments(args); 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.JOIN_STEP)==0){ //TODO: It is necessary to document that 80000 is the max time for the waiting states by default so //in the Jason code of the participant this data is eliminated. Update examples in document. This value //must be greater than the wait_for_proposals deadline. int timeOut = 80000; String myfactName = getFactoryName(agentConversationID,"FCN",false); String inifactName = getFactoryName(agentConversationID,"FCN",true); MessageFilter filter = new MessageFilter("performative = CFP AND factoryname = "+inifactName); if (fcnp == null){ fcnp = new Jason_FCN_Participant(agName, ts); } if (args.length >2) { timeOut = (int)((NumberTerm)args[1]).solve(); } ConvCFactory tmpFactory = fcnp.newFactory(myfactName, filter,null,1, ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent(),timeOut); // Finally the factory is setup to answer to incoming messages that // can start the participation of the agent in a new conversation ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().addFactoryAsParticipant(tmpFactory); CFactories.put(agentConversationID, tmpFactory); } else if (protocolSteep.compareTo(Protocol_Template.MAKE_PROPOSAL_STEP)==0){ //the agent finished the evaluations of proposals if (conversationsList.get(agentConversationID) == null) { ConvCFactory tmpFactory = CFactories.get(agentConversationID); Conversation conv = tmpFactory.removeConversationByJasonID(agentConversationID); conversationsList.put(agentConversationID, conv); CFactories.remove(agentConversationID); } Term proposal = args[1]; ((FCNConversation)conversationsList.get(agentConversationID)).kindOfAnswer = "propose"; ((FCNConversation)conversationsList.get(agentConversationID)).proposal = getTermAsString(proposal); conversationsList.get(agentConversationID).release_semaphore(); } else if (protocolSteep.compareTo(Protocol_Template.REFUSE_STEP)==0){ if (conversationsList.get(agentConversationID) == null) { ConvCFactory tmpFactory = CFactories.get(agentConversationID); Conversation conv = tmpFactory.removeConversationByJasonID(agentConversationID); conversationsList.put(agentConversationID, conv); CFactories.remove(agentConversationID); } ((FCNConversation)conversationsList.get(agentConversationID)).kindOfAnswer = "refuse"; conversationsList.get(agentConversationID).release_semaphore(); } else if (protocolSteep.compareTo(Protocol_Template.NOT_UNDERSTOOD_STEP)==0){ if (conversationsList.get(agentConversationID) == null) { ConvCFactory tmpFactory = CFactories.get(agentConversationID); Conversation conv = tmpFactory.removeConversationByJasonID(agentConversationID); conversationsList.put(agentConversationID, conv); CFactories.remove(agentConversationID); } ((FCNConversation)conversationsList.get(agentConversationID)).kindOfAnswer = "notUnderstood"; conversationsList.get(agentConversationID).release_semaphore(); } else if (protocolSteep.compareTo(Protocol_Template.TASK_DONE_STEP)==0){ Term finalInfo = args[1]; ((FCNConversation)conversationsList.get(agentConversationID)).infoToSend = ((StringTerm)finalInfo).getString(); ((FCNConversation)conversationsList.get(agentConversationID)).taskDone = true; conversationsList.get(agentConversationID).release_semaphore(); } else if (protocolSteep.compareTo(Protocol_Template.TASK_NOT_DONE_STEP)==0){ Term finalInfo = args[1]; ((FCNConversation)conversationsList.get(agentConversationID)).infoToSend = ((StringTerm)finalInfo).getString(); ((FCNConversation)conversationsList.get(agentConversationID)).taskDone = false; conversationsList.get(agentConversationID).release_semaphore(); } // everything ok, so returns true return true; }
Definition at line 34 of file ia_FCN_Participant.java.
{ return 5; };
Definition at line 33 of file ia_FCN_Participant.java.
{ return 2; };
Definition at line 31 of file ia_FCN_Participant.java.