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

List of all members.

Public Member Functions

void run ()
String getAgName ()
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 ()
CAgent getJasonAgent ()
void setJasonAgent (CAgent jasonAgent)
Agent getAg ()
void setAg (Agent ag)
Queue< ACLMessagegetMessageList ()
void setMessageList (Queue< ACLMessage > messageList)
Map< String, String > getConversationIds ()
void setConversationIds (Map< String, String > conversationIds)
void setRunning (boolean running)

Static Public Member Functions

static Logger getLogger ()
static void setLogger (Logger logger)

Protected Member Functions

void init (String filename, CAgent agent) throws AgentSpeakNotFoundException, JasonException
Object translateContentToJason (ACLMessage m)
ACLMessage jasonToACL (Message m) throws IOException
void addMessage (ACLMessage msg)

Static Protected Member Functions

static int kqmlToACL (String p)
static String aclToKqml (int p)

Protected Attributes

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

Detailed Description

Author:
Ricard Lopez Fogues
Jose Alemany Bordera - jalemany1@dsic.upv.es

Definition at line 42 of file MagentixAgArch.java.


Member Function Documentation

static String es.upv.dsic.gti_ia.jason.MagentixAgArch.aclToKqml ( int  p) [static, protected]

Converts a fipa performative into a kqml one

Parameters:
p
Returns:

Definition at line 317 of file MagentixAgArch.java.

                                                 {
                switch (p) {
                case ACLMessage.INFORM:
                        return "tell";
                case ACLMessage.QUERY_REF:
                        return "askOne";
                case ACLMessage.REQUEST:
                        return "achieve";
                case UNTELL:
                        return "untell";
                case UNACHIEVE:
                        return "unachieve";
                case ASKALL:
                        return "askAll";
                case ASKHOW:
                        return "askHow";
                case TELLHOW:
                        return "tellHow";
                case UNTELLHOW:
                        return "untellHow";
                }
                return ACLMessage.getPerformative(p).toLowerCase().replaceAll("-", "_");
        }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.act ( ActionExec  action,
List< ActionExec >  feedback 
)

Definition at line 134 of file MagentixAgArch.java.

                                                                      {
                getTS().getLogger()
                                .info("Agent " + getAgName() + " 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 346 of file MagentixAgArch.java.

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

Definition at line 245 of file MagentixAgArch.java.

                                                                            {
        }

Definition at line 144 of file MagentixAgArch.java.

                                  {
                return true;
        }

Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.

Definition at line 178 of file MagentixAgArch.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().add(im);
                                }
                        }
                } while (m != null);
        }
Returns:
the ag

Definition at line 372 of file MagentixAgArch.java.

                             {
                return ag;
        }

Definition at line 119 of file MagentixAgArch.java.

                                  {
                return jasonAgent.getAid().name;
        }
Returns:
the conversationIds

Definition at line 417 of file MagentixAgArch.java.

                                                        {
                return conversationIds;
        }
Returns:
the jasonAgent

Definition at line 357 of file MagentixAgArch.java.

                                      {
                return jasonAgent;
        }
Returns:
the logger

Definition at line 387 of file MagentixAgArch.java.

                                         {
                return logger;
        }
Returns:
the messageList

Definition at line 402 of file MagentixAgArch.java.

                                                  {
                return messageList;
        }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.init ( String  filename,
CAgent  agent 
) throws AgentSpeakNotFoundException, JasonException [protected]

Starts the architecture

Parameters:
filenameFile with the AgentSepak code
agentAgent with this architecture
Exceptions:
AgentSpeakNotFoundExceptionThe filename is null or the file is not found
JasonException

Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.

Definition at line 63 of file MagentixAgArch.java.

                                                                           {

                if (filename == null)
                        throw new AgentSpeakNotFoundException(
                                        "the AgentSpeak source file is null");
                try {
                        filename = filename.replaceAll("\\\\", "/");
                        new URL(filename);
                } catch (MalformedURLException e) {
                        try {
                                new FileInputStream(filename);
                        } catch (FileNotFoundException e1) {
                                throw new AgentSpeakNotFoundException(
                                                "the AgentSpeak source file '" + filename
                                                                + "' was not found!");
                        }
                }

                try {

                        this.jasonAgent = agent;
                        ag = new Agent();

                        new TransitionSystem(ag, new Circumstance(), new Settings(), this);

                        ag.initAg(filename);

                } catch (Exception e) {
                        logger.log(Level.SEVERE, "Init error", e);
                        throw new JasonException(
                                        "Problem with the initialization of Jason agent!");
                }

        }

Definition at line 149 of file MagentixAgArch.java.

                                   {
                return running;
        }
ACLMessage es.upv.dsic.gti_ia.jason.MagentixAgArch.jasonToACL ( Message  m) throws IOException [protected]

Converts a jason message into an ACLMessage

Parameters:
m
Returns:
Exceptions:
IOException

Definition at line 255 of file MagentixAgArch.java.

                                                                      {
                ACLMessage acl = new ACLMessage(kqmlToACL(m.getIlForce()));
                // send content as string if it is a Term/String (it is better for
                // interoperability)
                if (m.getPropCont() instanceof Term
                                || m.getPropCont() instanceof String) {
                        acl.setContent(m.getPropCont().toString());
                } else {
                        acl.setContentObject((Serializable) m.getPropCont());
                }
                acl.setReceiver(new AgentID(m.getReceiver()));
                acl.setSender(this.jasonAgent.getAid());
                acl.setReplyWith(m.getMsgId());
                acl.setLanguage("AgentSpeak");
                if (m.getInReplyTo() != null) {
                        acl.setInReplyTo(m.getInReplyTo());
                }
                return acl;
        }
static int es.upv.dsic.gti_ia.jason.MagentixAgArch.kqmlToACL ( String  p) [static, protected]

Converts a kqml performative into a fipa performative

Parameters:
p
Returns:

Definition at line 288 of file MagentixAgArch.java.

                                                 {
                if (p.equals("tell")) {
                        return ACLMessage.INFORM;
                } else if (p.equals("askOne")) {
                        return ACLMessage.QUERY_REF;
                } else if (p.equals("achieve")) {
                        return ACLMessage.REQUEST;
                } else if (p.equals("untell")) {
                        return UNTELL;
                } else if (p.equals("unachieve")) {
                        return UNACHIEVE;
                } else if (p.equals("askAll")) {
                        return ASKALL;
                } else if (p.equals("askHow")) {
                        return ASKHOW;
                } else if (p.equals("tellHow")) {
                        return TELLHOW;
                } else if (p.equals("untellHow")) {
                        return UNTELLHOW;
                }
                return ACLMessage.getPerformative(p);
        }

Definition at line 126 of file MagentixAgArch.java.

                                        {
                List<Literal> l = new ArrayList<Literal>();
                return l;
        }

Runs the reasoning cycle

Definition at line 102 of file MagentixAgArch.java.

                          {
                // RunCentralisedMAS.setupLogger();
                try {
                        while (isRunning()) {
                                // calls the Jason engine to perform one reasoning cycle
                                logger.fine("Reasoning....");
                                // 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.MagentixAgArch.sendMsg ( jason.asSemantics.Message  m) throws Exception

Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.

Definition at line 165 of file MagentixAgArch.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);
                        }
                }
                this.jasonAgent.send(acl);
        }
Parameters:
agthe ag to set

Definition at line 380 of file MagentixAgArch.java.

                                    {
                this.ag = ag;
        }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setConversationIds ( Map< String, String >  conversationIds)
Parameters:
conversationIdsthe conversationIds to set

Definition at line 425 of file MagentixAgArch.java.

Parameters:
jasonAgentthe jasonAgent to set

Definition at line 365 of file MagentixAgArch.java.

                                                     {
                this.jasonAgent = jasonAgent;
        }
static void es.upv.dsic.gti_ia.jason.MagentixAgArch.setLogger ( Logger  logger) [static]
Parameters:
loggerthe logger to set

Definition at line 395 of file MagentixAgArch.java.

                                                    {
                MagentixAgArch.logger = logger;
        }
Parameters:
messageListthe messageList to set

Definition at line 410 of file MagentixAgArch.java.

                                                                  {
                this.messageList = messageList;
        }
Parameters:
runningthe running to set

Definition at line 433 of file MagentixAgArch.java.

                                                {
                this.running = running;
        }

Definition at line 155 of file MagentixAgArch.java.

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

Definition at line 350 of file MagentixAgArch.java.

                             {
                running = false;
        }

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

Parameters:
mMessage to translate

Definition at line 218 of file MagentixAgArch.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.MagentixAgArch.conversationIds = new HashMap<String, String>() [protected]

Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.

Definition at line 162 of file MagentixAgArch.java.

Definition at line 48 of file MagentixAgArch.java.


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