Package madkit.kernel

Class Madkit

java.lang.Object
madkit.kernel.Madkit

public final class Madkit extends Object
MaDKit 5 booter class.

MaDKit v.5 new features

  • One big change that comes with version 5 is how agents are identified and localized within the artificial society. An agent is no longer binded to a single agent address but has as many agent addresses as holden positions in the artificial society. see AgentAddress for more information.

  • With respect to the previous change, a withRole version of all the messaging methods has been added. See AbstractAgent.sendMessageWithRole(AgentAddress, Message, String) for an example of such a method.

  • A replying mechanism has been introduced through SendReply methods. It enables the agent with the possibility of replying directly to a given message. Also, it is now possible to get the reply to a message, or to wait for a reply ( for Agent subclasses only as they are threaded) See AbstractAgent.sendReply(Message, Message) for more details.

  • Agents now have a formal state during a MaDKit session. See the AbstractAgent.getState() method for detailed information.

  • One of the most convenient improvement of v.5 is the logging mechanism which is provided. See the AbstractAgent.getLogger() for more details.

  • Internationalization is being made (fr_fr and en_us for now).
Since:
MaDKit 4.0
Version:
5.2
Author:
Fabien Michel, Jacques Ferber
  • Field Details

    • VERSION

      public static final String VERSION
    • BUILD_ID

      public static final String BUILD_ID
    • WEB

      public static final String WEB
  • Constructor Details

    • Madkit

      public Madkit(String... options)
      Launch a new kernel with predefined options. The call returns when the new kernel has finished to take care of all options. Moreover the kernel automatically ends when all the agents living on this kernel are done.

      Here is an example of use:

       
       public void somewhereInYourCode() {
              new Madkit(Option.launchAgents.toString(), // gets the --launchAgents string
                              Client.class.getName() + ",true,20;" + Broker.class.getName() + ",true,10;"
                                              + Provider.class.getName() + ",false,20");
       }
       
      Parameters:
      options - the options which should be used to launch Madkit. If null, the dektop mode is automatically used.
      See Also:
  • Method Details

    • main

      public static void main(String[] options)
      This main could be used to launch a new kernel using predefined options. The new kernel automatically ends when all the agents living on this kernel are done. So the JVM automatically quits if there is no other remaining threads. Basically this call just instantiates a new kernel like this:
       
       public static void main(String[] options) {
              new Madkit(options);
       }
       
      So, this main can be used as a MAS application entry point in two ways :

      (1) From the command line:

      For instance, assuming that your classpath is already set correctly:

      >java madkit.kernel.Madkit agentLogLevel INFO --launchAgents madkit.marketorg.Client,20,true;madkit.marketorg.Broker,10,true;madkit.marketorg.Provider,20,true;

      (2) It can be used programmatically anywhere, especially within main method of agent classes to ease their launch within an IDE.

      Here is an example of how it can be used in this way:

       
       public static void main(String[] args) {
              String[] argss = { LevelOption.agentLogLevel.toString(), "FINE", Option.launchAgents.toString(), // gets the
                                                                                                                                                                                                                      // --
                                                                                                                                                                                                                      // launchAgents
                                                                                                                                                                                                                      // string
                              Client.class.getName() + ",true,20;" + Broker.class.getName() + ",true,10;"
                                              + Provider.class.getName() + ",false,20" };
              Madkit.main(argss);// launching the application
       }
       
      Parameters:
      options - the options which should be used to launch Madkit: see Madkit.LevelOption, Madkit.BooleanOption and Madkit.Option
    • doAction

      public void doAction(KernelAction action, Object... parameters)
      Makes the kernel do the corresponding action. This is done by sending a message directly to the kernel agent. This should not be used intensively since it is better to control the execution flow of the application using the agents running in the kernel. Still it provides a way to launch and manage a kernel from any java application as a third party service.
       public void somewhereInYourCode() {
                                      ...
                                      Madkit m = new Madkit(args);
                                      ...
                                      m.doAction(KernelAction.LAUNCH_NETWORK); //start the network
                                      ...
                                      m.doAction(KernelAction.LAUNCH_AGENT, new Agent(), true); //launch a new agent with a GUI
                                      ...
       }
       
      Parameters:
      action - the action to request
      parameters - the parameters of the request. To work properly, the actual class of the parameters should match the class of the parameters of the underlying targeted method. For instance, for launching an Agent, one must use m.doAction(KernelAction.LAUNCH_AGENT, new Agent(),Boolean.TRUE); That is, in this case, using "true" does not work since it is a String.
    • toString

      public String toString()
      Overrides:
      toString in class Object