Magentix2  2.1.1
es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch Class Reference
Inheritance diagram for es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch:
Collaboration diagram for es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch:

List of all members.

Public Member Functions

void run ()
String getAgName ()
void setPerception (List< Literal > perc)
List< Literal > perceive ()
void act (ActionExec action, List< ActionExec > feedback)
boolean canSleep ()
boolean isRunning ()
void sleep ()
void sendMsg (jason.asSemantics.Message m) throws Exception
void checkMail ()
void broadcast (jason.asSemantics.Message m) throws Exception
void stopAg ()
ConvJasonAgent getJasonAgent ()

Protected Member Functions

void init (String filename, CAgent agent, BeliefBase bb, String[] bbParameters)
Object translateContentToJason (ACLMessage m)
void addMessage (ACLMessage msg)

Protected Attributes

boolean running = true
Map< String, String > conversationIds = new HashMap<String,String>()

Detailed Description

This class represents the architecture of the Jason agent for it to keep conversations by using the Conversations Factory

Author:
Bexy Alfonso Espinosa

Definition at line 39 of file ConvMagentixAgArch.java.


Member Function Documentation

void es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch.act ( ActionExec  action,
List< ActionExec >  feedback 
)

Definition at line 123 of file ConvMagentixAgArch.java.

        {
                getTS().getLogger().info("Agent " +  action.getActionTerm() + 
                                " is doing: " +  action.getActionTerm());
                // return confirming the action execution was OK
                action.setResult(true);
                feedback.add(action);
        }

Adds a message to the message list

Parameters:
msg

Definition at line 318 of file ConvMagentixAgArch.java.

                                                 {
                this.messageList.add(msg);
        }
void es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch.broadcast ( jason.asSemantics.Message  m) throws Exception

Definition at line 232 of file ConvMagentixAgArch.java.

                                                                            {
        }

Definition at line 167 of file ConvMagentixAgArch.java.

                                {
                ACLMessage m;
                do{
                        m = messageList.poll(); 
                        if (m != null){  
                                String ilForce = aclToKqml(m.getPerformativeInt());
                                String sender = m.getSender().name;
                                String receiver = m.getReceiver().name;
                                String replyWith = m.getReplyWith();
                                String irt = m.getInReplyTo();
                                
                                 // also remembers conversation ID
                if (replyWith != null && replyWith.length() > 0) {
                    if (m.getConversationId() != null) {
                        conversationIds.put(replyWith, m.getConversationId());
                    }
                } else {
                    replyWith = "noid";
                }
                                
                                Object propCont = translateContentToJason(m);
                                if (propCont != null) {
                                        jason.asSemantics.Message im = new jason.asSemantics.Message(ilForce, sender, receiver, propCont, replyWith);
                                        if (irt != null) {
                                                im.setInReplyTo(irt);
                                        }
                                        this.getTS().getC().getMailBox().offer(im); // Bexy: Substituting add by offer
                                }
                        }
                } while(m != null);

        }
void es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch.init ( String  filename,
CAgent  agent,
BeliefBase  bb,
String[]  bbParameters 
) [protected]

Starts the architecture

Parameters:
filenameFile with the AgentSepak code
agentAgent with this architecture

Definition at line 52 of file ConvMagentixAgArch.java.

                                                                                                {
                try {
                        this.jasonAgent = (ConvJasonAgent) agent;
                        Agent ag = new Agent();
                        Settings set = new Settings();//Bexy
                        set.setVerbose(0);//Bexy
                        new TransitionSystem(ag, new Circumstance(), new Settings(), this);
                        
                        if (bb!=null)
                        {
                                ag.setBB(bb);
                        }
                        ag.initAg(filename);
                        ag.getBB().init(ag, bbParameters);
                } catch (Exception e) {
                        logger.log(Level.SEVERE, "Init error", e);
                }
        }

Definition at line 109 of file ConvMagentixAgArch.java.

        {
                //List<Literal> l = new ArrayList<Literal>();
                List<Literal> tmpPerc;
                if ((Perceptions!=null)&&(Perceptions.size()>0)){
                        tmpPerc = new ArrayList<Literal>(Perceptions);}
                else { tmpPerc = new ArrayList<Literal>(); }
                Perceptions.clear();
                
                return  new ArrayList<Literal>(tmpPerc);
        }

Runs the reasoning cycle

Definition at line 74 of file ConvMagentixAgArch.java.

                          {
                RunCentralisedMAS.setupLogger();
                try {
                        while (isRunning()) {
                                // Ricard: calls the Jason engine to perform one reasoning cycle
                                logger.fine("Reasoning....");
                                // Ricard: parche para arreglar la sincronizacion, buscar mejor solucion y porque occure esto
                                if(this.jasonAgent.getMutexHoldCount() > 0)
                                        this.jasonAgent.unlock();
                                getTS().reasoningCycle();
                                
                        }
                } catch (Exception e) {
                        logger.log(Level.SEVERE, "Run error", e);
                }
        }
void es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch.sendMsg ( jason.asSemantics.Message  m) throws Exception

Definition at line 153 of file ConvMagentixAgArch.java.

                                                                          {
                ACLMessage acl = jasonToACL(m);
                acl.addReceiver(new AgentID(m.getReceiver()));
                if (m.getInReplyTo() != null) {
                        String convid = conversationIds.get(m.getInReplyTo());
                        if (convid != null) {
                                acl.setConversationId(convid);
                        }
                }
                acl.getHeaders().put("jason", "true");
                this.jasonAgent.send(acl);
        }

Definition at line 98 of file ConvMagentixAgArch.java.

                                                     {
                for (Literal p:perc){
                        Perceptions.add(p);
                }
        }

Definition at line 144 of file ConvMagentixAgArch.java.

                            {
                try {
                        Thread.sleep(100);
                } catch (InterruptedException e) {}
        }

returns the content of the message m and implements some pro-processing of the content, if necessary

Parameters:
mMessage to translate

Definition at line 204 of file ConvMagentixAgArch.java.

                                                           {
        Object propCont = null;
        try {
            propCont = m.getContentObject();
            if (propCont instanceof String) {
                // try to parse as term
                try {
                    propCont = ASSyntax.parseTerm((String)propCont);
                } catch (Exception e) {  // no problem 
                }
            }            
        } catch (Exception e) { // no problem try another thing
        }
        
        if (propCont == null) { // still null
            // try to parse as term
            try {
                propCont = ASSyntax.parseTerm(m.getContent());
            } catch (Exception e) {
                // not AS messages are treated as string 
                propCont = new StringTermImpl(m.getContent());
            }
        }
        return propCont;
    }

Member Data Documentation

Map<String,String> es.upv.dsic.gti_ia.jason.conversationsFactory.ConvMagentixAgArch.conversationIds = new HashMap<String,String>() [protected]

Definition at line 150 of file ConvMagentixAgArch.java.


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