-2

I am working with JADE framework and I want to know is there any way for intelligent agents to work with some kind of data base, where they can read from it and write some information?..

I tried to make a connection between excel (using jxl) and my project but there is a problem: below is the code for writing in excel file:

public static void write(String[] args) throws Exception {
    // TODO code application logic here
    File f = new File("C:\\Users\\Mastisa\\Desktop\\Master.xls");
    WritableWorkbook  Master = Workbook.createWorkbook(f);
    WritableSheet History_Table = Master.createSheet("History_Table", 0);

    Label L00 = new Label (0,0,"RUN#");

    History_Table.addCell(L00);


    Master.write();

    System.out.println("finished...");

    Master.close();
}

}

but I want agents to do something like this:

Database D;
D.add(myAgent.getLocalName);

but it is not possible as jxl doesn't provide functions for working with agents. and it looks like that everything must be written in that excel file manually.... but it is not what I want.. I want agents comfortably read and write...

Is there any other way?

1 Answers1

1

Yes basically when you create a JADE agent, you can add behaviors to those Agents, There are several types of behaviors, you should be choosing them based on your requirement. You can find the list of behaviors here

For an Example,

public class MyAgent extends Agent
{
    @Override
    protected void setup()
    {
         addBehaviour( new InformBehaviour() );
    }
    private class InformBehaviour extends CyclicBehaviour
    {
        //dostuff
    }
}

So basic idea is you need to do all these inside a behavior of a agent.

Make sure you choose right behaviour which suites your requirement.

Damith
  • 710
  • 3
  • 11
  • Thank you, so we come to this conclusion that JADE itself doesn't provide a tool for agents working with a kind of specialized database? – Mehregan Rahmani Nov 02 '18 at 10:43
  • 1
    Correct. There are no in-build facilities in JADE to cater database and/or other outgoing requests. JADE is specialized to handle requests in between agents, for the agent platform basically. But you can integrate your app with spring framework and then you can have those kind of cool database connections. its not JADE's duty but Spring has all those functionalities. But integrating JADE and Spring, is not something straight forward and not that you can add a Bean of JADE Container to your Spring context. So if you choose that path, anyway you have to have a custom Integration. – Damith Nov 02 '18 at 10:49
  • hello again, I have a question about using behaviours: as far as i have understood, we cannot define a method for agents, we only Override the abstract methods of behaviours, is it true? if so, then how can I work with a database like excel using jade behaviours? because creating an excel file requires handling exceptions while I cannot write: `public void action() throws Exception` because I get an error message as: overridden method does not throw exception.... can you help me with this? – Mehregan Rahmani Nov 15 '18 at 21:14
  • 1
    Hi, "we cannot define a method for agents" this is not true. You can define any method inside your custom agent class as in my answer. There you can have for example public void writeToDB() or something like that. "I cannot write: public void action() throws Exception" this is true as action method is already in the behavior class and it does not throw an exception in its abstract definition. – Damith Nov 17 '18 at 03:00
  • Thanks for your help, now two more questions appeared to me, then what is the use of abstract methods of behaviours like `action();` or `done();` if we can define methods of our own, And what is the differences between their execution and the execution of a new defined method by me? I mean, which one do agents prefer to execute?.. and also I could realize how to override action() in the way I want as writing try catch, instead of throw exception! that was pretty easy.. and it worked – Mehregan Rahmani Nov 17 '18 at 18:59
  • 1
    The question you are asking is too broad to discuss here. Anyways calling a method on a agent instance from a different class of a non-agent class is not something desired and it does not have a meaning. So think of this in "Agents way" So that agents have their own behaviors and they communicate via messages. Not directly calling methods of a agent instance. In that case, the behavioral methods are very useful and its the way of adding a functionality to the agent. Not just call a method on a agent. which is not a good practice. And yes feel free to ask for any clarification. – Damith Nov 19 '18 at 05:32