Magentix2  2.1.1
es.upv.dsic.gti_ia.argAgents.CommitmentStore Class Reference
Inheritance diagram for es.upv.dsic.gti_ia.argAgents.CommitmentStore:
Collaboration diagram for es.upv.dsic.gti_ia.argAgents.CommitmentStore:

List of all members.

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, Dialoguedialogues
HashMap< String, HashMap
< String, ArrayList< Argument > > > 
arguments
HashMap< String, HashMap
< String, Position > > 
positions
HashMap< String, Long > lastModificationDates

Detailed Description

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.

Author:
Jaume Jordan

Definition at line 26 of file CommitmentStore.java.


Constructor & Destructor Documentation

Constructor of the CommitmentStore. It takes the agent id as a parameter and it initializes all the structures.

Parameters:
aidAgent identifier
Exceptions:
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>();
        }

Member Function Documentation

void es.upv.dsic.gti_ia.argAgents.CommitmentStore.execution ( CProcessor  firstProcessor,
ACLMessage  welcomeMessage 
) [protected, virtual]

This is the main method of the agent

Parameters:
firstProcessorThe CProcessor managing the welcome conversation
welcomeMessageThe 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.

Author:
Jaume Jordan

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

Parameters:
firstProcessorThe CProcessor managing the welcome conversation
finalizeMessageThe final message produced by this conversation

Implements es.upv.dsic.gti_ia.cAgents.CAgent.

Definition at line 63 of file CommitmentStore.java.

                                                    {
                logger.info("+++++++++++++++++++++++++++++++++++++++ "+this.getName()+": Finalizing");
        }

Member Data Documentation

HashMap<String,HashMap<String,ArrayList<Argument> > > es.upv.dsic.gti_ia.argAgents.CommitmentStore.arguments [package]

Definition at line 29 of file CommitmentStore.java.

Definition at line 28 of file CommitmentStore.java.

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.


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