11

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?

jzd
  • 23,473
  • 9
  • 54
  • 76
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67

2 Answers2

8

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) {}
Lev Khomich
  • 2,247
  • 14
  • 18
  • I have still several instances of Deliverer running (`jade.core.messaging.MessageManager$Deliverer`). The problem with those is that I can't kill the threads they are running on, because they ignore InterruptedExceptions... – daniel kullmann Aug 12 '11 at 10:24
0

You can shutdown the whole JADE platform with:

try {
    this.getContainerController().getPlatformController().kill(); 
}
catch (final ControllerException e) {
    System.out.println("Failed to end simulation.");
}

"this" refers to an Agent class object.