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_Fipa_Subscribe_Initiator | fsi = null |
This class represents the internal action to be used when adding a conversation to a Jason agent under the Fipa Subscribe Protocol as initiator
Definition at line 28 of file ia_fipa_subscribe_Initiator.java.
void jason.stdlib.ia_fipa_subscribe_Initiator.checkArguments | ( | Term[] | args | ) | throws JasonException |
Definition at line 42 of file ia_fipa_subscribe_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.isAtom())||(result&&t.isString())); break; case 2:result = (result&&t.isNumeric()); break; case 3:result = (result&&t.isString()); break; } cont++; } } if (protocolSteep.compareTo(Protocol_Template.SUBSCRIBE_STEP)==0) { int cont = 0; for (Term t:args){ switch (cont){ case 1:result = (result&&t.isList()); break; case 2:result = ((result&&t.isAtom())||(result&&t.isString())); break; } cont++; } } if (!result) { throw JasonException.createWrongArgument(this,"Parameters must be in correct format."); } }
Object jason.stdlib.ia_fipa_subscribe_Initiator.execute | ( | TransitionSystem | ts, |
Unifier | un, | ||
Term[] | args | ||
) | throws Exception |
Definition at line 94 of file ia_fipa_subscribe_Initiator.java.
{ protocolSteep = getTermAsString(args[0]); checkArguments(args); agentConversationID = getTermAsString(args[args.length-1]); if (((Term)args[args.length-1]).isString()){ agentConversationID = "\""+agentConversationID+"\""; } agName = ts.getUserAgArch().getAgName(); ConvJasonAgent myag = ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent(); if (ts.getSettings().verbose()>1) ts.getAg().getLogger().info("CALLING INTERNAL ACTION WITH STEEP: '"+protocolSteep+"'"+" CID: "+agentConversationID); /* * When a FS 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[3]); //building message template ACLMessage msg = new ACLMessage(); msg.setProtocol("fipa-subscribe"); msg.setContent(initialInfo); String factName = getFactoryName(agentConversationID,"FS",true); //if (fsi == null){ fsi = new Jason_Fipa_Subscribe_Initiator(agName, ts); String prevFactory = ""; if (Protocol_Factory!=null) prevFactory = Protocol_Factory.getName(); 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 = fsi.newFactory(factName, null, 1, ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent(),timeOut); /* The factory is setup to answer start conversation requests from the agent using the FIPA_REQUEST protocol.*/ ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().addFactoryAsInitiator(Protocol_Factory); } //} /* finally the new conversation starts an asynchronous conversation.*/ myag.lock(); String ConvID = myag.newConvID(); FSConversation conv = new FSConversation(agentConversationID,ConvID,new AgentID(participant),initialInfo, ((ConvMagentixAgArch)ts.getUserAgArch()).getJasonAgent().getAid(),factName); 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.SUBSCRIBE_STEP)==0){ List<String> objects = getTermAsStringList(args[1]); Iterator<String> itr = objects.iterator(); while (itr.hasNext()) { ((FSConversation)conversationsList.get(agentConversationID)).objects.put(itr.next(), ""); } conversationsList.get(agentConversationID).release_semaphore(); }else if(protocolSteep.compareTo(Protocol_Template.CANCEL_STEP)==0){ ACLMessage cancelmsg = new ACLMessage(); cancelmsg.setSender(myag.getAid()); cancelmsg.setReceiver(myag.getAid()); cancelmsg.setProtocol("fipa-subscribe"); cancelmsg.setPerformative(ACLMessage.CANCEL); cancelmsg.setContent("Canceling conversation"); cancelmsg.setConversationId(((FSConversation)conversationsList.get(agentConversationID)).internalConvID); //Message for getting out of the WAIT_FOR_INFORM state myag.send(cancelmsg); } return true; }
Definition at line 39 of file ia_fipa_subscribe_Initiator.java.
{ return 5; };
Definition at line 38 of file ia_fipa_subscribe_Initiator.java.
{ return 2; };
Definition at line 36 of file ia_fipa_subscribe_Initiator.java.