Magentix2
2.1.1
|
Public Member Functions | |
CommitmentStore (AgentID aid) throws Exception | |
Protected Member Functions | |
void | finalize (CProcessor firstProcessor, ACLMessage finalizeMessage) |
void | execution (CProcessor firstProcessor, ACLMessage welcomeMessage) |
Package Attributes | |
HashMap< String, Dialogue > | dialogues |
HashMap< String, HashMap < String, ArrayList< Argument > > > | arguments |
HashMap< String, HashMap < String, Position > > | positions |
HashMap< String, Long > | lastModificationDates |
This agent, named CommitmentStore, stores all the information about the dialogues, including: positions, arguments and modification times. It responds to the petitions of the agents in the dialogue process.
Definition at line 26 of file CommitmentStore.java.
es.upv.dsic.gti_ia.argAgents.CommitmentStore.CommitmentStore | ( | AgentID | aid | ) | throws Exception |
Constructor of the CommitmentStore. It takes the agent id as a parameter and it initializes all the structures.
aid | Agent identifier |
Exception |
Definition at line 53 of file CommitmentStore.java.
{ super(aid); this.arguments = new HashMap<String, HashMap<String,ArrayList<Argument>>>(); this.positions = new HashMap<String, HashMap<String,Position>>(); this.dialogues = new HashMap<String, Dialogue>(); this.lastModificationDates = new HashMap<String, Long>(); }
void es.upv.dsic.gti_ia.argAgents.CommitmentStore.execution | ( | CProcessor | firstProcessor, |
ACLMessage | welcomeMessage | ||
) | [protected, virtual] |
This is the main method of the agent
firstProcessor | The CProcessor managing the welcome conversation |
welcomeMessage | The message sent by the platform to the agent |
This class extends the CommitmentStore protocol to do the necessary functionalities of this agent implementing the abstract methods.
Implements es.upv.dsic.gti_ia.cAgents.CAgent.
Definition at line 69 of file CommitmentStore.java.
{ class myCSProtocol extends CommitmentStore_Protocol{ @Override protected ACLMessage doRespond(CProcessor myProcessor, ACLMessage msg) { ACLMessage response=null; logger.info(getAid().name+": "+"message received: "+"from: "+msg.getSender().getLocalName()+" dialogueID: "+msg.getConversationId()+" locution: "+msg.getHeaderValue("locution")); String locution=msg.getHeaderValue("locution"); try{ if(locution.equalsIgnoreCase("LASTMODIFICATIONDATE")){ Long lastDate=lastModificationDates.get(msg.getConversationId()); Long millisDifference=System.currentTimeMillis()-lastDate; response=createMessage(msg.getSender().getLocalName(), "LASTMODIFICATIONDATE", msg.getConversationId(), millisDifference); } else if(locution.equalsIgnoreCase(ADDARGUMENT) || locution.equalsIgnoreCase(ATTACK) || locution.equalsIgnoreCase(ASSERT)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Argument arg=(Argument)msg.getContentObject(); addArgument(arg, msg.getSender().getLocalName(), msg.getConversationId()); } else if(locution.equalsIgnoreCase(REMOVEARGUMENT)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Argument arg=(Argument)msg.getContentObject(); removeArgument(arg, msg.getSender().getLocalName(),msg.getConversationId()); } else if(locution.equalsIgnoreCase(ADDPOSITION)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Position pos=(Position)msg.getContentObject(); addPosition(pos, msg.getSender().getLocalName(),msg.getConversationId()); } else if(locution.equalsIgnoreCase(GETPOSITION)){ Position pos=getPosition(msg.getHeaderValue("agentID"), msg.getConversationId()); response=createMessage(msg.getSender().getLocalName(), GETPOSITION, msg.getConversationId(), pos); } else if(locution.equalsIgnoreCase(GETALLPOSITIONS)){ ArrayList<Position> allPositions=getAllPositions(msg.getConversationId(),msg.getSender().getLocalName()); response=createMessage(msg.getSender().getLocalName(), GETALLPOSITIONS, msg.getConversationId(), allPositions); } else if(locution.equalsIgnoreCase(NOCOMMIT)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); removePosition(msg.getSender().getLocalName(), msg.getConversationId()); } else if(locution.equalsIgnoreCase(ADDDIALOGUE)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Dialogue dialogue=(Dialogue) msg.getContentObject(); addDialogue(dialogue); } else if(locution.equalsIgnoreCase(GETDIALOGUE)){ String dialogueID=msg.getConversationId(); Dialogue dialogue=getDialogue(dialogueID); response=createMessage(msg.getSender().getLocalName(),GETDIALOGUE,dialogueID,dialogue); } else if(locution.equalsIgnoreCase(ENTERDIALOGUE)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Dialogue dialogue=dialogues.get(msg.getConversationId()); dialogue.addAgentID(msg.getSender().getLocalName()); dialogues.put(msg.getConversationId(), dialogue); } else if(locution.equalsIgnoreCase(WITHDRAWDIALOGUE)){ lastModificationDates.put(msg.getConversationId(), System.currentTimeMillis()); Dialogue dialogue=dialogues.get(msg.getConversationId()); dialogue.removeAgentID(msg.getSender().getLocalName()); dialogues.put(msg.getConversationId(), dialogue); } else{ logger.info(getAid().name+": not understood"); } }catch(Exception e){ e.printStackTrace(); } return response; } @Override protected void doDie(CProcessor myProcessor) { myProcessor.getMyAgent().Shutdown(); } } CFactory talk = new myCSProtocol().newFactory("TALK", 1, this); this.addFactoryAsParticipant(talk); }
void es.upv.dsic.gti_ia.argAgents.CommitmentStore.finalize | ( | CProcessor | firstProcessor, |
ACLMessage | finalizeMessage | ||
) | [protected, virtual] |
This method is executed just before the agent ends its execution
firstProcessor | The CProcessor managing the welcome conversation |
finalizeMessage | The final message produced by this conversation |
Implements es.upv.dsic.gti_ia.cAgents.CAgent.
Definition at line 63 of file CommitmentStore.java.
HashMap<String,HashMap<String,ArrayList<Argument> > > es.upv.dsic.gti_ia.argAgents.CommitmentStore.arguments [package] |
Definition at line 29 of file CommitmentStore.java.
HashMap<String,Dialogue> es.upv.dsic.gti_ia.argAgents.CommitmentStore.dialogues [package] |
Definition at line 28 of file CommitmentStore.java.
HashMap<String,Long> es.upv.dsic.gti_ia.argAgents.CommitmentStore.lastModificationDates [package] |
Definition at line 32 of file CommitmentStore.java.
HashMap<String,HashMap<String,Position> > es.upv.dsic.gti_ia.argAgents.CommitmentStore.positions [package] |
Definition at line 30 of file CommitmentStore.java.