Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop a JADE system (Java agents)

I run JADE embedded in a Java program, i.e. not with java jade.Boot .... Now I wanted to stop the JADE system, but I have found no nice way to do that. I can exit the whole program using System.exit(), but that's not what I want to do.

I tried several different things, and I succeeded stopping my agent behaviours, but a couple of Threads continue running: the AMS, the DF, a web server, the JADE Timer dispatcher, several Deliverer threads, etc.

This is how my current shutdown method looks like:

  @Override
  public void shutdown() {
    // TODO This does not work yet..
    try {
      for (WeakReference<AgentController> acr : agents) {
        AgentController ac = acr.get(); // jade.wrapper.AgentController 
        if ( ac != null ) ac.kill();
      }
      container.kill(); // jade.wrapper.AgentContainer
      Runtime.instance().shutDown(); // jade.core.Runtime
    } catch ( StaleProxyException e ) {
      e.printStackTrace();
    }
  }

The reason I want to do that is that I have some JUnit tests for my agent system.

Any ideas how to accomplish that?

like image 503
daniel kullmann Avatar asked Aug 11 '11 12:08

daniel kullmann


1 Answers

You can request AMS to stop the platform in such way:

Codec codec = new SLCodec();    
Ontology jmo = JADEManagementOntology.getInstance();
getContentManager().registerLanguage(codec);
getContentManager().registerOntology(jmo);
ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
msg.addReceiver(getAMS());
msg.setLanguage(codec.getName());
msg.setOntology(jmo.getName());
try {
    getContentManager().fillContent(msg, new Action(getAID(), new ShutdownPlatform()));
    send(msg);
}
catch (Exception e) {}
like image 188
Lev Khomich Avatar answered Nov 15 '22 13:11

Lev Khomich