diff --git a/.gitignore b/.gitignore index 82dbe30..edfcd7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ bin build -release *~ .externalToolBuilders simu_template diff --git a/lib/madkit-5.2.jar b/lib/madkit-5.2.jar deleted file mode 100755 index ed1f942..0000000 Binary files a/lib/madkit-5.2.jar and /dev/null differ diff --git a/release/MaDKit-tutorials-project.zip b/release/MaDKit-tutorials-project.zip new file mode 100644 index 0000000..a0e2782 Binary files /dev/null and b/release/MaDKit-tutorials-project.zip differ diff --git a/release/html/MaDKit.png b/release/html/MaDKit.png new file mode 100644 index 0000000..bb7b624 Binary files /dev/null and b/release/html/MaDKit.png differ diff --git a/release/html/communication/AllClasses.html b/release/html/communication/AllClasses.html new file mode 100644 index 0000000..f8fd574 --- /dev/null +++ b/release/html/communication/AllClasses.html @@ -0,0 +1,23 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+Agent1
+Agent2
+Agent3
+Agent4
+Agent5
+Agent6
+Agent7
+PingAgent
+PingAgent2
+ReplierAgent
+Society + diff --git a/release/html/communication/communication.ex01.index.html b/release/html/communication/communication.ex01.index.html new file mode 100644 index 0000000..937fcd8 --- /dev/null +++ b/release/html/communication/communication.ex01.index.html @@ -0,0 +1,13 @@ + + + + +Package communication.ex01 (Java2HTML) + + + +Package communication.ex01 +
+PingAgent
+Society + diff --git a/release/html/communication/communication.ex02_targetingRoles.index.html b/release/html/communication/communication.ex02_targetingRoles.index.html new file mode 100644 index 0000000..886d5af --- /dev/null +++ b/release/html/communication/communication.ex02_targetingRoles.index.html @@ -0,0 +1,12 @@ + + + + +Package communication.ex02_targetingRoles (Java2HTML) + + + +Package communication.ex02_targetingRoles +
+PingAgent2 + diff --git a/release/html/communication/communication.ex03_replyingToMessages.index.html b/release/html/communication/communication.ex03_replyingToMessages.index.html new file mode 100644 index 0000000..a7ddd3d --- /dev/null +++ b/release/html/communication/communication.ex03_replyingToMessages.index.html @@ -0,0 +1,12 @@ + + + + +Package communication.ex03_replyingToMessages (Java2HTML) + + + +Package communication.ex03_replyingToMessages +
+ReplierAgent + diff --git a/release/html/communication/communication.ex04.index.html b/release/html/communication/communication.ex04.index.html new file mode 100644 index 0000000..c9368da --- /dev/null +++ b/release/html/communication/communication.ex04.index.html @@ -0,0 +1,14 @@ + + + + +Package communication.ex04 (Java2HTML) + + + +Package communication.ex04 +
+Agent1
+Agent2
+Agent3 + diff --git a/release/html/communication/communication.ex05.index.html b/release/html/communication/communication.ex05.index.html new file mode 100644 index 0000000..f101024 --- /dev/null +++ b/release/html/communication/communication.ex05.index.html @@ -0,0 +1,13 @@ + + + + +Package communication.ex05 (Java2HTML) + + + +Package communication.ex05 +
+Agent4
+Agent5 + diff --git a/release/html/communication/communication.ex06.index.html b/release/html/communication/communication.ex06.index.html new file mode 100644 index 0000000..a40e487 --- /dev/null +++ b/release/html/communication/communication.ex06.index.html @@ -0,0 +1,13 @@ + + + + +Package communication.ex06 (Java2HTML) + + + +Package communication.ex06 +
+Agent6
+Agent7 + diff --git a/release/html/communication/communication/ex01/PingAgent.java.html b/release/html/communication/communication/ex01/PingAgent.java.html new file mode 100644 index 0000000..299c2c8 --- /dev/null +++ b/release/html/communication/communication/ex01/PingAgent.java.html @@ -0,0 +1,107 @@ + + + + + +communication.ex01.PingAgent (Java2HTML) + + + + + + + + +
+package communication.ex01;
+
+import static communication.ex01.Society.COMMUNITY;
+import static communication.ex01.Society.GROUP;
+import static communication.ex01.Society.ROLE;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Agent;
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ *
+ *
+ *
+ *            
+ *     
+ *
+ *
+ *
+ * To exchange messages, agents have to exist in an artificial society. That is, agents have to create communities
+ * containing groups and take roles within to interact with others. Doing so, agents get agent addresses which could be
+ * used to send them messages. Here, two agents take a role and ping the other one.
+ */
+public class PingAgent extends Agent {
+
+    /**
+     * Firstly, take a position in the artificial society
+     */
+    @Override
+    protected void activate() {
+
+        getLogger().setLevel(Level.FINEST);
+
+        createGroup(COMMUNITY, GROUP);
+        requestRole(COMMUNITY, GROUP, ROLE);
+
+        pause(500);
+    }
+
+    /**
+     * Now ping the other agent with a message
+     */
+    @Override
+    protected void live() {
+
+        // method seen in organization's tutorial
+        AgentAddress other = null;
+        while (other == null) {
+            other = getAgentWithRole(COMMUNITY, GROUP, ROLE);
+            pause(1000);
+        }
+
+        getLogger().info("\n\tI found someone !!\n" + other + "\n\n");
+        pause(2000);
+
+        // sending the message to other: Success will be logged
+        sendMessage(other, new Message());
+        pause(2000);
+
+        // waiting other's message: The reception will be logged
+        waitNextMessage();
+        pause(20000);
+    }
+
+    /**
+     * @param args
+     */
+    public static void main(String[] argss) {
+        executeThisAgent(2, true);
+        // or
+        // String[] args = { "--launchAgents", PingAgent.class.getName() + ",true,2" };
+        // Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex01/Society.java.html b/release/html/communication/communication/ex01/Society.java.html new file mode 100644 index 0000000..5980f8e --- /dev/null +++ b/release/html/communication/communication/ex01/Society.java.html @@ -0,0 +1,38 @@ + + + + + +communication.ex01.Society (Java2HTML) + + + + + + + + +
+package communication.ex01;
+
+public class Society {
+
+    public static final String COMMUNITY = "communication";
+    public static final String GROUP = "ex01";
+    public static final String ROLE = "ping agent";
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex02_targetingRoles/PingAgent2.java.html b/release/html/communication/communication/ex02_targetingRoles/PingAgent2.java.html new file mode 100644 index 0000000..e3a91de --- /dev/null +++ b/release/html/communication/communication/ex02_targetingRoles/PingAgent2.java.html @@ -0,0 +1,88 @@ + + + + + +communication.ex02_targetingRoles.PingAgent2 (Java2HTML) + + + + + + + + +
+package communication.ex02_targetingRoles;
+
+import static communication.ex01.Society.COMMUNITY;
+import static communication.ex01.Society.GROUP;
+import static communication.ex01.Society.ROLE;
+
+import java.util.logging.Level;
+
+import communication.ex01.PingAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages by targeting roles.
+ * 
+ * 
+ * 
+ *            
+ *     
+ * 
+ * 
+ * 
+ * Looking for someone, agents do not necessarily need to know who they talk to in terms of real ID. Indeed, what
+ * matters in the artificial society is the roles an agent take. organization tell a lot about what the agent is capable of and
+ * supposed to do. So, agents can send messages to roles rather than to IDs. Here, the idea is: I need to contact a
+ * "ping agent", no matter who will receive the message. And it is possible to do so using what follows:
+ */
+public class PingAgent2 extends PingAgent {// So I do the same activate
+
+    /**
+     * Now ping another agent, just by targeting the role
+     */
+    @Override
+    protected void live() {
+
+       getLogger().setLevel(Level.ALL);
+
+       ReturnCode code = null;
+
+       // until I find someone having role
+       while (code != ReturnCode.SUCCESS) {
+           // This will randomly choose a receiver having this role
+           code = sendMessage(COMMUNITY, GROUP, ROLE, new Message());
+           pause((int) (Math.random() * 1000 + 100));
+       }
+
+       nextMessage();
+       pause(10000);
+    }
+
+    @SuppressWarnings("unused")
+    public static void main(String[] args) {
+       //This will launch a new kernel. It will automatically ends when all the agents living on this kernel are done.
+       new Madkit("--launchAgents", PingAgent2.class.getName() + ",true,3;", PingAgent.class.getName()// This one so that PingAgent2 agents always find someone (breaking the
+                                                                                           // first while)
+       );
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex03_replyingToMessages/ReplierAgent.java.html b/release/html/communication/communication/ex03_replyingToMessages/ReplierAgent.java.html new file mode 100644 index 0000000..f38126e --- /dev/null +++ b/release/html/communication/communication/ex03_replyingToMessages/ReplierAgent.java.html @@ -0,0 +1,80 @@ + + + + + +communication.ex03_replyingToMessages.ReplierAgent (Java2HTML) + + + + + + + + +
+package communication.ex03_replyingToMessages;
+
+import static communication.ex01.Society.COMMUNITY;
+import static communication.ex01.Society.GROUP;
+import static communication.ex01.Society.ROLE;
+
+import communication.ex01.PingAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+import madkit.message.StringMessage;
+
+/**
+ * Shows how agents exchange messages by targeting roles.
+ * 
+ * 
+ * 
+ *            
+ *     
+ * 
+ * 
+ * 
+ * Receiving a message, you can learn information about the sender. This is illustrated firstly in this example.
+ * Sometimes, agents need to communicate by replying to messages. There are primitives for that and they have two
+ * advantages. (1) This will identify the message as being a concrete reply to the received message thus easing the
+ * programming of protocols for instance. (2) This greatly improves code legibility
+ */
+public class ReplierAgent extends PingAgent {// So I do the same activate
+
+    @Override
+    protected void live() {
+
+       // until I found someone having that role
+       while (sendMessage(COMMUNITY, GROUP, ROLE, new Message()) != ReturnCode.SUCCESS) {
+           pause((int) (Math.random() * 1000 + 100));
+       }
+
+       Message m = nextMessage();
+       if (m != null) {
+           getLogger().info("I have to thank " + m.getSender());
+           sendReply(m, new StringMessage("thanks"));
+       }
+       pause(10000);
+    }
+
+    @SuppressWarnings("unused")
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", ReplierAgent.class.getName() + ",true,10;", PingAgent.class.getName()// This one so that agents always find someone (breaking the first while)
+       );
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex04/Agent1.java.html b/release/html/communication/communication/ex04/Agent1.java.html new file mode 100644 index 0000000..5a33d06 --- /dev/null +++ b/release/html/communication/communication/ex04/Agent1.java.html @@ -0,0 +1,115 @@ + + + + + +communication.ex04.Agent1 (Java2HTML) + + + + + + + + +
+package communication.ex04;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ * 
+ * 
+ * 
+ *            
+ *     
+ * 
+ * 
+ * 
+ * To exchange messages, agents have to exist in an artificial society. That is, agents have to create communities
+ * containing groups and take roles within to interact with others. Doing so, agents get agent addresses which could be
+ * used to send them messages. Here, one agent (Agent1) is communicating with another agent (Agent2) by getting its
+ * agent address in the artificial society and using it with sendMessage.
+ */
+public class Agent1 extends Agent {
+
+    /*
+     * Firstly, take a position in the artificial society.
+     */
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroup("communication", "GroupTest");// Create the group GroupTest in the community communication.
+       requestRole("communication", "GroupTest", "RoleTest1");// Request the role RoleTest1.
+       pause(500);
+    }
+
+    /*
+     * First getting an Agent address, and then sending him a message.
+     */
+    @Override
+    protected void live() {
+       AgentAddress other = null;
+       // Until we have an agent (in the group GroupTest in the community communication) having the role RoleTest2.
+       while (other == null) {
+           // Getting the address of an agent being in the community "communication" and the group "GroupTest", and having the role
+           // "RoleTest2".
+           other = getAgentWithRole("communication", "GroupTest", "RoleTest2");
+
+           // Trying to get another agent (Agent3).
+           if (other == null) {
+              other = getAgentWithRole("communication", "GroupTest", "RoleTest3");
+           }
+           pause(1000);
+       }
+       getLogger().info("\n\tI found someone !!\n" + other + "\n\n");
+       pause(1000);
+
+       sendMessage(other, new Message());// Sending the message to the agent we found.
+       pause(1000);
+
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    /*
+     * Set where the agent's window will be for avoiding a clear presentation. This method give
+        * the opportunity to modify the default settings of the frame.
+     * It will be more explained in GUI tutorial.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(100, 320 * (hashCode() - 2));
+    }
+
+    /**
+     * @param argss
+     *            Running Agent1 will launch 2 instances of both Agent1 and Agent2. They will send themselves 1 message.
+     */
+    @SuppressWarnings("unused")
+    public static void main(String[] argss) {
+       new Madkit("--launchAgents", Agent1.class.getName() + ",true,2;", Agent2.class.getName() + ",true,2;");
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex04/Agent2.java.html b/release/html/communication/communication/ex04/Agent2.java.html new file mode 100644 index 0000000..77e54d3 --- /dev/null +++ b/release/html/communication/communication/ex04/Agent2.java.html @@ -0,0 +1,92 @@ + + + + + +communication.ex04.Agent2 (Java2HTML) + + + + + + + + +
+package communication.ex04;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Agent2 works as Agent1, using a different role.
+ * 
+ * #jws communication.ex05.Agent1 jws#
+ * 
+ * Agent2 is almost like Agent1, the only difference is the role and frame's location.
+ */
+
+public class Agent2 extends Agent {
+
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroup("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest2");
+       pause(500);
+    }
+
+    @Override
+    protected void live() {
+       AgentAddress other = null;
+       while (other == null) {
+           other = getAgentWithRole("communication", "GroupTest", "RoleTest1");
+           pause(1000);
+       }
+       getLogger().info("\n\tI found someone !!\n" + other + "\n\n");
+       pause(1000);
+
+       sendMessage(other, new Message());
+       pause(1000);
+
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    /**
+     * Will launch 2 instances of both Agent1 and Agent2. They will send themselves 1 message.
+     */
+    @SuppressWarnings("unused")
+    public static void main(String[] argss) {
+       new Madkit("--launchAgents", Agent1.class.getName() + ",true,2;", Agent2.class.getName() + ",true,2;");
+    }
+
+    /*
+     * Setting where the agent's window will be.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(550, 350 * (hashCode() - 4));
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex04/Agent3.java.html b/release/html/communication/communication/ex04/Agent3.java.html new file mode 100644 index 0000000..659f54f --- /dev/null +++ b/release/html/communication/communication/ex04/Agent3.java.html @@ -0,0 +1,103 @@ + + + + + +communication.ex04.Agent3 (Java2HTML) + + + + + + + + +
+package communication.ex04;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ * 
+ * 
+ *     
+ *  
+ *  
+ * 
+ * This Agent3 is communicating using another method than Agent 1 and 2.
+ */
+public class Agent3 extends Agent {
+
+    /*
+     * This Activate period is almost the same as Agent 1 and 2, the difference is that this Agent 3 create is own Role.
+     */
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroup("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest3");
+       pause(500);
+    }
+
+    /**
+     * Agent3 is sending his message in a loop, until this message is successfully sent to another Agent having the Role
+     * "RoleTest1".
+     */
+    @Override
+    protected void live() {
+       ReturnCode code = null;
+
+       // Until we succeed in sending a message to an agent (in the group GroupTest in the community communication with the
+       // role RoleTest1).
+       while (code != ReturnCode.SUCCESS) {
+           // If several agents match, the target is chosen randomly.
+           code = sendMessage("communication", "GroupTest", "RoleTest1", new Message());
+           pause((int) (Math.random() * 1000 + 100));
+       }
+
+       while (nextMessage() != null)
+           pause(6000);
+       pause(6000);
+    }
+
+    /**
+     * @param argss
+     *            Running Agent1 will launch 2 Agent1 and 2 Agent2. They will send themselves 1 message.
+     */
+    public static void main(String[] argss) {
+       new Madkit("--launchAgents", Agent1.class.getName() + ",true,1;", // During his the live() period, Agent 1 will first try to found an Agent with the role "RoleTest2", than
+                                                                 // he will find Agend3 ("RoleTest3").
+              Agent3.class.getName() + ",true,1;");
+    }
+
+    /**
+     * Setting where the agent's window will be.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(550, 100);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex05/Agent4.java.html b/release/html/communication/communication/ex05/Agent4.java.html new file mode 100644 index 0000000..2288e08 --- /dev/null +++ b/release/html/communication/communication/ex05/Agent4.java.html @@ -0,0 +1,105 @@ + + + + + +communication.ex05.Agent4 (Java2HTML) + + + + + + + + +
+package communication.ex05;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.Option;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ * 
+ * 
+ *     
+ *  
+ * 
+ * 
+ * Agent4 will get an agent's address, and then send his message using sendMessageWithRole.
+ */
+
+public class Agent4 extends Agent {
+
+    /**
+     * Firstly, taking position in the artificial society (having a RoleTest4).
+     */
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroup("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest4");
+       pause(500);
+    }
+
+    @Override
+    protected void live() {
+       AgentAddress other = null;// other will contain the Agent's address.
+       while (other == null)// Until we found an Agent having "("communication","GroupTest","RoleTest4")".
+       {
+           other = getAgentWithRole("communication", "GroupTest", "RoleTest4");
+           pause(1000);
+
+           if (other == null)// Or an Agent having "("communication","GroupTest","RoleTest5")".
+           {
+              other = getAgentWithRole("communication", "GroupTest", "RoleTest5");
+           }
+           pause(1000);
+       }
+       getLogger().info("\n\tI found someone !!\n" + other + "\n\n");// Displaying our Agent properties (the one we founded).
+       pause(1000);
+
+       sendMessageWithRole(other, new Message(), "RoleTest4");// Sending the message specifying the sender's role.
+
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    /**
+     * @param argss
+     *            Running Agent4 will launch 2 Agent4.
+     */
+    public static void main(String[] argss)// Launching two Agent4.
+    {
+       new Madkit(Option.launchAgents.toString(), Agent4.class.getName() + ",true,2;");
+    }
+
+    /*
+     * Setting where the agent's window will be for a clear presentation.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(100, 350 * (hashCode() - 2));
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex05/Agent5.java.html b/release/html/communication/communication/ex05/Agent5.java.html new file mode 100644 index 0000000..7eb82d1 --- /dev/null +++ b/release/html/communication/communication/ex05/Agent5.java.html @@ -0,0 +1,102 @@ + + + + + +communication.ex05.Agent5 (Java2HTML) + + + + + + + + +
+package communication.ex05;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ *
+ * 
+ *     
+ *  
+ *
+ * 
+ * Agent5 is almost like Agent4, the only difference is their roles.
+ */
+
+public class Agent5 extends Agent {
+
+    /*
+     * Firstly, taking position in the artificial society (having a RoleTest5).
+     */
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroup("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest5");
+       pause(500);
+    }
+
+    /*
+     * First getting an Agent address, and then sending him a message.
+     */
+    @Override
+    protected void live()// In this live period, Agent5 is doing exactly the same as Agent4, with a different role (RoleTest5).
+    {
+       AgentAddress other = null;
+       while (other == null) {
+           other = getAgentWithRole("communication", "GroupTest", "RoleTest4");
+           pause(1000);
+       }
+
+       getLogger().info("\n\tI found someone !!\n" + other + "\n\n");
+       pause(1000);
+
+       sendMessageWithRole(other, new Message(), "RoleTest5");
+
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    /**
+     * @param argss
+     *            Launching one Agent4 and one Agent 5.
+     */
+    public static void main(String[] argss) {
+       new Madkit("--launchAgents", Agent4.class.getName() + ",true,1;", Agent5.class.getName() + ",true,1;");
+    }
+
+    /*
+     * Setting where the agent's window will be for a clear presentation.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(100, 350 * (hashCode() - 2));
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex06/Agent6.java.html b/release/html/communication/communication/ex06/Agent6.java.html new file mode 100644 index 0000000..68b7146 --- /dev/null +++ b/release/html/communication/communication/ex06/Agent6.java.html @@ -0,0 +1,100 @@ + + + + + +communication.ex06.Agent6 (Java2HTML) + + + + + + + + +
+package communication.ex06;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages.
+ * 
+ *
+ *  
+ *  
+ *
+ * 
+ * Agent6 won't get an agent address, he will send him a message using sendMessageWithRole.
+ * 
+ * @author Authors ARAGON Joseph and WAGNER Pascal.
+ */
+
+public class Agent6 extends Agent {
+
+    /*
+     * Firstly, taking position in the artificial society (having a RoleTest6).
+     */
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroupIfAbsent("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest6");
+       pause(500);
+    }
+
+    /**
+     * Trying to send a message in a loop until this Agent succeeds sending a message with sendMessageWithRole.
+     */
+    @Override
+    protected void live() {
+       ReturnCode code = null;
+       while (code != ReturnCode.SUCCESS)// Until we succeed sending the message.
+       {
+           // Sending a message to an Agent having a RoleTest7 Specifying Agent6's role.
+           code = sendMessageWithRole("communication", "GroupTest", "RoleTest7", new Message(), "RoleTest6");
+           pause(3000);
+       }
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    /**
+     * @param argss
+     *            It will run one Agent6 and one Agent7.
+     */
+    @SuppressWarnings("unused")
+    public static void main(String[] argss)// Launching two agents, Agent6 and Agent7.
+    {
+       new Madkit("--launchAgents", Agent6.class.getName() + ",true,1;", Agent7.class.getName() + ",true,1;");
+    }
+
+    /*
+     * Setting where the agent's window will be for a clear presentation.
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(100, 350 * (hashCode() - 2));
+    }
+
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/communication/ex06/Agent7.java.html b/release/html/communication/communication/ex06/Agent7.java.html new file mode 100644 index 0000000..10bf604 --- /dev/null +++ b/release/html/communication/communication/ex06/Agent7.java.html @@ -0,0 +1,76 @@ + + + + + +communication.ex06.Agent7 (Java2HTML) + + + + + + + + +
+package communication.ex06;
+
+import java.util.logging.Level;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.Message;
+
+/**
+ * Shows how agents exchange messages. As in previous examples, Agent7 is doing the same job as Agent6, having a
+ * RoleTest7.
+ * 
+ * @author Authors ARAGON Joseph and WAGNER Pascal.
+ */
+
+public class Agent7 extends Agent {
+
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.FINEST);
+
+       createGroupIfAbsent("communication", "GroupTest");
+       requestRole("communication", "GroupTest", "RoleTest7");
+       pause(500);
+    }
+
+    /*
+     * Trying to send a message in a loop until this Agent succeeds sending a message with sendMessageWithRole.
+     */
+    @Override
+    protected void live() {
+       ReturnCode code = null;
+
+       while (code != ReturnCode.SUCCESS) {
+           code = sendMessageWithRole("communication", "GroupTest", "RoleTest6", new Message(), "RoleTest7");
+           pause(2000);
+       }
+       while (nextMessage() != null)
+           pause(6000);
+    }
+
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(500, 100);
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/communication/front.html b/release/html/communication/front.html new file mode 100644 index 0000000..27a0a81 --- /dev/null +++ b/release/html/communication/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Communication

+ +

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/communication/index.html b/release/html/communication/index.html new file mode 100644 index 0000000..d04ba00 --- /dev/null +++ b/release/html/communication/index.html @@ -0,0 +1,20 @@ + + + + +Communication (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/communication/packages.html b/release/html/communication/packages.html new file mode 100644 index 0000000..da5ceb1 --- /dev/null +++ b/release/html/communication/packages.html @@ -0,0 +1,20 @@ + + + + +Communication (Java2HTML) + + + + +Communication +
All Classes +
Packages +
+communication.ex01
+communication.ex02_targetingRoles
+communication.ex03_replyingToMessages
+communication.ex04
+communication.ex05
+communication.ex06 + diff --git a/release/html/communication/stylesheet.css b/release/html/communication/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/communication/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/download.png b/release/html/download.png new file mode 100644 index 0000000..b2e411b Binary files /dev/null and b/release/html/download.png differ diff --git a/release/html/gui/AllClasses.html b/release/html/gui/AllClasses.html new file mode 100644 index 0000000..1d062c4 --- /dev/null +++ b/release/html/gui/AllClasses.html @@ -0,0 +1,17 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+CustomPanel
+DefaultGUIAgent
+IndependentGUI
+MultiGUI
+OverridingDefaultSettings + diff --git a/release/html/gui/front.html b/release/html/gui/front.html new file mode 100644 index 0000000..7e759aa --- /dev/null +++ b/release/html/gui/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

GUI with MaDKit

+ +

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/gui/gui.ex01_defaultGUI.index.html b/release/html/gui/gui.ex01_defaultGUI.index.html new file mode 100644 index 0000000..57ca9c2 --- /dev/null +++ b/release/html/gui/gui.ex01_defaultGUI.index.html @@ -0,0 +1,12 @@ + + + + +Package gui.ex01_defaultGUI (Java2HTML) + + + +Package gui.ex01_defaultGUI +
+DefaultGUIAgent + diff --git a/release/html/gui/gui.ex02_overridingDefaultsettings.index.html b/release/html/gui/gui.ex02_overridingDefaultsettings.index.html new file mode 100644 index 0000000..8448f3e --- /dev/null +++ b/release/html/gui/gui.ex02_overridingDefaultsettings.index.html @@ -0,0 +1,12 @@ + + + + +Package gui.ex02_overridingDefaultsettings (Java2HTML) + + + +Package gui.ex02_overridingDefaultsettings +
+OverridingDefaultSettings + diff --git a/release/html/gui/gui.ex03_customPanel.index.html b/release/html/gui/gui.ex03_customPanel.index.html new file mode 100644 index 0000000..66548e8 --- /dev/null +++ b/release/html/gui/gui.ex03_customPanel.index.html @@ -0,0 +1,12 @@ + + + + +Package gui.ex03_customPanel (Java2HTML) + + + +Package gui.ex03_customPanel +
+CustomPanel + diff --git a/release/html/gui/gui.ex04_independentGUI.index.html b/release/html/gui/gui.ex04_independentGUI.index.html new file mode 100644 index 0000000..33e5c72 --- /dev/null +++ b/release/html/gui/gui.ex04_independentGUI.index.html @@ -0,0 +1,12 @@ + + + + +Package gui.ex04_independentGUI (Java2HTML) + + + +Package gui.ex04_independentGUI +
+IndependentGUI + diff --git a/release/html/gui/gui.ex05_multi_GUI.index.html b/release/html/gui/gui.ex05_multi_GUI.index.html new file mode 100644 index 0000000..ee4cf21 --- /dev/null +++ b/release/html/gui/gui.ex05_multi_GUI.index.html @@ -0,0 +1,12 @@ + + + + +Package gui.ex05_multi_GUI (Java2HTML) + + + +Package gui.ex05_multi_GUI +
+MultiGUI + diff --git a/release/html/gui/gui/ex01_defaultGUI/DefaultGUIAgent.java.html b/release/html/gui/gui/ex01_defaultGUI/DefaultGUIAgent.java.html new file mode 100644 index 0000000..f2bef57 --- /dev/null +++ b/release/html/gui/gui/ex01_defaultGUI/DefaultGUIAgent.java.html @@ -0,0 +1,74 @@ + + + + + +gui.ex01_defaultGUI.DefaultGUIAgent (Java2HTML) + + + + + + + + +
+package gui.ex01_defaultGUI;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+/**
+ * Shows how the default GUI mechanism works in MaDKit 5.
+ * 
+ *            
+ *     
+ * 
+ * The only thing to do for obtaining a default GUI for an agent is to launch it with the GUI parameter set to true.
+ * This could be done either in the MaDKit arguments or when launching an agent.
+ */
+
+public class DefaultGUIAgent extends Agent {
+
+    @Override
+    protected void activate() {
+
+       getLogger().info(
+              "I have a default GUI which is automatically created for me \n because there was \n " + "--launchAgents " + getClass().getName() + ",true \n on the command line");
+       pause(2000);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().info("I now launch two hello world agents:\n one with a GUI and one without");
+       pause(1000);
+       // the one with no GUI: default argument for launchAgent
+       launchAgent(new helloworld.ex01.HelloWorldAgent());
+       // the one with a GUI: adding the GUI parameter to launchAgent
+       launchAgent(new helloworld.ex01.HelloWorldAgent(), true);
+       pause(2000);
+    }
+
+    /**
+     * @param args
+     */
+    public static void main(String[] argss) {
+       String[] args = { "--launchAgents", DefaultGUIAgent.class.getName() + ",true" };
+       Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/gui/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java.html b/release/html/gui/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java.html new file mode 100644 index 0000000..0485dec --- /dev/null +++ b/release/html/gui/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java.html @@ -0,0 +1,73 @@ + + + + + +gui.ex02_overridingDefaultsettings.OverridingDefaultSettings (Java2HTML) + + + + + + + + +
+package gui.ex02_overridingDefaultsettings;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+/**
+ * Shows how to override the default frame settings of the default GUI.
+ * 
+ *  
+ *     
+ * 
+ * When an agent is launched with a GUI, the setupFrame method is automatically called before activate. This method is
+ * the opportunity for the agent to modify the default settings of the frame.
+ */
+
+public class OverridingDefaultSettings extends Agent {
+
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       // adds the default output panel
+       super.setupFrame(frame);
+
+       // Overriding default settings
+       frame.setTitle("Overriding Default Frame Behavior");
+       frame.setLocation(200, 200);
+       frame.setSize(500, 500);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().info("\n\tDo you see I changed my frame settings ?");
+       pause(5000);
+    }
+
+    /**
+     * @param args
+     */
+    public static void main(String[] argss) {
+       String[] args = { "--launchAgents", OverridingDefaultSettings.class.getName() + ",true" };
+       Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/gui/gui/ex03_customPanel/CustomPanel.java.html b/release/html/gui/gui/ex03_customPanel/CustomPanel.java.html new file mode 100644 index 0000000..b2598f8 --- /dev/null +++ b/release/html/gui/gui/ex03_customPanel/CustomPanel.java.html @@ -0,0 +1,88 @@ + + + + + +gui.ex03_customPanel.CustomPanel (Java2HTML) + + + + + + + + +
+package gui.ex03_customPanel;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import madkit.gui.AgentFrame;
+import madkit.gui.OutputPanel;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+/**
+ * Shows how to set a custom panel to the default frame.
+ * 
+ * 
+ *     
+ * 
+ * In this example, we customize the default frame layout. Doing so, we still use the madkit.gui.OutputPanel component
+ * to ease the work.
+ */
+
+public class CustomPanel extends Agent {
+
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       JPanel p = new JPanel(new BorderLayout());
+
+       // customizing but still using the madkit.gui.OutputPanel component
+       JPanel talkPanel = new OutputPanel(this);
+       talkPanel.setBackground(Color.LIGHT_GRAY);
+       p.add(talkPanel, BorderLayout.CENTER);
+
+       //Add the image to the frame
+       p.add(new JLabel(new ImageIcon(getClass().getResource("agent.png"))), BorderLayout.NORTH);
+
+       frame.add(p);
+       frame.setLocation(200, 0);
+       frame.setSize(400, 500);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().info("\n\tDo you see my customized panel ?");
+       pause(10000);
+    }
+
+    /**
+     * @param argss
+     */
+    public static void main(String[] argss) {
+              //To display the panel of an agent, before that we always need to set the MadKit kernel online
+       String[] args = { "--launchAgents", CustomPanel.class.getName() + ",true" };
+       Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/gui/gui/ex04_independentGUI/IndependentGUI.java.html b/release/html/gui/gui/ex04_independentGUI/IndependentGUI.java.html new file mode 100644 index 0000000..04a7455 --- /dev/null +++ b/release/html/gui/gui/ex04_independentGUI/IndependentGUI.java.html @@ -0,0 +1,124 @@ + + + + + +gui.ex04_independentGUI.IndependentGUI (Java2HTML) + + + + + + + + +
+package gui.ex04_independentGUI;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenuBar;
+import javax.swing.JPanel;
+
+import gui.ex03_customPanel.CustomPanel;
+import madkit.gui.OutputPanel;
+import madkit.gui.menu.AgentLogLevelMenu;
+import madkit.gui.menu.AgentMenu;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+/**
+ * Shows how to build a totally independent GUI for an agent.
+ * 
+ * 
+ *     
+ * 
+ * Not using the default GUI mechanism of course makes the source code much more longer without any real benefits here.
+ * So, it is safe to say that the default mechanism should be used almost always. This because: (1) the default
+ * mechanism does not prevent a full control over the created frame. (2) the life cycle of the agent is automatically
+ * related with the frame's, so that nothing has to be added. Still, there are of course cases where it could be a
+ * convenient solution. Especially, it could be interesting to use both the default mechanism and an independent GUI for
+ * developing/debugging purposes like in the next example.
+ */
+
+public class IndependentGUI extends Agent {
+
+    private JFrame myFrame;
+
+    /**
+     * building my own GUI here
+     */
+    @Override
+    protected void activate() {
+       myFrame = new JFrame("My own title");
+
+       JPanel p = new JPanel(new BorderLayout());
+
+       JPanel talkPanel = new OutputPanel(this);
+       talkPanel.setBackground(Color.LIGHT_GRAY);
+       p.add(talkPanel, BorderLayout.CENTER);
+
+       p.add(new JLabel(new ImageIcon(CustomPanel.class.getResource("agent.png"))), BorderLayout.NORTH);
+
+       myFrame.add(p);
+       // but still getting some help from madkit.gui components
+       JMenuBar menuBar = new JMenuBar();
+       menuBar.add(new AgentMenu(this));
+       menuBar.add(new AgentLogLevelMenu(this));
+       myFrame.setJMenuBar(menuBar);
+
+       myFrame.setSize(400, 500);
+       myFrame.setLocationRelativeTo(null);// centered
+
+       // Beware that end will not be called
+       // if the frame is closed by the user...
+       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+       myFrame.setVisible(true);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().info("\n\tI have defined my own frame,\n\twith some predefined menus, though");
+       pause(5000);
+    }
+
+    /**
+     * I have to close the frame myself because its life cycle is not managed by the MaDKit kernel.
+     */
+    @Override
+    protected void end() {
+       myFrame.dispose();
+
+       System.exit(0);
+    }
+
+    /**
+     * @param argss
+     *            unused here
+     */
+    public static void main(String[] argss) {
+       String[] args = { "--launchAgents", IndependentGUI.class.getName() };
+       // + ",false" }; would not change anything as it is the default setting
+       Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/gui/gui/ex05_multi_GUI/MultiGUI.java.html b/release/html/gui/gui/ex05_multi_GUI/MultiGUI.java.html new file mode 100644 index 0000000..ff22fd2 --- /dev/null +++ b/release/html/gui/gui/ex05_multi_GUI/MultiGUI.java.html @@ -0,0 +1,102 @@ + + + + + +gui.ex05_multi_GUI.MultiGUI (Java2HTML) + + + + + + + + +
+package gui.ex05_multi_GUI;
+
+import java.awt.BorderLayout;
+
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+
+import gui.ex03_customPanel.CustomPanel;
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+/**
+ * Shows how to build a totally independent GUI while still using a default GUI for the agent. 
+ *
+ *  
+ *     
+ * 
+ * The idea is that it could be interesting to have several GUI for an agent: A main and the default which could be used
+ * as a console for the agent.
+ */
+
+public class MultiGUI extends Agent {
+
+    private JFrame myFrame;
+
+    /**
+     * building my own GUI here
+     */
+    @Override
+    protected void activate() {
+       myFrame = new JFrame("My GUI");
+       myFrame.add(new JLabel(new ImageIcon(CustomPanel.class.getResource("agent.png"))), BorderLayout.CENTER);
+       myFrame.setSize(400, 500);
+       myFrame.setLocation(100, 100);// centered
+       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+       myFrame.setVisible(true);
+    }
+
+    /**
+     * But still customizing the default GUI if activated
+     */
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setLocation(500, 100);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().info("\n\tI have defined my personnal frame,\n\tbut this is displayed in my default GUI");
+       pause(10000);
+    }
+
+    /**
+     * I have to close the frame myself because its life cycle is not managed by the MaDKit kernel.
+     */
+    @Override
+    protected void end() {
+       myFrame.dispose();
+    }
+
+    /**
+     * @param argss
+     *            unused here
+     */
+    public static void main(String[] argss) {
+       String[] args = { "--launchAgents", MultiGUI.class.getName() + ",true" };
+       Madkit.main(args);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/gui/index.html b/release/html/gui/index.html new file mode 100644 index 0000000..5aa5e8d --- /dev/null +++ b/release/html/gui/index.html @@ -0,0 +1,20 @@ + + + + +GUI with MaDKit (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/gui/packages.html b/release/html/gui/packages.html new file mode 100644 index 0000000..377638d --- /dev/null +++ b/release/html/gui/packages.html @@ -0,0 +1,19 @@ + + + + +GUI with MaDKit (Java2HTML) + + + + +GUI with MaDKit +
All Classes +
Packages +
+gui.ex01_defaultGUI
+gui.ex02_overridingDefaultsettings
+gui.ex03_customPanel
+gui.ex04_independentGUI
+gui.ex05_multi_GUI + diff --git a/release/html/gui/stylesheet.css b/release/html/gui/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/gui/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/hello_world/AllClasses.html b/release/html/hello_world/AllClasses.html new file mode 100644 index 0000000..aba326c --- /dev/null +++ b/release/html/hello_world/AllClasses.html @@ -0,0 +1,19 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+AddingParametersToExecuteThisAgent
+AgentLifeCycle
+DesktopHelloWorld
+HelloWorldAgent
+LaunchingTwoAgentsA
+LaunchingTwoAgentsB
+ThreeAgentsWithNoGUI + diff --git a/release/html/hello_world/front.html b/release/html/hello_world/front.html new file mode 100644 index 0000000..e555860 --- /dev/null +++ b/release/html/hello_world/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Hello world

+ +

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/hello_world/helloworld.ex01.index.html b/release/html/hello_world/helloworld.ex01.index.html new file mode 100644 index 0000000..88f4867 --- /dev/null +++ b/release/html/hello_world/helloworld.ex01.index.html @@ -0,0 +1,12 @@ + + + + +Package helloworld.ex01 (Java2HTML) + + + +Package helloworld.ex01 +
+HelloWorldAgent + diff --git a/release/html/hello_world/helloworld.ex02.index.html b/release/html/hello_world/helloworld.ex02.index.html new file mode 100644 index 0000000..4465cda --- /dev/null +++ b/release/html/hello_world/helloworld.ex02.index.html @@ -0,0 +1,12 @@ + + + + +Package helloworld.ex02 (Java2HTML) + + + +Package helloworld.ex02 +
+AgentLifeCycle + diff --git a/release/html/hello_world/helloworld.ex03.index.html b/release/html/hello_world/helloworld.ex03.index.html new file mode 100644 index 0000000..2f25fe7 --- /dev/null +++ b/release/html/hello_world/helloworld.ex03.index.html @@ -0,0 +1,13 @@ + + + + +Package helloworld.ex03 (Java2HTML) + + + +Package helloworld.ex03 +
+LaunchingTwoAgentsA
+LaunchingTwoAgentsB + diff --git a/release/html/hello_world/helloworld.ex04.index.html b/release/html/hello_world/helloworld.ex04.index.html new file mode 100644 index 0000000..77cce8d --- /dev/null +++ b/release/html/hello_world/helloworld.ex04.index.html @@ -0,0 +1,13 @@ + + + + +Package helloworld.ex04 (Java2HTML) + + + +Package helloworld.ex04 +
+AddingParametersToExecuteThisAgent
+ThreeAgentsWithNoGUI + diff --git a/release/html/hello_world/helloworld.ex05.index.html b/release/html/hello_world/helloworld.ex05.index.html new file mode 100644 index 0000000..859a677 --- /dev/null +++ b/release/html/hello_world/helloworld.ex05.index.html @@ -0,0 +1,12 @@ + + + + +Package helloworld.ex05 (Java2HTML) + + + +Package helloworld.ex05 +
+DesktopHelloWorld + diff --git a/release/html/hello_world/helloworld/ex01/HelloWorldAgent.java.html b/release/html/hello_world/helloworld/ex01/HelloWorldAgent.java.html new file mode 100644 index 0000000..858b221 --- /dev/null +++ b/release/html/hello_world/helloworld/ex01/HelloWorldAgent.java.html @@ -0,0 +1,94 @@ + + + + + +helloworld.ex01.HelloWorldAgent (Java2HTML) + + + + + + + + +
+package helloworld.ex01;
+
+import madkit.kernel.Agent;
+
+/**
+
+ As of MaDKit-5, one source file can be enough to launch a MAS.
+
+ Here we just :
+
+ 1. extend the madkit.kernel.Agent class (the MaDKit's threaded agent class).
+ 2. override its live method.
+ 3. launch the agent using executeThisAgent() within the main method.
+
+ 
+ *            
+ */
+
+public class HelloWorldAgent extends Agent {
+    
+    @Override
+    protected void live() {
+       getLogger().info("\t Hello World! \n"); // This has several advantages over using System.out.println().
+                                                                                           // There is a tutorial about the logging mechanism of MaDKit-5.
+       for (int i = 10; i > 0; i--) {
+           getLogger().info("Living... I will quit in " + i + " seconds");
+           pause(1000); // pauses the agent's thread for 1000 ms
+       }
+    }
+
+       /** live() here is a method which is called automatically. It will be explained later in the next tutorial
+        * ex03(agentlifecycle) **/
+
+    public static void main(String[] args) {
+       executeThisAgent(); // a convenient static method for easily launching agents using an IDE
+    }
+
+       /**
+
+        Implementing a main method within an agent's class is not required at all but it could be
+        used to simulate a command line call to MaDKit with the desired options.
+
+        For this example, the corresponding command line is as follows (assuming a correct classpath)
+
+        > java madkit.kernel.MaDKit --launchAgents helloworld.ex01.HelloWorldAgent,true
+
+        Here we just use the executeThisAgent() method inside the main method
+        so that the launching is greatly simplified using an IDE.
+
+        Here we could also have used:
+
+        public static void main(String[] args) {
+        new Madkit("--launchAgents", "helloworld.ex01.HelloWorldAgent,true");
+        }
+
+        Or
+
+        public static void main(String[] args) {
+        String[] args2 = { "--launchAgents", "helloworld.ex01.HelloWorldAgent,true" };
+        Madkit.main(args2);
+        }
+
+        All of these calls are equivalent.
+
+        */
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex02/AgentLifeCycle.java.html b/release/html/hello_world/helloworld/ex02/AgentLifeCycle.java.html new file mode 100644 index 0000000..baa6c73 --- /dev/null +++ b/release/html/hello_world/helloworld/ex02/AgentLifeCycle.java.html @@ -0,0 +1,83 @@ + + + + + +helloworld.ex02.AgentLifeCycle (Java2HTML) + + + + + + + + +
+package helloworld.ex02;
+
+import madkit.kernel.Agent;
+
+/**
+ 
+ The default life cycle of a threaded agent is composed of three methods 
+ which are automatically called sequentially, and each of which being optional:
+
+ 1. activate(): The first behavior in the life cycle of an agent.
+ It could be considered as a constructor which is called once the agent is launched.
+ The agent cannot use agent primitives before that (e.g. in its constructor).
+ Activate is a good place to initialize the agent's position in the artificial society.
+ (Artificial society is a notion that will be explained later in the tutorials)
+ 
+ 2. live(): This behavior is automatically called when the agent exits activate. It usually
+ implements an infinite loop wherein the agent send and receive messages: 
+ It corresponds to the life of the agent. Here the agent lives 10 seconds and quits.
+ 
+ 3. end() this behavior is automatically called when live exits or when the agent is killed, 
+ e.g. by the user when closing the agent's GUI. 
+ It is usually used to release resources and log the end of life event. 
+ 
+       
+ *     
+*/
+
+public class AgentLifeCycle extends Agent {
+
+    @Override
+    protected void activate() {
+       getLogger().info("\tHello World!!\n\n\tI am activating...");
+       pause(2000);
+    }
+
+    @Override
+    protected void live() {
+       int nb = 10;
+       while (nb-- > 0) {
+           getLogger().info("Living... I will quit in " + nb + " seconds");
+           pause(1000);
+       }
+    }
+
+    @Override
+    protected void end() {
+       getLogger().info("Bye bye !");
+       pause(2000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsA.java.html b/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsA.java.html new file mode 100644 index 0000000..8ba328d --- /dev/null +++ b/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsA.java.html @@ -0,0 +1,71 @@ + + + + + +helloworld.ex03.LaunchingTwoAgentsA (Java2HTML) + + + + + + + + +
+package helloworld.ex03;
+
+import madkit.kernel.Agent;
+
+/**
+
+ By default {@link #executeThisAgent()} launches one agent with a GUI. 
+ However, we can add parameters to launch more agents or add other options.
+ 
+ Let us launch two similar agents by using executeThisAgent(int, boolean, String...).
+ 
+              
+              
+ */
+
+public class LaunchingTwoAgentsA extends Agent {
+
+    @Override
+    protected void activate() {
+       getLogger().info("Hello, my name is "+getName());
+       /*
+        The agent's default name is built using its class + its ID (instantiation number). 
+        Here the name should be LaunchingTwoAgents-02 and -03. 
+        This is because two agents were priorly launched: (0) The kernel agent & (1) The GUI manager
+       */
+    }
+
+    @Override
+    protected void live() {
+        getLogger().info("We are 2 agents but our GUI has not been managed");
+       for (int i = 10; i > 0; i--) {
+           getLogger().info("Living... I will quit in " + i + " seconds");
+           pause(1000); 
+       }
+    }
+
+    public static void main(String[] args) {
+       // the first parameter is the number of agents to launch
+       // the second specifies if a GUI should be installed or not for the agents
+       executeThisAgent(2, true);
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsB.java.html b/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsB.java.html new file mode 100644 index 0000000..8552ec9 --- /dev/null +++ b/release/html/hello_world/helloworld/ex03/LaunchingTwoAgentsB.java.html @@ -0,0 +1,80 @@ + + + + + +helloworld.ex03.LaunchingTwoAgentsB (Java2HTML) + + + + + + + + +
+package helloworld.ex03;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+
+/**
+
+ By default, the GUI of an agent is placed in the center of the screen.
+ So probably that the agents of the previous example were not visible at first sight...
+
+ Let us change this default location by overriding the {@link #setupFrame} method, which
+ allows to modify the default GUI's characteristics.
+
+ First we import the AgentFrame class to Override one of its method : setupFrame(AgentFrame frame)
+
+ Here, the trick is to use the hashCode() method to distinguish the agents.
+ Indeed, each agent has a unique hashcode corresponding to their instantiation number.
+ So one can use this hashcode to place similar agents at different locations.
+
+ 
+ 
+
+ */
+
+public class LaunchingTwoAgentsB extends Agent {
+
+    @Override
+    protected void activate() {
+           getLogger().info("Hello, my name is "+getName());
+    }
+
+    @Override
+    protected void live() {
+        getLogger().info("Our GUI is managed !");
+           for (int i = 10; i > 0; i--) {
+               getLogger().info("Living... I will quit in " + i + " seconds");
+               pause(1000);
+           }
+    }
+
+    //We override the setupFrame method in the agent class to change the GUI position
+    @Override
+    public void setupFrame(AgentFrame frame) {
+        super.setupFrame(frame);
+        frame.setLocation(hashCode()*150, hashCode()*150);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent(2, true);
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex04/AddingParametersToExecuteThisAgent.java.html b/release/html/hello_world/helloworld/ex04/AddingParametersToExecuteThisAgent.java.html new file mode 100644 index 0000000..193e143 --- /dev/null +++ b/release/html/hello_world/helloworld/ex04/AddingParametersToExecuteThisAgent.java.html @@ -0,0 +1,69 @@ + + + + + +helloworld.ex04.AddingParametersToExecuteThisAgent (Java2HTML) + + + + + + + + +
+package helloworld.ex04;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit.BooleanOption;
+
+/**
+  If you used Java web start and did not open its console, 
+  maybe that you did not see anything in the previous example as the agents were launched without a GUI.
+  
+  executeThisAgent(int, boolean, String...) can also take 
+  additional parameters, especially MaDKit options such as 
+  specified in the madkit.kernel.Madkit.BooleanOption enumeration.
+  
+  Let us add the BooleanOption#console option to request the launching of the madkit.gui.ConsoleAgent,
+  which is a specific agent embedded that gathers all System.out outputs
+  in its own GUI, so that we can also see the outputs of agents that have no GUI.
+  
+              
+              
+  
+ */
+
+public class AddingParametersToExecuteThisAgent extends Agent {
+
+    @Override
+    protected void live() {
+       int nb = 10;
+       while (nb-- > 0) {
+           getLogger().info("Living... I will quit in " + nb + " seconds");
+           pause(1000);
+       }
+       getLogger().info("Bye !!");
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent(3, false, BooleanOption.console.toString());
+       // which is strictly equivalent to 
+       // executeThisAgent(3, false, "--console");
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex04/ThreeAgentsWithNoGUI.java.html b/release/html/hello_world/helloworld/ex04/ThreeAgentsWithNoGUI.java.html new file mode 100644 index 0000000..8a69dc1 --- /dev/null +++ b/release/html/hello_world/helloworld/ex04/ThreeAgentsWithNoGUI.java.html @@ -0,0 +1,59 @@ + + + + + +helloworld.ex04.ThreeAgentsWithNoGUI (Java2HTML) + + + + + + + + +
+package helloworld.ex04;
+
+import madkit.kernel.Agent;
+
+/**
+  
+  Let us try executeThisAgent(int, boolean, String...) with no GUI for the agents.
+  
+              
+              
+  
+ */
+
+public class ThreeAgentsWithNoGUI extends Agent {
+
+    @Override
+    protected void live() {
+       for (int i = 10; i > 0; i--) {
+           getLogger().info("Living... I will quit in " + i + " seconds");
+           pause(1000); // pauses the agent's thread for 1000 ms
+       }
+       getLogger().info("Bye !!");
+    }
+
+    public static void main(String[] args) {
+       // the first parameter is the number of agents to launch
+       // the second specifies if a GUI should installed or not for the agents -> no GUI here
+       executeThisAgent(3, false);
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/helloworld/ex05/DesktopHelloWorld.java.html b/release/html/hello_world/helloworld/ex05/DesktopHelloWorld.java.html new file mode 100644 index 0000000..ffced1d --- /dev/null +++ b/release/html/hello_world/helloworld/ex05/DesktopHelloWorld.java.html @@ -0,0 +1,63 @@ + + + + + +helloworld.ex05.DesktopHelloWorld (Java2HTML) + + + + + + + + +
+package helloworld.ex05;
+
+import madkit.kernel.Madkit;
+
+/**
+  Here, we just test the desktop mode of MaDKit-5.
+  
+       
+       
+  
+  The Desktop is a GUI front end embedding the agents and which features different actions that can help developing 
+  applications. The Desktop do not quit when there is no more active agents, contrary to all the previous examples.
+ */
+public class DesktopHelloWorld {
+
+    /**
+
+      The only thing to do is to pass the --desktop parameter to the main method of MaDKit.
+     
+     */
+    public static void main(String[] args) {
+       String[] args2 = { "--desktop", "--launchAgents", "helloworld.ex01.HelloWorldAgent,true" };
+       Madkit.main(args2);
+    }
+
+    /*
+      What we used here is exactly the same as : 
+    public static void main(String[] args) {
+      String[] argss = {BooleanOption.desktop.toString(),Madkit.Option.launchAgents.toString(),HelloWorldAgent.class.getName()+",true"};
+      Madkit.main(argss);
+   }
+     */
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/hello_world/index.html b/release/html/hello_world/index.html new file mode 100644 index 0000000..e5eccdb --- /dev/null +++ b/release/html/hello_world/index.html @@ -0,0 +1,20 @@ + + + + +Hello world (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/hello_world/packages.html b/release/html/hello_world/packages.html new file mode 100644 index 0000000..31fb28e --- /dev/null +++ b/release/html/hello_world/packages.html @@ -0,0 +1,19 @@ + + + + +Hello world (Java2HTML) + + + + +Hello world +
All Classes +
Packages +
+helloworld.ex01
+helloworld.ex02
+helloworld.ex03
+helloworld.ex04
+helloworld.ex05 + diff --git a/release/html/hello_world/stylesheet.css b/release/html/hello_world/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/hello_world/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/logging/AllClasses.html b/release/html/logging/AllClasses.html new file mode 100644 index 0000000..202717b --- /dev/null +++ b/release/html/logging/AllClasses.html @@ -0,0 +1,19 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+LevelFinerFinest
+LevelMessage
+LogLevel
+LogMessage
+MessageWithLevel
+TheDefaultLogLevel
+TheDifferentLevels + diff --git a/release/html/logging/front.html b/release/html/logging/front.html new file mode 100644 index 0000000..faed19c --- /dev/null +++ b/release/html/logging/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Logging

+
    +
  • Using the agent's logging mechanism of MaDKit
  • +





    +





    +
+

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/logging/index.html b/release/html/logging/index.html new file mode 100644 index 0000000..abc0865 --- /dev/null +++ b/release/html/logging/index.html @@ -0,0 +1,20 @@ + + + + +Logging (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/logging/logging.ex01a_intro.index.html b/release/html/logging/logging.ex01a_intro.index.html new file mode 100644 index 0000000..0eb15b7 --- /dev/null +++ b/release/html/logging/logging.ex01a_intro.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex01a_intro (Java2HTML) + + + +Package logging.ex01a_intro +
+LogMessage + diff --git a/release/html/logging/logging.ex01b_levels.index.html b/release/html/logging/logging.ex01b_levels.index.html new file mode 100644 index 0000000..02d6eb2 --- /dev/null +++ b/release/html/logging/logging.ex01b_levels.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex01b_levels (Java2HTML) + + + +Package logging.ex01b_levels +
+LevelMessage + diff --git a/release/html/logging/logging.ex01c_levels.index.html b/release/html/logging/logging.ex01c_levels.index.html new file mode 100644 index 0000000..813c22f --- /dev/null +++ b/release/html/logging/logging.ex01c_levels.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex01c_levels (Java2HTML) + + + +Package logging.ex01c_levels +
+MessageWithLevel + diff --git a/release/html/logging/logging.ex02a_introLogLevel.index.html b/release/html/logging/logging.ex02a_introLogLevel.index.html new file mode 100644 index 0000000..aa583b9 --- /dev/null +++ b/release/html/logging/logging.ex02a_introLogLevel.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex02a_introLogLevel (Java2HTML) + + + +Package logging.ex02a_introLogLevel +
+LogLevel + diff --git a/release/html/logging/logging.ex02b_defaultLogLevel.index.html b/release/html/logging/logging.ex02b_defaultLogLevel.index.html new file mode 100644 index 0000000..79e4fe2 --- /dev/null +++ b/release/html/logging/logging.ex02b_defaultLogLevel.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex02b_defaultLogLevel (Java2HTML) + + + +Package logging.ex02b_defaultLogLevel +
+TheDefaultLogLevel + diff --git a/release/html/logging/logging.ex02c_theDifferentLevels.index.html b/release/html/logging/logging.ex02c_theDifferentLevels.index.html new file mode 100644 index 0000000..e3c88bb --- /dev/null +++ b/release/html/logging/logging.ex02c_theDifferentLevels.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex02c_theDifferentLevels (Java2HTML) + + + +Package logging.ex02c_theDifferentLevels +
+TheDifferentLevels + diff --git a/release/html/logging/logging.ex03a_levelFinerFinest.index.html b/release/html/logging/logging.ex03a_levelFinerFinest.index.html new file mode 100644 index 0000000..e17fa1e --- /dev/null +++ b/release/html/logging/logging.ex03a_levelFinerFinest.index.html @@ -0,0 +1,12 @@ + + + + +Package logging.ex03a_levelFinerFinest (Java2HTML) + + + +Package logging.ex03a_levelFinerFinest +
+LevelFinerFinest + diff --git a/release/html/logging/logging/ex01a_intro/LogMessage.java.html b/release/html/logging/logging/ex01a_intro/LogMessage.java.html new file mode 100644 index 0000000..d504480 --- /dev/null +++ b/release/html/logging/logging/ex01a_intro/LogMessage.java.html @@ -0,0 +1,67 @@ + + + + + +logging.ex01a_intro.LogMessage (Java2HTML) + + + + + + + + +
+package logging.ex01a_intro;
+
+import madkit.kernel.Agent;
+
+/**
+ * This tutorial is about the agent's logger attribute which is an alternative to the method System.out.println(). In
+ * fact the logger can do the same thing as System.out.println() : displaying message on the screen but it does many
+ * other things. The logger is an instance of the AgentLogger class of the MaDKit library which extends the Logger class
+ * of the Java SE. In this tutorial we will see why and how the logger replaces the method System.out.println() in
+ * MaDKit. In the different examples of this tutorial we will see : - how to log a message - the different log levels -
+ * the "finest" level particular features - how to create a log file - how to choose the log directory Firstly, we just
+ * display a message to the screen with the method AgentLogger#info(String) of the getLogger(). A simple agent is used,
+ * which has a default GUI, lives 10 seconds and quits. During the life of the agent, we show how to log an "info"
+ * message. As you will see, by default this message is displayed in both the output console and the agent's GUI
+ * 
+ * 
+ * 
+ *  
+ *      
+ * 
+ * 
+ * 
+ * @author Pascal Wagner
+ */
+
+public class LogMessage extends Agent {
+
+    @Override
+    protected void live() {
+       pause(2000);
+       getLogger().info("This agent logs an 'info' message.");
+       pause(8000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex01b_levels/LevelMessage.java.html b/release/html/logging/logging/ex01b_levels/LevelMessage.java.html new file mode 100644 index 0000000..d4295ec --- /dev/null +++ b/release/html/logging/logging/ex01b_levels/LevelMessage.java.html @@ -0,0 +1,60 @@ + + + + + +logging.ex01b_levels.LevelMessage (Java2HTML) + + + + + + + + +
+package logging.ex01b_levels;
+
+import madkit.kernel.Agent;
+
+/**
+ * The main advantage of using the Logger class is that all messages are associated with a level. Indeed, depending on
+ * the logging method used, a message will have a particular level. This level will have an impact on how the message is
+ * displayed. In this example, we will log two messages with different levels. You will observe that the messages are
+ * preceded by their own log level.
+ * 
+ *  
+ *      
+ * 
+ * @author Pascal Wagner
+ */
+
+public class LevelMessage extends Agent {
+
+    @Override
+    protected void live() {
+       pause(2000);
+       getLogger().info("This is a message which has a level 'info'.");
+       pause(3000);
+       getLogger().warning("This is a message which has a level 'warning'.");
+       pause(5000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex01c_levels/MessageWithLevel.java.html b/release/html/logging/logging/ex01c_levels/MessageWithLevel.java.html new file mode 100644 index 0000000..ba1f7b5 --- /dev/null +++ b/release/html/logging/logging/ex01c_levels/MessageWithLevel.java.html @@ -0,0 +1,91 @@ + + + + + +logging.ex01c_levels.MessageWithLevel (Java2HTML) + + + + + + + + +
+/*
+ * Copyright 2011-2017 Fabien Michel
+ * 
+ * This file is part of MaDKit-tutorials.
+ * 
+ * MaDKit-tutorials is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * MaDKit-tutorials is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with MaDKit-tutorials. If not, see <http://www.gnu.org/licenses/>.
+ */
+package logging.ex01c_levels;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Agent;
+
+/**
+ * We have seen how to log a message but it exists several ways to do it. So we will see another way to associate
+ * different levels to messages and one of messages will not display at the screen. Here we show another method for
+ * logging a message: Logger#log(Level, String). During the life of this agent, four messages are logged : two 'info'
+ * messages and two 'config' messages. The last two will not be displayed. The next example of this tutorial explains
+ * why...
+ * 
+ * 
+ *  
+ *      
+ * 
+ * 
+ * 
+ * @author Pascal Wagner
+ */
+
+public class MessageWithLevel extends Agent {
+
+    @Override
+    protected void live() {
+       Level infoLevel = Level.INFO;
+       Level configLevel = Level.CONFIG;
+       String infoMessage = "This is an info message.";
+       String configMessage = "This is a config message.";
+       pause(2000);
+       getLogger().info(infoMessage);
+       pause(3000);
+       getLogger().log(infoLevel, infoMessage + "\n\nThe two next config messages will not display at the screen.");
+       pause(3000);
+       getLogger().config(infoMessage);
+       getLogger().log(configLevel, configMessage);
+       pause(3000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex02a_introLogLevel/LogLevel.java.html b/release/html/logging/logging/ex02a_introLogLevel/LogLevel.java.html new file mode 100644 index 0000000..55b153e --- /dev/null +++ b/release/html/logging/logging/ex02a_introLogLevel/LogLevel.java.html @@ -0,0 +1,90 @@ + + + + + +logging.ex02a_introLogLevel.LogLevel (Java2HTML) + + + + + + + + +
+/*
+ * Copyright 2011-2017 Fabien Michel
+ * 
+ * This file is part of MaDKit-tutorials.
+ * 
+ * MaDKit-tutorials is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * MaDKit-tutorials is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with MaDKit-tutorials. If not, see <http://www.gnu.org/licenses/>.
+ */
+package logging.ex02a_introLogLevel;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Agent;
+
+/**
+ * In the last example, two messages have not been displayed, not because of a mistake in the code but because of their
+ * level. Indeed, messages are displayed according to the current level of the getLogger(). So the logger acts as a
+ * filter on the message which are logged: For being logged the message's level has to be higher than the logger's
+ * level. The idea is that you can have different setting for the logger so that you can have different output modes for
+ * your agent: From quiet (OFF) to verbose (ALL). The logger's level can be modified with the method
+ * getLogger().setLevel(). Here, we log a config message and an info message but the first one will not be displayed.
+ * Then the logger's level is changed so that 'config' messages will appear.
+ * 
+ * 
+ *  
+ *   
+ * 
+ * 
+ * @author Pascal Wager
+ */
+
+public class LogLevel extends Agent {
+
+    @Override
+    protected void live() {
+       pause(2000);
+       getLogger().info("There are two log records but the second will not be displayed.\n");
+       getLogger().config("The logger's level is too low to display this message.");
+       pause(4000);
+
+       getLogger().setLevel(Level.CONFIG);
+
+       getLogger().info("The logger's level has been set to " + Level.CONFIG);
+       pause(3000);
+       getLogger().config("So now the config messages can appear\non the screen!");
+       pause(8000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java.html b/release/html/logging/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java.html new file mode 100644 index 0000000..fa3b316 --- /dev/null +++ b/release/html/logging/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java.html @@ -0,0 +1,57 @@ + + + + + +logging.ex02b_defaultLogLevel.TheDefaultLogLevel (Java2HTML) + + + + + + + + +
+package logging.ex02b_defaultLogLevel;
+
+import madkit.kernel.Agent;
+
+/**
+ * So we can set the log level with getLogger().setLevel() and we will see the different existing levels in the next
+ * example. Here we go to see the method getLevel() and see the default log level which is used in MaDKit. 
+ * 
+ * 
+ * 
+ *  
+ * 
+ * 
+ * @author Pascal Wagner
+ */
+
+public class TheDefaultLogLevel extends Agent {
+
+    @Override
+    protected void live() {
+       pause(2000);
+       getLogger().info("The default log level is : " + getLogger().getLevel());
+       pause(8000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex02c_theDifferentLevels/TheDifferentLevels.java.html b/release/html/logging/logging/ex02c_theDifferentLevels/TheDifferentLevels.java.html new file mode 100644 index 0000000..2bb6200 --- /dev/null +++ b/release/html/logging/logging/ex02c_theDifferentLevels/TheDifferentLevels.java.html @@ -0,0 +1,110 @@ + + + + + +logging.ex02c_theDifferentLevels.TheDifferentLevels (Java2HTML) + + + + + + + + +
+package logging.ex02c_theDifferentLevels;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+
+import madkit.kernel.Agent;
+import madkit.kernel.AgentLogger;
+
+/**
+ * The java.util.logging.Level class of the Java SE defines a set of standard logging levels that can be used to control
+ * logging outputs: Here they are in descending order : - severe - warning - info - config - fine - finer - finest In
+ * addition there is a level OFF that can be used to turn off logging, and a level ALL that can be used to enable the
+ * logging of all messages. In MaDKit, the {@link AgentLogger#talk(String)} method is added to define an additional
+ * level which is used log a talk message. This is an example which recaps how to set and get the log level and how we
+ * display or not messages according to their level. All the levels are used here. 
+ * 
+ * 
+ *  
+ *      
+ * 
+ * 
+ * @author Pascal Wagner
+ */
+
+public class TheDifferentLevels extends Agent {
+
+    private static List<Level> levels = Arrays.asList(Level.ALL, Level.FINEST, Level.FINER, Level.FINE, Level.CONFIG, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF);
+
+    @Override
+    protected void activate() {
+       pause(2000);
+    }
+
+    @Override
+    protected void live() {
+       getLogger().talk("\n\t************************************\n" + "\t   The different levels of display\n" + "\t************************************\n\n");
+       pause(1000);
+
+       getLogger().talk("\n\nLog level = " + getLogger().getLevel() + " (default Level)\n");
+       getLogger().severe("Default log level = " + getLogger().getLevel());
+       getLogger().warning("Default log level = " + getLogger().getLevel());
+       getLogger().info("Default log level = " + getLogger().getLevel());
+       getLogger().config("Default log level = " + getLogger().getLevel());
+       getLogger().fine("Default log level = " + getLogger().getLevel());
+       getLogger().finer("Default log level = " + getLogger().getLevel());
+       getLogger().finest("Default log level = " + getLogger().getLevel());
+       pause(2000);
+       int i = 10;
+       for (Level l : levels) {
+           getLogger().talk("\n\nLog level --> " + l + "\n");
+           getLogger().setLevel(l);
+
+           getLogger().severe("severe message");
+           getLogger().warning("warning message");
+           getLogger().info("info message");
+           getLogger().config("config message");
+           getLogger().fine("fine message");
+           getLogger().finer("finer message");
+           getLogger().finest("finest message");
+           pause(1000 * (i--));
+       }
+       if (getLogger().getLevel() == Level.OFF) {
+           System.out.println("This message is displayed thanks to System.out.println()\n" + "In fact with the log level OFF neither is displayed.\n");
+           pause(2000);
+       }
+       getLogger().setLevel(Level.INFO);
+
+       getLogger().talk("\nThe loggger is set back to " + getLogger().getLevel() + "\n\n\n");
+       pause(1000);
+    }
+
+    @Override
+    protected void end() {
+       getLogger().info("Bye bye !");
+       pause(5000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/logging/ex03a_levelFinerFinest/LevelFinerFinest.java.html b/release/html/logging/logging/ex03a_levelFinerFinest/LevelFinerFinest.java.html new file mode 100644 index 0000000..45e517f --- /dev/null +++ b/release/html/logging/logging/ex03a_levelFinerFinest/LevelFinerFinest.java.html @@ -0,0 +1,78 @@ + + + + + +logging.ex03a_levelFinerFinest.LevelFinerFinest (Java2HTML) + + + + + + + + +
+package logging.ex03a_levelFinerFinest;
+
+import java.util.logging.Level;
+
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Agent;
+import madkit.kernel.AgentLogger;
+import madkit.kernel.Message;
+
+/**
+ * You have surely noticed that some additional finer and finest messages appeared in the console in the last example
+ * while they did not appear in the code. In fact, finest messages are used to log many of the agent methods defined in
+ * MaDKit. And the agent's life cycle is traced at the finer level. So, setting the logger's level to finer, finest or
+ * all represents a very easy way of debugging MaDKit agents ! Here, we just set the logger's level to all to show that
+ * there are log messages which are displayed whereas there is no explicit code here. notes : - agent's life is composed
+ * by the methods : activate(), live() and end(). - the different pauses are only there for you to see the agent's life
+ * cycle.
+ * 
+ * 
+ *  
+ *      
+ * 
+ * 
+ * @author Pascal Wagner
+ */
+
+public class LevelFinerFinest extends Agent {
+
+    @Override
+    protected void activate() {
+       getLogger().setLevel(Level.ALL);
+       pause(5000);
+    }
+
+    @Override
+    protected void live() {
+       Message m = nextMessage(); /**  In MaDKit, the {@link AbstractAgent#nextMessage()} method is added to
+                                    retrieves and removes the oldest received message contained in the mailbox.  */
+       pause(5000);
+    }
+
+    @Override
+    protected void end() {
+       pause(5000);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent();
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/logging/packages.html b/release/html/logging/packages.html new file mode 100644 index 0000000..13d1c5f --- /dev/null +++ b/release/html/logging/packages.html @@ -0,0 +1,21 @@ + + + + +Logging (Java2HTML) + + + + +Logging +
All Classes +
Packages +
+logging.ex01a_intro
+logging.ex01b_levels
+logging.ex01c_levels
+logging.ex02a_introLogLevel
+logging.ex02b_defaultLogLevel
+logging.ex02c_theDifferentLevels
+logging.ex03a_levelFinerFinest + diff --git a/release/html/logging/stylesheet.css b/release/html/logging/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/logging/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/madkitoptions/AllClasses.html b/release/html/madkitoptions/AllClasses.html new file mode 100644 index 0000000..05da1c9 --- /dev/null +++ b/release/html/madkitoptions/AllClasses.html @@ -0,0 +1,34 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+TutorialAgent
+_1_Console
+_1_LaunchAgents
+_1_MadkitLogLevel
+_2_AgentLogLevel
+_2_CgrWarnings
+_2_ConfigFile
+_3_Debug
+_3_DesktopFrame
+_3_GuiLogLevel
+_4_AgentFrame
+_4_Desktop
+_4_KernelLogLevel
+_5_CreateLogFiles
+_5_LogDirectory
+_5_NetworkLogLevel
+_6_AgentWithCGRWarnings
+_6_NoAgentConsoleLog
+_6_WarningLogLevel
+_7_LoadLocalDemos
+_8_Network
+_9_AutoConnectMadkitWebsite + diff --git a/release/html/madkitoptions/front.html b/release/html/madkitoptions/front.html new file mode 100644 index 0000000..5ab979b --- /dev/null +++ b/release/html/madkitoptions/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Options in MaDKit

+
    +
  • Basics for handling MaDKit options
  • +





    +





    +
+

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/madkitoptions/index.html b/release/html/madkitoptions/index.html new file mode 100644 index 0000000..f001f9e --- /dev/null +++ b/release/html/madkitoptions/index.html @@ -0,0 +1,20 @@ + + + + +Options in MaDKit (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions.ex1_BooleanOptions.index.html b/release/html/madkitoptions/madkitoptions.ex1_BooleanOptions.index.html new file mode 100644 index 0000000..f41878c --- /dev/null +++ b/release/html/madkitoptions/madkitoptions.ex1_BooleanOptions.index.html @@ -0,0 +1,20 @@ + + + + +Package madkitoptions.ex1_BooleanOptions (Java2HTML) + + + +Package madkitoptions.ex1_BooleanOptions +
+_1_Console
+_2_CgrWarnings
+_3_Debug
+_4_Desktop
+_5_CreateLogFiles
+_6_NoAgentConsoleLog
+_7_LoadLocalDemos
+_8_Network
+_9_AutoConnectMadkitWebsite + diff --git a/release/html/madkitoptions/madkitoptions.ex2_LevelOptions.index.html b/release/html/madkitoptions/madkitoptions.ex2_LevelOptions.index.html new file mode 100644 index 0000000..b6d96ea --- /dev/null +++ b/release/html/madkitoptions/madkitoptions.ex2_LevelOptions.index.html @@ -0,0 +1,18 @@ + + + + +Package madkitoptions.ex2_LevelOptions (Java2HTML) + + + +Package madkitoptions.ex2_LevelOptions +
+_1_MadkitLogLevel
+_2_AgentLogLevel
+_3_GuiLogLevel
+_4_KernelLogLevel
+_5_NetworkLogLevel
+_6_AgentWithCGRWarnings
+_6_WarningLogLevel + diff --git a/release/html/madkitoptions/madkitoptions.ex3_MadkitOptions.index.html b/release/html/madkitoptions/madkitoptions.ex3_MadkitOptions.index.html new file mode 100644 index 0000000..06021cd --- /dev/null +++ b/release/html/madkitoptions/madkitoptions.ex3_MadkitOptions.index.html @@ -0,0 +1,16 @@ + + + + +Package madkitoptions.ex3_MadkitOptions (Java2HTML) + + + +Package madkitoptions.ex3_MadkitOptions +
+_1_LaunchAgents
+_2_ConfigFile
+_3_DesktopFrame
+_4_AgentFrame
+_5_LogDirectory + diff --git a/release/html/madkitoptions/madkitoptions.util.index.html b/release/html/madkitoptions/madkitoptions.util.index.html new file mode 100644 index 0000000..21a72cc --- /dev/null +++ b/release/html/madkitoptions/madkitoptions.util.index.html @@ -0,0 +1,12 @@ + + + + +Package madkitoptions.util (Java2HTML) + + + +Package madkitoptions.util +
+TutorialAgent + diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_1_Console.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_1_Console.java.html new file mode 100644 index 0000000..123e940 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_1_Console.java.html @@ -0,0 +1,68 @@ + + + + + +madkitoptions.ex1_BooleanOptions._1_Console (Java2HTML) + + + + + + + + +
+/**
+ * READ ME
+ * 
+ * This tutorial is about MaDKit options. An option is a feature that may be specified or activated.
+ * You can find more details here : http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/.
+ * MaDKit options are divided in three categories :
+ *    - Boolean Options
+ *    - Level Options  
+ *    - MaDKit Options
+ *    
+ * In this first set of examples, we will present you Boolean Options.
+ * Among the others options, boolean options are either activated or not. 
+ */
+
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This class exemplifies the use of the console option.
+ * If this boolean option is set to true, the MaDKit console agent is launched.
+ * The default value is false.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _1_Console {
+
+        public static void main(String[] args) {
+               
+               /* If no boolean is specified, MaDKit considers it as true */
+               new Madkit(Madkit.BooleanOption.console.toString()); /* Equivalent to : new Madkit(Madkit.BooleanOption.console.toString(), Boolean.TRUE.toString()); */
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               // new Madkit(Madkit.BooleanOption.console.toString(), Boolean.FALSE.toString());
+        }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java.html new file mode 100644 index 0000000..13bc7af --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java.html @@ -0,0 +1,65 @@ + + + + + +madkitoptions.ex1_BooleanOptions._2_CgrWarnings (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+/** 
+ * This class exemplifies the use of cgrWarnings's option.
+ * If this boolean option is set to true, warnings concerning
+ * Community/Group/Role notifications are activated.
+ * The default value is false.
+ * 
+ * 
+ * 
+ */
+
+public class _2_CgrWarnings  extends TutorialAgent{
+
+       @Override
+       protected void activate() {
+              requestRole("COMMUNITY", "GROUP", "ROLE");
+              /**
+               * By requesting a role in a community that does not exist,
+               * our agent will cause a CGR warning.
+               */
+       }
+       
+        public static void main(String[] args) {
+               
+               new Madkit(Madkit.BooleanOption.cgrWarnings.toString(), Madkit.Option.launchAgents.toString(), _2_CgrWarnings.class.getName() + " ,true,1", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString());
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               // new Madkit(Madkit.BooleanOption.cgrWarnings.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), _2_Agent.class.getName() + " ,true,1", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString());
+        }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_3_Debug.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_3_Debug.java.html new file mode 100644 index 0000000..6d6dd86 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_3_Debug.java.html @@ -0,0 +1,54 @@ + + + + + +madkitoptions.ex1_BooleanOptions._3_Debug (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+/**
+ * This class exemplifies the use of debug's option.
+ * If this boolean option is set to true, all the agents' LogLevel are set to "ALL".
+ * The default value is false.
+ * 
+ * 
+ * 
+ */
+
+public class _3_Debug {
+        public static void main(String[] args) {
+               
+               new Madkit(Madkit.BooleanOption.debug.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + ",true,1;");
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. 
+                * You should have less log displayed
+                */
+               // new Madkit(Madkit.BooleanOption.debug.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + ",true,1;");
+        }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_4_Desktop.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_4_Desktop.java.html new file mode 100644 index 0000000..6bb7607 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_4_Desktop.java.html @@ -0,0 +1,61 @@ + + + + + +madkitoptions.ex1_BooleanOptions._4_Desktop (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This class exemplifies the use of desktop's option.
+ * If this boolean option is set to true, MaDKit desktop is launched.
+ * The default value is false.
+ * 
+ * 
+ * 
+ */
+public class _4_Desktop {
+
+       /**
+        * Despite default value being "false", if this property is not explicitly set
+        * to "false" and if Madkit.Option.launchAgents and Madkit.Option.configFile
+        * are both null, then the desktop mode will be automatically set to true
+        * during startup.
+        */
+        public static void main(String[] args) {
+               
+               new Madkit(Madkit.BooleanOption.desktop.toString());
+              
+               /* Notice that it is the same behavior as the next line */
+               // new Madkit(Madkit.Option.launchAgents.toString(), "null", Madkit.Option.configFile.toString(), "null");
+               
+               /* Nevertheless if we specify it... There is not any MaDKit desktop displayed. */
+               // new Madkit(Madkit.BooleanOption.desktop.toString(), Boolean.FALSE.toString()); 
+        }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java.html new file mode 100644 index 0000000..cca6d6e --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java.html @@ -0,0 +1,57 @@ + + + + + +madkitoptions.ex1_BooleanOptions._5_CreateLogFiles (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+/**
+ * This class exemplifies the use of createLogFiles' option.
+ * If this boolean option is set to true, then file(s) storing
+ * the logs of every MaDKit's agent with a log level greater
+ * than the "OFF" level will be created. These file(s) are generated
+ * in a "logs" directory which is created in the working directory (the project's root in eclipse by default).
+ * The default value is false.
+ * 
+ * 
+ * 
+ */
+
+public class _5_CreateLogFiles {
+
+        public static void main(String[] args) {
+
+               /**
+                * Do not forget to check in the "logs" directory (root of
+                * the imported project) to see the generated file.
+                */
+               new Madkit(Madkit.BooleanOption.createLogFiles.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName());
+        }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java.html new file mode 100644 index 0000000..7abab57 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java.html @@ -0,0 +1,58 @@ + + + + + +madkitoptions.ex1_BooleanOptions._6_NoAgentConsoleLog (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+/**
+ * This class exemplifies the use of noAgentConsoleLog's option.
+ * If this boolean option is set to true, there is no log displayed
+ * in the default console used by the jvm.
+ * The default value is false.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _6_NoAgentConsoleLog {
+       
+        public static void main(String[] args) {
+       
+               new Madkit(Madkit.BooleanOption.noAgentConsoleLog.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + " ,true, 2", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString());
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               //new Madkit(Madkit.BooleanOption.noAgentConsoleLog.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + " ,true, 2", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString());
+        }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java.html new file mode 100644 index 0000000..4567e19 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java.html @@ -0,0 +1,58 @@ + + + + + +madkitoptions.ex1_BooleanOptions._7_LoadLocalDemos (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This class exemplifies the use of loadLocalDemos
+ * option. This option load all the demos that are 
+ * available so far. 
+ * If this boolean is set to true, you can access
+ * to all of the demos and launch them in the
+ * "MAS" tab of MaDKit GUI (graphical user interface). 
+ * The default value is false.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _7_LoadLocalDemos {
+
+        public static void main(String[] args) {
+       
+               new Madkit(Madkit.BooleanOption.loadLocalDemos.toString());
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               // new Madkit(Madkit.BooleanOption.loadLocalDemos.toString(), Boolean.FALSE.toString());
+        }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_8_Network.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_8_Network.java.html new file mode 100644 index 0000000..ea66efb --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_8_Network.java.html @@ -0,0 +1,56 @@ + + + + + +madkitoptions.ex1_BooleanOptions._8_Network (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This class exemplifies the use of network's option.
+ * If this boolean option is set to true, MaDKit starts
+ * the network on startup. By "network" we imply the ability
+ * for MaDKit to be connected to another MaDKit app.
+ * The default value is false.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _8_Network {
+
+        public static void main(String[] args) {
+               
+               new Madkit(Madkit.BooleanOption.network.toString());
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               // new Madkit(Madkit.BooleanOption.network.toString(), Boolean.FALSE.toString());
+        }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java.html b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java.html new file mode 100644 index 0000000..aada8c4 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java.html @@ -0,0 +1,56 @@ + + + + + +madkitoptions.ex1_BooleanOptions._9_AutoConnectMadkitWebsite (Java2HTML) + + + + + + + + +
+package madkitoptions.ex1_BooleanOptions;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This class exemplifies the use of autoConnectMaDKitWebsite
+ * option. If this boolean is set to true, it connects  MaDKit
+ * to the MaDKit repository when launched making all the main classes
+ * or demos available in the MaDKit gui.
+ * The default value is false.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _9_AutoConnectMadkitWebsite {
+
+        public static void main(String[] args) {
+               
+               new Madkit(Madkit.BooleanOption.autoConnectMadkitWebsite.toString());
+               
+               /* Check the difference by commenting the previous line and uncommenting the next one. */
+               // new Madkit(Madkit.BooleanOption.autoConnectMadkitWebsite.toString(), Boolean.FALSE.toString());
+        }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java.html new file mode 100644 index 0000000..1c5a1d2 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java.html @@ -0,0 +1,77 @@ + + + + + +madkitoptions.ex2_LevelOptions._1_MadkitLogLevel (Java2HTML) + + + + + + + + +
+/**
+ * Now we will interest into Level Options.
+ * These features are more detailed than Boolean Options,
+ * and allow slight differences. 
+ * 
+ * There are nine different levels, from :
+ * 
+ * OFF (turn off logging)
+ * SEVERE (highest value : the less detailed)
+ * WARNING
+ * INFO
+ * CONFIG
+ * FINE
+ * FINER
+ * FINEST (lowest value : the more detailed)
+ * ALL (enable all messages)
+ * 
+ * To understand their nuances you can check the official documentation
+ * ( https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html?is-external=true )
+ * or the logging tutorial.
+ */
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This example is about the level option MadkitLogLevel.
+ * This option allows the specification of MaDKit's log level.
+ *
+ * 
+ * 
+ */
+public class _1_MadkitLogLevel {
+
+        public static void main(String[] args) {
+               
+              /* Displays everything */
+              new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.ALL.toString());
+              
+              /* Displays only informational messages */
+              //new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.INFO.toString());
+              
+              /* The logging is turned off */ 
+              //new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.OFF.toString());
+        }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java.html new file mode 100644 index 0000000..0210187 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java.html @@ -0,0 +1,55 @@ + + + + + +madkitoptions.ex2_LevelOptions._2_AgentLogLevel (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This example is about the level option AgentLogLevel.
+ * This option allows the specifications of MaDKit agents'
+ * log level.
+ *
+ * 
+ * 
+ */
+
+public class _2_AgentLogLevel {
+       
+       public static void main(String[] args) {
+       
+              /* Displays everything */
+              new Madkit(Madkit.LevelOption.agentLogLevel.toString(),Level.ALL.toString(), Madkit.Option.launchAgents.toString(), madkitoptions.util.TutorialAgent.class.getName() + ",true,1;");
+              
+              /* Displays only informational messages */
+              // new Madkit(Madkit.LevelOption.agentLogLevel.toString(),Level.INFO.toString(), Madkit.Option.launchAgents.toString(), Agent.class.getName() + ",true,1;");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java.html new file mode 100644 index 0000000..a39c83d --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java.html @@ -0,0 +1,57 @@ + + + + + +madkitoptions.ex2_LevelOptions._3_GuiLogLevel (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This example concerns GuiLogLevel's option.
+ * This option allows the specification of MaDKit
+ * graphical user interface's log level.
+ * It is mainly useful for kernel developers.
+ * 
+ * 
+ * 
+ */
+
+public class _3_GuiLogLevel {
+
+       public static void main(String[] args) {
+              
+              /* Displays everything */
+              new Madkit(Madkit.LevelOption.guiLogLevel.toString(),Level.ALL.toString());
+              
+              /* Displays only informational messages */
+              // new Madkit(Madkit.LevelOption.guiLogLevel.toString(),Level.INFO.toString());
+       }
+       
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java.html new file mode 100644 index 0000000..485e5f0 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java.html @@ -0,0 +1,56 @@ + + + + + +madkitoptions.ex2_LevelOptions._4_KernelLogLevel (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This example is about the level option KernelLogLevel.
+ * This option allows the specification of MaDKit's kernel's
+ * log level and is extremely useful for debugging.
+ * It is mainly useful for kernel developers.
+ *  
+ * 
+ * 
+ */
+
+public class _4_KernelLogLevel {
+
+       public static void main(String[] args) {
+              
+              /* Displays everything */
+              new Madkit(Madkit.LevelOption.kernelLogLevel.toString(),Level.ALL.toString());
+              
+              /* Displays only informational messages */
+              // new Madkit(Madkit.LevelOption.kernelLogLevel.toString(),Level.INFO.toString());
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java.html new file mode 100644 index 0000000..e73dc52 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java.html @@ -0,0 +1,55 @@ + + + + + +madkitoptions.ex2_LevelOptions._5_NetworkLogLevel (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * This example is about the level option NetworkLogLevel.
+ * This option allows the specification of MaDKit
+ * network's log level.
+ * 
+ * 
+ * 
+ */
+
+public class _5_NetworkLogLevel {
+
+       public static void main(String[] args) {
+              
+              /* Displays everything */
+              new Madkit(Madkit.LevelOption.networkLogLevel.toString(),Level.ALL.toString());
+              
+              /* Displays only informational messages */
+              // new Madkit(Madkit.LevelOption.networkLogLevel.toString(),Level.INFO.toString());
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java.html new file mode 100644 index 0000000..deee8a8 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java.html @@ -0,0 +1,49 @@ + + + + + +madkitoptions.ex2_LevelOptions._6_AgentWithCGRWarnings (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import madkit.kernel.Agent;
+
+/**
+ * 
+ * This class outlines how to use enableCGRWarnings().
+ * 
+ * 
+ * 
+ * 
+ */
+public class _6_AgentWithCGRWarnings extends Agent{
+
+       @Override
+       protected void activate() {
+              getLogger().enableCGRWarnings();
+              requestRole("COMMUNITY", "GROUP", "ROLE");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java.html b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java.html new file mode 100644 index 0000000..f58804c --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java.html @@ -0,0 +1,56 @@ + + + + + +madkitoptions.ex2_LevelOptions._6_WarningLogLevel (Java2HTML) + + + + + + + + +
+package madkitoptions.ex2_LevelOptions;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+import madkitoptions.ex1_BooleanOptions._2_CgrWarnings;
+
+/**
+ * This example is about the deprecated option : warningLogLevel.
+ * 
+ * Since MaDKit v5.2 it is replaced by AgentLogger.enableCGRWarnings().
+ * You can check how we use enableCGRWarnings() in the 
+ * _6_AgentWithCGRWarnings class.
+ *  
+ * 
+ * 
+ */
+
+public class _6_WarningLogLevel {
+       
+       public static void main(String[] args) {
+              
+              /* This was how we used the warningLogLevel. Keep in mind that it is now deprecated. */
+              new Madkit(Madkit.LevelOption.warningLogLevel.toString(),Level.ALL.toString(), Madkit.Option.launchAgents.toString(), _2_CgrWarnings.class.getName() + " ,true,1");
+       
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java.html b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java.html new file mode 100644 index 0000000..c6aa1b5 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java.html @@ -0,0 +1,106 @@ + + + + + +madkitoptions.ex3_MadkitOptions._1_LaunchAgents (Java2HTML) + + + + + + + + +
+/**
+ * Now we will interest to other Options.
+ * These features are no longer valued by boolean nor 
+ * level but with a string. 
+ */
+package madkitoptions.ex3_MadkitOptions;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+
+/**
+ * 
+ * In this example we will discover how to
+ * launch agents as soon as a new MaDKit is
+ * launched. 
+ * 
+ * You may see that there is different ways of doing it,
+ * that you can launch several agents, or even different 
+ * types of agent.
+ *
+ * Feel free to (un)comment the lines to test and 
+ * understand the differences.
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _1_LaunchAgents {
+       
+       protected static void pause() throws InterruptedException {
+              Thread.sleep(7000);
+       }
+
+       public static void main(String[] args) throws InterruptedException {
+                            
+              /** 
+               * If nothing else than the class name of the agent to launch is specified,
+               * MaDKit launch one agent of the precised class without graphical user interface (GUI)
+               */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName());
+              pause();
+              
+              /* The previous line was equivalent to the next one. */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",false,1");
+              pause();
+              
+              /* You can decide whether or not the agent has a GUI. */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",true");
+              pause();
+              
+              /**
+               * You can also launch several agents by adding the number
+               * of wanted agents right after the class name.
+               */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",3");
+              pause();
+              
+              /* Let's launch several agents with a GUI. */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",true,2");
+              pause();
+              
+              /* Now, let's launch different kind of agents. */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ";" + Agent.class.getName());
+              pause();
+              
+              /**
+               * Finally, you can note that while launching several (and possibly different)
+               * agents you don't have to precise everything each time. In that case,
+               * default values will be used.
+               */
+              new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",2;" + TutorialAgent.class.getName() + ",true,1;");
+              pause();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java.html b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java.html new file mode 100644 index 0000000..7056f17 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java.html @@ -0,0 +1,59 @@ + + + + + +madkitoptions.ex3_MadkitOptions._2_ConfigFile (Java2HTML) + + + + + + + + +
+package madkitoptions.ex3_MadkitOptions;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.Option;
+
+/**
+ * With the configFile option you can specify a property file that MaDKit will load on startup.
+ * The configuration file of this example just contains one line: " test=23 "
+ * If you want extra detail about MaDKit properties, check out the dedicated tutorial.
+ * 
+ * 
+
+
+
+
+
+
+
+
+package madkitoptions.ex3_MadkitOptions;
+
+import java.awt.Color;
+
+import madkit.gui.MDKDesktopFrame;
+import madkit.kernel.Madkit;
+
+/**
+ * This option allows MaDKit users to
+ * change MaDKit desktop's display.
+ * 
+ * Of course, desktopFrameClass need to be associated with an existing 
+ * class, here _3_CustomDesktopFrame.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _3_DesktopFrame extends MDKDesktopFrame{
+
+       public _3_DesktopFrame() {
+              super();
+              setBackground(Color.BLUE);
+       }
+       
+       public static void main(String[] args) {
+              new Madkit(Madkit.Option.desktopFrameClass.toString(), _3_DesktopFrame.class.getName());
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java.html b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java.html new file mode 100644 index 0000000..449e665 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java.html @@ -0,0 +1,64 @@ + + + + + +madkitoptions.ex3_MadkitOptions._4_AgentFrame (Java2HTML) + + + + + + + + +
+package madkitoptions.ex3_MadkitOptions;
+
+import java.awt.Color;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Madkit;
+
+/**
+ * This option allows MaDKit users to modify the display of a category of agent.
+ * 
+ * Of course, agentFrameClass needs to be associated with an existing 
+ * class, here _4_CustomAgentFrame.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _4_AgentFrame extends AgentFrame{
+
+       public _4_AgentFrame(AbstractAgent agent) {
+              super(agent);
+              setBackground(Color.GREEN);
+       }
+
+       /**
+        * Now we will launch a TutorialAgent after setting his
+        * agentFrameClass to _4_CustomAgentFrame.
+        */
+       public static void main(String[] args) {
+              new Madkit(Madkit.Option.agentFrameClass.toString(), _4_AgentFrame.class.getName(), Madkit.Option.launchAgents.toString(), madkitoptions.util.TutorialAgent.class.getName() + ",true");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java.html b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java.html new file mode 100644 index 0000000..893fbb1 --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java.html @@ -0,0 +1,59 @@ + + + + + +madkitoptions.ex3_MadkitOptions._5_LogDirectory (Java2HTML) + + + + + + + + +
+package madkitoptions.ex3_MadkitOptions;
+
+import madkit.kernel.Madkit;
+import madkitoptions.util.TutorialAgent;
+
+/**
+ * This option allows MaDKit users to specify
+ * the directory in which the log files should
+ * be stored. 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _5_LogDirectory {
+
+       public static void main(String[] args) {
+              
+              /**
+               *  Here the created directory is : "myLogs".
+               *  We are launching a TutorialAgent to generate logs.
+               *  Do not forget to trigger the creation of log files using "createLogFiles".
+               */
+              new Madkit(
+                     Madkit.Option.logDirectory.toString(), "myLogs",
+                     Madkit.BooleanOption.createLogFiles.toString(),
+                     Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName());
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/madkitoptions/util/TutorialAgent.java.html b/release/html/madkitoptions/madkitoptions/util/TutorialAgent.java.html new file mode 100644 index 0000000..ba44c9a --- /dev/null +++ b/release/html/madkitoptions/madkitoptions/util/TutorialAgent.java.html @@ -0,0 +1,63 @@ + + + + + +madkitoptions.util.TutorialAgent (Java2HTML) + + + + + + + + +
+/**
+ * READ ME
+ * 
+ * This tutorial is about MaDKit options. An option is a feature that may be specified or activated.
+ * You can find more details here : http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/.
+ * MaDKit options are divided in three categories :
+ *    - Boolean Options
+ *    - Level Options  
+ *    - MaDKit Options
+ *    
+ * In this first set of examples, we will present you Boolean Options.
+ * Among the others options, boolean options are either activated or not. 
+ */
+
+package madkitoptions.util;
+
+import madkit.kernel.Agent;
+
+/**
+ * This class represents an agent that may be used for this tutorial.
+ */
+
+public class TutorialAgent extends Agent{
+
+       @Override
+       protected void activate() {
+              pause(5000);
+       }
+       
+       @Override
+       protected void live() {
+              getLogger().info("\n\t Hello ! I am an instance of Tutorial Agent.\t\n");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitoptions/packages.html b/release/html/madkitoptions/packages.html new file mode 100644 index 0000000..9665de9 --- /dev/null +++ b/release/html/madkitoptions/packages.html @@ -0,0 +1,18 @@ + + + + +Options in MaDKit (Java2HTML) + + + + +Options in MaDKit +
All Classes +
Packages +
+madkitoptions.ex1_BooleanOptions
+madkitoptions.ex2_LevelOptions
+madkitoptions.ex3_MadkitOptions
+madkitoptions.util + diff --git a/release/html/madkitoptions/stylesheet.css b/release/html/madkitoptions/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/madkitoptions/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/madkitproperties/AllClasses.html b/release/html/madkitproperties/AllClasses.html new file mode 100644 index 0000000..c5a17ad --- /dev/null +++ b/release/html/madkitproperties/AllClasses.html @@ -0,0 +1,19 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+_1_DisplayMadkitProperties
+_2_ToStringEquivalent
+_3_ModifyingProperty
+_4_CreateNewProperty
+_5_AgentLoadingPropertyFile
+_6_LoadXMLPropertyFile
+_6_ParameterizedAgent + diff --git a/release/html/madkitproperties/front.html b/release/html/madkitproperties/front.html new file mode 100644 index 0000000..478be06 --- /dev/null +++ b/release/html/madkitproperties/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

MaDKit properties

+
    +
  • Introducing MaDKit properties.
  • +





    +





    +
+

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/madkitproperties/index.html b/release/html/madkitproperties/index.html new file mode 100644 index 0000000..676a967 --- /dev/null +++ b/release/html/madkitproperties/index.html @@ -0,0 +1,20 @@ + + + + +MaDKit properties (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties.index.html b/release/html/madkitproperties/madkitproperties.index.html new file mode 100644 index 0000000..5bd3259 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties.index.html @@ -0,0 +1,18 @@ + + + + +Package madkitproperties (Java2HTML) + + + +Package madkitproperties +
+_1_DisplayMadkitProperties
+_2_ToStringEquivalent
+_3_ModifyingProperty
+_4_CreateNewProperty
+_5_AgentLoadingPropertyFile
+_6_LoadXMLPropertyFile
+_6_ParameterizedAgent + diff --git a/release/html/madkitproperties/madkitproperties/_1_DisplayMadkitProperties.java.html b/release/html/madkitproperties/madkitproperties/_1_DisplayMadkitProperties.java.html new file mode 100644 index 0000000..454a709 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_1_DisplayMadkitProperties.java.html @@ -0,0 +1,75 @@ + + + + + +madkitproperties._1_DisplayMadkitProperties (Java2HTML) + + + + + + + + +
+/**
+ * READ ME
+ * 
+ * This tutorial enlighten MaDKit properties : what is a property and how to use it.
+ * As MaDKit is a Java API, you may already be familiar with Java Property.
+ * If you are not and you want to get used to it before starting this tutorial, you may
+ * have a look here in the official documentation or with the following tutorial.
+ * 
+ * Documentation : https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html
+ * Tutorial : https://docs.oracle.com/javase/tutorial/essential/environment/properties.html
+ * 
+ * The following exercises introduce how to have a look at the different properties owned by
+ * MaDKit how to add or modify them and finally, how to store them. 
+ * 
+ * This tutorial is strongly linked with the MaDKit Options tutorial. Indeed, if this
+ * tutorial presents globally the use of properties, in the Options one, we have a focus on
+ * each of the default properties that are part of MaDKit configuration.
+ */
+
+package madkitproperties;
+
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.LevelOption;
+
+/**
+ * A Property is a distinctive feature that may be used for every MaDKit project.
+ * MaDKit has a configuration which is stored in its internal properties file.
+ *  
+ * We here present how to display the properties of a MaDKit run at startup.
+ * 
+ * 
+ * 
+ */
+public class _1_DisplayMadkitProperties {
+
+       public static void main(String[] args) {
+
+              /**
+               * Here we launch a new MaDKit with the option madkitLogLevel activated. 
+               * This property allows all the logs concerning MaDKit to be displayed, these
+               * logs include MaDKit options. Logs can be seen in the console.
+               */
+              new Madkit(
+                     LevelOption.madkitLogLevel.toString(),"FINER");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_2_ToStringEquivalent.java.html b/release/html/madkitproperties/madkitproperties/_2_ToStringEquivalent.java.html new file mode 100644 index 0000000..21a8fd1 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_2_ToStringEquivalent.java.html @@ -0,0 +1,67 @@ + + + + + +madkitproperties._2_ToStringEquivalent (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.BooleanOption;
+import madkit.kernel.Madkit.LevelOption;
+
+/**
+ * Each of the default MaDKit properties can be specified while launching MaDKit.
+ * To do so, you have to specify the name of the wanted option as an argument of the
+ * Madkit() method. To do so, you have two possibilities,which will be presented in this example.
+ * 
+ * 
+ * 
+ */
+public class _2_ToStringEquivalent {
+
+       public static void main(String[] args) {
+              
+              /**
+               * First you can specify the name of a property preceded by "--".
+               */
+              new Madkit("--madkitLogLevel","FINER","--desktop","false");
+              
+              /**
+               * However, the previous solution is not absolutely reliable.
+               * Indeed if the option name is misspelled, then MaDKit does not
+               * recognize the property. Then, we will prefer the second option.
+               * 
+               * Note that this way we can benefit from the auto-completion.
+               */
+              new Madkit(
+                     LevelOption.madkitLogLevel.toString(),Level.FINER.toString(),
+                     BooleanOption.desktop.toString(),Boolean.FALSE.toString()
+                     );
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_3_ModifyingProperty.java.html b/release/html/madkitproperties/madkitproperties/_3_ModifyingProperty.java.html new file mode 100644 index 0000000..f280e60 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_3_ModifyingProperty.java.html @@ -0,0 +1,53 @@ + + + + + +madkitproperties._3_ModifyingProperty (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Madkit;
+
+/**
+ * A property has a value that we can change.
+ * 
+ * 
+ * 
+ */
+public class _3_ModifyingProperty {
+
+       /**
+        * Here we will change the value of the debug property and set it to true. 
+        * The property madkitLogLevel is only here to notice the difference. 
+        */
+       public static void main(String[] args) {
+              new Madkit(
+                     Madkit.BooleanOption.debug.toString(), "true", 
+                     Madkit.LevelOption.madkitLogLevel.toString(),Level.FINER.toString());
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_4_CreateNewProperty.java.html b/release/html/madkitproperties/madkitproperties/_4_CreateNewProperty.java.html new file mode 100644 index 0000000..50ff79f --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_4_CreateNewProperty.java.html @@ -0,0 +1,65 @@ + + + + + +madkitproperties._4_CreateNewProperty (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.LevelOption;
+import madkit.kernel.Madkit.Option;
+
+/**
+ * You can also create the property you want and give it any value, which will be converted into a string.
+ * 
+ * 
+ * 
+ */
+public class _4_CreateNewProperty  extends Agent {
+
+    @Override
+    protected void live() {
+       getLogger().info("getting a property passed as a MaDKit argument:");
+       getLogger().info("myNewProperty has been set to "+getMadkitProperty("myNewProperty"));
+       pause(5000);
+    }
+
+       /**
+        * Notice the new property among the "Additional non MaDKit options" 
+        * logged at startup.
+        */
+       public static void main(String[] args) {
+              new Madkit(
+                     "--myNewProperty", "aNewValue",
+                     LevelOption.madkitLogLevel.toString(),Level.FINER.toString(),
+                     Option.launchAgents.toString(),_4_CreateNewProperty.class.getName()+",true"
+                     );
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_5_AgentLoadingPropertyFile.java.html b/release/html/madkitproperties/madkitproperties/_5_AgentLoadingPropertyFile.java.html new file mode 100644 index 0000000..0bf1004 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_5_AgentLoadingPropertyFile.java.html @@ -0,0 +1,74 @@ + + + + + +madkitproperties._5_AgentLoadingPropertyFile (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import java.io.IOException;
+
+import madkit.kernel.AbstractAgent;
+
+/**
+ * Now we will see how to load properties from a property file.
+ * The loadPropertiesFromFile(nameOfFile) method allows to 
+ * add and update properties that are stored in this particular file.
+ * 
+ * An exception is thrown if the specified file 
+ * does not exist.
+ * 
+ * 
+ * 
+ *
+ */
+
+public class _5_AgentLoadingPropertyFile extends AbstractAgent{
+
+       @Override
+       protected void activate() {
+              /* We display the original MaDKit configuration */
+              getLogger().talk(getMadkitConfig().toString());
+              try {
+                     /* Now we load new properties */
+                     getLogger().talk("\nNow I will load properties from the file: madkitproperties/PropertyFileToLoad.properties \n");
+                     getMadkitConfig().loadPropertiesFromFile("madkitproperties/PropertyFileToLoad.properties");
+              } catch (IOException e) {
+                     e.printStackTrace();
+              }
+              /* Finally, we display the properties again to notice the differences */
+              getLogger().talk(getMadkitConfig().toString());
+       }
+       
+       /**
+        * Launch a _5_AgentLoadingPropertyFile.
+        * @param args
+        */
+       public static void main(String[] args) {
+              executeThisAgent();
+       }
+       
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_6_LoadXMLPropertyFile.java.html b/release/html/madkitproperties/madkitproperties/_6_LoadXMLPropertyFile.java.html new file mode 100644 index 0000000..af14732 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_6_LoadXMLPropertyFile.java.html @@ -0,0 +1,54 @@ + + + + + +madkitproperties._6_LoadXMLPropertyFile (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import java.io.IOException;
+
+import madkit.kernel.Madkit;
+import madkit.kernel.Madkit.Option;
+
+/**
+ * Now we will see how to load properties from a XML property file.
+ * Unlike basics property files, XML allow a parameterization even
+ * more accurate. Here we will parameterized agents while launching
+ * them.
+ * 
+ * An exception is thrown if the specified file 
+ * does not exist.
+ * 
+ * 
+ *
+ */
+
+public class _6_LoadXMLPropertyFile {
+
+       public static void main(String[] args) throws IOException {
+                     new Madkit(Option.configFile.toString(),"madkitproperties/XMLPropertyFile.xml");
+       }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/madkitproperties/_6_ParameterizedAgent.java.html b/release/html/madkitproperties/madkitproperties/_6_ParameterizedAgent.java.html new file mode 100644 index 0000000..af78e63 --- /dev/null +++ b/release/html/madkitproperties/madkitproperties/_6_ParameterizedAgent.java.html @@ -0,0 +1,50 @@ + + + + + +madkitproperties._6_ParameterizedAgent (Java2HTML) + + + + + + + + +
+package madkitproperties;
+
+import madkit.kernel.Agent;
+
+/**
+ * This class only purpose is to exemplify the use of a XML property file with MaDKit.
+ */
+
+public class _6_ParameterizedAgent extends Agent{
+
+       public String message;
+       
+       @Override
+       protected void live() {
+              pause(2500);
+              getLogger().talk("\n\t" + message + "\t\n");
+              pause(2500);
+              getLogger().info(getMadkitProperty("varDefinedInXML"));
+              pause(5000);
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/madkitproperties/packages.html b/release/html/madkitproperties/packages.html new file mode 100644 index 0000000..7d32621 --- /dev/null +++ b/release/html/madkitproperties/packages.html @@ -0,0 +1,15 @@ + + + + +MaDKit properties (Java2HTML) + + + + +MaDKit properties +
All Classes +
Packages +
+madkitproperties + diff --git a/release/html/madkitproperties/stylesheet.css b/release/html/madkitproperties/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/madkitproperties/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/returncode/AllClasses.html b/release/html/returncode/AllClasses.html new file mode 100644 index 0000000..f8abbec --- /dev/null +++ b/release/html/returncode/AllClasses.html @@ -0,0 +1,34 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+CrashingAgent
+SendingMessageWithReturnCode
+SuccessfulAgent
+TutorialAgent
+_1_CantReply
+_1_CrashingAgent
+_1_NotCommunity
+_1_NotYetLaunched
+_2_AlreadyGroup
+_2_AlreadyLaunched
+_2_LaunchingNewCrashingAgentsWithMadkit
+_2_NoRecipientFound
+_3_AgentCrash
+_3_AgentLaunchingNewCrashingAgents
+_3_InvalidAgentAddress
+_3_NotGroup
+_4_NotInGroup
+_4_TimeOut
+_5_AlreadyKilled
+_5_NotRole
+_6_RoleAlreadyHandled
+_7_RoleNotHandled + diff --git a/release/html/returncode/front.html b/release/html/returncode/front.html new file mode 100644 index 0000000..3740615 --- /dev/null +++ b/release/html/returncode/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Return codes in MaDKit

+
    +
  • Basics for handling some exceptions and return code in MaDKit
  • +





    +





    +
+

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/returncode/index.html b/release/html/returncode/index.html new file mode 100644 index 0000000..8196045 --- /dev/null +++ b/release/html/returncode/index.html @@ -0,0 +1,20 @@ + + + + +Return codes in MaDKit (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/returncode/packages.html b/release/html/returncode/packages.html new file mode 100644 index 0000000..7fcdbc5 --- /dev/null +++ b/release/html/returncode/packages.html @@ -0,0 +1,22 @@ + + + + +Return codes in MaDKit (Java2HTML) + + + + +Return codes in MaDKit +
All Classes +
Packages +
+returncode.ex1_javaException
+returncode.ex2_madkitCodingError
+returncode.ex3_introducingReturnCodes
+returncode.ex4_launchReturnCodes
+returncode.ex5_CGRReturnCodes
+returncode.ex6_communicationReturnCodes
+returncode.ex7_concreteUseOfReturnCode
+returncode.utils + diff --git a/release/html/returncode/returncode.ex1_javaException.index.html b/release/html/returncode/returncode.ex1_javaException.index.html new file mode 100644 index 0000000..47a64a2 --- /dev/null +++ b/release/html/returncode/returncode.ex1_javaException.index.html @@ -0,0 +1,12 @@ + + + + +Package returncode.ex1_javaException (Java2HTML) + + + +Package returncode.ex1_javaException +
+CrashingAgent + diff --git a/release/html/returncode/returncode.ex2_madkitCodingError.index.html b/release/html/returncode/returncode.ex2_madkitCodingError.index.html new file mode 100644 index 0000000..0a91e7c --- /dev/null +++ b/release/html/returncode/returncode.ex2_madkitCodingError.index.html @@ -0,0 +1,14 @@ + + + + +Package returncode.ex2_madkitCodingError (Java2HTML) + + + +Package returncode.ex2_madkitCodingError +
+_1_CrashingAgent
+_2_LaunchingNewCrashingAgentsWithMadkit
+_3_AgentLaunchingNewCrashingAgents + diff --git a/release/html/returncode/returncode.ex3_introducingReturnCodes.index.html b/release/html/returncode/returncode.ex3_introducingReturnCodes.index.html new file mode 100644 index 0000000..ab036a2 --- /dev/null +++ b/release/html/returncode/returncode.ex3_introducingReturnCodes.index.html @@ -0,0 +1,12 @@ + + + + +Package returncode.ex3_introducingReturnCodes (Java2HTML) + + + +Package returncode.ex3_introducingReturnCodes +
+SuccessfulAgent + diff --git a/release/html/returncode/returncode.ex4_launchReturnCodes.index.html b/release/html/returncode/returncode.ex4_launchReturnCodes.index.html new file mode 100644 index 0000000..2537fd6 --- /dev/null +++ b/release/html/returncode/returncode.ex4_launchReturnCodes.index.html @@ -0,0 +1,16 @@ + + + + +Package returncode.ex4_launchReturnCodes (Java2HTML) + + + +Package returncode.ex4_launchReturnCodes +
+_1_NotYetLaunched
+_2_AlreadyLaunched
+_3_AgentCrash
+_4_TimeOut
+_5_AlreadyKilled + diff --git a/release/html/returncode/returncode.ex5_CGRReturnCodes.index.html b/release/html/returncode/returncode.ex5_CGRReturnCodes.index.html new file mode 100644 index 0000000..2de66ea --- /dev/null +++ b/release/html/returncode/returncode.ex5_CGRReturnCodes.index.html @@ -0,0 +1,18 @@ + + + + +Package returncode.ex5_CGRReturnCodes (Java2HTML) + + + +Package returncode.ex5_CGRReturnCodes +
+_1_NotCommunity
+_2_AlreadyGroup
+_3_NotGroup
+_4_NotInGroup
+_5_NotRole
+_6_RoleAlreadyHandled
+_7_RoleNotHandled + diff --git a/release/html/returncode/returncode.ex6_communicationReturnCodes.index.html b/release/html/returncode/returncode.ex6_communicationReturnCodes.index.html new file mode 100644 index 0000000..119201a --- /dev/null +++ b/release/html/returncode/returncode.ex6_communicationReturnCodes.index.html @@ -0,0 +1,14 @@ + + + + +Package returncode.ex6_communicationReturnCodes (Java2HTML) + + + +Package returncode.ex6_communicationReturnCodes +
+_1_CantReply
+_2_NoRecipientFound
+_3_InvalidAgentAddress + diff --git a/release/html/returncode/returncode.ex7_concreteUseOfReturnCode.index.html b/release/html/returncode/returncode.ex7_concreteUseOfReturnCode.index.html new file mode 100644 index 0000000..e25039b --- /dev/null +++ b/release/html/returncode/returncode.ex7_concreteUseOfReturnCode.index.html @@ -0,0 +1,12 @@ + + + + +Package returncode.ex7_concreteUseOfReturnCode (Java2HTML) + + + +Package returncode.ex7_concreteUseOfReturnCode +
+SendingMessageWithReturnCode + diff --git a/release/html/returncode/returncode.utils.index.html b/release/html/returncode/returncode.utils.index.html new file mode 100644 index 0000000..2e8f44e --- /dev/null +++ b/release/html/returncode/returncode.utils.index.html @@ -0,0 +1,12 @@ + + + + +Package returncode.utils (Java2HTML) + + + +Package returncode.utils +
+TutorialAgent + diff --git a/release/html/returncode/returncode/ex1_javaException/CrashingAgent.java.html b/release/html/returncode/returncode/ex1_javaException/CrashingAgent.java.html new file mode 100644 index 0000000..22456a9 --- /dev/null +++ b/release/html/returncode/returncode/ex1_javaException/CrashingAgent.java.html @@ -0,0 +1,106 @@ + + + + + +returncode.ex1_javaException.CrashingAgent (Java2HTML) + + + + + + + + +
+/**
+ * READ ME
+ * This tutorial shows how MaDKit is dealing with exceptions. We advise you to not start with this tutorial.
+ * You can check previous tutorials at: http://www.madkit.net/madkit/tutorials/ . Among those tutorials, you
+ * may use here notions seen in logging and communication tutorials.
+ * 
+ * In this tutorial we will see what kind of exceptions may be encountered while developing
+ * an application with MaDKit and what MadKit provides to improve our programs' reliability: AbstractAgent.ReturnCode.
+ * 
+ */
+
+package returncode.ex1_javaException;
+
+import java.util.logging.Level;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * In this example you will understand that as MaDKit is a Java library, you will have to deal
+ * with the same errors and exception that you may have encountered with Java.
+ * 
+ * Thus as in any Java-based program, you will have to be rigorous :)
+ * 
+ * 
+ *  
+ *  
+ * 
+ */
+
+public class CrashingAgent extends TutorialAgent{
+       
+       /*
+        * On activation, we want the agent to throw a NullPointer Exception.
+        */
+       @Override
+       protected void activate() {
+              getLogger().setLevel(Level.FINEST); /* So that the agent's life cycle is traced. See the logging tutorial for more information. */
+              
+              pause(2000);
+              /* Now we throw an exception */
+              throw new NullPointerException();
+       }
+       
+       /*
+        * As the agent throw a NullPointerException, this method should not be called.
+        */
+       @Override
+       protected void live() {
+              getLogger().info("\n\tI have crashed, this message shall not be displayed.\t\n");
+       }
+       
+       @Override
+       protected void end() {
+              getLogger().info("\n\tI have crashed. :(\t\n");
+              super.end();
+       }
+       
+       /**
+        * We launch a CrashingAgent that throws a NullPointer exception 
+        * and the agent terminates.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+              /**
+               * The previous line of code shall cause this error:
+               * 
+               * [CrashingAgent-2] SEVERE : -*-ACTIVATE BUG*-*
+               * ** java.lang.NullPointerException
+               *                   at exception.ex1_exceptions.ex11_javaException.CrashingAgent.activate(CrashingAgent.java:40)
+               *
+               * Followed by the agent's life cycle.
+               * 
+               */
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex2_madkitCodingError/_1_CrashingAgent.java.html b/release/html/returncode/returncode/ex2_madkitCodingError/_1_CrashingAgent.java.html new file mode 100644 index 0000000..2ecaced --- /dev/null +++ b/release/html/returncode/returncode/ex2_madkitCodingError/_1_CrashingAgent.java.html @@ -0,0 +1,71 @@ + + + + + +returncode.ex2_madkitCodingError._1_CrashingAgent (Java2HTML) + + + + + + + + +
+package returncode.ex2_madkitCodingError;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * In addition of Java's exceptions, there is another category of failure that may happen with MaDKit:
+ * madkit.kernel.KernelException. KernelException is a class of MaDKit that extends RuntimeException. 
+ * Actually it is an exception thrown to indicate that the agent is trying to use a method
+ * while not launched or already dead.
+ * 
+ * In this example we will see a KernelException being thrown while we try to
+ * send a message with an agent without launching him.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _1_CrashingAgent extends TutorialAgent {
+       
+       /**
+        * This will throw a KernelException.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              _1_CrashingAgent agent = new _1_CrashingAgent();
+              agent.sendMessage("myCommunity", "myGroup", "myRole", new Message());
+              
+              /**
+               * The previous line of code shall cause this error:
+               * 
+               * madkit.kernel.KernelException: _1_CrashingAgent-0 (NOT_LAUNCHED) must be launched to use this method 
+               *                   at madkit.kernel.AbstractAgent.sendMessage(Unknown Source)
+               * Exception in thread "main" madkit.kernel.KernelException: _1_CrashingAgent-0 (NOT_LAUNCHED) must be launched to use this method 
+               *                   at madkit.kernel.AbstractAgent.sendMessage(Unknown Source)
+               *
+               */
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java.html b/release/html/returncode/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java.html new file mode 100644 index 0000000..3ac8188 --- /dev/null +++ b/release/html/returncode/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java.html @@ -0,0 +1,62 @@ + + + + + +returncode.ex2_madkitCodingError._2_LaunchingNewCrashingAgentsWithMadkit (Java2HTML) + + + + + + + + +
+package returncode.ex2_madkitCodingError;
+
+import madkit.kernel.Madkit;
+import returncode.ex1_javaException.CrashingAgent;
+import returncode.utils.TutorialAgent;
+
+/**
+ * Now that we have seen that misusing MaDKit may generate KernelException, we will
+ * see how other agents are impacted if one of them crash.
+ * 
+ * Good failure managing is extremely important in multi-agent system.
+ * We do not want the whole society to crash because of the crash of one of our agents.
+ * 
+ * Here we launch two agents and see if the crash of one impacts the activity of the other.
+ * 
+ * 
+ *  
+ *  
+ * 
+ */
+
+public class _2_LaunchingNewCrashingAgentsWithMadkit{
+
+       /**
+        * Launches one TutorialAgent and one CrashingAgent. As expected, the last agent will crash
+        * but without having any impact on the life of the agents. 
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              new Madkit("--launchAgents", TutorialAgent.class.getName() + ",true,1;", CrashingAgent.class.getName() + ",true,1;");
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java.html b/release/html/returncode/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java.html new file mode 100644 index 0000000..2b40299 --- /dev/null +++ b/release/html/returncode/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java.html @@ -0,0 +1,90 @@ + + + + + +returncode.ex2_madkitCodingError._3_AgentLaunchingNewCrashingAgents (Java2HTML) + + + + + + + + +
+package returncode.ex2_madkitCodingError;
+
+import java.util.logging.Level;
+
+import returncode.ex1_javaException.CrashingAgent;
+import returncode.utils.TutorialAgent;
+
+/**
+ * Now that we have seen that misusing MaDKit may generate KernelException, we will
+ * see how other agents are impacted if one of them crash.
+ * 
+ * Good failure managing is extremely important in multi-agent system.
+ * We do not want the whole society to crash because of the crash of one of our agents.
+ * 
+ * Here we launch an agent that will launch two agents during his life.
+ * The first one is a basic TutorialAgent while the second is a CrashingAgent.
+ * The aim of this exercise is to see if the crash of a launched agent may have any
+ * impact on the launcher agent.
+ * 
+ * 
+ *  
+ *  
+ * 
+ */
+
+public class _3_AgentLaunchingNewCrashingAgents extends TutorialAgent{
+       
+       /**
+        * On activation we will just set the log level on FINEST so that
+        * the agent's life cycle is traced.
+        * See the logging tutorial for more information.
+        */
+       @Override
+       protected void activate() {
+              getLogger().setLevel(Level.FINEST);
+       }
+       
+       /**
+        * Launches a TutorialAgent and a CrashingAgent. 
+        */
+       @Override
+       protected void live() {
+              //first launch a TutorialAgent
+              launchAgent(new TutorialAgent(),true);
+
+              //then launch a CrashingAgent
+              launchAgent(new CrashingAgent(),true);
+       }
+       
+       /**
+        * Launch a _3_AgentLaunchingNewCrashingAgents. As expected, the
+        * CrashingAgent will crash but without having any impact
+        * on the life of the others. 
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent(1, true);
+       }
+}
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java.html b/release/html/returncode/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java.html new file mode 100644 index 0000000..cd40a38 --- /dev/null +++ b/release/html/returncode/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java.html @@ -0,0 +1,75 @@ + + + + + +returncode.ex3_introducingReturnCodes.SuccessfulAgent (Java2HTML) + + + + + + + + +
+package returncode.ex3_introducingReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * In this example we will show you how you can ensure your programs with methods' return code.
+ * In MaDKit AbstractAgent.ReturnCode is an enumeration of codes which are returned by some methods of the API classes.
+ * You can find the different constants in the documentation (http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/)
+ * 
+ * In further exercises we will present you these codes : what they mean and example of how you can use them.
+ * We can class them into three categories:
+ *    ReturnCode for launch ; 
+ *    ReturnCode for Community-Group-Role (CGR) ; 
+ *    ReturnCode for communication.
+ *  
+ * In this example we will show you how you can use these codes by starting with the easiest:
+ * AbstractCode.ReturnCode.SUCCESS. As you could have guessed, this code means that the called method
+ * has not encountered any problem.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class SuccessfulAgent extends TutorialAgent {
+       
+       /** We will call createOrganization(...) and check if something went wrong thanks to
+        *  the ReturnCode.SUCCESS.
+        */
+       @Override
+       protected void activate() {
+              ReturnCode createFeedback;
+              createFeedback = createGroup("mySuccessfulCommunity", "mySuccessfulGroup");
+              getLogger().info("\n\t The ReturnCode is: \"" + createFeedback.toString() +"\" .\n\tIt means that the method ended successfully.\t\n");
+              
+       }
+       /**
+        * Launch a SuccessfulAgent.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java.html b/release/html/returncode/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java.html new file mode 100644 index 0000000..9ace572 --- /dev/null +++ b/release/html/returncode/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java.html @@ -0,0 +1,64 @@ + + + + + +returncode.ex4_launchReturnCodes._1_NotYetLaunched (Java2HTML) + + + + + + + + +
+package returncode.ex4_launchReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NOT_YET_LAUNCHED. This ReturnCode is returned by
+ * kill primitives when the targeted agent has not been launched priorly.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _1_NotYetLaunched extends TutorialAgent {
+
+       /**
+        * During his life, the agent will try to kill a TutorialAgent that is not launched. 
+        * Thus a WARNING message saying that killAgent() has failed will be displayed.
+        */
+       @Override
+       protected void live() {
+              ReturnCode killFeedback;
+              killFeedback = killAgent(new TutorialAgent()); /* we kill a new TutorialAgent otherwise an agent who has not been launched */
+              getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\tIt means that I can not kill another agent if he is not launched. \t\n");
+       }
+       
+       /**
+        * We launch a _1_NotYetLaunched agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java.html b/release/html/returncode/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java.html new file mode 100644 index 0000000..29863b0 --- /dev/null +++ b/release/html/returncode/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java.html @@ -0,0 +1,67 @@ + + + + + +returncode.ex4_launchReturnCodes._2_AlreadyLaunched (Java2HTML) + + + + + + + + +
+package returncode.ex4_launchReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies ALREADY_LAUNCHED.
+ * This ReturnCode is returned when we try to launch an agent which is already launched.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _2_AlreadyLaunched extends TutorialAgent{
+
+       /**
+        * On activation, the agent will try to launched himself whereas... He is already launched...
+        * Thus a message saying that launchAgent() has failed will be displayed.
+        */
+       @Override
+       protected void activate() {
+              ReturnCode launchFeedback;
+              launchFeedback = launchAgent(this);
+              getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that I have already been launched : I can not be launched twice \n\t");
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * We launch a _2_AlreadyLaunched agent.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex4_launchReturnCodes/_3_AgentCrash.java.html b/release/html/returncode/returncode/ex4_launchReturnCodes/_3_AgentCrash.java.html new file mode 100644 index 0000000..d78b33d --- /dev/null +++ b/release/html/returncode/returncode/ex4_launchReturnCodes/_3_AgentCrash.java.html @@ -0,0 +1,67 @@ + + + + + +returncode.ex4_launchReturnCodes._3_AgentCrash (Java2HTML) + + + + + + + + +
+package returncode.ex4_launchReturnCodes;
+
+import returncode.ex1_javaException.CrashingAgent;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: AGENT_CRASH.
+ * This ReturnCode is returned by launch primitives when the launched agent crashes in activate().
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _3_AgentCrash extends TutorialAgent{
+
+       /**
+        * On activation the agent will try to launch an agent that systematically crashes.
+        * Thus messages saying that launchAgent() has failed will be displayed before our own message.
+        */
+       @Override
+       protected void activate() {
+              ReturnCode launchFeedback;
+              launchFeedback = launchAgent(new CrashingAgent(),true); /* The new CrashingAgent() will crash */ 
+              getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that the agent I wanted to launched has crashed... \n\tTherefore you can notice that I am still alive.\t\n");
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _3_AgentCrash agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex4_launchReturnCodes/_4_TimeOut.java.html b/release/html/returncode/returncode/ex4_launchReturnCodes/_4_TimeOut.java.html new file mode 100644 index 0000000..9ba642d --- /dev/null +++ b/release/html/returncode/returncode/ex4_launchReturnCodes/_4_TimeOut.java.html @@ -0,0 +1,78 @@ + + + + + +returncode.ex4_launchReturnCodes._4_TimeOut (Java2HTML) + + + + + + + + +
+package returncode.ex4_launchReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: TIMEOUT.
+ * This ReturnCode is returned by various timed primitives of the Agent class.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _4_TimeOut extends TutorialAgent {
+
+       /**
+        * We install our agent in his virtual society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myTimedOutCommunity", "myTimedOutGroup");
+              requestRole("myTimedOutCommunity", "myTimedOutGroup", "myTimedOutRole");
+       }
+       
+       @Override
+       protected void live() {
+              int timeBeforeTimeOut = 0;  /* an absurd duration */
+              
+       
+              /**
+               * The ReturnCode of the next method will be TIME_OUT if the agent we launch has not ended his activate method.
+               * Here as we are giving him 0 micro second to finish it. Thus it will return this code.
+               */
+              
+              ReturnCode launchFeedback;
+              launchFeedback = launchAgent(new TutorialAgent(), timeBeforeTimeOut, false); /* while minuting we launch a TutorialAgent. */
+              getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that the activate method did not ended in time. \t\n");
+       }
+       
+       /**
+        * Launch a _4_TimeOut agent.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent(1,true);
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java.html b/release/html/returncode/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java.html new file mode 100644 index 0000000..3f76b5f --- /dev/null +++ b/release/html/returncode/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java.html @@ -0,0 +1,70 @@ + + + + + +returncode.ex4_launchReturnCodes._5_AlreadyKilled (Java2HTML) + + + + + + + + +
+package returncode.ex4_launchReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: ALREADY_KILLED.
+ * This ReturnCode is returned by kill primitives when the targeted agent is already terminated.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _5_AlreadyKilled extends TutorialAgent {
+       
+       /** During his life, the agent will try to kill twice the same TutorialAgent. 
+        *  Thus a message saying that killAgent() has failed will be displayed.
+        */
+       @Override
+       protected void live() {
+              TutorialAgent agentToKill = new TutorialAgent();
+              launchAgent(agentToKill,true); /* Otherwise we will get an "NOT_YET_LAUNCHED" returnCode*/
+              
+              ReturnCode killFeedback;
+              killFeedback = killAgent(agentToKill);
+              getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\t I have successfully killed this agent. \t\n");
+              killFeedback = killAgent(agentToKill); 
+              getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\tIt means that I have already killed this agent. I can not killed the same person twice. \t\n");            
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _5_AlreadyKilled agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java.html new file mode 100644 index 0000000..43d617d --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java.html @@ -0,0 +1,70 @@ + + + + + +returncode.ex5_CGRReturnCodes._1_NotCommunity (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NOT_COMMUNITY.
+ * This ReturnCode indicates that a community does not exist.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _1_NotCommunity extends TutorialAgent{
+
+       /**
+        * When activate, the _1_NotCommunity agent will request a role while he has not create any group.
+        * Thus the community is not set and does not exist for MaDKit. Our agent will display a message explaining why the method
+        * has failed.
+        * 
+        * A message informing that the requestRole() has failed will also be displayed as a warning.
+        */
+       @Override     
+       protected void activate() {
+              ReturnCode requestFeedback;
+              requestFeedback = requestRole("myCommunity", "myGroup", "myRole");
+              getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback.toString() + "\" .\n\tIt means that I can not request a role in a community that does not exist. \t\n");
+                     
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _1_NotCommunity agent.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java.html new file mode 100644 index 0000000..c06e8f0 --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java.html @@ -0,0 +1,71 @@ + + + + + +returncode.ex5_CGRReturnCodes._2_AlreadyGroup (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: ALREADY_GROUP.
+ * This ReturnCode is returned when using createOrganization(String, String, boolean, Gatekeeper)
+ * and that a group already exists.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _2_AlreadyGroup extends TutorialAgent {
+
+       /**
+        * This _2_AlreadyGroup agent does nothing in particular: he is just creating a group.
+        * What is interesting here is that the agent will display a message saying if the group has
+        * already been created.
+        */
+       @Override
+       protected void activate() {
+              ReturnCode createFeedback ;
+              createGroup("myCommunity", "myGroup");
+              createFeedback = createGroup("myCommunity", "myGroup");
+              getLogger().info("\n\tThe ReturnCode is: \"" + createFeedback.toString() + "\" .\n\tIt means that the group I wanted to create already exists. \t\n");
+              pause(500);
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _2_AlreadyGroup agents.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_3_NotGroup.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_3_NotGroup.java.html new file mode 100644 index 0000000..244507e --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_3_NotGroup.java.html @@ -0,0 +1,78 @@ + + + + + +returncode.ex5_CGRReturnCodes._3_NotGroup (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NOT_GROUP.
+ * This Returncode indicates that a group does not exist.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _3_NotGroup extends TutorialAgent {
+
+       /**
+        *  We are initializing our _3_NotGroup agent in its virtual society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              requestRole("myCommunity", "myGroup", "myRole");
+              pause(500);
+       }
+       
+       /**
+        * The _3_NotGroup send a message to a group that does not exist. Thus method sendMessage() fails and a 
+        * warning is displayed.
+        * While checking the returnCode we display a message explaining why the method has failed.
+        */
+       @Override
+       protected void live(){
+              ReturnCode sendFeedback;
+              sendFeedback = sendMessage("myCommunity", "nilGroup", "myRole", new Message()); 
+              getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not send a message to a group that does not exist. \t\n");
+                                   
+              /* Then you do what you want with this agent */
+       }
+              
+       /**
+        * Launch an _3_NotGroup agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java.html new file mode 100644 index 0000000..51ed17b --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java.html @@ -0,0 +1,88 @@ + + + + + +returncode.ex5_CGRReturnCodes._4_NotInGroup (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NOT_IN_GROUP.
+ * This ReturnCode indicates that an agent is not in a group.
+ *
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _4_NotInGroup extends TutorialAgent {
+
+       /**
+        *  We are initializing our _4_NotInGroup agent
+        *  in its virtual society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              requestRole("myCommunity", "myGroup", "myRole");
+              pause(1500);
+       }
+       
+       /**
+        * The _4_NotInGroup while deliberately leave the same group twice.
+        * At the first call of the method he will leave the group. At the second
+        * the method will fail as he is not in this group and a warning is displayed.
+        * 
+        * While checking the returnCode we have decided to display a message explaining why the
+        * method has failed. A message informing that the sendMessage() has failed will also be
+        * displayed as a warning.
+        */
+       @Override
+       protected void live() {
+              ReturnCode leaveFeedback;
+              leaveGroup("myCommunity", "myGroup");
+              leaveFeedback = leaveGroup("myCommunity", "myGroup");
+              if(leaveFeedback == ReturnCode.NOT_IN_GROUP) {
+                     getLogger().info("\n\tThe ReturnCode is: \"" + leaveFeedback.toString() + "\" .\n\tIt means that I already have left this group, I can not leave a group twice. \t\n");
+              }
+              
+              /* Then you do what you want with this agent */
+       }
+              
+
+/**
+ * Launch three _4_NotInGroup agents.
+ * All the agent's second leaveGroup() call will return a ReturnCode.NOT_IN_GROUP
+ * except the last one that will return a ReturnCode.NOT_COMMUNITY.
+ * 
+ * @param argss
+ */
+    public static void main(String[] argss) {
+       executeThisAgent(3,true);
+    }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_5_NotRole.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_5_NotRole.java.html new file mode 100644 index 0000000..c20fa6e --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_5_NotRole.java.html @@ -0,0 +1,79 @@ + + + + + +returncode.ex5_CGRReturnCodes._5_NotRole (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NOT_ROLE.
+ * This ReturnCode indicates that a role does not exist.
+ *
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _5_NotRole extends TutorialAgent{
+       
+       /**
+        *  We are initializing our _5_NotRole agent in its virtual society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              requestRole("myCommunity", "myGroup", "myRole");
+              pause(500);
+       }
+              
+       /**
+        * The _5_NotRole agent send a message to a role that does not exist. Thus the method sendMessage() will fail and a 
+        * warning is displayed.
+        * While checking the returnCode we have decided to display a message explaining why the method has failed.
+        * 
+        * A message informing that the sendMessage() has failed will also be displayed as a warning.
+        */
+       @Override
+       protected void live(){
+              ReturnCode sendFeedback;
+              sendFeedback = sendMessage("myCommunity", "myGroup", "notExistingRole", new Message()); /* Note that the role is different then "myRole" */
+              getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not send a message to an agent whose role does not exist. \t\n");
+                     
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _5_NotRole agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java.html new file mode 100644 index 0000000..763a208 --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java.html @@ -0,0 +1,79 @@ + + + + + +returncode.ex5_CGRReturnCodes._6_RoleAlreadyHandled (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: ROLE_ALREADY_HANDLED.
+ * This ReturnCode is returned when the agent already has the
+ * requested role.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _6_RoleAlreadyHandled extends TutorialAgent{
+       
+       /**
+        * Our _6_RoleAlreadyHandled agent will deliberately ask twice the same role: when activate and in his lifetime.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              ReturnCode requestFeedback1 = requestRole("myCommunity", "myGroup", "myRole");
+              getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback1.toString() + "\" .\n\tI have the role I wanted !\t\n");
+       }
+       
+       @Override
+       protected void live() {
+              /**
+               * The _6_RoleAlreadyHandled agent forgets that he already has this role,
+               * so he asks for it again... Thus a message saying that the requestRole()
+               * has failed will be displayed.
+               */
+              ReturnCode requestFeedback2;
+              requestFeedback2 = requestRole("myCommunity", "myGroup", "myRole");
+              getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback2.toString() + "\" .\n\tIt means that I already have this role \t\n");
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _6_RoleAlreadyHandled agent.
+        * 
+        * @param argss
+        */
+    public static void main(String[] argss) {
+       executeThisAgent();
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java.html b/release/html/returncode/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java.html new file mode 100644 index 0000000..689b039 --- /dev/null +++ b/release/html/returncode/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java.html @@ -0,0 +1,82 @@ + + + + + +returncode.ex5_CGRReturnCodes._7_RoleNotHandled (Java2HTML) + + + + + + + + +
+package returncode.ex5_CGRReturnCodes;
+
+import madkit.kernel.Madkit;
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: ROLE_NOT_HANDLED.
+ * This ReturnCode is returned when the agent does not have the role
+ * needed if he wants to do a particular action.
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+public class _7_RoleNotHandled extends TutorialAgent{
+
+       /**
+        * We activate the _7_RoleNotHandled agent in the same virtual society than the
+        * TutorialAgent. Nevertheless, our agent will have a different role: myDifferentRole.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              requestRole("myCommunity", "myGroup", "myDifferentRole");
+              pause(500);
+       }
+       
+       /**
+        * The agent will try to send a message to a TutorialAgent.
+        * However, in the method he uses : sendMessageWithRole(String community, String group, String role, Message message, String senderRole)
+        * our agent makes a mistake and specifies a role that is not his as senderRole.
+        */
+       @Override
+       protected void live(){
+              ReturnCode sendFeedback;
+              sendFeedback = sendMessageWithRole("myCommunity", "myGroup", "myRole", new Message(), "myRole"); 
+              getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I do not have this role. \t\n");
+                                   
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch an _7_RoleNotHandled agent and a TutorialAgent (as receiver).
+        * 
+        * @param argss
+        */
+    public static void main(String[] argss){
+       new Madkit("--launchAgents", _7_RoleNotHandled.class.getName() + ",true,1;", _5_NotRole.class.getName() + ",true,1;");
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex6_communicationReturnCodes/_1_CantReply.java.html b/release/html/returncode/returncode/ex6_communicationReturnCodes/_1_CantReply.java.html new file mode 100644 index 0000000..2fc72d2 --- /dev/null +++ b/release/html/returncode/returncode/ex6_communicationReturnCodes/_1_CantReply.java.html @@ -0,0 +1,70 @@ + + + + + +returncode.ex6_communicationReturnCodes._1_CantReply (Java2HTML) + + + + + + + + +
+package returncode.ex6_communicationReturnCodes;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: CANT_REPLY.
+ * This ReturnCode is returned when an agent tries to reply to a message which has not been
+ * received from another agent, e.g. newly created or sent directly by an object using
+ * AbstractAgent.receiveMessage(Message).
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _1_CantReply extends TutorialAgent{
+
+       /**
+        * During his life, the agent will try to answer to a new message which is not possible as this message
+        * was not sent by any other agent.
+        */
+       @Override
+       protected void live() {
+              ReturnCode sendFeedback;
+              sendFeedback = sendReply(new Message(), new Message()); /* the agent try to answer a new message */
+              getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not reply to a message that was not send before. \n\t");
+              
+              /* Then you do what you want with this agent */
+       }
+       
+       /**
+        * Launch a _1_CantReply agent.
+        * 
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java.html b/release/html/returncode/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java.html new file mode 100644 index 0000000..2a7eeb5 --- /dev/null +++ b/release/html/returncode/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java.html @@ -0,0 +1,76 @@ + + + + + +returncode.ex6_communicationReturnCodes._2_NoRecipientFound (Java2HTML) + + + + + + + + +
+package returncode.ex6_communicationReturnCodes;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: NO_RECIPIENT_FOUND.
+ * This ReturnCode is returned by send primitives when the targeted CGR location does not exist nor contain any agent.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _2_NoRecipientFound extends TutorialAgent {
+
+       /**
+        * Puts the agent in a virtual and lonely society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myLonelyCommunity", "myLonelyGroup");
+              requestRole("myLonelyCommunity", "myLonelyGroup", "myLonelyRole");
+       }
+       
+       /**
+        * During his life our agent will try to send a message to another agent of his group. As he is the only member of the group, sendMessage()
+        * will fail and an error message will be displayed before our own.
+        */
+       @Override
+       protected void live() {
+              ReturnCode sendFeedback;
+              sendFeedback = sendMessage("myLonelyCommunity", "myLonelyGroup", "myLonelyRole", new Message());
+              getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I am the only agent of the group... \n\t");
+                                   
+              /* Then you do what you want with this agent */
+       }
+
+       /**
+        * Launch a _2_NoRecipientFound agent.
+        * @param argss
+        */
+       public static void main(String[] argss) {
+              executeThisAgent();
+       }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java.html b/release/html/returncode/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java.html new file mode 100644 index 0000000..7e0cbe1 --- /dev/null +++ b/release/html/returncode/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java.html @@ -0,0 +1,92 @@ + + + + + +returncode.ex6_communicationReturnCodes._3_InvalidAgentAddress (Java2HTML) + + + + + + + + +
+package returncode.ex6_communicationReturnCodes;
+
+import madkit.kernel.AgentAddress;
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/**
+ * This class exemplifies: INVALID_AGENT_ADDRESS.
+ * This ReturnCode is returned by send primitives when the targeted agent address does not exist anymore, i.e.
+ * the related agent has leaved the corresponding role.
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+public class _3_InvalidAgentAddress extends TutorialAgent{
+       
+       /**
+        *  We are initializing our _3_InvalidAgentAddress agent.
+        *  in its virtual society.
+        */
+       @Override
+       protected void activate() {
+              createGroupIfAbsent("myCommunity", "myGroup");
+              requestRole("myCommunity", "myGroup", "myRole");
+              pause(1500);
+       }
+       
+       /**
+        * During his life, the agent will look for the address of another agent in his group. Then he will change his role
+        * (so that means that the previous address is no more accurate). Using the previous address,
+        * the agent will try to send a Message to his interlocutor.
+        * 
+        * Thus sendMessage(AgentAddress, Message) will fail, an error message will be displayed as a warning. 
+        */
+       @Override
+       protected void live() {
+              // get a AgentAddress to exchange messages with.
+              AgentAddress interlocutor = getAgentAddressIn("myCommunity", "myGroup", "myRole") ;
+              
+              // leave the role so the address other interlocutors obtained is now wrong.
+              leaveRole("myCommunity", "myGroup", "myRole");          
+              
+              // try to send a message with the wrong obtained address.
+              ReturnCode sendFeedback;
+              sendFeedback = sendMessage(interlocutor, new Message());
+              getLogger().warning("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that the given address does not match with anyone. \n\tI can not communicate. :( \t\n");
+
+              /* Then you do what you want with this agent */
+       }
+              
+
+/**
+ * Launch two _3_InvalidAgentAddress agent so that they can communicate.
+ * @param argss
+ */
+    public static void main(String[] argss) {
+       executeThisAgent(2,false);
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java.html b/release/html/returncode/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java.html new file mode 100644 index 0000000..3c353be --- /dev/null +++ b/release/html/returncode/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java.html @@ -0,0 +1,128 @@ + + + + + +returncode.ex7_concreteUseOfReturnCode.SendingMessageWithReturnCode (Java2HTML) + + + + + + + + +
+package returncode.ex7_concreteUseOfReturnCode;
+
+import java.util.logging.Level;
+
+import madkit.kernel.Message;
+import returncode.utils.TutorialAgent;
+
+/** 
+ * Now that we have see ReturnCodes, we will learn to use them
+ * in order to correct a method that has failed.
+ *
+ *
+ * 
+ * 
+ *
+ */
+
+public class SendingMessageWithReturnCode extends TutorialAgent {
+
+       /**
+        * On activate() the agent allow the most precise's log level in order
+        * to see its life cycle's trace.
+        */
+       @Override
+       protected void activate() {
+              getLogger().setLevel(Level.FINEST);
+              
+              pause(3000);
+       }
+       
+       /**
+        * During his lifetime, the agent will try to send a message. At first the method will failed because
+        * of missing criteria but by using ReturnCode we will fulfill one of them before calling this function
+        * again until we have met all the requirements.
+        */
+       @Override
+       protected void live() {
+              ReturnCode sendFeedback;
+              do {
+                     
+                     sendFeedback = sendMessage("myCommunity", "myGroup", "myRole", new Message());
+                     /* We display the name of the ReturnCode and its value. */
+                     getLogger().info("\n\t" + sendFeedback.name() + "\t" + sendFeedback.toString() +"\n\t");
+                     
+                     switch(sendFeedback) {
+                            case SUCCESS:
+                                   getLogger().info("\n\t Message send ! \n\t");
+                                   break;
+                            case NOT_COMMUNITY:
+                                   getLogger().info("\n\t I should create the community. \n\t");
+                                   createGroupIfAbsent("myCommunity", "myGroup");
+                                   break;
+                            case NOT_GROUP:
+                                   getLogger().info("\n\t I should create the group. \n\t");
+                                   createGroup("myCommunity", "myGroup");
+                                   break;
+                            case NOT_ROLE:
+                                   getLogger().info("\n\t I should demand my role. \t\n");
+                                   requestRole("myCommunity", "myGroup", "myRole");
+                                   break;
+                            case NOT_IN_GROUP:
+                                   getLogger().info("\n\t I am not in the group. This implies that the group exists. \n\t I will ask to join it. \t\n");
+                                   requestRole("myCommunity", "myGroup", "myRole");
+                                   break;
+                            case NO_RECIPIENT_FOUND:
+                                   getLogger().info("\n\tI am alone, thus I can not find someone to send a message.\t\n");
+                                   getLogger().info("\n\tI should launch another instance of myself\t\n");
+                                   launchAgent(new SendingMessageWithReturnCode(),true);
+                                   break;
+                            default:
+                                   getLogger().info("\n\t Mmh. Something went wrong. Better quit this place. \n\t");
+                                   killAgent(this);
+                                   break;
+                     }
+                     
+              }while(sendFeedback != ReturnCode.SUCCESS);
+       }
+       
+       /**
+        * Before dying the agent will pause a long time so that you can have the time to read his message.
+        */
+       @Override
+       protected void end() {
+              getLogger().info("\n\t My mission is over ! See you next time. \n\t");
+              pause(35000);
+       }
+       
+       /**
+        * We launch three agents.
+        * 
+        * The first agent that will be launch will have to create the group as it does not exist.
+        * Then for the next agents, the group will exist but as they are not part of it, they will have to ask to join it by requesting a role.
+        * They all have to request the role.
+        */
+       public static void main(String[] argss) {
+              executeThisAgent(3, true);
+       }
+       
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/returncode/utils/TutorialAgent.java.html b/release/html/returncode/returncode/utils/TutorialAgent.java.html new file mode 100644 index 0000000..fdb2e80 --- /dev/null +++ b/release/html/returncode/returncode/utils/TutorialAgent.java.html @@ -0,0 +1,62 @@ + + + + + +returncode.utils.TutorialAgent (Java2HTML) + + + + + + + + +
+package returncode.utils;
+
+import madkit.gui.AgentFrame;
+import madkit.kernel.Agent;
+
+/**
+ * We create a new agent for this tutorial.
+ */
+
+public class TutorialAgent extends Agent {
+
+    @Override
+    protected void activate() {
+       createGroupIfAbsent("myCommunity", "myGroup");
+       requestRole("myCommunity", "myGroup", "myRole");
+       pause(200);
+    }
+
+    @Override
+    protected void live() {
+    }
+
+    @Override
+    protected void end() {
+       pause(8000);
+    }
+
+    @Override
+    public void setupFrame(AgentFrame frame) {
+       super.setupFrame(frame);
+       frame.setSize(800, 400);
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/returncode/stylesheet.css b/release/html/returncode/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/returncode/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/html/simulation/AllClasses.html b/release/html/simulation/AllClasses.html new file mode 100644 index 0000000..4e390f7 --- /dev/null +++ b/release/html/simulation/AllClasses.html @@ -0,0 +1,30 @@ + + + + +All Classes (Java2HTML) + + + + +All Classes +
+EnvironmentAgent
+ImageViewer
+MyScheduler
+MyScheduler02
+MyScheduler03
+MyScheduler04
+MyScheduler05
+MySimulationModel
+MySimulationModel06
+MySimulationModel08
+SimulatedAgent02
+SimulatedAgent03
+SimulatedAgent04
+SimulatedAgent06
+SimulationModel
+SituatedAgent
+Test
+Viewer + diff --git a/release/html/simulation/front.html b/release/html/simulation/front.html new file mode 100644 index 0000000..4f41052 --- /dev/null +++ b/release/html/simulation/front.html @@ -0,0 +1,19 @@ + + + +Java2HTML + + + +

MDK

Simulation with MaDKit

+
    +
  • Basics for building simulators with MaDKit
  • +





    +





    +
+

Examples are structured in packages explicitely named and ordered according to their complexity














Credits:-

+ +
+ + diff --git a/release/html/simulation/index.html b/release/html/simulation/index.html new file mode 100644 index 0000000..f55fa48 --- /dev/null +++ b/release/html/simulation/index.html @@ -0,0 +1,20 @@ + + + + +Simulation with MaDKit (Java2HTML) + + + + + + + + + + +<H2>Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + + \ No newline at end of file diff --git a/release/html/simulation/packages.html b/release/html/simulation/packages.html new file mode 100644 index 0000000..2976aa1 --- /dev/null +++ b/release/html/simulation/packages.html @@ -0,0 +1,22 @@ + + + + +Simulation with MaDKit (Java2HTML) + + + + +Simulation with MaDKit +
All Classes +
Packages +
+simulation.ex01
+simulation.ex02
+simulation.ex03
+simulation.ex04
+simulation.ex05
+simulation.ex06
+simulation.ex07
+simulation.ex08 + diff --git a/release/html/simulation/simulation.ex01.index.html b/release/html/simulation/simulation.ex01.index.html new file mode 100644 index 0000000..5f377f7 --- /dev/null +++ b/release/html/simulation/simulation.ex01.index.html @@ -0,0 +1,12 @@ + + + + +Package simulation.ex01 (Java2HTML) + + + +Package simulation.ex01 +
+MyScheduler + diff --git a/release/html/simulation/simulation.ex02.index.html b/release/html/simulation/simulation.ex02.index.html new file mode 100644 index 0000000..d9a93f2 --- /dev/null +++ b/release/html/simulation/simulation.ex02.index.html @@ -0,0 +1,14 @@ + + + + +Package simulation.ex02 (Java2HTML) + + + +Package simulation.ex02 +
+MyScheduler02
+SimulatedAgent02
+SimulationModel + diff --git a/release/html/simulation/simulation.ex03.index.html b/release/html/simulation/simulation.ex03.index.html new file mode 100644 index 0000000..f8dbf1e --- /dev/null +++ b/release/html/simulation/simulation.ex03.index.html @@ -0,0 +1,13 @@ + + + + +Package simulation.ex03 (Java2HTML) + + + +Package simulation.ex03 +
+MyScheduler03
+SimulatedAgent03 + diff --git a/release/html/simulation/simulation.ex04.index.html b/release/html/simulation/simulation.ex04.index.html new file mode 100644 index 0000000..8787648 --- /dev/null +++ b/release/html/simulation/simulation.ex04.index.html @@ -0,0 +1,13 @@ + + + + +Package simulation.ex04 (Java2HTML) + + + +Package simulation.ex04 +
+MyScheduler04
+SimulatedAgent04 + diff --git a/release/html/simulation/simulation.ex05.index.html b/release/html/simulation/simulation.ex05.index.html new file mode 100644 index 0000000..2703e2e --- /dev/null +++ b/release/html/simulation/simulation.ex05.index.html @@ -0,0 +1,12 @@ + + + + +Package simulation.ex05 (Java2HTML) + + + +Package simulation.ex05 +
+MyScheduler05 + diff --git a/release/html/simulation/simulation.ex06.index.html b/release/html/simulation/simulation.ex06.index.html new file mode 100644 index 0000000..f1af8c7 --- /dev/null +++ b/release/html/simulation/simulation.ex06.index.html @@ -0,0 +1,13 @@ + + + + +Package simulation.ex06 (Java2HTML) + + + +Package simulation.ex06 +
+MySimulationModel06
+SimulatedAgent06 + diff --git a/release/html/simulation/simulation.ex07.index.html b/release/html/simulation/simulation.ex07.index.html new file mode 100644 index 0000000..3615b6a --- /dev/null +++ b/release/html/simulation/simulation.ex07.index.html @@ -0,0 +1,15 @@ + + + + +Package simulation.ex07 (Java2HTML) + + + +Package simulation.ex07 +
+EnvironmentAgent
+MySimulationModel
+SituatedAgent
+Viewer + diff --git a/release/html/simulation/simulation.ex08.index.html b/release/html/simulation/simulation.ex08.index.html new file mode 100644 index 0000000..5033c3a --- /dev/null +++ b/release/html/simulation/simulation.ex08.index.html @@ -0,0 +1,14 @@ + + + + +Package simulation.ex08 (Java2HTML) + + + +Package simulation.ex08 +
+ImageViewer
+MySimulationModel08
+Test + diff --git a/release/html/simulation/simulation/ex01/MyScheduler.java.html b/release/html/simulation/simulation/ex01/MyScheduler.java.html new file mode 100644 index 0000000..c649249 --- /dev/null +++ b/release/html/simulation/simulation/ex01/MyScheduler.java.html @@ -0,0 +1,77 @@ + + + + + +simulation.ex01.MyScheduler (Java2HTML) + + + + + + + + +
+package simulation.ex01;
+
+import java.util.logging.Level;
+
+import madkit.gui.ConsoleAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Scheduler;
+
+/**
+ * 
+ *  
+ *     
+ *
+ *
+ * The madkit.kernel.Scheduler class defines a generic threaded scheduler agent.
+ * It holds a collection of activators. The default state of a scheduler is Scheduler.SimulationState.PAUSED
+ *
+ * Let us illustrate some basic features of a scheduler
+ */
+
+public class MyScheduler extends Scheduler {
+
+    @Override
+    protected void activate() {
+       // This makes a pause of 300 ms between two simulation steps and can be modified later in the code or
+       // using the scheduler GUI.
+       setDelay(300);
+
+       // Let us also display more information:
+       // the FINER log level of the Scheduler displays activation information
+       getLogger().setLevel(Level.FINER);
+
+       // The simulation will run until getGVT() >= 10 and then automatically quit
+       setSimulationDuration(10);
+
+       super.activate();
+    }
+
+    /**
+     * A simple way of launching this scheduler
+     * 
+     * @param
+     */
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", MyScheduler.class.getName() + ",true;" + ConsoleAgent.class.getName());
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex02/MyScheduler02.java.html b/release/html/simulation/simulation/ex02/MyScheduler02.java.html new file mode 100644 index 0000000..4ee0dbc --- /dev/null +++ b/release/html/simulation/simulation/ex02/MyScheduler02.java.html @@ -0,0 +1,84 @@ + + + + + +simulation.ex02.MyScheduler02 (Java2HTML) + + + + + + + + +
+package simulation.ex02;
+
+import madkit.gui.ConsoleAgent;
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Scheduler;
+import madkit.simulation.activator.GenericBehaviorActivator;
+
+/**
+ * 
+ *  
+ *  
+ * 
+ * In this example, the goal is only to manage the execution of some agents. Two classes are needed : a
+ * madkit.kernel.Scheduler that manages an madkit.kernel.Activator and a simulated agent class:
+ * simulation.ex02.SimulatedAgent02.
+ *
+ * The madkit.kernel.Activator class defines a tool for scheduling mechanism.
+ * An activator is configured according to a community, a group and a role.
+ * It could be used to activate a group of agents on a particular behavior
+ */
+
+public class MyScheduler02 extends Scheduler {
+
+    private GenericBehaviorActivator<AbstractAgent> activator1;
+
+    @Override
+    protected void activate() {
+
+       // 1 : create the simulation group
+       createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP);
+
+       // 2 : launch some simulated agents
+       for (int i = 0; i < 10; i++) {
+           launchAgent(new SimulatedAgent02());
+       }
+
+       // 3 : initialize the activator on the correct (1) CGR location and (2) behavior
+       activator1 = new GenericBehaviorActivator<AbstractAgent>(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt");
+       addActivator(activator1);
+
+       // 4 : we are done, because Scheduler already defines a live method
+       // calling the execution of the activator. We will override it later.
+       // here we just slow down the simulation to not flood the console
+       setDelay(300);
+    }
+
+    /**
+     * A simple way of launching this scheduler
+     */
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", MyScheduler02.class.getName() + ",true;" + ConsoleAgent.class.getName());
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex02/SimulatedAgent02.java.html b/release/html/simulation/simulation/ex02/SimulatedAgent02.java.html new file mode 100644 index 0000000..1cf26f4 --- /dev/null +++ b/release/html/simulation/simulation/ex02/SimulatedAgent02.java.html @@ -0,0 +1,46 @@ + + + + + +simulation.ex02.SimulatedAgent02 (Java2HTML) + + + + + + + + +
+package simulation.ex02;
+
+import madkit.kernel.AbstractAgent;
+
+public class SimulatedAgent02 extends AbstractAgent {
+
+    @Override
+    protected void activate() {
+       requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE);
+    }
+
+    @SuppressWarnings("unused")
+    private void doIt() {
+       getLogger().info("I am doing it");
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex02/SimulationModel.java.html b/release/html/simulation/simulation/ex02/SimulationModel.java.html new file mode 100644 index 0000000..ab153bc --- /dev/null +++ b/release/html/simulation/simulation/ex02/SimulationModel.java.html @@ -0,0 +1,45 @@ + + + + + +simulation.ex02.SimulationModel (Java2HTML) + + + + + + + + +
+package simulation.ex02;
+
+/**
+ * Stocking some global properties for this tutorial.
+ * 
+ * @author Fabien Michel
+ * @version 0.9
+ */
+public class SimulationModel {
+
+    public static final String MY_COMMUNITY = "simu";
+    public static final String SIMU_GROUP = "simu";
+    public static final String ROLE = "bot";
+    public static final String ANOTHER_ROLE = "anotherRole";
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex03/MyScheduler03.java.html b/release/html/simulation/simulation/ex03/MyScheduler03.java.html new file mode 100644 index 0000000..bfed5e5 --- /dev/null +++ b/release/html/simulation/simulation/ex03/MyScheduler03.java.html @@ -0,0 +1,80 @@ + + + + + +simulation.ex03.MyScheduler03 (Java2HTML) + + + + + + + + +
+package simulation.ex03;
+
+import madkit.gui.ConsoleAgent;
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Scheduler;
+import madkit.simulation.activator.GenericBehaviorActivator;
+import simulation.ex02.SimulatedAgent02;
+import simulation.ex02.SimulationModel;
+
+/**
+ *  
+ *  
+ * 
+ * Let us have more fun by adding another simulated agent class with a different result for the doIt method and see what
+ * we now need. We need nothing else and just have to launch this new type of agent: Activators do not care about the
+ * exact type of the activated agents. Only the organizational position matters.
+ */
+
+public class MyScheduler03 extends Scheduler {
+
+    private GenericBehaviorActivator<AbstractAgent> activator1;
+
+    @Override
+    protected void activate() {
+       // 1 : create the simulation group
+       createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP);
+
+       // 2 : launch some simulated agents
+       for (int i = 0; i < 20; i++) {
+           launchAgent(new SimulatedAgent02());
+           launchAgent(new SimulatedAgent03());
+       }
+
+       // 3 : initialize the activator
+       activator1 = new GenericBehaviorActivator<AbstractAgent>(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt");
+       addActivator(activator1);
+
+       setDelay(300);
+    }
+
+    /**
+     * A simple way of launching this scheduler
+     * 
+     * @param
+     */
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", MyScheduler03.class.getName() + ",true;" + ConsoleAgent.class.getName());
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex03/SimulatedAgent03.java.html b/release/html/simulation/simulation/ex03/SimulatedAgent03.java.html new file mode 100644 index 0000000..c6573be --- /dev/null +++ b/release/html/simulation/simulation/ex03/SimulatedAgent03.java.html @@ -0,0 +1,47 @@ + + + + + +simulation.ex03.SimulatedAgent03 (Java2HTML) + + + + + + + + +
+package simulation.ex03;
+
+import madkit.kernel.AbstractAgent;
+import simulation.ex02.SimulationModel;
+
+public class SimulatedAgent03 extends AbstractAgent {
+
+    @Override
+    protected void activate() {
+       requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE);
+    }
+
+    @SuppressWarnings("unused")
+    private void doIt() {
+       getLogger().info("I am doing it, but my way");
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex04/MyScheduler04.java.html b/release/html/simulation/simulation/ex04/MyScheduler04.java.html new file mode 100644 index 0000000..90eac88 --- /dev/null +++ b/release/html/simulation/simulation/ex04/MyScheduler04.java.html @@ -0,0 +1,90 @@ + + + + + +simulation.ex04.MyScheduler04 (Java2HTML) + + + + + + + + +
+package simulation.ex04;
+
+import madkit.gui.ConsoleAgent;
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Scheduler;
+import madkit.simulation.activator.GenericBehaviorActivator;
+import simulation.ex02.SimulatedAgent02;
+import simulation.ex02.SimulationModel;
+import simulation.ex03.SimulatedAgent03;
+
+/**
+ * 
+ *  
+ *     
+ * 
+ * Let us have more fun by adding another activator on another role to execute the other behavior of
+ * {@link SimulatedAgent04}
+ */
+
+public class MyScheduler04 extends Scheduler {
+
+    protected GenericBehaviorActivator<AbstractAgent> activator1;
+    protected GenericBehaviorActivator<AbstractAgent> activator2;
+
+    @Override
+    protected void activate() {
+
+       // 1 : create the simulation group
+       createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP);
+
+       // 2 : launch some simulated agents
+       for (int i = 0; i < 10; i++) {
+           launchAgent(new SimulatedAgent02());
+           launchAgent(new SimulatedAgent03());
+           launchAgent(new SimulatedAgent04());
+       }
+
+       // 3 : initialize the activators
+       // by default, they are activated once each in the order they have been added
+       activator1 = new GenericBehaviorActivator<AbstractAgent>(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt");
+       addActivator(activator1);
+       activator2 = new GenericBehaviorActivator<AbstractAgent>(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ANOTHER_ROLE, "anotherBehavior");
+       addActivator(activator2);
+
+       setDelay(300);
+
+       // 4 : let us start the simulation automatically
+       setSimulationState(SimulationState.RUNNING);
+    }
+
+    /**
+     * A simple way of launching this scheduler
+     * 
+     * @param
+     */
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", MyScheduler04.class.getName() + ",true;" + ConsoleAgent.class.getName());
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex04/SimulatedAgent04.java.html b/release/html/simulation/simulation/ex04/SimulatedAgent04.java.html new file mode 100644 index 0000000..2601825 --- /dev/null +++ b/release/html/simulation/simulation/ex04/SimulatedAgent04.java.html @@ -0,0 +1,54 @@ + + + + + +simulation.ex04.SimulatedAgent04 (Java2HTML) + + + + + + + + +
+package simulation.ex04;
+
+import madkit.kernel.AbstractAgent;
+import simulation.ex02.SimulationModel;
+
+public class SimulatedAgent04 extends AbstractAgent {
+
+    @Override
+    protected void activate() {
+       requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE);
+       // I use this role to identify me as an agent that know how to do another behavior
+       requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ANOTHER_ROLE);
+    }
+
+    @SuppressWarnings("unused")
+    private void doIt() {
+       getLogger().info("I am doing it, but my way");
+    }
+
+    @SuppressWarnings("unused")
+    private void anotherBehavior() {
+       getLogger().info("I am doing something else");
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex05/MyScheduler05.java.html b/release/html/simulation/simulation/ex05/MyScheduler05.java.html new file mode 100644 index 0000000..4b8560e --- /dev/null +++ b/release/html/simulation/simulation/ex05/MyScheduler05.java.html @@ -0,0 +1,68 @@ + + + + + +simulation.ex05.MyScheduler05 (Java2HTML) + + + + + + + + +
+package simulation.ex05;
+
+import madkit.gui.ConsoleAgent;
+import madkit.kernel.Madkit;
+import madkit.kernel.Scheduler;
+import simulation.ex04.MyScheduler04;
+
+/**
+ * 
+ *  
+ *     
+ * 
+ * 
+ * Let us define explicitly how a simulation step takes place in order to define our own scheduling policy at will. This
+ * is done by overriding {@link Scheduler#doSimulationStep()}.
+ */
+
+public class MyScheduler05 extends MyScheduler04 {
+
+    /**
+     * Our step consists in activating the first activator one time and the second two times. It could have been anything
+     * else. In fact, we could do anything we want here, especially we also define another granularity for the step: 0.5
+     */
+    @Override
+    public void doSimulationStep() {
+       activator1.execute();
+       activator2.execute();
+       activator2.execute();
+       setGVT(getGVT() + 0.5);
+    }
+
+    /**
+     * A simple way of launching this scheduler. It is inherited but this is to make the IDE launch this one properly.
+     */
+    public static void main(String[] args) {
+       new Madkit("--launchAgents", MyScheduler05.class.getName() + ",true;" + ConsoleAgent.class.getName());
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex06/MySimulationModel06.java.html b/release/html/simulation/simulation/ex06/MySimulationModel06.java.html new file mode 100644 index 0000000..81170df --- /dev/null +++ b/release/html/simulation/simulation/ex06/MySimulationModel06.java.html @@ -0,0 +1,44 @@ + + + + + +simulation.ex06.MySimulationModel06 (Java2HTML) + + + + + + + + +
+package simulation.ex06;
+
+/**
+ * Stocking some global properties for this tutorial.
+ */
+
+ public class MySimulationModel06{
+
+    public static final String MY_COMMUNITY = "simu";
+    public static final String SIMU_GROUP = "simu";
+    public static final String AGENT_ROLE = "agent";
+    public static final String SPY_ROLE = "spy";
+    public static final String SCH_ROLE = "scheduler";
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex06/SimulatedAgent06.java.html b/release/html/simulation/simulation/ex06/SimulatedAgent06.java.html new file mode 100644 index 0000000..2016b87 --- /dev/null +++ b/release/html/simulation/simulation/ex06/SimulatedAgent06.java.html @@ -0,0 +1,51 @@ + + + + + +simulation.ex06.SimulatedAgent06 (Java2HTML) + + + + + + + + +
+package simulation.ex06;
+
+import madkit.kernel.AbstractAgent;
+
+/**
+ * In this example, we create a simulated agent extended from the AbstractAgent class
+ * to set a role to this agent. We also give him a name so that the spy can probe his name.
+ */
+
+public class SimulatedAgent06 extends AbstractAgent {
+
+    protected String name = "SimulatedAgent06";
+
+    @Override
+    protected void activate() {
+        requestRole(MySimulationModel06.MY_COMMUNITY, MySimulationModel06.SIMU_GROUP, MySimulationModel06.AGENT_ROLE);
+    }
+
+    private void doIt() {
+        getLogger().info("I am doing it");
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex07/EnvironmentAgent.java.html b/release/html/simulation/simulation/ex07/EnvironmentAgent.java.html new file mode 100644 index 0000000..d6e5f36 --- /dev/null +++ b/release/html/simulation/simulation/ex07/EnvironmentAgent.java.html @@ -0,0 +1,81 @@ + + + + + +simulation.ex07.EnvironmentAgent (Java2HTML) + + + + + + + + +
+package simulation.ex07;
+
+import java.awt.Dimension;
+
+import madkit.kernel.AbstractAgent;
+import madkit.kernel.Watcher;
+import madkit.simulation.probe.PropertyProbe;
+
+/**
+ * This agent is used to model a quite simple environment. Nothing in it; It just defines its boundaries and uses a
+ * {@link PropertyProbe} to set the agents' environment field so that they can use the environment's methods once they
+ * enter the artificial society.
+ */
+public class EnvironmentAgent extends Watcher {
+
+    /**
+     * environment's boundaries
+     */
+    private Dimension dimension;
+
+    /**
+     * so that the agents can perceive my dimension
+     */
+    public Dimension getDimension() {
+       return dimension;
+    }
+
+    @Override
+    protected void activate() {
+       dimension = new Dimension(400, 400);
+       
+       // 1 : request my role so that the viewer can probe me
+       requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.ENV_ROLE);
+
+       // 2 : this probe is used to initialize the agents' environment field
+       addProbe(new AgentsProbe(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE, "environment"));
+       
+   }
+
+    class AgentsProbe extends PropertyProbe<AbstractAgent, EnvironmentAgent> {
+
+       public AgentsProbe(String community, String group, String role, String fieldName) {
+           super(community, group, role, fieldName);
+       }
+
+       @Override
+       protected void adding(AbstractAgent agent) {
+           super.adding(agent);
+           setPropertyValue(agent, EnvironmentAgent.this);
+       }
+    }
+
+}
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex07/MySimulationModel.java.html b/release/html/simulation/simulation/ex07/MySimulationModel.java.html new file mode 100644 index 0000000..013645f --- /dev/null +++ b/release/html/simulation/simulation/ex07/MySimulationModel.java.html @@ -0,0 +1,78 @@ + + + + + +simulation.ex07.MySimulationModel (Java2HTML) + + + + + + + + +
+package simulation.ex07;
+
+import madkit.kernel.AbstractAgent;
+
+/**
+ * 
+ * 
+
+
+
+
+
+
+
+
+package simulation.ex07;
+
+import java.awt.Dimension;
+
+import madkit.kernel.AbstractAgent;
+
+public class SituatedAgent extends AbstractAgent {
+
+    /**
+     * The agent's environment. Here it is just used to know its boundaries. It will be automatically set by the environment
+     * agent itself: No need to instantiate anything here.
+     */
+    protected EnvironmentAgent environment;
+
+    /**
+     * agent's position
+     */
+    protected Dimension location = new Dimension();
+
+    /**
+     * initialize my role and fields
+     */
+    @Override
+    protected void activate() {
+       requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE);
+       Dimension envDim = environment.getDimension();
+       location.width = (int) (Math.random() * envDim.width);
+       location.height = (int) (Math.random() * envDim.height);
+    }
+
+    /**
+     * A non sense behavior, just moving around.
+     */
+    @SuppressWarnings("unused")
+    private void doIt() {
+       Dimension envDim = environment.getDimension();
+       location.width += Math.random() * 4 - 1;
+       location.height += Math.random() * 4 - 1;
+       location.width %= envDim.width;
+       location.height %= envDim.height;
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex07/Viewer.java.html b/release/html/simulation/simulation/ex07/Viewer.java.html new file mode 100644 index 0000000..073b1a4 --- /dev/null +++ b/release/html/simulation/simulation/ex07/Viewer.java.html @@ -0,0 +1,104 @@ + + + + + +simulation.ex07.Viewer (Java2HTML) + + + + + + + + +
+package simulation.ex07;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+
+import madkit.kernel.Watcher;
+import madkit.simulation.probe.PropertyProbe;
+import madkit.simulation.probe.SingleAgentProbe;
+import madkit.simulation.viewer.SwingViewer;
+
+/**
+ * This class will be used to display the simulation. We could have extended the {@link Watcher} class, but there are a
+ * lot of things already defined in {@link SwingViewer}. So why not use it.
+ */
+public class Viewer extends SwingViewer {
+
+    /**
+     * environment's size, probed using a {@link SingleAgentProbe}.
+     */
+    private Dimension envSize;
+
+    /**
+     * The probe by which we will get the agents' location
+     */
+    protected PropertyProbe<SituatedAgent, Dimension> agentsLocationProbe;
+
+    @Override
+    protected void activate() {
+       // 1 : request my role so that the scheduler can take me into account
+       requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.VIEWER_ROLE);
+
+       // 2 : adding the probes
+
+       // probing the environment using an anonymous inner class
+       SingleAgentProbe<EnvironmentAgent, Dimension> envProbe = new SingleAgentProbe<EnvironmentAgent, Dimension>(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP,
+              MySimulationModel.ENV_ROLE, "dimension") {
+
+           @Override
+           protected void adding(EnvironmentAgent agent) {
+              super.adding(agent);
+              envSize = getPropertyValue();
+           }
+       };
+       addProbe(envProbe);
+       
+       // probing agents' location
+       agentsLocationProbe = new PropertyProbe<SituatedAgent, Dimension>(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE, "location");
+       addProbe(agentsLocationProbe);
+
+       // 3 : Now that the probes are added,
+       // we can setup the frame for the display according to the environment's properties
+       getDisplayPane().setPreferredSize(envSize);
+       getFrame().pack();
+
+       // 4 (optional) set the synchronous painting mode: The display will be updated
+       // for each step of the simulation.
+       // Here it is useful because the simulation goes so fast that the agents
+       // are almost invisible
+       setSynchronousPainting(true);
+    }
+
+    /**
+     * render is the method where the custom painting has to be done. Here, we just draw red points at the agents' location
+     */
+    @Override
+    protected void render(Graphics g) {
+       g.setColor(Color.RED);
+       for (SituatedAgent a : agentsLocationProbe.getCurrentAgentsList()) {
+           Dimension location = agentsLocationProbe.getPropertyValue(a);
+           g.drawRect(location.width, location.height, 1, 1);
+       }
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex08/ImageViewer.java.html b/release/html/simulation/simulation/ex08/ImageViewer.java.html new file mode 100644 index 0000000..85d4c1f --- /dev/null +++ b/release/html/simulation/simulation/ex08/ImageViewer.java.html @@ -0,0 +1,66 @@ + + + + + +simulation.ex08.ImageViewer (Java2HTML) + + + + + + + + +
+package simulation.ex08;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+
+import javax.swing.ImageIcon;
+
+import simulation.ex07.SituatedAgent;
+import simulation.ex07.Viewer;
+
+/**
+ * 
+ * 
+ * 
+ * 
+ * 
+ * We can of course use images to represent the agents.
+ */
+public class ImageViewer extends Viewer {
+
+    /**
+     * Taking an image used in another tutorial
+     */
+    private final Image car = new ImageIcon(getClass().getResource("/gui/ex03_customPanel/agent.png")).getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
+
+    /**
+     * render is the method where the custom painting has to be made. Here, we use the image at the agents' location
+     */
+    @Override
+    protected void render(Graphics g) {
+       for (SituatedAgent a : agentsLocationProbe.getCurrentAgentsList()) {
+              Dimension location = agentsLocationProbe.getPropertyValue(a);
+              g.drawImage(car, location.width, location.height, null);
+       }
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex08/MySimulationModel08.java.html b/release/html/simulation/simulation/ex08/MySimulationModel08.java.html new file mode 100644 index 0000000..822b8f6 --- /dev/null +++ b/release/html/simulation/simulation/ex08/MySimulationModel08.java.html @@ -0,0 +1,54 @@ + + + + + +simulation.ex08.MySimulationModel08 (Java2HTML) + + + + + + + + +
+package simulation.ex08;
+
+import simulation.ex07.MySimulationModel;
+
+/**
+ *  
+ *     
+ * 
+ * It is time to display using an alternative representation for the agents !! See {@link ImageViewer}
+ */
+public class MySimulationModel08 extends MySimulationModel {
+
+    @Override
+    protected void activate() {
+       super.activate();
+
+       // adding the new viewer
+       ImageViewer viewer = new ImageViewer();
+       launchAgent(viewer, true);
+    }
+
+    public static void main(String[] args) {
+       executeThisAgent(1, false); // no gui for me
+    }
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/simulation/ex08/Test.java.html b/release/html/simulation/simulation/ex08/Test.java.html new file mode 100644 index 0000000..b802b1a --- /dev/null +++ b/release/html/simulation/simulation/ex08/Test.java.html @@ -0,0 +1,44 @@ + + + + + +simulation.ex08.Test (Java2HTML) + + + + + + + + +
+package simulation.ex08;
+
+import madkit.kernel.Agent;
+import madkit.kernel.Madkit;
+
+public class Test extends Agent {
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+       new Madkit();
+    }
+
+}
+
+ + + + + + + + + \ No newline at end of file diff --git a/release/html/simulation/stylesheet.css b/release/html/simulation/stylesheet.css new file mode 100644 index 0000000..6ff3293 --- /dev/null +++ b/release/html/simulation/stylesheet.css @@ -0,0 +1,82 @@ +/* Java2HTML - Colour Definitions*/ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background Colour */ +body { background-color: #FFFFFF; } + +/* Default Text Colour */ +body { color: #000000} + +/* Header/Footer Colours */ +#Header { font-family: Arial, Helvetica, sans-serif; color: #000000; background-color:#EEEEFF } + +/* Line Number */ +#LN { color: #BBBBBB; background-color:#FFFFFF } + +/* Link Colours */ +#Classes A:link { color: #000000; } +#Classes A:visited { color: #000000; } +#Classes PRE { color: #000000; } + +/* Token Colours */ +#CharacerLiteral { color: #FF00FF; } +#StringLiteral { color: #FF00FF; } +#SingleLineComment { color: #008000; } +#FormalComment { color: #008000; } +#MultiLineComment { color: #008000; } +#Abstract { color: #0000FF ; font-weight: bold } +#Boolean { color: #0000FF ; font-weight: bold } +#Break { color: #0000FF ; font-weight: bold } +#Byte { color: #0000FF ; font-weight: bold } +#Case { color: #0000FF ; font-weight: bold } +#Catch { color: #0000FF ; font-weight: bold } +#Char { color: #0000FF ; font-weight: bold } +#Class { color: #0000FF ; font-weight: bold } +#Const { color: #0000FF ; font-weight: bold } +#Continue { color: #0000FF ; font-weight: bold } +#Default { color: #0000FF ; font-weight: bold } +#Do { color: #0000FF ; font-weight: bold } +#Double { color: #0000FF ; font-weight: bold } +#Else { color: #0000FF ; font-weight: bold } +#Extends { color: #0000FF ; font-weight: bold } +#False { color: #0000FF ; font-weight: bold } +#Final { color: #0000FF ; font-weight: bold } +#Finally { color: #0000FF ; font-weight: bold } +#Float { color: #0000FF ; font-weight: bold } +#For { color: #0000FF ; font-weight: bold } +#Goto { color: #0000FF ; font-weight: bold } +#If { color: #0000FF ; font-weight: bold } +#Implements { color: #0000FF ; font-weight: bold } +#Import { color: #0000FF ; font-weight: bold } +#InstanceOf { color: #0000FF ; font-weight: bold } +#Int { color: #0000FF ; font-weight: bold } +#Interface { color: #0000FF ; font-weight: bold } +#Long { color: #0000FF ; font-weight: bold } +#Native { color: #0000FF ; font-weight: bold } +#New { color: #0000FF ; font-weight: bold } +#Package { color: #0000FF ; font-weight: bold } +#Private { color: #0000FF ; font-weight: bold } +#Protected { color: #0000FF ; font-weight: bold } +#Public { color: #0000FF ; font-weight: bold } +#Return { color: #0000FF ; font-weight: bold } +#Short { color: #0000FF ; font-weight: bold } +#Static { color: #0000FF ; font-weight: bold } +#Super { color: #0000FF ; font-weight: bold } +#Switch { color: #0000FF ; font-weight: bold } +#Synchronized { color: #0000FF ; font-weight: bold } +#This { color: #0000FF ; font-weight: bold } +#Throw { color: #0000FF ; font-weight: bold } +#Throws { color: #0000FF ; font-weight: bold } +#Transient { color: #0000FF ; font-weight: bold } +#True { color: #0000FF ; font-weight: bold } +#Try { color: #0000FF ; font-weight: bold } +#Void { color: #0000FF ; font-weight: bold } +#Volatile { color: #0000FF ; font-weight: bold } +#While { color: #0000FF ; font-weight: bold } +#StrictFP { color: #0000FF ; font-weight: bold } +#IntegerLiteral { color: #000000 } +#DecimalLiteral { color: #000000 } +#HexLiteral { color: #000000 } +#OctalLiteral { color: #000000 } +#FloatPointLiteral { color: #000000 } \ No newline at end of file diff --git a/release/index.html b/release/index.html new file mode 100644 index 0000000..b4a33cc --- /dev/null +++ b/release/index.html @@ -0,0 +1,52 @@ + + + +The MaDKit-5 tutorials +

The MaDKit-5 tutorials

+

MDK

+ +Over-commented source code examples, structured in packages named to be naturally ordered according to their complexity. +These tutorials describe specific topics featuring:
+ +
+Browsing this web site, you will be able to launch some of the examples using Java Web Start. +In such a case and for best results, you should activate the console of JavaWebStart by opening your +Java plugin control panel and ensure that "display the console" is checked (in the advanced section). +


+
+

You can also test all the examples by importing MaDKit-tutorials-project.zip in Eclipse

+This archive is a working Eclipse project containing all the examples presented here. It could be imported as follows:
+
    +
  1. Within Eclipse, do Import > +Existing project > Select Archive File > +MaDKit-tutorials-project.zip > finish
  2. +
  3. Explore the examples!
  4. +
+
+
+
+

Online help
+

+

+

+ +
+
+

Licenses

+ +
+ + diff --git a/release/jnlp/communication.ex01.PingAgent.jnlp b/release/jnlp/communication.ex01.PingAgent.jnlp new file mode 100644 index 0000000..189b727 --- /dev/null +++ b/release/jnlp/communication.ex01.PingAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex01.PingAgent,true,2 + + diff --git a/release/jnlp/communication.ex02.Agent4.jnlp b/release/jnlp/communication.ex02.Agent4.jnlp new file mode 100644 index 0000000..350ee95 --- /dev/null +++ b/release/jnlp/communication.ex02.Agent4.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex02.Agent4,true,2 + + diff --git a/release/jnlp/communication.ex02.Agent5.jnlp b/release/jnlp/communication.ex02.Agent5.jnlp new file mode 100644 index 0000000..970ea5f --- /dev/null +++ b/release/jnlp/communication.ex02.Agent5.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex02.Agent4,true,1;communication.ex02.Agent5,true,1 + + diff --git a/release/jnlp/communication.ex02_targetingRoles.PingAgent2.jnlp b/release/jnlp/communication.ex02_targetingRoles.PingAgent2.jnlp new file mode 100644 index 0000000..5180983 --- /dev/null +++ b/release/jnlp/communication.ex02_targetingRoles.PingAgent2.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex01.PingAgent;communication.ex02_targetingRoles.PingAgent2,true,10 + + diff --git a/release/jnlp/communication.ex03_replyingToMessages.ReplierAgent.jnlp b/release/jnlp/communication.ex03_replyingToMessages.ReplierAgent.jnlp new file mode 100644 index 0000000..10eb069 --- /dev/null +++ b/release/jnlp/communication.ex03_replyingToMessages.ReplierAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex01.PingAgent,true,2 + + diff --git a/release/jnlp/communication.ex05.Agent1.jnlp b/release/jnlp/communication.ex05.Agent1.jnlp new file mode 100644 index 0000000..a7844ca --- /dev/null +++ b/release/jnlp/communication.ex05.Agent1.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex05.Agent1,true,2;communication.ex05.Agent2,true,2 + + diff --git a/release/jnlp/communication.ex05.Agent3.jnlp b/release/jnlp/communication.ex05.Agent3.jnlp new file mode 100644 index 0000000..d1c8fb1 --- /dev/null +++ b/release/jnlp/communication.ex05.Agent3.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex05.Agent1,true,1;communication.ex05.Agent3,true,1 + + diff --git a/release/jnlp/communication.ex06.Agent6.jnlp b/release/jnlp/communication.ex06.Agent6.jnlp new file mode 100644 index 0000000..f2e31b6 --- /dev/null +++ b/release/jnlp/communication.ex06.Agent6.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents communication.ex06.Agent6,true,1;communication.ex06.Agent7,true,1 + + diff --git a/release/jnlp/gui.ex01_defaultGUI.DefaultGUIAgent.jnlp b/release/jnlp/gui.ex01_defaultGUI.DefaultGUIAgent.jnlp new file mode 100644 index 0000000..3bc9a38 --- /dev/null +++ b/release/jnlp/gui.ex01_defaultGUI.DefaultGUIAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents gui.ex01_defaultGUI.DefaultGUIAgent,true + + diff --git a/release/jnlp/gui.ex02_overridingDefaultsettings.OverridingDefaultSettings.jnlp b/release/jnlp/gui.ex02_overridingDefaultsettings.OverridingDefaultSettings.jnlp new file mode 100644 index 0000000..cd40088 --- /dev/null +++ b/release/jnlp/gui.ex02_overridingDefaultsettings.OverridingDefaultSettings.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents gui.ex02_overridingDefaultsettings.OverridingDefaultSettings,true + + diff --git a/release/jnlp/gui.ex03_customPanel.CustomPanel.jnlp b/release/jnlp/gui.ex03_customPanel.CustomPanel.jnlp new file mode 100644 index 0000000..c3c0099 --- /dev/null +++ b/release/jnlp/gui.ex03_customPanel.CustomPanel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents gui.ex03_customPanel.CustomPanel,true + + diff --git a/release/jnlp/gui.ex04_independentGUI.IndependentGUI.jnlp b/release/jnlp/gui.ex04_independentGUI.IndependentGUI.jnlp new file mode 100644 index 0000000..4d6504b --- /dev/null +++ b/release/jnlp/gui.ex04_independentGUI.IndependentGUI.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents gui.ex04_independentGUI.IndependentGUI + + diff --git a/release/jnlp/gui.ex05_multi_GUI.MultiGUI.jnlp b/release/jnlp/gui.ex05_multi_GUI.MultiGUI.jnlp new file mode 100644 index 0000000..1baa7f3 --- /dev/null +++ b/release/jnlp/gui.ex05_multi_GUI.MultiGUI.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents gui.ex05_multi_GUI.MultiGUI,true + + diff --git a/release/jnlp/helloworld.ex01.HelloWorldAgent.jnlp b/release/jnlp/helloworld.ex01.HelloWorldAgent.jnlp new file mode 100644 index 0000000..533e995 --- /dev/null +++ b/release/jnlp/helloworld.ex01.HelloWorldAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents helloworld.ex01.HelloWorldAgent,true + + diff --git a/release/jnlp/helloworld.ex02.AgentLifeCycle.jnlp b/release/jnlp/helloworld.ex02.AgentLifeCycle.jnlp new file mode 100644 index 0000000..4354d19 --- /dev/null +++ b/release/jnlp/helloworld.ex02.AgentLifeCycle.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents helloworld.ex02.AgentLifeCycle,true + + diff --git a/release/jnlp/helloworld.ex04.AddingParametersToExecuteThisAgent.jnlp b/release/jnlp/helloworld.ex04.AddingParametersToExecuteThisAgent.jnlp new file mode 100644 index 0000000..29a2afb --- /dev/null +++ b/release/jnlp/helloworld.ex04.AddingParametersToExecuteThisAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --console --launchAgents helloworld.ex04.AddingParametersToExecuteThisAgent,false,3 + + diff --git a/release/jnlp/helloworld.ex04.LaunchingTwoAgents.jnlp b/release/jnlp/helloworld.ex04.LaunchingTwoAgents.jnlp new file mode 100644 index 0000000..104c35f --- /dev/null +++ b/release/jnlp/helloworld.ex04.LaunchingTwoAgents.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents helloworld.ex03.LaunchingTwoAgents,true,2 + + diff --git a/release/jnlp/helloworld.ex04.ModifyingGUILocation.jnlp b/release/jnlp/helloworld.ex04.ModifyingGUILocation.jnlp new file mode 100644 index 0000000..81b58b5 --- /dev/null +++ b/release/jnlp/helloworld.ex04.ModifyingGUILocation.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents helloworld.ex03.ModifyingGUILocation,true,3 + + diff --git a/release/jnlp/helloworld.ex04.ThreeAgentsWithNoGUI.jnlp b/release/jnlp/helloworld.ex04.ThreeAgentsWithNoGUI.jnlp new file mode 100644 index 0000000..bd98482 --- /dev/null +++ b/release/jnlp/helloworld.ex04.ThreeAgentsWithNoGUI.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents helloworld.ex04.ThreeAgentsWithNoGUI,false,3 + + diff --git a/release/jnlp/helloworld.ex05.DesktopHelloWorld.jnlp b/release/jnlp/helloworld.ex05.DesktopHelloWorld.jnlp new file mode 100644 index 0000000..ed9045b --- /dev/null +++ b/release/jnlp/helloworld.ex05.DesktopHelloWorld.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --desktop --launchAgents helloworld.ex01.HelloWorldAgent,true,1 + + diff --git a/release/jnlp/logging.ex01a_intro.LogMessage.jnlp b/release/jnlp/logging.ex01a_intro.LogMessage.jnlp new file mode 100644 index 0000000..347cd72 --- /dev/null +++ b/release/jnlp/logging.ex01a_intro.LogMessage.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex01a_intro.LogMessage,true + + diff --git a/release/jnlp/logging.ex01b_levels.LevelMessage.jnlp b/release/jnlp/logging.ex01b_levels.LevelMessage.jnlp new file mode 100644 index 0000000..ca981be --- /dev/null +++ b/release/jnlp/logging.ex01b_levels.LevelMessage.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex01b_levels.LevelMessage,true + + diff --git a/release/jnlp/logging.ex01c_levels.MessageWithLevel.jnlp b/release/jnlp/logging.ex01c_levels.MessageWithLevel.jnlp new file mode 100644 index 0000000..08d3185 --- /dev/null +++ b/release/jnlp/logging.ex01c_levels.MessageWithLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex01c_levels.MessageWithLevel,true + + diff --git a/release/jnlp/logging.ex02a_introLogLevel.LogLevel.jnlp b/release/jnlp/logging.ex02a_introLogLevel.LogLevel.jnlp new file mode 100644 index 0000000..a7521ad --- /dev/null +++ b/release/jnlp/logging.ex02a_introLogLevel.LogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex02a_introLogLevel.LogLevel,true + + diff --git a/release/jnlp/logging.ex02b_defaultLogLevel.TheDefaultLogLevel.jnlp b/release/jnlp/logging.ex02b_defaultLogLevel.TheDefaultLogLevel.jnlp new file mode 100644 index 0000000..efa8512 --- /dev/null +++ b/release/jnlp/logging.ex02b_defaultLogLevel.TheDefaultLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex02b_defaultLogLevel.TheDefaultLogLevel,true + + diff --git a/release/jnlp/logging.ex02c_theDifferentLevels.TheDifferentLevels.jnlp b/release/jnlp/logging.ex02c_theDifferentLevels.TheDifferentLevels.jnlp new file mode 100644 index 0000000..d332931 --- /dev/null +++ b/release/jnlp/logging.ex02c_theDifferentLevels.TheDifferentLevels.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex02c_theDifferentLevels.theDifferentLevels,true + + diff --git a/release/jnlp/logging.ex03a_levelFinerFinest.LevelFinerFinest.jnlp b/release/jnlp/logging.ex03a_levelFinerFinest.LevelFinerFinest.jnlp new file mode 100644 index 0000000..049cedd --- /dev/null +++ b/release/jnlp/logging.ex03a_levelFinerFinest.LevelFinerFinest.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents logging.ex03a_levelFinerFinest.LevelFinerFinest,true + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._1_Console.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._1_Console.jnlp new file mode 100644 index 0000000..a6fc248 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._1_Console.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._2_CgrWarnings.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._2_CgrWarnings.jnlp new file mode 100644 index 0000000..c059249 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._2_CgrWarnings.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._3_Debug.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._3_Debug.jnlp new file mode 100644 index 0000000..0b3c11e --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._3_Debug.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._4_Desktop.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._4_Desktop.jnlp new file mode 100644 index 0000000..a4e0788 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._4_Desktop.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._5_CreateLogFiles.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._5_CreateLogFiles.jnlp new file mode 100644 index 0000000..ca3002d --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._5_CreateLogFiles.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._6_NoAgentConsoleLog.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._6_NoAgentConsoleLog.jnlp new file mode 100644 index 0000000..fcd92d4 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._6_NoAgentConsoleLog.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._7_LoadLocalDemos.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._7_LoadLocalDemos.jnlp new file mode 100644 index 0000000..cc663d6 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._7_LoadLocalDemos.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._8_Network.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._8_Network.jnlp new file mode 100644 index 0000000..ffe6ca9 --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._8_Network.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex1_BooleanOptions._9_AutoConnectMadkitWebsite.jnlp b/release/jnlp/madkitoptions.ex1_BooleanOptions._9_AutoConnectMadkitWebsite.jnlp new file mode 100644 index 0000000..745570f --- /dev/null +++ b/release/jnlp/madkitoptions.ex1_BooleanOptions._9_AutoConnectMadkitWebsite.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._1_MadkitLogLevel.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._1_MadkitLogLevel.jnlp new file mode 100644 index 0000000..7c53e89 --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._1_MadkitLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._2_AgentLogLevel.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._2_AgentLogLevel.jnlp new file mode 100644 index 0000000..33abbf2 --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._2_AgentLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._3_GuiLogLevel.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._3_GuiLogLevel.jnlp new file mode 100644 index 0000000..3fa3855 --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._3_GuiLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._4_KernelLogLevel.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._4_KernelLogLevel.jnlp new file mode 100644 index 0000000..3ba2a56 --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._4_KernelLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._5_NetworkLogLevel.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._5_NetworkLogLevel.jnlp new file mode 100644 index 0000000..c9d8c43 --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._5_NetworkLogLevel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex2_LevelOptions._6_AgentWithCGRWarnings.jnlp b/release/jnlp/madkitoptions.ex2_LevelOptions._6_AgentWithCGRWarnings.jnlp new file mode 100644 index 0000000..cec4a8a --- /dev/null +++ b/release/jnlp/madkitoptions.ex2_LevelOptions._6_AgentWithCGRWarnings.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents madkitoptions.ex2_LevelOptions._6_AgentWithCGRWarnings, true + + diff --git a/release/jnlp/madkitoptions.ex3_MadkitOptions._1_LaunchAgents.jnlp b/release/jnlp/madkitoptions.ex3_MadkitOptions._1_LaunchAgents.jnlp new file mode 100644 index 0000000..9a0314e --- /dev/null +++ b/release/jnlp/madkitoptions.ex3_MadkitOptions._1_LaunchAgents.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex3_MadkitOptions._2_ConfigFile.jnlp b/release/jnlp/madkitoptions.ex3_MadkitOptions._2_ConfigFile.jnlp new file mode 100644 index 0000000..9776385 --- /dev/null +++ b/release/jnlp/madkitoptions.ex3_MadkitOptions._2_ConfigFile.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex3_MadkitOptions._3_DesktopFrameClass.jnlp b/release/jnlp/madkitoptions.ex3_MadkitOptions._3_DesktopFrameClass.jnlp new file mode 100644 index 0000000..ff13dc7 --- /dev/null +++ b/release/jnlp/madkitoptions.ex3_MadkitOptions._3_DesktopFrameClass.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex3_MadkitOptions._4_AgentFrame.jnlp b/release/jnlp/madkitoptions.ex3_MadkitOptions._4_AgentFrame.jnlp new file mode 100644 index 0000000..ebc67ed --- /dev/null +++ b/release/jnlp/madkitoptions.ex3_MadkitOptions._4_AgentFrame.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitoptions.ex3_MadkitOptions._5_LogDirectory.jnlp b/release/jnlp/madkitoptions.ex3_MadkitOptions._5_LogDirectory.jnlp new file mode 100644 index 0000000..23f0839 --- /dev/null +++ b/release/jnlp/madkitoptions.ex3_MadkitOptions._5_LogDirectory.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitproperties._1_DisplayMadkitProperties.jnlp b/release/jnlp/madkitproperties._1_DisplayMadkitProperties.jnlp new file mode 100644 index 0000000..12345c7 --- /dev/null +++ b/release/jnlp/madkitproperties._1_DisplayMadkitProperties.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitproperties._2_ToStringEquivalent.jnlp b/release/jnlp/madkitproperties._2_ToStringEquivalent.jnlp new file mode 100644 index 0000000..3fd8365 --- /dev/null +++ b/release/jnlp/madkitproperties._2_ToStringEquivalent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitproperties._3_ModifyingProperty.jnlp b/release/jnlp/madkitproperties._3_ModifyingProperty.jnlp new file mode 100644 index 0000000..5c54e14 --- /dev/null +++ b/release/jnlp/madkitproperties._3_ModifyingProperty.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitproperties._4_CreateNewProperty.jnlp b/release/jnlp/madkitproperties._4_CreateNewProperty.jnlp new file mode 100644 index 0000000..673caa7 --- /dev/null +++ b/release/jnlp/madkitproperties._4_CreateNewProperty.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/madkitproperties._5_AgentLoadingPropertyFile.jnlp b/release/jnlp/madkitproperties._5_AgentLoadingPropertyFile.jnlp new file mode 100644 index 0000000..714e85f --- /dev/null +++ b/release/jnlp/madkitproperties._5_AgentLoadingPropertyFile.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents madkitproperties._5_AgentLoadingPropertyFile,true + + diff --git a/release/jnlp/madkitproperties._6_LoadXMLPropertyFile.jnlp b/release/jnlp/madkitproperties._6_LoadXMLPropertyFile.jnlp new file mode 100644 index 0000000..c7c7e0b --- /dev/null +++ b/release/jnlp/madkitproperties._6_LoadXMLPropertyFile.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/returncode.ex1_javaException.CrashingAgent.jnlp b/release/jnlp/returncode.ex1_javaException.CrashingAgent.jnlp new file mode 100644 index 0000000..70f9d11 --- /dev/null +++ b/release/jnlp/returncode.ex1_javaException.CrashingAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex1_javaException.CrashingAgent, true + + diff --git a/release/jnlp/returncode.ex2_madkitCodingError._1_CrashingAgent.jnlp b/release/jnlp/returncode.ex2_madkitCodingError._1_CrashingAgent.jnlp new file mode 100644 index 0000000..1761aa5 --- /dev/null +++ b/release/jnlp/returncode.ex2_madkitCodingError._1_CrashingAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex2_madkitCodingError._1_CrashingAgent, true + + diff --git a/release/jnlp/returncode.ex2_madkitCodingError._2_LaunchingNewCrashingAgentsWithMadkit.jnlp b/release/jnlp/returncode.ex2_madkitCodingError._2_LaunchingNewCrashingAgentsWithMadkit.jnlp new file mode 100644 index 0000000..7b73e2a --- /dev/null +++ b/release/jnlp/returncode.ex2_madkitCodingError._2_LaunchingNewCrashingAgentsWithMadkit.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + + + diff --git a/release/jnlp/returncode.ex2_madkitCodingError._3_AgentLaunchingNewCrashingAgents.jnlp b/release/jnlp/returncode.ex2_madkitCodingError._3_AgentLaunchingNewCrashingAgents.jnlp new file mode 100644 index 0000000..1eed3db --- /dev/null +++ b/release/jnlp/returncode.ex2_madkitCodingError._3_AgentLaunchingNewCrashingAgents.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex2_madkitCodingError._3_AgentLaunchingNewCrashingAgents,true + + diff --git a/release/jnlp/returncode.ex3_introducingReturnCodes.SuccessfulAgent.jnlp b/release/jnlp/returncode.ex3_introducingReturnCodes.SuccessfulAgent.jnlp new file mode 100644 index 0000000..2eb0c52 --- /dev/null +++ b/release/jnlp/returncode.ex3_introducingReturnCodes.SuccessfulAgent.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex3_introducingReturnCodes.SuccessfulAgent,true + + diff --git a/release/jnlp/returncode.ex4_launchReturnCodes._1_NotYetLaunched.jnlp b/release/jnlp/returncode.ex4_launchReturnCodes._1_NotYetLaunched.jnlp new file mode 100644 index 0000000..3c90596 --- /dev/null +++ b/release/jnlp/returncode.ex4_launchReturnCodes._1_NotYetLaunched.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex4_launchReturnCodes._1_NotYetLaunched, true + + diff --git a/release/jnlp/returncode.ex4_launchReturnCodes._2_AlreadyLaunched.jnlp b/release/jnlp/returncode.ex4_launchReturnCodes._2_AlreadyLaunched.jnlp new file mode 100644 index 0000000..f447c4b --- /dev/null +++ b/release/jnlp/returncode.ex4_launchReturnCodes._2_AlreadyLaunched.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex4_launchReturnCodes._2_AlreadyLaunched, true + + diff --git a/release/jnlp/returncode.ex4_launchReturnCodes._3_AgentCrash.jnlp b/release/jnlp/returncode.ex4_launchReturnCodes._3_AgentCrash.jnlp new file mode 100644 index 0000000..7620caf --- /dev/null +++ b/release/jnlp/returncode.ex4_launchReturnCodes._3_AgentCrash.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex4_launchReturnCodes._3_AgentCrash, true + + diff --git a/release/jnlp/returncode.ex4_launchReturnCodes._4_TimeOut.jnlp b/release/jnlp/returncode.ex4_launchReturnCodes._4_TimeOut.jnlp new file mode 100644 index 0000000..0d79cfb --- /dev/null +++ b/release/jnlp/returncode.ex4_launchReturnCodes._4_TimeOut.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex4_launchReturnCodes._4_TimeOut, true + + diff --git a/release/jnlp/returncode.ex4_launchReturnCodes._5_AlreadyKilled.jnlp b/release/jnlp/returncode.ex4_launchReturnCodes._5_AlreadyKilled.jnlp new file mode 100644 index 0000000..e04b6f7 --- /dev/null +++ b/release/jnlp/returncode.ex4_launchReturnCodes._5_AlreadyKilled.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex4_launchReturnCodes._5_AlreadyKilled, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._1_NotCommunity.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._1_NotCommunity.jnlp new file mode 100644 index 0000000..f7b789b --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._1_NotCommunity.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._1_NotCommunity, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._2_AlreadyGroup.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._2_AlreadyGroup.jnlp new file mode 100644 index 0000000..6ef2109 --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._2_AlreadyGroup.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._2_AlreadyGroup, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._3_NotGroup.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._3_NotGroup.jnlp new file mode 100644 index 0000000..b8aa3ec --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._3_NotGroup.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._3_NotGroup, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._4_NotInGroup.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._4_NotInGroup.jnlp new file mode 100644 index 0000000..104cbc2 --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._4_NotInGroup.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._4_NotInGroup, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._5_NotRole.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._5_NotRole.jnlp new file mode 100644 index 0000000..ce9a98d --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._5_NotRole.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._5_NotRole, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._6_RoleAlreadyHandled.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._6_RoleAlreadyHandled.jnlp new file mode 100644 index 0000000..4f45c20 --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._6_RoleAlreadyHandled.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._6_RoleAlreadyHandled, true + + diff --git a/release/jnlp/returncode.ex5_CGRReturnCodes._7_RoleNotHandled.jnlp b/release/jnlp/returncode.ex5_CGRReturnCodes._7_RoleNotHandled.jnlp new file mode 100644 index 0000000..432f335 --- /dev/null +++ b/release/jnlp/returncode.ex5_CGRReturnCodes._7_RoleNotHandled.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex5_CGRReturnCodes._7_RoleNotHandled, true + + diff --git a/release/jnlp/returncode.ex6_communicationReturnCodes._1_CantReply.jnlp b/release/jnlp/returncode.ex6_communicationReturnCodes._1_CantReply.jnlp new file mode 100644 index 0000000..527ae93 --- /dev/null +++ b/release/jnlp/returncode.ex6_communicationReturnCodes._1_CantReply.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex6_communicationReturnCodes._1_CantReply, true + + diff --git a/release/jnlp/returncode.ex6_communicationReturnCodes._2_NoRecipientFound.jnlp b/release/jnlp/returncode.ex6_communicationReturnCodes._2_NoRecipientFound.jnlp new file mode 100644 index 0000000..19db952 --- /dev/null +++ b/release/jnlp/returncode.ex6_communicationReturnCodes._2_NoRecipientFound.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex6_communicationReturnCodes._2_NoRecipientFound, true + + diff --git a/release/jnlp/returncode.ex6_communicationReturnCodes._3_InvalidAgentAddress.jnlp b/release/jnlp/returncode.ex6_communicationReturnCodes._3_InvalidAgentAddress.jnlp new file mode 100644 index 0000000..225373b --- /dev/null +++ b/release/jnlp/returncode.ex6_communicationReturnCodes._3_InvalidAgentAddress.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex6_communicationReturnCodes._3_InvalidAgentAddress, true + + diff --git a/release/jnlp/returncode.ex7_concreteUseOfReturnCode.SendingMessageWithReturnCode.jnlp b/release/jnlp/returncode.ex7_concreteUseOfReturnCode.SendingMessageWithReturnCode.jnlp new file mode 100644 index 0000000..07d5519 --- /dev/null +++ b/release/jnlp/returncode.ex7_concreteUseOfReturnCode.SendingMessageWithReturnCode.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents returncode.ex7_concreteUseOfReturnCode.SendingMessageWithReturnCode, true + + diff --git a/release/jnlp/simulation.ex02.MyScheduler02.jnlp b/release/jnlp/simulation.ex02.MyScheduler02.jnlp new file mode 100644 index 0000000..d3aad9c --- /dev/null +++ b/release/jnlp/simulation.ex02.MyScheduler02.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex02.MyScheduler02,true;madkit.gui.ConsoleAgent + + diff --git a/release/jnlp/simulation.ex03.MyScheduler03.jnlp b/release/jnlp/simulation.ex03.MyScheduler03.jnlp new file mode 100644 index 0000000..743781c --- /dev/null +++ b/release/jnlp/simulation.ex03.MyScheduler03.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex03.MyScheduler03,true;madkit.gui.ConsoleAgent + + diff --git a/release/jnlp/simulation.ex04.MyScheduler04.jnlp b/release/jnlp/simulation.ex04.MyScheduler04.jnlp new file mode 100644 index 0000000..365d1db --- /dev/null +++ b/release/jnlp/simulation.ex04.MyScheduler04.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex04.MyScheduler04,true;madkit.gui.ConsoleAgent + + diff --git a/release/jnlp/simulation.ex05.MyScheduler02.jnlp b/release/jnlp/simulation.ex05.MyScheduler02.jnlp new file mode 100644 index 0000000..b61198e --- /dev/null +++ b/release/jnlp/simulation.ex05.MyScheduler02.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex05.MyScheduler02,true;madkit.gui.ConsoleAgent + + diff --git a/release/jnlp/simulation.ex06.MyScheduler06.jnlp b/release/jnlp/simulation.ex06.MyScheduler06.jnlp new file mode 100644 index 0000000..b03afb1 --- /dev/null +++ b/release/jnlp/simulation.ex06.MyScheduler06.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex06.MyScheduler06,true;madkit.gui.ConsoleAgent + + diff --git a/release/jnlp/simulation.ex07.MyScheduler07.jnlp b/release/jnlp/simulation.ex07.MyScheduler07.jnlp new file mode 100644 index 0000000..c1ba06e --- /dev/null +++ b/release/jnlp/simulation.ex07.MyScheduler07.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + >--launchAgents simulation.ex07.EnvironmentAgent --agentLogLevel ALL + + diff --git a/release/jnlp/simulation.ex07.MySimulationModel.jnlp b/release/jnlp/simulation.ex07.MySimulationModel.jnlp new file mode 100644 index 0000000..08edb19 --- /dev/null +++ b/release/jnlp/simulation.ex07.MySimulationModel.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex07.MySimulationModel + + diff --git a/release/jnlp/simulation.ex08.MySimulationModel08.jnlp b/release/jnlp/simulation.ex08.MySimulationModel08.jnlp new file mode 100644 index 0000000..ebc848c --- /dev/null +++ b/release/jnlp/simulation.ex08.MySimulationModel08.jnlp @@ -0,0 +1,24 @@ + + + + + The MaDKit Tutorials + Fabien Michel + + The MaDKit Tutorials: Illustrating MaDKit with simple source code examples + The MaDKit Tutorials + + + + + + + + + + + + The MaDKit tutorials + --launchAgents simulation.ex08.MySimulationModel08 + + diff --git a/release/src/communication/ex01/PingAgent.java b/release/src/communication/ex01/PingAgent.java new file mode 100644 index 0000000..f36dd61 --- /dev/null +++ b/release/src/communication/ex01/PingAgent.java @@ -0,0 +1,76 @@ +package communication.ex01; + +import static communication.ex01.Society.COMMUNITY; +import static communication.ex01.Society.GROUP; +import static communication.ex01.Society.ROLE; + +import java.util.logging.Level; + +import madkit.kernel.Agent; +import madkit.kernel.AgentAddress; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * + * + * To exchange messages, agents have to exist in an artificial society. That is, agents have to create communities + * containing groups and take roles within to interact with others. Doing so, agents get agent addresses which could be + * used to send them messages. Here, two agents take a role and ping the other one. + */ +public class PingAgent extends Agent { + + /** + * Firstly, take a position in the artificial society + */ + @Override + protected void activate() { + + getLogger().setLevel(Level.FINEST); + + createGroup(COMMUNITY, GROUP); + requestRole(COMMUNITY, GROUP, ROLE); + + pause(500); + } + + /** + * Now ping the other agent with a message + */ + @Override + protected void live() { + + // method seen in organization's tutorial + AgentAddress other = null; + while (other == null) { + other = getAgentWithRole(COMMUNITY, GROUP, ROLE); + pause(1000); + } + + getLogger().info("\n\tI found someone !!\n" + other + "\n\n"); + pause(2000); + + // sending the message to other: Success will be logged + sendMessage(other, new Message()); + pause(2000); + + // waiting other's message: The reception will be logged + waitNextMessage(); + pause(20000); + } + + /** + * @param args + */ + public static void main(String[] argss) { + executeThisAgent(2, true); + // or + // String[] args = { "--launchAgents", PingAgent.class.getName() + ",true,2" }; + // Madkit.main(args); + } + +} diff --git a/release/src/communication/ex01/Society.java b/release/src/communication/ex01/Society.java new file mode 100644 index 0000000..da8ae2f --- /dev/null +++ b/release/src/communication/ex01/Society.java @@ -0,0 +1,9 @@ +package communication.ex01; + +public class Society { + + public static final String COMMUNITY = "communication"; + public static final String GROUP = "ex01"; + public static final String ROLE = "ping agent"; + +} diff --git a/release/src/communication/ex02_targetingRoles/PingAgent2.java b/release/src/communication/ex02_targetingRoles/PingAgent2.java new file mode 100644 index 0000000..03a3e54 --- /dev/null +++ b/release/src/communication/ex02_targetingRoles/PingAgent2.java @@ -0,0 +1,57 @@ +package communication.ex02_targetingRoles; + +import static communication.ex01.Society.COMMUNITY; +import static communication.ex01.Society.GROUP; +import static communication.ex01.Society.ROLE; + +import java.util.logging.Level; + +import communication.ex01.PingAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages by targeting roles. + * + * + * + * + * + * + * Looking for someone, agents do not necessarily need to know who they talk to in terms of real ID. Indeed, what + * matters in the artificial society is the roles an agent take. organization tell a lot about what the agent is capable of and + * supposed to do. So, agents can send messages to roles rather than to IDs. Here, the idea is: I need to contact a + * "ping agent", no matter who will receive the message. And it is possible to do so using what follows: + */ +public class PingAgent2 extends PingAgent {// So I do the same activate + + /** + * Now ping another agent, just by targeting the role + */ + @Override + protected void live() { + + getLogger().setLevel(Level.ALL); + + ReturnCode code = null; + + // until I find someone having role + while (code != ReturnCode.SUCCESS) { + // This will randomly choose a receiver having this role + code = sendMessage(COMMUNITY, GROUP, ROLE, new Message()); + pause((int) (Math.random() * 1000 + 100)); + } + + nextMessage(); + pause(10000); + } + + @SuppressWarnings("unused") + public static void main(String[] args) { + //This will launch a new kernel. It will automatically ends when all the agents living on this kernel are done. + new Madkit("--launchAgents", PingAgent2.class.getName() + ",true,3;", PingAgent.class.getName()// This one so that PingAgent2 agents always find someone (breaking the + // first while) + ); + } + +} diff --git a/release/src/communication/ex03_replyingToMessages/ReplierAgent.java b/release/src/communication/ex03_replyingToMessages/ReplierAgent.java new file mode 100644 index 0000000..2d238ca --- /dev/null +++ b/release/src/communication/ex03_replyingToMessages/ReplierAgent.java @@ -0,0 +1,49 @@ +package communication.ex03_replyingToMessages; + +import static communication.ex01.Society.COMMUNITY; +import static communication.ex01.Society.GROUP; +import static communication.ex01.Society.ROLE; + +import communication.ex01.PingAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Message; +import madkit.message.StringMessage; + +/** + * Shows how agents exchange messages by targeting roles. + * + * + * + * + * + * + * Receiving a message, you can learn information about the sender. This is illustrated firstly in this example. + * Sometimes, agents need to communicate by replying to messages. There are primitives for that and they have two + * advantages. (1) This will identify the message as being a concrete reply to the received message thus easing the + * programming of protocols for instance. (2) This greatly improves code legibility + */ +public class ReplierAgent extends PingAgent {// So I do the same activate + + @Override + protected void live() { + + // until I found someone having that role + while (sendMessage(COMMUNITY, GROUP, ROLE, new Message()) != ReturnCode.SUCCESS) { + pause((int) (Math.random() * 1000 + 100)); + } + + Message m = nextMessage(); + if (m != null) { + getLogger().info("I have to thank " + m.getSender()); + sendReply(m, new StringMessage("thanks")); + } + pause(10000); + } + + @SuppressWarnings("unused") + public static void main(String[] args) { + new Madkit("--launchAgents", ReplierAgent.class.getName() + ",true,10;", PingAgent.class.getName()// This one so that agents always find someone (breaking the first while) + ); + } + +} diff --git a/release/src/communication/ex04/Agent1.java b/release/src/communication/ex04/Agent1.java new file mode 100644 index 0000000..1c33750 --- /dev/null +++ b/release/src/communication/ex04/Agent1.java @@ -0,0 +1,85 @@ +package communication.ex04; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.AgentAddress; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * + * + * To exchange messages, agents have to exist in an artificial society. That is, agents have to create communities + * containing groups and take roles within to interact with others. Doing so, agents get agent addresses which could be + * used to send them messages. Here, one agent (Agent1) is communicating with another agent (Agent2) by getting its + * agent address in the artificial society and using it with sendMessage. + */ +public class Agent1 extends Agent { + + /* + * Firstly, take a position in the artificial society. + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroup("communication", "GroupTest");// Create the group GroupTest in the community communication. + requestRole("communication", "GroupTest", "RoleTest1");// Request the role RoleTest1. + pause(500); + } + + /* + * First getting an Agent address, and then sending him a message. + */ + @Override + protected void live() { + AgentAddress other = null; + // Until we have an agent (in the group GroupTest in the community communication) having the role RoleTest2. + while (other == null) { + // Getting the address of an agent being in the community "communication" and the group "GroupTest", and having the role + // "RoleTest2". + other = getAgentWithRole("communication", "GroupTest", "RoleTest2"); + + // Trying to get another agent (Agent3). + if (other == null) { + other = getAgentWithRole("communication", "GroupTest", "RoleTest3"); + } + pause(1000); + } + getLogger().info("\n\tI found someone !!\n" + other + "\n\n"); + pause(1000); + + sendMessage(other, new Message());// Sending the message to the agent we found. + pause(1000); + + while (nextMessage() != null) + pause(6000); + } + + /* + * Set where the agent's window will be for avoiding a clear presentation. This method give + * the opportunity to modify the default settings of the frame. + * It will be more explained in GUI tutorial. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(100, 320 * (hashCode() - 2)); + } + + /** + * @param argss + * Running Agent1 will launch 2 instances of both Agent1 and Agent2. They will send themselves 1 message. + */ + @SuppressWarnings("unused") + public static void main(String[] argss) { + new Madkit("--launchAgents", Agent1.class.getName() + ",true,2;", Agent2.class.getName() + ",true,2;"); + } +} \ No newline at end of file diff --git a/release/src/communication/ex04/Agent2.java b/release/src/communication/ex04/Agent2.java new file mode 100644 index 0000000..0053751 --- /dev/null +++ b/release/src/communication/ex04/Agent2.java @@ -0,0 +1,63 @@ +package communication.ex04; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.AgentAddress; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Agent2 works as Agent1, using a different role. + * + * #jws communication.ex05.Agent1 jws# + * + * Agent2 is almost like Agent1, the only difference is the role and frame's location. + */ + +public class Agent2 extends Agent { + + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroup("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest2"); + pause(500); + } + + @Override + protected void live() { + AgentAddress other = null; + while (other == null) { + other = getAgentWithRole("communication", "GroupTest", "RoleTest1"); + pause(1000); + } + getLogger().info("\n\tI found someone !!\n" + other + "\n\n"); + pause(1000); + + sendMessage(other, new Message()); + pause(1000); + + while (nextMessage() != null) + pause(6000); + } + + /** + * Will launch 2 instances of both Agent1 and Agent2. They will send themselves 1 message. + */ + @SuppressWarnings("unused") + public static void main(String[] argss) { + new Madkit("--launchAgents", Agent1.class.getName() + ",true,2;", Agent2.class.getName() + ",true,2;"); + } + + /* + * Setting where the agent's window will be. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(550, 350 * (hashCode() - 4)); + } +} diff --git a/release/src/communication/ex04/Agent3.java b/release/src/communication/ex04/Agent3.java new file mode 100644 index 0000000..e174acf --- /dev/null +++ b/release/src/communication/ex04/Agent3.java @@ -0,0 +1,72 @@ +package communication.ex04; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * This Agent3 is communicating using another method than Agent 1 and 2. + */ +public class Agent3 extends Agent { + + /* + * This Activate period is almost the same as Agent 1 and 2, the difference is that this Agent 3 create is own Role. + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroup("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest3"); + pause(500); + } + + /** + * Agent3 is sending his message in a loop, until this message is successfully sent to another Agent having the Role + * "RoleTest1". + */ + @Override + protected void live() { + ReturnCode code = null; + + // Until we succeed in sending a message to an agent (in the group GroupTest in the community communication with the + // role RoleTest1). + while (code != ReturnCode.SUCCESS) { + // If several agents match, the target is chosen randomly. + code = sendMessage("communication", "GroupTest", "RoleTest1", new Message()); + pause((int) (Math.random() * 1000 + 100)); + } + + while (nextMessage() != null) + pause(6000); + pause(6000); + } + + /** + * @param argss + * Running Agent1 will launch 2 Agent1 and 2 Agent2. They will send themselves 1 message. + */ + public static void main(String[] argss) { + new Madkit("--launchAgents", Agent1.class.getName() + ",true,1;", // During his the live() period, Agent 1 will first try to found an Agent with the role "RoleTest2", than + // he will find Agend3 ("RoleTest3"). + Agent3.class.getName() + ",true,1;"); + } + + /** + * Setting where the agent's window will be. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(550, 100); + } + +} diff --git a/release/src/communication/ex05/Agent4.java b/release/src/communication/ex05/Agent4.java new file mode 100644 index 0000000..7cbf85c --- /dev/null +++ b/release/src/communication/ex05/Agent4.java @@ -0,0 +1,75 @@ +package communication.ex05; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.AgentAddress; +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.Option; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * Agent4 will get an agent's address, and then send his message using sendMessageWithRole. + */ + +public class Agent4 extends Agent { + + /** + * Firstly, taking position in the artificial society (having a RoleTest4). + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroup("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest4"); + pause(500); + } + + @Override + protected void live() { + AgentAddress other = null;// other will contain the Agent's address. + while (other == null)// Until we found an Agent having "("communication","GroupTest","RoleTest4")". + { + other = getAgentWithRole("communication", "GroupTest", "RoleTest4"); + pause(1000); + + if (other == null)// Or an Agent having "("communication","GroupTest","RoleTest5")". + { + other = getAgentWithRole("communication", "GroupTest", "RoleTest5"); + } + pause(1000); + } + getLogger().info("\n\tI found someone !!\n" + other + "\n\n");// Displaying our Agent properties (the one we founded). + pause(1000); + + sendMessageWithRole(other, new Message(), "RoleTest4");// Sending the message specifying the sender's role. + + while (nextMessage() != null) + pause(6000); + } + + /** + * @param argss + * Running Agent4 will launch 2 Agent4. + */ + public static void main(String[] argss)// Launching two Agent4. + { + new Madkit(Option.launchAgents.toString(), Agent4.class.getName() + ",true,2;"); + } + + /* + * Setting where the agent's window will be for a clear presentation. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(100, 350 * (hashCode() - 2)); + } +} \ No newline at end of file diff --git a/release/src/communication/ex05/Agent5.java b/release/src/communication/ex05/Agent5.java new file mode 100644 index 0000000..53cfa5f --- /dev/null +++ b/release/src/communication/ex05/Agent5.java @@ -0,0 +1,71 @@ +package communication.ex05; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.AgentAddress; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * Agent5 is almost like Agent4, the only difference is their roles. + */ + +public class Agent5 extends Agent { + + /* + * Firstly, taking position in the artificial society (having a RoleTest5). + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroup("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest5"); + pause(500); + } + + /* + * First getting an Agent address, and then sending him a message. + */ + @Override + protected void live()// In this live period, Agent5 is doing exactly the same as Agent4, with a different role (RoleTest5). + { + AgentAddress other = null; + while (other == null) { + other = getAgentWithRole("communication", "GroupTest", "RoleTest4"); + pause(1000); + } + + getLogger().info("\n\tI found someone !!\n" + other + "\n\n"); + pause(1000); + + sendMessageWithRole(other, new Message(), "RoleTest5"); + + while (nextMessage() != null) + pause(6000); + } + + /** + * @param argss + * Launching one Agent4 and one Agent 5. + */ + public static void main(String[] argss) { + new Madkit("--launchAgents", Agent4.class.getName() + ",true,1;", Agent5.class.getName() + ",true,1;"); + } + + /* + * Setting where the agent's window will be for a clear presentation. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(100, 350 * (hashCode() - 2)); + } +} diff --git a/release/src/communication/ex06/Agent6.java b/release/src/communication/ex06/Agent6.java new file mode 100644 index 0000000..79307d3 --- /dev/null +++ b/release/src/communication/ex06/Agent6.java @@ -0,0 +1,70 @@ +package communication.ex06; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. + * + * + * + * + * Agent6 won't get an agent address, he will send him a message using sendMessageWithRole. + * + * @author Authors ARAGON Joseph and WAGNER Pascal. + */ + +public class Agent6 extends Agent { + + /* + * Firstly, taking position in the artificial society (having a RoleTest6). + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroupIfAbsent("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest6"); + pause(500); + } + + /** + * Trying to send a message in a loop until this Agent succeeds sending a message with sendMessageWithRole. + */ + @Override + protected void live() { + ReturnCode code = null; + while (code != ReturnCode.SUCCESS)// Until we succeed sending the message. + { + // Sending a message to an Agent having a RoleTest7 Specifying Agent6's role. + code = sendMessageWithRole("communication", "GroupTest", "RoleTest7", new Message(), "RoleTest6"); + pause(3000); + } + while (nextMessage() != null) + pause(6000); + } + + /** + * @param argss + * It will run one Agent6 and one Agent7. + */ + @SuppressWarnings("unused") + public static void main(String[] argss)// Launching two agents, Agent6 and Agent7. + { + new Madkit("--launchAgents", Agent6.class.getName() + ",true,1;", Agent7.class.getName() + ",true,1;"); + } + + /* + * Setting where the agent's window will be for a clear presentation. + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(100, 350 * (hashCode() - 2)); + } + +} \ No newline at end of file diff --git a/release/src/communication/ex06/Agent7.java b/release/src/communication/ex06/Agent7.java new file mode 100644 index 0000000..e25bc21 --- /dev/null +++ b/release/src/communication/ex06/Agent7.java @@ -0,0 +1,47 @@ +package communication.ex06; + +import java.util.logging.Level; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.Message; + +/** + * Shows how agents exchange messages. As in previous examples, Agent7 is doing the same job as Agent6, having a + * RoleTest7. + * + * @author Authors ARAGON Joseph and WAGNER Pascal. + */ + +public class Agent7 extends Agent { + + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + createGroupIfAbsent("communication", "GroupTest"); + requestRole("communication", "GroupTest", "RoleTest7"); + pause(500); + } + + /* + * Trying to send a message in a loop until this Agent succeeds sending a message with sendMessageWithRole. + */ + @Override + protected void live() { + ReturnCode code = null; + + while (code != ReturnCode.SUCCESS) { + code = sendMessageWithRole("communication", "GroupTest", "RoleTest6", new Message(), "RoleTest7"); + pause(2000); + } + while (nextMessage() != null) + pause(6000); + } + + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(500, 100); + } +} diff --git a/release/src/gui/ex01_defaultGUI/DefaultGUIAgent.java b/release/src/gui/ex01_defaultGUI/DefaultGUIAgent.java new file mode 100644 index 0000000..13f71de --- /dev/null +++ b/release/src/gui/ex01_defaultGUI/DefaultGUIAgent.java @@ -0,0 +1,43 @@ +package gui.ex01_defaultGUI; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +/** + * Shows how the default GUI mechanism works in MaDKit 5. + * + * + * The only thing to do for obtaining a default GUI for an agent is to launch it with the GUI parameter set to true. + * This could be done either in the MaDKit arguments or when launching an agent. + */ + +public class DefaultGUIAgent extends Agent { + + @Override + protected void activate() { + + getLogger().info( + "I have a default GUI which is automatically created for me \n because there was \n " + "--launchAgents " + getClass().getName() + ",true \n on the command line"); + pause(2000); + } + + @Override + protected void live() { + getLogger().info("I now launch two hello world agents:\n one with a GUI and one without"); + pause(1000); + // the one with no GUI: default argument for launchAgent + launchAgent(new helloworld.ex01.HelloWorldAgent()); + // the one with a GUI: adding the GUI parameter to launchAgent + launchAgent(new helloworld.ex01.HelloWorldAgent(), true); + pause(2000); + } + + /** + * @param args + */ + public static void main(String[] argss) { + String[] args = { "--launchAgents", DefaultGUIAgent.class.getName() + ",true" }; + Madkit.main(args); + } + +} diff --git a/release/src/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java b/release/src/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java new file mode 100644 index 0000000..fa4fcad --- /dev/null +++ b/release/src/gui/ex02_overridingDefaultsettings/OverridingDefaultSettings.java @@ -0,0 +1,42 @@ +package gui.ex02_overridingDefaultsettings; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +/** + * Shows how to override the default frame settings of the default GUI. + * + * + * When an agent is launched with a GUI, the setupFrame method is automatically called before activate. This method is + * the opportunity for the agent to modify the default settings of the frame. + */ + +public class OverridingDefaultSettings extends Agent { + + @Override + public void setupFrame(AgentFrame frame) { + // adds the default output panel + super.setupFrame(frame); + + // Overriding default settings + frame.setTitle("Overriding Default Frame Behavior"); + frame.setLocation(200, 200); + frame.setSize(500, 500); + } + + @Override + protected void live() { + getLogger().info("\n\tDo you see I changed my frame settings ?"); + pause(5000); + } + + /** + * @param args + */ + public static void main(String[] argss) { + String[] args = { "--launchAgents", OverridingDefaultSettings.class.getName() + ",true" }; + Madkit.main(args); + } + +} diff --git a/release/src/gui/ex03_customPanel/CustomPanel.java b/release/src/gui/ex03_customPanel/CustomPanel.java new file mode 100644 index 0000000..c284a3e --- /dev/null +++ b/release/src/gui/ex03_customPanel/CustomPanel.java @@ -0,0 +1,57 @@ +package gui.ex03_customPanel; + +import java.awt.BorderLayout; +import java.awt.Color; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import madkit.gui.AgentFrame; +import madkit.gui.OutputPanel; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +/** + * Shows how to set a custom panel to the default frame. + * + * + * In this example, we customize the default frame layout. Doing so, we still use the madkit.gui.OutputPanel component + * to ease the work. + */ + +public class CustomPanel extends Agent { + + @Override + public void setupFrame(AgentFrame frame) { + JPanel p = new JPanel(new BorderLayout()); + + // customizing but still using the madkit.gui.OutputPanel component + JPanel talkPanel = new OutputPanel(this); + talkPanel.setBackground(Color.LIGHT_GRAY); + p.add(talkPanel, BorderLayout.CENTER); + + //Add the image to the frame + p.add(new JLabel(new ImageIcon(getClass().getResource("agent.png"))), BorderLayout.NORTH); + + frame.add(p); + frame.setLocation(200, 0); + frame.setSize(400, 500); + } + + @Override + protected void live() { + getLogger().info("\n\tDo you see my customized panel ?"); + pause(10000); + } + + /** + * @param argss + */ + public static void main(String[] argss) { + //To display the panel of an agent, before that we always need to set the MadKit kernel online + String[] args = { "--launchAgents", CustomPanel.class.getName() + ",true" }; + Madkit.main(args); + } + +} diff --git a/release/src/gui/ex03_customPanel/agent.png b/release/src/gui/ex03_customPanel/agent.png new file mode 100644 index 0000000..37383a3 Binary files /dev/null and b/release/src/gui/ex03_customPanel/agent.png differ diff --git a/release/src/gui/ex04_independentGUI/IndependentGUI.java b/release/src/gui/ex04_independentGUI/IndependentGUI.java new file mode 100644 index 0000000..9adae9b --- /dev/null +++ b/release/src/gui/ex04_independentGUI/IndependentGUI.java @@ -0,0 +1,93 @@ +package gui.ex04_independentGUI; + +import java.awt.BorderLayout; +import java.awt.Color; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenuBar; +import javax.swing.JPanel; + +import gui.ex03_customPanel.CustomPanel; +import madkit.gui.OutputPanel; +import madkit.gui.menu.AgentLogLevelMenu; +import madkit.gui.menu.AgentMenu; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +/** + * Shows how to build a totally independent GUI for an agent. + * + * + * Not using the default GUI mechanism of course makes the source code much more longer without any real benefits here. + * So, it is safe to say that the default mechanism should be used almost always. This because: (1) the default + * mechanism does not prevent a full control over the created frame. (2) the life cycle of the agent is automatically + * related with the frame's, so that nothing has to be added. Still, there are of course cases where it could be a + * convenient solution. Especially, it could be interesting to use both the default mechanism and an independent GUI for + * developing/debugging purposes like in the next example. + */ + +public class IndependentGUI extends Agent { + + private JFrame myFrame; + + /** + * building my own GUI here + */ + @Override + protected void activate() { + myFrame = new JFrame("My own title"); + + JPanel p = new JPanel(new BorderLayout()); + + JPanel talkPanel = new OutputPanel(this); + talkPanel.setBackground(Color.LIGHT_GRAY); + p.add(talkPanel, BorderLayout.CENTER); + + p.add(new JLabel(new ImageIcon(CustomPanel.class.getResource("agent.png"))), BorderLayout.NORTH); + + myFrame.add(p); + // but still getting some help from madkit.gui components + JMenuBar menuBar = new JMenuBar(); + menuBar.add(new AgentMenu(this)); + menuBar.add(new AgentLogLevelMenu(this)); + myFrame.setJMenuBar(menuBar); + + myFrame.setSize(400, 500); + myFrame.setLocationRelativeTo(null);// centered + + // Beware that end will not be called + // if the frame is closed by the user... + myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + myFrame.setVisible(true); + } + + @Override + protected void live() { + getLogger().info("\n\tI have defined my own frame,\n\twith some predefined menus, though"); + pause(5000); + } + + /** + * I have to close the frame myself because its life cycle is not managed by the MaDKit kernel. + */ + @Override + protected void end() { + myFrame.dispose(); + + System.exit(0); + } + + /** + * @param argss + * unused here + */ + public static void main(String[] argss) { + String[] args = { "--launchAgents", IndependentGUI.class.getName() }; + // + ",false" }; would not change anything as it is the default setting + Madkit.main(args); + } + +} diff --git a/release/src/gui/ex05_multi_GUI/MultiGUI.java b/release/src/gui/ex05_multi_GUI/MultiGUI.java new file mode 100644 index 0000000..4fa2696 --- /dev/null +++ b/release/src/gui/ex05_multi_GUI/MultiGUI.java @@ -0,0 +1,71 @@ +package gui.ex05_multi_GUI; + +import java.awt.BorderLayout; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + +import gui.ex03_customPanel.CustomPanel; +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +/** + * Shows how to build a totally independent GUI while still using a default GUI for the agent. + * + * + * The idea is that it could be interesting to have several GUI for an agent: A main and the default which could be used + * as a console for the agent. + */ + +public class MultiGUI extends Agent { + + private JFrame myFrame; + + /** + * building my own GUI here + */ + @Override + protected void activate() { + myFrame = new JFrame("My GUI"); + myFrame.add(new JLabel(new ImageIcon(CustomPanel.class.getResource("agent.png"))), BorderLayout.CENTER); + myFrame.setSize(400, 500); + myFrame.setLocation(100, 100);// centered + myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + myFrame.setVisible(true); + } + + /** + * But still customizing the default GUI if activated + */ + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(500, 100); + } + + @Override + protected void live() { + getLogger().info("\n\tI have defined my personnal frame,\n\tbut this is displayed in my default GUI"); + pause(10000); + } + + /** + * I have to close the frame myself because its life cycle is not managed by the MaDKit kernel. + */ + @Override + protected void end() { + myFrame.dispose(); + } + + /** + * @param argss + * unused here + */ + public static void main(String[] argss) { + String[] args = { "--launchAgents", MultiGUI.class.getName() + ",true" }; + Madkit.main(args); + } + +} diff --git a/release/src/helloworld/ex01/HelloWorldAgent.java b/release/src/helloworld/ex01/HelloWorldAgent.java new file mode 100644 index 0000000..6193ba9 --- /dev/null +++ b/release/src/helloworld/ex01/HelloWorldAgent.java @@ -0,0 +1,64 @@ +package helloworld.ex01; + +import madkit.kernel.Agent; + +/** + + As of MaDKit-5, one source file can be enough to launch a MAS. + + Here we just : + + 1. extend the madkit.kernel.Agent class (the MaDKit's threaded agent class). + 2. override its live method. + 3. launch the agent using executeThisAgent() within the main method. + + */ + +public class HelloWorldAgent extends Agent { + + @Override + protected void live() { + getLogger().info("\t Hello World! \n"); // This has several advantages over using System.out.println(). + // There is a tutorial about the logging mechanism of MaDKit-5. + for (int i = 10; i > 0; i--) { + getLogger().info("Living... I will quit in " + i + " seconds"); + pause(1000); // pauses the agent's thread for 1000 ms + } + } + + /** live() here is a method which is called automatically. It will be explained later in the next tutorial + * ex03(agentlifecycle) **/ + + public static void main(String[] args) { + executeThisAgent(); // a convenient static method for easily launching agents using an IDE + } + + /** + + Implementing a main method within an agent's class is not required at all but it could be + used to simulate a command line call to MaDKit with the desired options. + + For this example, the corresponding command line is as follows (assuming a correct classpath) + + > java madkit.kernel.MaDKit --launchAgents helloworld.ex01.HelloWorldAgent,true + + Here we just use the executeThisAgent() method inside the main method + so that the launching is greatly simplified using an IDE. + + Here we could also have used: + + public static void main(String[] args) { + new Madkit("--launchAgents", "helloworld.ex01.HelloWorldAgent,true"); + } + + Or + + public static void main(String[] args) { + String[] args2 = { "--launchAgents", "helloworld.ex01.HelloWorldAgent,true" }; + Madkit.main(args2); + } + + All of these calls are equivalent. + + */ +} \ No newline at end of file diff --git a/release/src/helloworld/ex02/AgentLifeCycle.java b/release/src/helloworld/ex02/AgentLifeCycle.java new file mode 100644 index 0000000..6303ee1 --- /dev/null +++ b/release/src/helloworld/ex02/AgentLifeCycle.java @@ -0,0 +1,52 @@ +package helloworld.ex02; + +import madkit.kernel.Agent; + +/** + + The default life cycle of a threaded agent is composed of three methods + which are automatically called sequentially, and each of which being optional: + + 1. activate(): The first behavior in the life cycle of an agent. + It could be considered as a constructor which is called once the agent is launched. + The agent cannot use agent primitives before that (e.g. in its constructor). + Activate is a good place to initialize the agent's position in the artificial society. + (Artificial society is a notion that will be explained later in the tutorials) + + 2. live(): This behavior is automatically called when the agent exits activate. It usually + implements an infinite loop wherein the agent send and receive messages: + It corresponds to the life of the agent. Here the agent lives 10 seconds and quits. + + 3. end() this behavior is automatically called when live exits or when the agent is killed, + e.g. by the user when closing the agent's GUI. + It is usually used to release resources and log the end of life event. + +*/ + +public class AgentLifeCycle extends Agent { + + @Override + protected void activate() { + getLogger().info("\tHello World!!\n\n\tI am activating..."); + pause(2000); + } + + @Override + protected void live() { + int nb = 10; + while (nb-- > 0) { + getLogger().info("Living... I will quit in " + nb + " seconds"); + pause(1000); + } + } + + @Override + protected void end() { + getLogger().info("Bye bye !"); + pause(2000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} diff --git a/release/src/helloworld/ex03/LaunchingTwoAgentsA.java b/release/src/helloworld/ex03/LaunchingTwoAgentsA.java new file mode 100644 index 0000000..d1397e5 --- /dev/null +++ b/release/src/helloworld/ex03/LaunchingTwoAgentsA.java @@ -0,0 +1,40 @@ +package helloworld.ex03; + +import madkit.kernel.Agent; + +/** + + By default {@link #executeThisAgent()} launches one agent with a GUI. + However, we can add parameters to launch more agents or add other options. + + Let us launch two similar agents by using executeThisAgent(int, boolean, String...). + + */ + +public class LaunchingTwoAgentsA extends Agent { + + @Override + protected void activate() { + getLogger().info("Hello, my name is "+getName()); + /* + The agent's default name is built using its class + its ID (instantiation number). + Here the name should be LaunchingTwoAgents-02 and -03. + This is because two agents were priorly launched: (0) The kernel agent & (1) The GUI manager + */ + } + + @Override + protected void live() { + getLogger().info("We are 2 agents but our GUI has not been managed"); + for (int i = 10; i > 0; i--) { + getLogger().info("Living... I will quit in " + i + " seconds"); + pause(1000); + } + } + + public static void main(String[] args) { + // the first parameter is the number of agents to launch + // the second specifies if a GUI should be installed or not for the agents + executeThisAgent(2, true); + } +} diff --git a/release/src/helloworld/ex03/LaunchingTwoAgentsB.java b/release/src/helloworld/ex03/LaunchingTwoAgentsB.java new file mode 100644 index 0000000..752782d --- /dev/null +++ b/release/src/helloworld/ex03/LaunchingTwoAgentsB.java @@ -0,0 +1,49 @@ +package helloworld.ex03; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; + +/** + + By default, the GUI of an agent is placed in the center of the screen. + So probably that the agents of the previous example were not visible at first sight... + + Let us change this default location by overriding the {@link #setupFrame} method, which + allows to modify the default GUI's characteristics. + + First we import the AgentFrame class to Override one of its method : setupFrame(AgentFrame frame) + + Here, the trick is to use the hashCode() method to distinguish the agents. + Indeed, each agent has a unique hashcode corresponding to their instantiation number. + So one can use this hashcode to place similar agents at different locations. + + + */ + +public class LaunchingTwoAgentsB extends Agent { + + @Override + protected void activate() { + getLogger().info("Hello, my name is "+getName()); + } + + @Override + protected void live() { + getLogger().info("Our GUI is managed !"); + for (int i = 10; i > 0; i--) { + getLogger().info("Living... I will quit in " + i + " seconds"); + pause(1000); + } + } + + //We override the setupFrame method in the agent class to change the GUI position + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setLocation(hashCode()*150, hashCode()*150); + } + + public static void main(String[] args) { + executeThisAgent(2, true); + } +} diff --git a/release/src/helloworld/ex04/AddingParametersToExecuteThisAgent.java b/release/src/helloworld/ex04/AddingParametersToExecuteThisAgent.java new file mode 100644 index 0000000..dd8c7db --- /dev/null +++ b/release/src/helloworld/ex04/AddingParametersToExecuteThisAgent.java @@ -0,0 +1,38 @@ +package helloworld.ex04; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit.BooleanOption; + +/** + If you used Java web start and did not open its console, + maybe that you did not see anything in the previous example as the agents were launched without a GUI. + + executeThisAgent(int, boolean, String...) can also take + additional parameters, especially MaDKit options such as + specified in the madkit.kernel.Madkit.BooleanOption enumeration. + + Let us add the BooleanOption#console option to request the launching of the madkit.gui.ConsoleAgent, + which is a specific agent embedded that gathers all System.out outputs + in its own GUI, so that we can also see the outputs of agents that have no GUI. + + + */ + +public class AddingParametersToExecuteThisAgent extends Agent { + + @Override + protected void live() { + int nb = 10; + while (nb-- > 0) { + getLogger().info("Living... I will quit in " + nb + " seconds"); + pause(1000); + } + getLogger().info("Bye !!"); + } + + public static void main(String[] args) { + executeThisAgent(3, false, BooleanOption.console.toString()); + // which is strictly equivalent to + // executeThisAgent(3, false, "--console"); + } +} diff --git a/release/src/helloworld/ex04/ThreeAgentsWithNoGUI.java b/release/src/helloworld/ex04/ThreeAgentsWithNoGUI.java new file mode 100644 index 0000000..f9d2cdb --- /dev/null +++ b/release/src/helloworld/ex04/ThreeAgentsWithNoGUI.java @@ -0,0 +1,28 @@ +package helloworld.ex04; + +import madkit.kernel.Agent; + +/** + + Let us try executeThisAgent(int, boolean, String...) with no GUI for the agents. + + + */ + +public class ThreeAgentsWithNoGUI extends Agent { + + @Override + protected void live() { + for (int i = 10; i > 0; i--) { + getLogger().info("Living... I will quit in " + i + " seconds"); + pause(1000); // pauses the agent's thread for 1000 ms + } + getLogger().info("Bye !!"); + } + + public static void main(String[] args) { + // the first parameter is the number of agents to launch + // the second specifies if a GUI should installed or not for the agents -> no GUI here + executeThisAgent(3, false); + } +} diff --git a/release/src/helloworld/ex05/DesktopHelloWorld.java b/release/src/helloworld/ex05/DesktopHelloWorld.java new file mode 100644 index 0000000..5936b1e --- /dev/null +++ b/release/src/helloworld/ex05/DesktopHelloWorld.java @@ -0,0 +1,32 @@ +package helloworld.ex05; + +import madkit.kernel.Madkit; + +/** + Here, we just test the desktop mode of MaDKit-5. + + + The Desktop is a GUI front end embedding the agents and which features different actions that can help developing + applications. The Desktop do not quit when there is no more active agents, contrary to all the previous examples. + */ +public class DesktopHelloWorld { + + /** + + The only thing to do is to pass the --desktop parameter to the main method of MaDKit. + + */ + public static void main(String[] args) { + String[] args2 = { "--desktop", "--launchAgents", "helloworld.ex01.HelloWorldAgent,true" }; + Madkit.main(args2); + } + + /* + What we used here is exactly the same as : + public static void main(String[] args) { + String[] argss = {BooleanOption.desktop.toString(),Madkit.Option.launchAgents.toString(),HelloWorldAgent.class.getName()+",true"}; + Madkit.main(argss); + } + */ + +} diff --git a/release/src/logging/ex01a_intro/LogMessage.java b/release/src/logging/ex01a_intro/LogMessage.java new file mode 100644 index 0000000..fbb046f --- /dev/null +++ b/release/src/logging/ex01a_intro/LogMessage.java @@ -0,0 +1,36 @@ +package logging.ex01a_intro; + +import madkit.kernel.Agent; + +/** + * This tutorial is about the agent's logger attribute which is an alternative to the method System.out.println(). In + * fact the logger can do the same thing as System.out.println() : displaying message on the screen but it does many + * other things. The logger is an instance of the AgentLogger class of the MaDKit library which extends the Logger class + * of the Java SE. In this tutorial we will see why and how the logger replaces the method System.out.println() in + * MaDKit. In the different examples of this tutorial we will see : - how to log a message - the different log levels - + * the "finest" level particular features - how to create a log file - how to choose the log directory Firstly, we just + * display a message to the screen with the method AgentLogger#info(String) of the getLogger(). A simple agent is used, + * which has a default GUI, lives 10 seconds and quits. During the life of the agent, we show how to log an "info" + * message. As you will see, by default this message is displayed in both the output console and the agent's GUI + * + * + * + * + * + * + * @author Pascal Wagner + */ + +public class LogMessage extends Agent { + + @Override + protected void live() { + pause(2000); + getLogger().info("This agent logs an 'info' message."); + pause(8000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} diff --git a/release/src/logging/ex01b_levels/LevelMessage.java b/release/src/logging/ex01b_levels/LevelMessage.java new file mode 100644 index 0000000..19cb29a --- /dev/null +++ b/release/src/logging/ex01b_levels/LevelMessage.java @@ -0,0 +1,29 @@ +package logging.ex01b_levels; + +import madkit.kernel.Agent; + +/** + * The main advantage of using the Logger class is that all messages are associated with a level. Indeed, depending on + * the logging method used, a message will have a particular level. This level will have an impact on how the message is + * displayed. In this example, we will log two messages with different levels. You will observe that the messages are + * preceded by their own log level. + * + * + * @author Pascal Wagner + */ + +public class LevelMessage extends Agent { + + @Override + protected void live() { + pause(2000); + getLogger().info("This is a message which has a level 'info'."); + pause(3000); + getLogger().warning("This is a message which has a level 'warning'."); + pause(5000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} diff --git a/release/src/logging/ex01c_levels/MessageWithLevel.java b/release/src/logging/ex01c_levels/MessageWithLevel.java new file mode 100644 index 0000000..c7249df --- /dev/null +++ b/release/src/logging/ex01c_levels/MessageWithLevel.java @@ -0,0 +1,60 @@ +/* + * Copyright 2011-2017 Fabien Michel + * + * This file is part of MaDKit-tutorials. + * + * MaDKit-tutorials is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MaDKit-tutorials is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MaDKit-tutorials. If not, see . + */ +package logging.ex01c_levels; + +import java.util.logging.Level; + +import madkit.kernel.Agent; + +/** + * We have seen how to log a message but it exists several ways to do it. So we will see another way to associate + * different levels to messages and one of messages will not display at the screen. Here we show another method for + * logging a message: Logger#log(Level, String). During the life of this agent, four messages are logged : two 'info' + * messages and two 'config' messages. The last two will not be displayed. The next example of this tutorial explains + * why... + * + * + * + * + * + * @author Pascal Wagner + */ + +public class MessageWithLevel extends Agent { + + @Override + protected void live() { + Level infoLevel = Level.INFO; + Level configLevel = Level.CONFIG; + String infoMessage = "This is an info message."; + String configMessage = "This is a config message."; + pause(2000); + getLogger().info(infoMessage); + pause(3000); + getLogger().log(infoLevel, infoMessage + "\n\nThe two next config messages will not display at the screen."); + pause(3000); + getLogger().config(infoMessage); + getLogger().log(configLevel, configMessage); + pause(3000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} diff --git a/release/src/logging/ex02a_introLogLevel/LogLevel.java b/release/src/logging/ex02a_introLogLevel/LogLevel.java new file mode 100644 index 0000000..0a28406 --- /dev/null +++ b/release/src/logging/ex02a_introLogLevel/LogLevel.java @@ -0,0 +1,60 @@ +/* + * Copyright 2011-2017 Fabien Michel + * + * This file is part of MaDKit-tutorials. + * + * MaDKit-tutorials is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MaDKit-tutorials is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MaDKit-tutorials. If not, see . + */ +package logging.ex02a_introLogLevel; + +import java.util.logging.Level; + +import madkit.kernel.Agent; + +/** + * In the last example, two messages have not been displayed, not because of a mistake in the code but because of their + * level. Indeed, messages are displayed according to the current level of the getLogger(). So the logger acts as a + * filter on the message which are logged: For being logged the message's level has to be higher than the logger's + * level. The idea is that you can have different setting for the logger so that you can have different output modes for + * your agent: From quiet (OFF) to verbose (ALL). The logger's level can be modified with the method + * getLogger().setLevel(). Here, we log a config message and an info message but the first one will not be displayed. + * Then the logger's level is changed so that 'config' messages will appear. + * + * + * + * + * @author Pascal Wager + */ + +public class LogLevel extends Agent { + + @Override + protected void live() { + pause(2000); + getLogger().info("There are two log records but the second will not be displayed.\n"); + getLogger().config("The logger's level is too low to display this message."); + pause(4000); + + getLogger().setLevel(Level.CONFIG); + + getLogger().info("The logger's level has been set to " + Level.CONFIG); + pause(3000); + getLogger().config("So now the config messages can appear\non the screen!"); + pause(8000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} \ No newline at end of file diff --git a/release/src/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java b/release/src/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java new file mode 100644 index 0000000..25f0543 --- /dev/null +++ b/release/src/logging/ex02b_defaultLogLevel/TheDefaultLogLevel.java @@ -0,0 +1,27 @@ +package logging.ex02b_defaultLogLevel; + +import madkit.kernel.Agent; + +/** + * So we can set the log level with getLogger().setLevel() and we will see the different existing levels in the next + * example. Here we go to see the method getLevel() and see the default log level which is used in MaDKit. + * + * + * + * + * @author Pascal Wagner + */ + +public class TheDefaultLogLevel extends Agent { + + @Override + protected void live() { + pause(2000); + getLogger().info("The default log level is : " + getLogger().getLevel()); + pause(8000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} \ No newline at end of file diff --git a/release/src/logging/ex02c_theDifferentLevels/TheDifferentLevels.java b/release/src/logging/ex02c_theDifferentLevels/TheDifferentLevels.java new file mode 100644 index 0000000..d6ec07a --- /dev/null +++ b/release/src/logging/ex02c_theDifferentLevels/TheDifferentLevels.java @@ -0,0 +1,80 @@ +package logging.ex02c_theDifferentLevels; + +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +import madkit.kernel.Agent; +import madkit.kernel.AgentLogger; + +/** + * The java.util.logging.Level class of the Java SE defines a set of standard logging levels that can be used to control + * logging outputs: Here they are in descending order : - severe - warning - info - config - fine - finer - finest In + * addition there is a level OFF that can be used to turn off logging, and a level ALL that can be used to enable the + * logging of all messages. In MaDKit, the {@link AgentLogger#talk(String)} method is added to define an additional + * level which is used log a talk message. This is an example which recaps how to set and get the log level and how we + * display or not messages according to their level. All the levels are used here. + * + * + * + * + * @author Pascal Wagner + */ + +public class TheDifferentLevels extends Agent { + + private static List levels = Arrays.asList(Level.ALL, Level.FINEST, Level.FINER, Level.FINE, Level.CONFIG, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF); + + @Override + protected void activate() { + pause(2000); + } + + @Override + protected void live() { + getLogger().talk("\n\t************************************\n" + "\t The different levels of display\n" + "\t************************************\n\n"); + pause(1000); + + getLogger().talk("\n\nLog level = " + getLogger().getLevel() + " (default Level)\n"); + getLogger().severe("Default log level = " + getLogger().getLevel()); + getLogger().warning("Default log level = " + getLogger().getLevel()); + getLogger().info("Default log level = " + getLogger().getLevel()); + getLogger().config("Default log level = " + getLogger().getLevel()); + getLogger().fine("Default log level = " + getLogger().getLevel()); + getLogger().finer("Default log level = " + getLogger().getLevel()); + getLogger().finest("Default log level = " + getLogger().getLevel()); + pause(2000); + int i = 10; + for (Level l : levels) { + getLogger().talk("\n\nLog level --> " + l + "\n"); + getLogger().setLevel(l); + + getLogger().severe("severe message"); + getLogger().warning("warning message"); + getLogger().info("info message"); + getLogger().config("config message"); + getLogger().fine("fine message"); + getLogger().finer("finer message"); + getLogger().finest("finest message"); + pause(1000 * (i--)); + } + if (getLogger().getLevel() == Level.OFF) { + System.out.println("This message is displayed thanks to System.out.println()\n" + "In fact with the log level OFF neither is displayed.\n"); + pause(2000); + } + getLogger().setLevel(Level.INFO); + + getLogger().talk("\nThe loggger is set back to " + getLogger().getLevel() + "\n\n\n"); + pause(1000); + } + + @Override + protected void end() { + getLogger().info("Bye bye !"); + pause(5000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} \ No newline at end of file diff --git a/release/src/logging/ex03a_levelFinerFinest/LevelFinerFinest.java b/release/src/logging/ex03a_levelFinerFinest/LevelFinerFinest.java new file mode 100644 index 0000000..b9ab480 --- /dev/null +++ b/release/src/logging/ex03a_levelFinerFinest/LevelFinerFinest.java @@ -0,0 +1,48 @@ +package logging.ex03a_levelFinerFinest; + +import java.util.logging.Level; + +import madkit.kernel.AbstractAgent; +import madkit.kernel.Agent; +import madkit.kernel.AgentLogger; +import madkit.kernel.Message; + +/** + * You have surely noticed that some additional finer and finest messages appeared in the console in the last example + * while they did not appear in the code. In fact, finest messages are used to log many of the agent methods defined in + * MaDKit. And the agent's life cycle is traced at the finer level. So, setting the logger's level to finer, finest or + * all represents a very easy way of debugging MaDKit agents ! Here, we just set the logger's level to all to show that + * there are log messages which are displayed whereas there is no explicit code here. notes : - agent's life is composed + * by the methods : activate(), live() and end(). - the different pauses are only there for you to see the agent's life + * cycle. + * + * + * + * + * @author Pascal Wagner + */ + +public class LevelFinerFinest extends Agent { + + @Override + protected void activate() { + getLogger().setLevel(Level.ALL); + pause(5000); + } + + @Override + protected void live() { + Message m = nextMessage(); /** In MaDKit, the {@link AbstractAgent#nextMessage()} method is added to + retrieves and removes the oldest received message contained in the mailbox. */ + pause(5000); + } + + @Override + protected void end() { + pause(5000); + } + + public static void main(String[] args) { + executeThisAgent(); + } +} \ No newline at end of file diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_1_Console.java b/release/src/madkitoptions/ex1_BooleanOptions/_1_Console.java new file mode 100644 index 0000000..2259fd9 --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_1_Console.java @@ -0,0 +1,37 @@ +/** + * READ ME + * + * This tutorial is about MaDKit options. An option is a feature that may be specified or activated. + * You can find more details here : http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/. + * MaDKit options are divided in three categories : + * - Boolean Options + * - Level Options + * - MaDKit Options + * + * In this first set of examples, we will present you Boolean Options. + * Among the others options, boolean options are either activated or not. + */ + +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; + +/** + * This class exemplifies the use of the console option. + * If this boolean option is set to true, the MaDKit console agent is launched. + * The default value is false. + * + * + */ + +public class _1_Console { + + public static void main(String[] args) { + + /* If no boolean is specified, MaDKit considers it as true */ + new Madkit(Madkit.BooleanOption.console.toString()); /* Equivalent to : new Madkit(Madkit.BooleanOption.console.toString(), Boolean.TRUE.toString()); */ + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + // new Madkit(Madkit.BooleanOption.console.toString(), Boolean.FALSE.toString()); + } +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java b/release/src/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java new file mode 100644 index 0000000..8ecfd9c --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_2_CgrWarnings.java @@ -0,0 +1,34 @@ +package madkitoptions.ex1_BooleanOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + +/** + * This class exemplifies the use of cgrWarnings's option. + * If this boolean option is set to true, warnings concerning + * Community/Group/Role notifications are activated. + * The default value is false. + * + */ + +public class _2_CgrWarnings extends TutorialAgent{ + + @Override + protected void activate() { + requestRole("COMMUNITY", "GROUP", "ROLE"); + /** + * By requesting a role in a community that does not exist, + * our agent will cause a CGR warning. + */ + } + + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.cgrWarnings.toString(), Madkit.Option.launchAgents.toString(), _2_CgrWarnings.class.getName() + " ,true,1", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString()); + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + // new Madkit(Madkit.BooleanOption.cgrWarnings.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), _2_Agent.class.getName() + " ,true,1", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString()); + } +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_3_Debug.java b/release/src/madkitoptions/ex1_BooleanOptions/_3_Debug.java new file mode 100644 index 0000000..639fa60 --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_3_Debug.java @@ -0,0 +1,23 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + +/** + * This class exemplifies the use of debug's option. + * If this boolean option is set to true, all the agents' LogLevel are set to "ALL". + * The default value is false. + * + */ + +public class _3_Debug { + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.debug.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + ",true,1;"); + + /* Check the difference by commenting the previous line and uncommenting the next one. + * You should have less log displayed + */ + // new Madkit(Madkit.BooleanOption.debug.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + ",true,1;"); + } +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_4_Desktop.java b/release/src/madkitoptions/ex1_BooleanOptions/_4_Desktop.java new file mode 100644 index 0000000..b2c899e --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_4_Desktop.java @@ -0,0 +1,30 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; + +/** + * This class exemplifies the use of desktop's option. + * If this boolean option is set to true, MaDKit desktop is launched. + * The default value is false. + * + */ +public class _4_Desktop { + + /** + * Despite default value being "false", if this property is not explicitly set + * to "false" and if Madkit.Option.launchAgents and Madkit.Option.configFile + * are both null, then the desktop mode will be automatically set to true + * during startup. + */ + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.desktop.toString()); + + /* Notice that it is the same behavior as the next line */ + // new Madkit(Madkit.Option.launchAgents.toString(), "null", Madkit.Option.configFile.toString(), "null"); + + /* Nevertheless if we specify it... There is not any MaDKit desktop displayed. */ + // new Madkit(Madkit.BooleanOption.desktop.toString(), Boolean.FALSE.toString()); + } + +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java b/release/src/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java new file mode 100644 index 0000000..6b3bd52 --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_5_CreateLogFiles.java @@ -0,0 +1,26 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + +/** + * This class exemplifies the use of createLogFiles' option. + * If this boolean option is set to true, then file(s) storing + * the logs of every MaDKit's agent with a log level greater + * than the "OFF" level will be created. These file(s) are generated + * in a "logs" directory which is created in the working directory (the project's root in eclipse by default). + * The default value is false. + * + */ + +public class _5_CreateLogFiles { + + public static void main(String[] args) { + + /** + * Do not forget to check in the "logs" directory (root of + * the imported project) to see the generated file. + */ + new Madkit(Madkit.BooleanOption.createLogFiles.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName()); + } +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java b/release/src/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java new file mode 100644 index 0000000..f716c63 --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_6_NoAgentConsoleLog.java @@ -0,0 +1,27 @@ +package madkitoptions.ex1_BooleanOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + +/** + * This class exemplifies the use of noAgentConsoleLog's option. + * If this boolean option is set to true, there is no log displayed + * in the default console used by the jvm. + * The default value is false. + * + * + */ + +public class _6_NoAgentConsoleLog { + + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.noAgentConsoleLog.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + " ,true, 2", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString()); + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + //new Madkit(Madkit.BooleanOption.noAgentConsoleLog.toString(), Boolean.FALSE.toString(), Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName() + " ,true, 2", Madkit.LevelOption.agentLogLevel.toString(), Level.SEVERE.toString()); + } + +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java b/release/src/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java new file mode 100644 index 0000000..a86f238 --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_7_LoadLocalDemos.java @@ -0,0 +1,27 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; + +/** + * This class exemplifies the use of loadLocalDemos + * option. This option load all the demos that are + * available so far. + * If this boolean is set to true, you can access + * to all of the demos and launch them in the + * "MAS" tab of MaDKit GUI (graphical user interface). + * The default value is false. + * + * + */ + +public class _7_LoadLocalDemos { + + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.loadLocalDemos.toString()); + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + // new Madkit(Madkit.BooleanOption.loadLocalDemos.toString(), Boolean.FALSE.toString()); + } + +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_8_Network.java b/release/src/madkitoptions/ex1_BooleanOptions/_8_Network.java new file mode 100644 index 0000000..8fc552b --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_8_Network.java @@ -0,0 +1,25 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; + +/** + * This class exemplifies the use of network's option. + * If this boolean option is set to true, MaDKit starts + * the network on startup. By "network" we imply the ability + * for MaDKit to be connected to another MaDKit app. + * The default value is false. + * + * + */ + +public class _8_Network { + + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.network.toString()); + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + // new Madkit(Madkit.BooleanOption.network.toString(), Boolean.FALSE.toString()); + } + +} diff --git a/release/src/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java b/release/src/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java new file mode 100644 index 0000000..7c0d9fb --- /dev/null +++ b/release/src/madkitoptions/ex1_BooleanOptions/_9_AutoConnectMadkitWebsite.java @@ -0,0 +1,25 @@ +package madkitoptions.ex1_BooleanOptions; + +import madkit.kernel.Madkit; + +/** + * This class exemplifies the use of autoConnectMaDKitWebsite + * option. If this boolean is set to true, it connects MaDKit + * to the MaDKit repository when launched making all the main classes + * or demos available in the MaDKit gui. + * The default value is false. + * + * + */ + +public class _9_AutoConnectMadkitWebsite { + + public static void main(String[] args) { + + new Madkit(Madkit.BooleanOption.autoConnectMadkitWebsite.toString()); + + /* Check the difference by commenting the previous line and uncommenting the next one. */ + // new Madkit(Madkit.BooleanOption.autoConnectMadkitWebsite.toString(), Boolean.FALSE.toString()); + } + +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java new file mode 100644 index 0000000..4fd4a2e --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_1_MadkitLogLevel.java @@ -0,0 +1,46 @@ +/** + * Now we will interest into Level Options. + * These features are more detailed than Boolean Options, + * and allow slight differences. + * + * There are nine different levels, from : + * + * OFF (turn off logging) + * SEVERE (highest value : the less detailed) + * WARNING + * INFO + * CONFIG + * FINE + * FINER + * FINEST (lowest value : the more detailed) + * ALL (enable all messages) + * + * To understand their nuances you can check the official documentation + * ( https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html?is-external=true ) + * or the logging tutorial. + */ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * This example is about the level option MadkitLogLevel. + * This option allows the specification of MaDKit's log level. + * + */ +public class _1_MadkitLogLevel { + + public static void main(String[] args) { + + /* Displays everything */ + new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.ALL.toString()); + + /* Displays only informational messages */ + //new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.INFO.toString()); + + /* The logging is turned off */ + //new Madkit(Madkit.LevelOption.madkitLogLevel.toString(),Level.OFF.toString()); + } +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java new file mode 100644 index 0000000..8cc06a0 --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_2_AgentLogLevel.java @@ -0,0 +1,24 @@ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * This example is about the level option AgentLogLevel. + * This option allows the specifications of MaDKit agents' + * log level. + * + */ + +public class _2_AgentLogLevel { + + public static void main(String[] args) { + + /* Displays everything */ + new Madkit(Madkit.LevelOption.agentLogLevel.toString(),Level.ALL.toString(), Madkit.Option.launchAgents.toString(), madkitoptions.util.TutorialAgent.class.getName() + ",true,1;"); + + /* Displays only informational messages */ + // new Madkit(Madkit.LevelOption.agentLogLevel.toString(),Level.INFO.toString(), Madkit.Option.launchAgents.toString(), Agent.class.getName() + ",true,1;"); + } +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java new file mode 100644 index 0000000..38a79d9 --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_3_GuiLogLevel.java @@ -0,0 +1,26 @@ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * This example concerns GuiLogLevel's option. + * This option allows the specification of MaDKit + * graphical user interface's log level. + * It is mainly useful for kernel developers. + * + */ + +public class _3_GuiLogLevel { + + public static void main(String[] args) { + + /* Displays everything */ + new Madkit(Madkit.LevelOption.guiLogLevel.toString(),Level.ALL.toString()); + + /* Displays only informational messages */ + // new Madkit(Madkit.LevelOption.guiLogLevel.toString(),Level.INFO.toString()); + } + +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java new file mode 100644 index 0000000..7c958cc --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_4_KernelLogLevel.java @@ -0,0 +1,25 @@ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * This example is about the level option KernelLogLevel. + * This option allows the specification of MaDKit's kernel's + * log level and is extremely useful for debugging. + * It is mainly useful for kernel developers. + * + */ + +public class _4_KernelLogLevel { + + public static void main(String[] args) { + + /* Displays everything */ + new Madkit(Madkit.LevelOption.kernelLogLevel.toString(),Level.ALL.toString()); + + /* Displays only informational messages */ + // new Madkit(Madkit.LevelOption.kernelLogLevel.toString(),Level.INFO.toString()); + } +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java new file mode 100644 index 0000000..bcfbd28 --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_5_NetworkLogLevel.java @@ -0,0 +1,24 @@ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * This example is about the level option NetworkLogLevel. + * This option allows the specification of MaDKit + * network's log level. + * + */ + +public class _5_NetworkLogLevel { + + public static void main(String[] args) { + + /* Displays everything */ + new Madkit(Madkit.LevelOption.networkLogLevel.toString(),Level.ALL.toString()); + + /* Displays only informational messages */ + // new Madkit(Madkit.LevelOption.networkLogLevel.toString(),Level.INFO.toString()); + } +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java b/release/src/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java new file mode 100644 index 0000000..84fc9bd --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_6_AgentWithCGRWarnings.java @@ -0,0 +1,18 @@ +package madkitoptions.ex2_LevelOptions; + +import madkit.kernel.Agent; + +/** + * + * This class outlines how to use enableCGRWarnings(). + * + * + */ +public class _6_AgentWithCGRWarnings extends Agent{ + + @Override + protected void activate() { + getLogger().enableCGRWarnings(); + requestRole("COMMUNITY", "GROUP", "ROLE"); + } +} diff --git a/release/src/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java b/release/src/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java new file mode 100644 index 0000000..feba631 --- /dev/null +++ b/release/src/madkitoptions/ex2_LevelOptions/_6_WarningLogLevel.java @@ -0,0 +1,25 @@ +package madkitoptions.ex2_LevelOptions; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; +import madkitoptions.ex1_BooleanOptions._2_CgrWarnings; + +/** + * This example is about the deprecated option : warningLogLevel. + * + * Since MaDKit v5.2 it is replaced by AgentLogger.enableCGRWarnings(). + * You can check how we use enableCGRWarnings() in the + * _6_AgentWithCGRWarnings class. + * + */ + +public class _6_WarningLogLevel { + + public static void main(String[] args) { + + /* This was how we used the warningLogLevel. Keep in mind that it is now deprecated. */ + new Madkit(Madkit.LevelOption.warningLogLevel.toString(),Level.ALL.toString(), Madkit.Option.launchAgents.toString(), _2_CgrWarnings.class.getName() + " ,true,1"); + + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java b/release/src/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java new file mode 100644 index 0000000..337c56a --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/_1_LaunchAgents.java @@ -0,0 +1,75 @@ +/** + * Now we will interest to other Options. + * These features are no longer valued by boolean nor + * level but with a string. + */ +package madkitoptions.ex3_MadkitOptions; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + + +/** + * + * In this example we will discover how to + * launch agents as soon as a new MaDKit is + * launched. + * + * You may see that there is different ways of doing it, + * that you can launch several agents, or even different + * types of agent. + * + * Feel free to (un)comment the lines to test and + * understand the differences. + * + * + */ + +public class _1_LaunchAgents { + + protected static void pause() throws InterruptedException { + Thread.sleep(7000); + } + + public static void main(String[] args) throws InterruptedException { + + /** + * If nothing else than the class name of the agent to launch is specified, + * MaDKit launch one agent of the precised class without graphical user interface (GUI) + */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName()); + pause(); + + /* The previous line was equivalent to the next one. */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",false,1"); + pause(); + + /* You can decide whether or not the agent has a GUI. */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",true"); + pause(); + + /** + * You can also launch several agents by adding the number + * of wanted agents right after the class name. + */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",3"); + pause(); + + /* Let's launch several agents with a GUI. */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",true,2"); + pause(); + + /* Now, let's launch different kind of agents. */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ";" + Agent.class.getName()); + pause(); + + /** + * Finally, you can note that while launching several (and possibly different) + * agents you don't have to precise everything each time. In that case, + * default values will be used. + */ + new Madkit(Madkit.Option.launchAgents.toString(),TutorialAgent.class.getName() + ",2;" + TutorialAgent.class.getName() + ",true,1;"); + pause(); + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java b/release/src/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java new file mode 100644 index 0000000..13e7be2 --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/_2_ConfigFile.java @@ -0,0 +1,28 @@ +package madkitoptions.ex3_MadkitOptions; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.Option; + +/** + * With the configFile option you can specify a property file that MaDKit will load on startup. + * The configuration file of this example just contains one line: " test=23 " + * If you want extra detail about MaDKit properties, check out the dedicated tutorial. + * + */ + +public class _2_ConfigFile extends Agent { + + @Override + protected void live() { + getLogger().info("getting a property from the loaded file:"); + getLogger().info(getMadkitProperty("test")); + } + + public static void main(String[] args) { + new Madkit( + Madkit.Option.configFile.toString(), "madkitoptions/ex3_MadkitOptions/myPropertyFile.properties", + Option.launchAgents.toString(), _2_ConfigFile.class.getName() + ); + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/_3_DesktopFrame.java b/release/src/madkitoptions/ex3_MadkitOptions/_3_DesktopFrame.java new file mode 100644 index 0000000..1364cca --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/_3_DesktopFrame.java @@ -0,0 +1,29 @@ +package madkitoptions.ex3_MadkitOptions; + +import java.awt.Color; + +import madkit.gui.MDKDesktopFrame; +import madkit.kernel.Madkit; + +/** + * This option allows MaDKit users to + * change MaDKit desktop's display. + * + * Of course, desktopFrameClass need to be associated with an existing + * class, here _3_CustomDesktopFrame. + * + * + * + */ + +public class _3_DesktopFrame extends MDKDesktopFrame{ + + public _3_DesktopFrame() { + super(); + setBackground(Color.BLUE); + } + + public static void main(String[] args) { + new Madkit(Madkit.Option.desktopFrameClass.toString(), _3_DesktopFrame.class.getName()); + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java b/release/src/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java new file mode 100644 index 0000000..fabb315 --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/_4_AgentFrame.java @@ -0,0 +1,33 @@ +package madkitoptions.ex3_MadkitOptions; + +import java.awt.Color; + +import madkit.gui.AgentFrame; +import madkit.kernel.AbstractAgent; +import madkit.kernel.Madkit; + +/** + * This option allows MaDKit users to modify the display of a category of agent. + * + * Of course, agentFrameClass needs to be associated with an existing + * class, here _4_CustomAgentFrame. + * + * + * + */ + +public class _4_AgentFrame extends AgentFrame{ + + public _4_AgentFrame(AbstractAgent agent) { + super(agent); + setBackground(Color.GREEN); + } + + /** + * Now we will launch a TutorialAgent after setting his + * agentFrameClass to _4_CustomAgentFrame. + */ + public static void main(String[] args) { + new Madkit(Madkit.Option.agentFrameClass.toString(), _4_AgentFrame.class.getName(), Madkit.Option.launchAgents.toString(), madkitoptions.util.TutorialAgent.class.getName() + ",true"); + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java b/release/src/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java new file mode 100644 index 0000000..4641965 --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/_5_LogDirectory.java @@ -0,0 +1,28 @@ +package madkitoptions.ex3_MadkitOptions; + +import madkit.kernel.Madkit; +import madkitoptions.util.TutorialAgent; + +/** + * This option allows MaDKit users to specify + * the directory in which the log files should + * be stored. + * + * + */ + +public class _5_LogDirectory { + + public static void main(String[] args) { + + /** + * Here the created directory is : "myLogs". + * We are launching a TutorialAgent to generate logs. + * Do not forget to trigger the creation of log files using "createLogFiles". + */ + new Madkit( + Madkit.Option.logDirectory.toString(), "myLogs", + Madkit.BooleanOption.createLogFiles.toString(), + Madkit.Option.launchAgents.toString(), TutorialAgent.class.getName()); + } +} diff --git a/release/src/madkitoptions/ex3_MadkitOptions/myPropertyFile.properties b/release/src/madkitoptions/ex3_MadkitOptions/myPropertyFile.properties new file mode 100644 index 0000000..5ef4158 --- /dev/null +++ b/release/src/madkitoptions/ex3_MadkitOptions/myPropertyFile.properties @@ -0,0 +1 @@ +test=23 \ No newline at end of file diff --git a/release/src/madkitoptions/util/TutorialAgent.java b/release/src/madkitoptions/util/TutorialAgent.java new file mode 100644 index 0000000..c5ed5a2 --- /dev/null +++ b/release/src/madkitoptions/util/TutorialAgent.java @@ -0,0 +1,34 @@ +/** + * READ ME + * + * This tutorial is about MaDKit options. An option is a feature that may be specified or activated. + * You can find more details here : http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/. + * MaDKit options are divided in three categories : + * - Boolean Options + * - Level Options + * - MaDKit Options + * + * In this first set of examples, we will present you Boolean Options. + * Among the others options, boolean options are either activated or not. + */ + +package madkitoptions.util; + +import madkit.kernel.Agent; + +/** + * This class represents an agent that may be used for this tutorial. + */ + +public class TutorialAgent extends Agent{ + + @Override + protected void activate() { + pause(5000); + } + + @Override + protected void live() { + getLogger().info("\n\t Hello ! I am an instance of Tutorial Agent.\t\n"); + } +} diff --git a/release/src/madkitproperties/PropertyFileToLoad.properties b/release/src/madkitproperties/PropertyFileToLoad.properties new file mode 100644 index 0000000..95cb4c6 --- /dev/null +++ b/release/src/madkitproperties/PropertyFileToLoad.properties @@ -0,0 +1,3 @@ +#some properties +agentLogLevel=FINE +warningLogLevel=FINE diff --git a/release/src/madkitproperties/XMLPropertyFile.xml b/release/src/madkitproperties/XMLPropertyFile.xml new file mode 100644 index 0000000..e2c7de1 --- /dev/null +++ b/release/src/madkitproperties/XMLPropertyFile.xml @@ -0,0 +1,18 @@ + + + + + + +  + + + + + +  + + \ No newline at end of file diff --git a/release/src/madkitproperties/_1_DisplayMadkitProperties.java b/release/src/madkitproperties/_1_DisplayMadkitProperties.java new file mode 100644 index 0000000..7b0a1b3 --- /dev/null +++ b/release/src/madkitproperties/_1_DisplayMadkitProperties.java @@ -0,0 +1,44 @@ +/** + * READ ME + * + * This tutorial enlighten MaDKit properties : what is a property and how to use it. + * As MaDKit is a Java API, you may already be familiar with Java Property. + * If you are not and you want to get used to it before starting this tutorial, you may + * have a look here in the official documentation or with the following tutorial. + * + * Documentation : https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html + * Tutorial : https://docs.oracle.com/javase/tutorial/essential/environment/properties.html + * + * The following exercises introduce how to have a look at the different properties owned by + * MaDKit how to add or modify them and finally, how to store them. + * + * This tutorial is strongly linked with the MaDKit Options tutorial. Indeed, if this + * tutorial presents globally the use of properties, in the Options one, we have a focus on + * each of the default properties that are part of MaDKit configuration. + */ + +package madkitproperties; + +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.LevelOption; + +/** + * A Property is a distinctive feature that may be used for every MaDKit project. + * MaDKit has a configuration which is stored in its internal properties file. + * + * We here present how to display the properties of a MaDKit run at startup. + * + */ +public class _1_DisplayMadkitProperties { + + public static void main(String[] args) { + + /** + * Here we launch a new MaDKit with the option madkitLogLevel activated. + * This property allows all the logs concerning MaDKit to be displayed, these + * logs include MaDKit options. Logs can be seen in the console. + */ + new Madkit( + LevelOption.madkitLogLevel.toString(),"FINER"); + } +} diff --git a/release/src/madkitproperties/_2_ToStringEquivalent.java b/release/src/madkitproperties/_2_ToStringEquivalent.java new file mode 100644 index 0000000..a2b6fc8 --- /dev/null +++ b/release/src/madkitproperties/_2_ToStringEquivalent.java @@ -0,0 +1,36 @@ +package madkitproperties; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.BooleanOption; +import madkit.kernel.Madkit.LevelOption; + +/** + * Each of the default MaDKit properties can be specified while launching MaDKit. + * To do so, you have to specify the name of the wanted option as an argument of the + * Madkit() method. To do so, you have two possibilities,which will be presented in this example. + * + */ +public class _2_ToStringEquivalent { + + public static void main(String[] args) { + + /** + * First you can specify the name of a property preceded by "--". + */ + new Madkit("--madkitLogLevel","FINER","--desktop","false"); + + /** + * However, the previous solution is not absolutely reliable. + * Indeed if the option name is misspelled, then MaDKit does not + * recognize the property. Then, we will prefer the second option. + * + * Note that this way we can benefit from the auto-completion. + */ + new Madkit( + LevelOption.madkitLogLevel.toString(),Level.FINER.toString(), + BooleanOption.desktop.toString(),Boolean.FALSE.toString() + ); + } +} diff --git a/release/src/madkitproperties/_3_ModifyingProperty.java b/release/src/madkitproperties/_3_ModifyingProperty.java new file mode 100644 index 0000000..66bced6 --- /dev/null +++ b/release/src/madkitproperties/_3_ModifyingProperty.java @@ -0,0 +1,22 @@ +package madkitproperties; + +import java.util.logging.Level; + +import madkit.kernel.Madkit; + +/** + * A property has a value that we can change. + * + */ +public class _3_ModifyingProperty { + + /** + * Here we will change the value of the debug property and set it to true. + * The property madkitLogLevel is only here to notice the difference. + */ + public static void main(String[] args) { + new Madkit( + Madkit.BooleanOption.debug.toString(), "true", + Madkit.LevelOption.madkitLogLevel.toString(),Level.FINER.toString()); + } +} diff --git a/release/src/madkitproperties/_4_CreateNewProperty.java b/release/src/madkitproperties/_4_CreateNewProperty.java new file mode 100644 index 0000000..03c125f --- /dev/null +++ b/release/src/madkitproperties/_4_CreateNewProperty.java @@ -0,0 +1,34 @@ +package madkitproperties; + +import java.util.logging.Level; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.LevelOption; +import madkit.kernel.Madkit.Option; + +/** + * You can also create the property you want and give it any value, which will be converted into a string. + * + */ +public class _4_CreateNewProperty extends Agent { + + @Override + protected void live() { + getLogger().info("getting a property passed as a MaDKit argument:"); + getLogger().info("myNewProperty has been set to "+getMadkitProperty("myNewProperty")); + pause(5000); + } + + /** + * Notice the new property among the "Additional non MaDKit options" + * logged at startup. + */ + public static void main(String[] args) { + new Madkit( + "--myNewProperty", "aNewValue", + LevelOption.madkitLogLevel.toString(),Level.FINER.toString(), + Option.launchAgents.toString(),_4_CreateNewProperty.class.getName()+",true" + ); + } +} diff --git a/release/src/madkitproperties/_5_AgentLoadingPropertyFile.java b/release/src/madkitproperties/_5_AgentLoadingPropertyFile.java new file mode 100644 index 0000000..6e32a3a --- /dev/null +++ b/release/src/madkitproperties/_5_AgentLoadingPropertyFile.java @@ -0,0 +1,43 @@ +package madkitproperties; + +import java.io.IOException; + +import madkit.kernel.AbstractAgent; + +/** + * Now we will see how to load properties from a property file. + * The loadPropertiesFromFile(nameOfFile) method allows to + * add and update properties that are stored in this particular file. + * + * An exception is thrown if the specified file + * does not exist. + * + * + */ + +public class _5_AgentLoadingPropertyFile extends AbstractAgent{ + + @Override + protected void activate() { + /* We display the original MaDKit configuration */ + getLogger().talk(getMadkitConfig().toString()); + try { + /* Now we load new properties */ + getLogger().talk("\nNow I will load properties from the file: madkitproperties/PropertyFileToLoad.properties \n"); + getMadkitConfig().loadPropertiesFromFile("madkitproperties/PropertyFileToLoad.properties"); + } catch (IOException e) { + e.printStackTrace(); + } + /* Finally, we display the properties again to notice the differences */ + getLogger().talk(getMadkitConfig().toString()); + } + + /** + * Launch a _5_AgentLoadingPropertyFile. + * @param args + */ + public static void main(String[] args) { + executeThisAgent(); + } + +} diff --git a/release/src/madkitproperties/_6_LoadXMLPropertyFile.java b/release/src/madkitproperties/_6_LoadXMLPropertyFile.java new file mode 100644 index 0000000..59351bb --- /dev/null +++ b/release/src/madkitproperties/_6_LoadXMLPropertyFile.java @@ -0,0 +1,24 @@ +package madkitproperties; + +import java.io.IOException; + +import madkit.kernel.Madkit; +import madkit.kernel.Madkit.Option; + +/** + * Now we will see how to load properties from a XML property file. + * Unlike basics property files, XML allow a parameterization even + * more accurate. Here we will parameterized agents while launching + * them. + * + * An exception is thrown if the specified file + * does not exist. + * + */ + +public class _6_LoadXMLPropertyFile { + + public static void main(String[] args) throws IOException { + new Madkit(Option.configFile.toString(),"madkitproperties/XMLPropertyFile.xml"); + } +} \ No newline at end of file diff --git a/release/src/madkitproperties/_6_ParameterizedAgent.java b/release/src/madkitproperties/_6_ParameterizedAgent.java new file mode 100644 index 0000000..b4a8eb4 --- /dev/null +++ b/release/src/madkitproperties/_6_ParameterizedAgent.java @@ -0,0 +1,21 @@ +package madkitproperties; + +import madkit.kernel.Agent; + +/** + * This class only purpose is to exemplify the use of a XML property file with MaDKit. + */ + +public class _6_ParameterizedAgent extends Agent{ + + public String message; + + @Override + protected void live() { + pause(2500); + getLogger().talk("\n\t" + message + "\t\n"); + pause(2500); + getLogger().info(getMadkitProperty("varDefinedInXML")); + pause(5000); + } +} diff --git a/release/src/returncode/ex1_javaException/CrashingAgent.java b/release/src/returncode/ex1_javaException/CrashingAgent.java new file mode 100644 index 0000000..5100286 --- /dev/null +++ b/release/src/returncode/ex1_javaException/CrashingAgent.java @@ -0,0 +1,75 @@ +/** + * READ ME + * This tutorial shows how MaDKit is dealing with exceptions. We advise you to not start with this tutorial. + * You can check previous tutorials at: http://www.madkit.net/madkit/tutorials/ . Among those tutorials, you + * may use here notions seen in logging and communication tutorials. + * + * In this tutorial we will see what kind of exceptions may be encountered while developing + * an application with MaDKit and what MadKit provides to improve our programs' reliability: AbstractAgent.ReturnCode. + * + */ + +package returncode.ex1_javaException; + +import java.util.logging.Level; + +import returncode.utils.TutorialAgent; + +/** + * In this example you will understand that as MaDKit is a Java library, you will have to deal + * with the same errors and exception that you may have encountered with Java. + * + * Thus as in any Java-based program, you will have to be rigorous :) + * + * + * + */ + +public class CrashingAgent extends TutorialAgent{ + + /* + * On activation, we want the agent to throw a NullPointer Exception. + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); /* So that the agent's life cycle is traced. See the logging tutorial for more information. */ + + pause(2000); + /* Now we throw an exception */ + throw new NullPointerException(); + } + + /* + * As the agent throw a NullPointerException, this method should not be called. + */ + @Override + protected void live() { + getLogger().info("\n\tI have crashed, this message shall not be displayed.\t\n"); + } + + @Override + protected void end() { + getLogger().info("\n\tI have crashed. :(\t\n"); + super.end(); + } + + /** + * We launch a CrashingAgent that throws a NullPointer exception + * and the agent terminates. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + /** + * The previous line of code shall cause this error: + * + * [CrashingAgent-2] SEVERE : -*-ACTIVATE BUG*-* + * ** java.lang.NullPointerException + * at exception.ex1_exceptions.ex11_javaException.CrashingAgent.activate(CrashingAgent.java:40) + * + * Followed by the agent's life cycle. + * + */ + } +} diff --git a/release/src/returncode/ex2_madkitCodingError/_1_CrashingAgent.java b/release/src/returncode/ex2_madkitCodingError/_1_CrashingAgent.java new file mode 100644 index 0000000..fb113d9 --- /dev/null +++ b/release/src/returncode/ex2_madkitCodingError/_1_CrashingAgent.java @@ -0,0 +1,40 @@ +package returncode.ex2_madkitCodingError; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * In addition of Java's exceptions, there is another category of failure that may happen with MaDKit: + * madkit.kernel.KernelException. KernelException is a class of MaDKit that extends RuntimeException. + * Actually it is an exception thrown to indicate that the agent is trying to use a method + * while not launched or already dead. + * + * In this example we will see a KernelException being thrown while we try to + * send a message with an agent without launching him. + * + * + * + */ + +public class _1_CrashingAgent extends TutorialAgent { + + /** + * This will throw a KernelException. + * + * @param argss + */ + public static void main(String[] argss) { + _1_CrashingAgent agent = new _1_CrashingAgent(); + agent.sendMessage("myCommunity", "myGroup", "myRole", new Message()); + + /** + * The previous line of code shall cause this error: + * + * madkit.kernel.KernelException: _1_CrashingAgent-0 (NOT_LAUNCHED) must be launched to use this method + * at madkit.kernel.AbstractAgent.sendMessage(Unknown Source) + * Exception in thread "main" madkit.kernel.KernelException: _1_CrashingAgent-0 (NOT_LAUNCHED) must be launched to use this method + * at madkit.kernel.AbstractAgent.sendMessage(Unknown Source) + * + */ + } +} diff --git a/release/src/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java b/release/src/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java new file mode 100644 index 0000000..00b4d1c --- /dev/null +++ b/release/src/returncode/ex2_madkitCodingError/_2_LaunchingNewCrashingAgentsWithMadkit.java @@ -0,0 +1,31 @@ +package returncode.ex2_madkitCodingError; + +import madkit.kernel.Madkit; +import returncode.ex1_javaException.CrashingAgent; +import returncode.utils.TutorialAgent; + +/** + * Now that we have seen that misusing MaDKit may generate KernelException, we will + * see how other agents are impacted if one of them crash. + * + * Good failure managing is extremely important in multi-agent system. + * We do not want the whole society to crash because of the crash of one of our agents. + * + * Here we launch two agents and see if the crash of one impacts the activity of the other. + * + * + * + */ + +public class _2_LaunchingNewCrashingAgentsWithMadkit{ + + /** + * Launches one TutorialAgent and one CrashingAgent. As expected, the last agent will crash + * but without having any impact on the life of the agents. + * + * @param argss + */ + public static void main(String[] argss) { + new Madkit("--launchAgents", TutorialAgent.class.getName() + ",true,1;", CrashingAgent.class.getName() + ",true,1;"); + } +} diff --git a/release/src/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java b/release/src/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java new file mode 100644 index 0000000..bf159b1 --- /dev/null +++ b/release/src/returncode/ex2_madkitCodingError/_3_AgentLaunchingNewCrashingAgents.java @@ -0,0 +1,59 @@ +package returncode.ex2_madkitCodingError; + +import java.util.logging.Level; + +import returncode.ex1_javaException.CrashingAgent; +import returncode.utils.TutorialAgent; + +/** + * Now that we have seen that misusing MaDKit may generate KernelException, we will + * see how other agents are impacted if one of them crash. + * + * Good failure managing is extremely important in multi-agent system. + * We do not want the whole society to crash because of the crash of one of our agents. + * + * Here we launch an agent that will launch two agents during his life. + * The first one is a basic TutorialAgent while the second is a CrashingAgent. + * The aim of this exercise is to see if the crash of a launched agent may have any + * impact on the launcher agent. + * + * + * + */ + +public class _3_AgentLaunchingNewCrashingAgents extends TutorialAgent{ + + /** + * On activation we will just set the log level on FINEST so that + * the agent's life cycle is traced. + * See the logging tutorial for more information. + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + } + + /** + * Launches a TutorialAgent and a CrashingAgent. + */ + @Override + protected void live() { + //first launch a TutorialAgent + launchAgent(new TutorialAgent(),true); + + //then launch a CrashingAgent + launchAgent(new CrashingAgent(),true); + } + + /** + * Launch a _3_AgentLaunchingNewCrashingAgents. As expected, the + * CrashingAgent will crash but without having any impact + * on the life of the others. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(1, true); + } +} + diff --git a/release/src/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java b/release/src/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java new file mode 100644 index 0000000..210334c --- /dev/null +++ b/release/src/returncode/ex3_introducingReturnCodes/SuccessfulAgent.java @@ -0,0 +1,44 @@ +package returncode.ex3_introducingReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * In this example we will show you how you can ensure your programs with methods' return code. + * In MaDKit AbstractAgent.ReturnCode is an enumeration of codes which are returned by some methods of the API classes. + * You can find the different constants in the documentation (http://www.madkit.net/madkit/repository/MaDKit-5.2/docs/api/) + * + * In further exercises we will present you these codes : what they mean and example of how you can use them. + * We can class them into three categories: + * ReturnCode for launch ; + * ReturnCode for Community-Group-Role (CGR) ; + * ReturnCode for communication. + * + * In this example we will show you how you can use these codes by starting with the easiest: + * AbstractCode.ReturnCode.SUCCESS. As you could have guessed, this code means that the called method + * has not encountered any problem. + * + * + * + */ + +public class SuccessfulAgent extends TutorialAgent { + + /** We will call createOrganization(...) and check if something went wrong thanks to + * the ReturnCode.SUCCESS. + */ + @Override + protected void activate() { + ReturnCode createFeedback; + createFeedback = createGroup("mySuccessfulCommunity", "mySuccessfulGroup"); + getLogger().info("\n\t The ReturnCode is: \"" + createFeedback.toString() +"\" .\n\tIt means that the method ended successfully.\t\n"); + + } + /** + * Launch a SuccessfulAgent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java b/release/src/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java new file mode 100644 index 0000000..6dd76c5 --- /dev/null +++ b/release/src/returncode/ex4_launchReturnCodes/_1_NotYetLaunched.java @@ -0,0 +1,33 @@ +package returncode.ex4_launchReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NOT_YET_LAUNCHED. This ReturnCode is returned by + * kill primitives when the targeted agent has not been launched priorly. + * + * + * + */ + +public class _1_NotYetLaunched extends TutorialAgent { + + /** + * During his life, the agent will try to kill a TutorialAgent that is not launched. + * Thus a WARNING message saying that killAgent() has failed will be displayed. + */ + @Override + protected void live() { + ReturnCode killFeedback; + killFeedback = killAgent(new TutorialAgent()); /* we kill a new TutorialAgent otherwise an agent who has not been launched */ + getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\tIt means that I can not kill another agent if he is not launched. \t\n"); + } + + /** + * We launch a _1_NotYetLaunched agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java b/release/src/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java new file mode 100644 index 0000000..c22c308 --- /dev/null +++ b/release/src/returncode/ex4_launchReturnCodes/_2_AlreadyLaunched.java @@ -0,0 +1,36 @@ +package returncode.ex4_launchReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies ALREADY_LAUNCHED. + * This ReturnCode is returned when we try to launch an agent which is already launched. + * + * + * + */ + +public class _2_AlreadyLaunched extends TutorialAgent{ + + /** + * On activation, the agent will try to launched himself whereas... He is already launched... + * Thus a message saying that launchAgent() has failed will be displayed. + */ + @Override + protected void activate() { + ReturnCode launchFeedback; + launchFeedback = launchAgent(this); + getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that I have already been launched : I can not be launched twice \n\t"); + + /* Then you do what you want with this agent */ + } + + /** + * We launch a _2_AlreadyLaunched agent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex4_launchReturnCodes/_3_AgentCrash.java b/release/src/returncode/ex4_launchReturnCodes/_3_AgentCrash.java new file mode 100644 index 0000000..00a5ff5 --- /dev/null +++ b/release/src/returncode/ex4_launchReturnCodes/_3_AgentCrash.java @@ -0,0 +1,36 @@ +package returncode.ex4_launchReturnCodes; + +import returncode.ex1_javaException.CrashingAgent; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: AGENT_CRASH. + * This ReturnCode is returned by launch primitives when the launched agent crashes in activate(). + * + * + * + */ + +public class _3_AgentCrash extends TutorialAgent{ + + /** + * On activation the agent will try to launch an agent that systematically crashes. + * Thus messages saying that launchAgent() has failed will be displayed before our own message. + */ + @Override + protected void activate() { + ReturnCode launchFeedback; + launchFeedback = launchAgent(new CrashingAgent(),true); /* The new CrashingAgent() will crash */ + getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that the agent I wanted to launched has crashed... \n\tTherefore you can notice that I am still alive.\t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _3_AgentCrash agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex4_launchReturnCodes/_4_TimeOut.java b/release/src/returncode/ex4_launchReturnCodes/_4_TimeOut.java new file mode 100644 index 0000000..aa0cd52 --- /dev/null +++ b/release/src/returncode/ex4_launchReturnCodes/_4_TimeOut.java @@ -0,0 +1,47 @@ +package returncode.ex4_launchReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: TIMEOUT. + * This ReturnCode is returned by various timed primitives of the Agent class. + * + * + * + */ + +public class _4_TimeOut extends TutorialAgent { + + /** + * We install our agent in his virtual society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myTimedOutCommunity", "myTimedOutGroup"); + requestRole("myTimedOutCommunity", "myTimedOutGroup", "myTimedOutRole"); + } + + @Override + protected void live() { + int timeBeforeTimeOut = 0; /* an absurd duration */ + + + /** + * The ReturnCode of the next method will be TIME_OUT if the agent we launch has not ended his activate method. + * Here as we are giving him 0 micro second to finish it. Thus it will return this code. + */ + + ReturnCode launchFeedback; + launchFeedback = launchAgent(new TutorialAgent(), timeBeforeTimeOut, false); /* while minuting we launch a TutorialAgent. */ + getLogger().info("\n\tThe ReturnCode is: \"" + launchFeedback.toString() + "\" .\n\tIt means that the activate method did not ended in time. \t\n"); + } + + /** + * Launch a _4_TimeOut agent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(1,true); + } +} diff --git a/release/src/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java b/release/src/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java new file mode 100644 index 0000000..079136b --- /dev/null +++ b/release/src/returncode/ex4_launchReturnCodes/_5_AlreadyKilled.java @@ -0,0 +1,39 @@ +package returncode.ex4_launchReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: ALREADY_KILLED. + * This ReturnCode is returned by kill primitives when the targeted agent is already terminated. + * + * + * + */ + +public class _5_AlreadyKilled extends TutorialAgent { + + /** During his life, the agent will try to kill twice the same TutorialAgent. + * Thus a message saying that killAgent() has failed will be displayed. + */ + @Override + protected void live() { + TutorialAgent agentToKill = new TutorialAgent(); + launchAgent(agentToKill,true); /* Otherwise we will get an "NOT_YET_LAUNCHED" returnCode*/ + + ReturnCode killFeedback; + killFeedback = killAgent(agentToKill); + getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\t I have successfully killed this agent. \t\n"); + killFeedback = killAgent(agentToKill); + getLogger().info("\n\tThe ReturnCode is: \"" + killFeedback.toString() + "\" .\n\tIt means that I have already killed this agent. I can not killed the same person twice. \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _5_AlreadyKilled agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java b/release/src/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java new file mode 100644 index 0000000..8ee6dc1 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_1_NotCommunity.java @@ -0,0 +1,39 @@ +package returncode.ex5_CGRReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NOT_COMMUNITY. + * This ReturnCode indicates that a community does not exist. + * + * + * + */ + +public class _1_NotCommunity extends TutorialAgent{ + + /** + * When activate, the _1_NotCommunity agent will request a role while he has not create any group. + * Thus the community is not set and does not exist for MaDKit. Our agent will display a message explaining why the method + * has failed. + * + * A message informing that the requestRole() has failed will also be displayed as a warning. + */ + @Override + protected void activate() { + ReturnCode requestFeedback; + requestFeedback = requestRole("myCommunity", "myGroup", "myRole"); + getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback.toString() + "\" .\n\tIt means that I can not request a role in a community that does not exist. \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _1_NotCommunity agent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java b/release/src/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java new file mode 100644 index 0000000..46023d2 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_2_AlreadyGroup.java @@ -0,0 +1,40 @@ +package returncode.ex5_CGRReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: ALREADY_GROUP. + * This ReturnCode is returned when using createOrganization(String, String, boolean, Gatekeeper) + * and that a group already exists. + * + * + * + */ + +public class _2_AlreadyGroup extends TutorialAgent { + + /** + * This _2_AlreadyGroup agent does nothing in particular: he is just creating a group. + * What is interesting here is that the agent will display a message saying if the group has + * already been created. + */ + @Override + protected void activate() { + ReturnCode createFeedback ; + createGroup("myCommunity", "myGroup"); + createFeedback = createGroup("myCommunity", "myGroup"); + getLogger().info("\n\tThe ReturnCode is: \"" + createFeedback.toString() + "\" .\n\tIt means that the group I wanted to create already exists. \t\n"); + pause(500); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _2_AlreadyGroup agents. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex5_CGRReturnCodes/_3_NotGroup.java b/release/src/returncode/ex5_CGRReturnCodes/_3_NotGroup.java new file mode 100644 index 0000000..a5b4589 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_3_NotGroup.java @@ -0,0 +1,47 @@ +package returncode.ex5_CGRReturnCodes; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NOT_GROUP. + * This Returncode indicates that a group does not exist. + * + * + * + */ + +public class _3_NotGroup extends TutorialAgent { + + /** + * We are initializing our _3_NotGroup agent in its virtual society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myRole"); + pause(500); + } + + /** + * The _3_NotGroup send a message to a group that does not exist. Thus method sendMessage() fails and a + * warning is displayed. + * While checking the returnCode we display a message explaining why the method has failed. + */ + @Override + protected void live(){ + ReturnCode sendFeedback; + sendFeedback = sendMessage("myCommunity", "nilGroup", "myRole", new Message()); + getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not send a message to a group that does not exist. \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch an _3_NotGroup agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java b/release/src/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java new file mode 100644 index 0000000..f127155 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_4_NotInGroup.java @@ -0,0 +1,58 @@ +package returncode.ex5_CGRReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NOT_IN_GROUP. + * This ReturnCode indicates that an agent is not in a group. + * + * + * + */ + +public class _4_NotInGroup extends TutorialAgent { + + /** + * We are initializing our _4_NotInGroup agent + * in its virtual society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myRole"); + pause(1500); + } + + /** + * The _4_NotInGroup while deliberately leave the same group twice. + * At the first call of the method he will leave the group. At the second + * the method will fail as he is not in this group and a warning is displayed. + * + * While checking the returnCode we have decided to display a message explaining why the + * method has failed. A message informing that the sendMessage() has failed will also be + * displayed as a warning. + */ + @Override + protected void live() { + ReturnCode leaveFeedback; + leaveGroup("myCommunity", "myGroup"); + leaveFeedback = leaveGroup("myCommunity", "myGroup"); + if(leaveFeedback == ReturnCode.NOT_IN_GROUP) { + getLogger().info("\n\tThe ReturnCode is: \"" + leaveFeedback.toString() + "\" .\n\tIt means that I already have left this group, I can not leave a group twice. \t\n"); + } + + /* Then you do what you want with this agent */ + } + + +/** + * Launch three _4_NotInGroup agents. + * All the agent's second leaveGroup() call will return a ReturnCode.NOT_IN_GROUP + * except the last one that will return a ReturnCode.NOT_COMMUNITY. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(3,true); + } +} \ No newline at end of file diff --git a/release/src/returncode/ex5_CGRReturnCodes/_5_NotRole.java b/release/src/returncode/ex5_CGRReturnCodes/_5_NotRole.java new file mode 100644 index 0000000..5b47ba8 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_5_NotRole.java @@ -0,0 +1,49 @@ +package returncode.ex5_CGRReturnCodes; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NOT_ROLE. + * This ReturnCode indicates that a role does not exist. + * + * + * + */ + +public class _5_NotRole extends TutorialAgent{ + + /** + * We are initializing our _5_NotRole agent in its virtual society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myRole"); + pause(500); + } + + /** + * The _5_NotRole agent send a message to a role that does not exist. Thus the method sendMessage() will fail and a + * warning is displayed. + * While checking the returnCode we have decided to display a message explaining why the method has failed. + * + * A message informing that the sendMessage() has failed will also be displayed as a warning. + */ + @Override + protected void live(){ + ReturnCode sendFeedback; + sendFeedback = sendMessage("myCommunity", "myGroup", "notExistingRole", new Message()); /* Note that the role is different then "myRole" */ + getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not send a message to an agent whose role does not exist. \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _5_NotRole agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} \ No newline at end of file diff --git a/release/src/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java b/release/src/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java new file mode 100644 index 0000000..417fb5b --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_6_RoleAlreadyHandled.java @@ -0,0 +1,48 @@ +package returncode.ex5_CGRReturnCodes; + +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: ROLE_ALREADY_HANDLED. + * This ReturnCode is returned when the agent already has the + * requested role. + * + * + * + */ + +public class _6_RoleAlreadyHandled extends TutorialAgent{ + + /** + * Our _6_RoleAlreadyHandled agent will deliberately ask twice the same role: when activate and in his lifetime. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + ReturnCode requestFeedback1 = requestRole("myCommunity", "myGroup", "myRole"); + getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback1.toString() + "\" .\n\tI have the role I wanted !\t\n"); + } + + @Override + protected void live() { + /** + * The _6_RoleAlreadyHandled agent forgets that he already has this role, + * so he asks for it again... Thus a message saying that the requestRole() + * has failed will be displayed. + */ + ReturnCode requestFeedback2; + requestFeedback2 = requestRole("myCommunity", "myGroup", "myRole"); + getLogger().info("\n\tThe ReturnCode is: \"" + requestFeedback2.toString() + "\" .\n\tIt means that I already have this role \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _6_RoleAlreadyHandled agent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java b/release/src/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java new file mode 100644 index 0000000..4141ed2 --- /dev/null +++ b/release/src/returncode/ex5_CGRReturnCodes/_7_RoleNotHandled.java @@ -0,0 +1,51 @@ +package returncode.ex5_CGRReturnCodes; + +import madkit.kernel.Madkit; +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: ROLE_NOT_HANDLED. + * This ReturnCode is returned when the agent does not have the role + * needed if he wants to do a particular action. + * + * + * + * + */ +public class _7_RoleNotHandled extends TutorialAgent{ + + /** + * We activate the _7_RoleNotHandled agent in the same virtual society than the + * TutorialAgent. Nevertheless, our agent will have a different role: myDifferentRole. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myDifferentRole"); + pause(500); + } + + /** + * The agent will try to send a message to a TutorialAgent. + * However, in the method he uses : sendMessageWithRole(String community, String group, String role, Message message, String senderRole) + * our agent makes a mistake and specifies a role that is not his as senderRole. + */ + @Override + protected void live(){ + ReturnCode sendFeedback; + sendFeedback = sendMessageWithRole("myCommunity", "myGroup", "myRole", new Message(), "myRole"); + getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I do not have this role. \t\n"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch an _7_RoleNotHandled agent and a TutorialAgent (as receiver). + * + * @param argss + */ + public static void main(String[] argss){ + new Madkit("--launchAgents", _7_RoleNotHandled.class.getName() + ",true,1;", _5_NotRole.class.getName() + ",true,1;"); + } +} diff --git a/release/src/returncode/ex6_communicationReturnCodes/_1_CantReply.java b/release/src/returncode/ex6_communicationReturnCodes/_1_CantReply.java new file mode 100644 index 0000000..c42932f --- /dev/null +++ b/release/src/returncode/ex6_communicationReturnCodes/_1_CantReply.java @@ -0,0 +1,39 @@ +package returncode.ex6_communicationReturnCodes; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: CANT_REPLY. + * This ReturnCode is returned when an agent tries to reply to a message which has not been + * received from another agent, e.g. newly created or sent directly by an object using + * AbstractAgent.receiveMessage(Message). + * + * + * + */ + +public class _1_CantReply extends TutorialAgent{ + + /** + * During his life, the agent will try to answer to a new message which is not possible as this message + * was not sent by any other agent. + */ + @Override + protected void live() { + ReturnCode sendFeedback; + sendFeedback = sendReply(new Message(), new Message()); /* the agent try to answer a new message */ + getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I can not reply to a message that was not send before. \n\t"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _1_CantReply agent. + * + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java b/release/src/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java new file mode 100644 index 0000000..44541b4 --- /dev/null +++ b/release/src/returncode/ex6_communicationReturnCodes/_2_NoRecipientFound.java @@ -0,0 +1,45 @@ +package returncode.ex6_communicationReturnCodes; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: NO_RECIPIENT_FOUND. + * This ReturnCode is returned by send primitives when the targeted CGR location does not exist nor contain any agent. + * + * + * + */ + +public class _2_NoRecipientFound extends TutorialAgent { + + /** + * Puts the agent in a virtual and lonely society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myLonelyCommunity", "myLonelyGroup"); + requestRole("myLonelyCommunity", "myLonelyGroup", "myLonelyRole"); + } + + /** + * During his life our agent will try to send a message to another agent of his group. As he is the only member of the group, sendMessage() + * will fail and an error message will be displayed before our own. + */ + @Override + protected void live() { + ReturnCode sendFeedback; + sendFeedback = sendMessage("myLonelyCommunity", "myLonelyGroup", "myLonelyRole", new Message()); + getLogger().info("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that I am the only agent of the group... \n\t"); + + /* Then you do what you want with this agent */ + } + + /** + * Launch a _2_NoRecipientFound agent. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(); + } +} diff --git a/release/src/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java b/release/src/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java new file mode 100644 index 0000000..7737945 --- /dev/null +++ b/release/src/returncode/ex6_communicationReturnCodes/_3_InvalidAgentAddress.java @@ -0,0 +1,61 @@ +package returncode.ex6_communicationReturnCodes; + +import madkit.kernel.AgentAddress; +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * This class exemplifies: INVALID_AGENT_ADDRESS. + * This ReturnCode is returned by send primitives when the targeted agent address does not exist anymore, i.e. + * the related agent has leaved the corresponding role. + * + * + * + */ + +public class _3_InvalidAgentAddress extends TutorialAgent{ + + /** + * We are initializing our _3_InvalidAgentAddress agent. + * in its virtual society. + */ + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myRole"); + pause(1500); + } + + /** + * During his life, the agent will look for the address of another agent in his group. Then he will change his role + * (so that means that the previous address is no more accurate). Using the previous address, + * the agent will try to send a Message to his interlocutor. + * + * Thus sendMessage(AgentAddress, Message) will fail, an error message will be displayed as a warning. + */ + @Override + protected void live() { + // get a AgentAddress to exchange messages with. + AgentAddress interlocutor = getAgentAddressIn("myCommunity", "myGroup", "myRole") ; + + // leave the role so the address other interlocutors obtained is now wrong. + leaveRole("myCommunity", "myGroup", "myRole"); + + // try to send a message with the wrong obtained address. + ReturnCode sendFeedback; + sendFeedback = sendMessage(interlocutor, new Message()); + getLogger().warning("\n\tThe ReturnCode is: \"" + sendFeedback.toString() + "\" .\n\tIt means that the given address does not match with anyone. \n\tI can not communicate. :( \t\n"); + + /* Then you do what you want with this agent */ + } + + +/** + * Launch two _3_InvalidAgentAddress agent so that they can communicate. + * @param argss + */ + public static void main(String[] argss) { + executeThisAgent(2,false); + } + +} diff --git a/release/src/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java b/release/src/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java new file mode 100644 index 0000000..79e3aed --- /dev/null +++ b/release/src/returncode/ex7_concreteUseOfReturnCode/SendingMessageWithReturnCode.java @@ -0,0 +1,97 @@ +package returncode.ex7_concreteUseOfReturnCode; + +import java.util.logging.Level; + +import madkit.kernel.Message; +import returncode.utils.TutorialAgent; + +/** + * Now that we have see ReturnCodes, we will learn to use them + * in order to correct a method that has failed. + * + * + * + */ + +public class SendingMessageWithReturnCode extends TutorialAgent { + + /** + * On activate() the agent allow the most precise's log level in order + * to see its life cycle's trace. + */ + @Override + protected void activate() { + getLogger().setLevel(Level.FINEST); + + pause(3000); + } + + /** + * During his lifetime, the agent will try to send a message. At first the method will failed because + * of missing criteria but by using ReturnCode we will fulfill one of them before calling this function + * again until we have met all the requirements. + */ + @Override + protected void live() { + ReturnCode sendFeedback; + do { + + sendFeedback = sendMessage("myCommunity", "myGroup", "myRole", new Message()); + /* We display the name of the ReturnCode and its value. */ + getLogger().info("\n\t" + sendFeedback.name() + "\t" + sendFeedback.toString() +"\n\t"); + + switch(sendFeedback) { + case SUCCESS: + getLogger().info("\n\t Message send ! \n\t"); + break; + case NOT_COMMUNITY: + getLogger().info("\n\t I should create the community. \n\t"); + createGroupIfAbsent("myCommunity", "myGroup"); + break; + case NOT_GROUP: + getLogger().info("\n\t I should create the group. \n\t"); + createGroup("myCommunity", "myGroup"); + break; + case NOT_ROLE: + getLogger().info("\n\t I should demand my role. \t\n"); + requestRole("myCommunity", "myGroup", "myRole"); + break; + case NOT_IN_GROUP: + getLogger().info("\n\t I am not in the group. This implies that the group exists. \n\t I will ask to join it. \t\n"); + requestRole("myCommunity", "myGroup", "myRole"); + break; + case NO_RECIPIENT_FOUND: + getLogger().info("\n\tI am alone, thus I can not find someone to send a message.\t\n"); + getLogger().info("\n\tI should launch another instance of myself\t\n"); + launchAgent(new SendingMessageWithReturnCode(),true); + break; + default: + getLogger().info("\n\t Mmh. Something went wrong. Better quit this place. \n\t"); + killAgent(this); + break; + } + + }while(sendFeedback != ReturnCode.SUCCESS); + } + + /** + * Before dying the agent will pause a long time so that you can have the time to read his message. + */ + @Override + protected void end() { + getLogger().info("\n\t My mission is over ! See you next time. \n\t"); + pause(35000); + } + + /** + * We launch three agents. + * + * The first agent that will be launch will have to create the group as it does not exist. + * Then for the next agents, the group will exist but as they are not part of it, they will have to ask to join it by requesting a role. + * They all have to request the role. + */ + public static void main(String[] argss) { + executeThisAgent(3, true); + } + +} diff --git a/release/src/returncode/utils/TutorialAgent.java b/release/src/returncode/utils/TutorialAgent.java new file mode 100644 index 0000000..7f37fa3 --- /dev/null +++ b/release/src/returncode/utils/TutorialAgent.java @@ -0,0 +1,33 @@ +package returncode.utils; + +import madkit.gui.AgentFrame; +import madkit.kernel.Agent; + +/** + * We create a new agent for this tutorial. + */ + +public class TutorialAgent extends Agent { + + @Override + protected void activate() { + createGroupIfAbsent("myCommunity", "myGroup"); + requestRole("myCommunity", "myGroup", "myRole"); + pause(200); + } + + @Override + protected void live() { + } + + @Override + protected void end() { + pause(8000); + } + + @Override + public void setupFrame(AgentFrame frame) { + super.setupFrame(frame); + frame.setSize(800, 400); + } +} diff --git a/release/src/simulation/ex01/MyScheduler.java b/release/src/simulation/ex01/MyScheduler.java new file mode 100644 index 0000000..32101a0 --- /dev/null +++ b/release/src/simulation/ex01/MyScheduler.java @@ -0,0 +1,46 @@ +package simulation.ex01; + +import java.util.logging.Level; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; + +/** + * + * + * + * The madkit.kernel.Scheduler class defines a generic threaded scheduler agent. + * It holds a collection of activators. The default state of a scheduler is Scheduler.SimulationState.PAUSED + * + * Let us illustrate some basic features of a scheduler + */ + +public class MyScheduler extends Scheduler { + + @Override + protected void activate() { + // This makes a pause of 300 ms between two simulation steps and can be modified later in the code or + // using the scheduler GUI. + setDelay(300); + + // Let us also display more information: + // the FINER log level of the Scheduler displays activation information + getLogger().setLevel(Level.FINER); + + // The simulation will run until getGVT() >= 10 and then automatically quit + setSimulationDuration(10); + + super.activate(); + } + + /** + * A simple way of launching this scheduler + * + * @param + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex02/MyScheduler02.java b/release/src/simulation/ex02/MyScheduler02.java new file mode 100644 index 0000000..d73b4d8 --- /dev/null +++ b/release/src/simulation/ex02/MyScheduler02.java @@ -0,0 +1,53 @@ +package simulation.ex02; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.AbstractAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; +import madkit.simulation.activator.GenericBehaviorActivator; + +/** + * + * + * In this example, the goal is only to manage the execution of some agents. Two classes are needed : a + * madkit.kernel.Scheduler that manages an madkit.kernel.Activator and a simulated agent class: + * simulation.ex02.SimulatedAgent02. + * + * The madkit.kernel.Activator class defines a tool for scheduling mechanism. + * An activator is configured according to a community, a group and a role. + * It could be used to activate a group of agents on a particular behavior + */ + +public class MyScheduler02 extends Scheduler { + + private GenericBehaviorActivator activator1; + + @Override + protected void activate() { + + // 1 : create the simulation group + createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP); + + // 2 : launch some simulated agents + for (int i = 0; i < 10; i++) { + launchAgent(new SimulatedAgent02()); + } + + // 3 : initialize the activator on the correct (1) CGR location and (2) behavior + activator1 = new GenericBehaviorActivator(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt"); + addActivator(activator1); + + // 4 : we are done, because Scheduler already defines a live method + // calling the execution of the activator. We will override it later. + // here we just slow down the simulation to not flood the console + setDelay(300); + } + + /** + * A simple way of launching this scheduler + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler02.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex02/SimulatedAgent02.java b/release/src/simulation/ex02/SimulatedAgent02.java new file mode 100644 index 0000000..c95247a --- /dev/null +++ b/release/src/simulation/ex02/SimulatedAgent02.java @@ -0,0 +1,17 @@ +package simulation.ex02; + +import madkit.kernel.AbstractAgent; + +public class SimulatedAgent02 extends AbstractAgent { + + @Override + protected void activate() { + requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE); + } + + @SuppressWarnings("unused") + private void doIt() { + getLogger().info("I am doing it"); + } + +} diff --git a/release/src/simulation/ex02/SimulationModel.java b/release/src/simulation/ex02/SimulationModel.java new file mode 100644 index 0000000..ba8f5aa --- /dev/null +++ b/release/src/simulation/ex02/SimulationModel.java @@ -0,0 +1,16 @@ +package simulation.ex02; + +/** + * Stocking some global properties for this tutorial. + * + * @author Fabien Michel + * @version 0.9 + */ +public class SimulationModel { + + public static final String MY_COMMUNITY = "simu"; + public static final String SIMU_GROUP = "simu"; + public static final String ROLE = "bot"; + public static final String ANOTHER_ROLE = "anotherRole"; + +} diff --git a/release/src/simulation/ex03/MyScheduler03.java b/release/src/simulation/ex03/MyScheduler03.java new file mode 100644 index 0000000..e8b6d78 --- /dev/null +++ b/release/src/simulation/ex03/MyScheduler03.java @@ -0,0 +1,49 @@ +package simulation.ex03; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.AbstractAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; +import madkit.simulation.activator.GenericBehaviorActivator; +import simulation.ex02.SimulatedAgent02; +import simulation.ex02.SimulationModel; + +/** + * + * Let us have more fun by adding another simulated agent class with a different result for the doIt method and see what + * we now need. We need nothing else and just have to launch this new type of agent: Activators do not care about the + * exact type of the activated agents. Only the organizational position matters. + */ + +public class MyScheduler03 extends Scheduler { + + private GenericBehaviorActivator activator1; + + @Override + protected void activate() { + // 1 : create the simulation group + createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP); + + // 2 : launch some simulated agents + for (int i = 0; i < 20; i++) { + launchAgent(new SimulatedAgent02()); + launchAgent(new SimulatedAgent03()); + } + + // 3 : initialize the activator + activator1 = new GenericBehaviorActivator(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt"); + addActivator(activator1); + + setDelay(300); + } + + /** + * A simple way of launching this scheduler + * + * @param + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler03.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex03/SimulatedAgent03.java b/release/src/simulation/ex03/SimulatedAgent03.java new file mode 100644 index 0000000..69ec27d --- /dev/null +++ b/release/src/simulation/ex03/SimulatedAgent03.java @@ -0,0 +1,18 @@ +package simulation.ex03; + +import madkit.kernel.AbstractAgent; +import simulation.ex02.SimulationModel; + +public class SimulatedAgent03 extends AbstractAgent { + + @Override + protected void activate() { + requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE); + } + + @SuppressWarnings("unused") + private void doIt() { + getLogger().info("I am doing it, but my way"); + } + +} diff --git a/release/src/simulation/ex04/MyScheduler04.java b/release/src/simulation/ex04/MyScheduler04.java new file mode 100644 index 0000000..27a3bcc --- /dev/null +++ b/release/src/simulation/ex04/MyScheduler04.java @@ -0,0 +1,59 @@ +package simulation.ex04; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.AbstractAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; +import madkit.simulation.activator.GenericBehaviorActivator; +import simulation.ex02.SimulatedAgent02; +import simulation.ex02.SimulationModel; +import simulation.ex03.SimulatedAgent03; + +/** + * + * + * Let us have more fun by adding another activator on another role to execute the other behavior of + * {@link SimulatedAgent04} + */ + +public class MyScheduler04 extends Scheduler { + + protected GenericBehaviorActivator activator1; + protected GenericBehaviorActivator activator2; + + @Override + protected void activate() { + + // 1 : create the simulation group + createGroup(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP); + + // 2 : launch some simulated agents + for (int i = 0; i < 10; i++) { + launchAgent(new SimulatedAgent02()); + launchAgent(new SimulatedAgent03()); + launchAgent(new SimulatedAgent04()); + } + + // 3 : initialize the activators + // by default, they are activated once each in the order they have been added + activator1 = new GenericBehaviorActivator(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE, "doIt"); + addActivator(activator1); + activator2 = new GenericBehaviorActivator(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ANOTHER_ROLE, "anotherBehavior"); + addActivator(activator2); + + setDelay(300); + + // 4 : let us start the simulation automatically + setSimulationState(SimulationState.RUNNING); + } + + /** + * A simple way of launching this scheduler + * + * @param + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler04.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex04/SimulatedAgent04.java b/release/src/simulation/ex04/SimulatedAgent04.java new file mode 100644 index 0000000..6a03589 --- /dev/null +++ b/release/src/simulation/ex04/SimulatedAgent04.java @@ -0,0 +1,25 @@ +package simulation.ex04; + +import madkit.kernel.AbstractAgent; +import simulation.ex02.SimulationModel; + +public class SimulatedAgent04 extends AbstractAgent { + + @Override + protected void activate() { + requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ROLE); + // I use this role to identify me as an agent that know how to do another behavior + requestRole(SimulationModel.MY_COMMUNITY, SimulationModel.SIMU_GROUP, SimulationModel.ANOTHER_ROLE); + } + + @SuppressWarnings("unused") + private void doIt() { + getLogger().info("I am doing it, but my way"); + } + + @SuppressWarnings("unused") + private void anotherBehavior() { + getLogger().info("I am doing something else"); + } + +} diff --git a/release/src/simulation/ex05/MyScheduler05.java b/release/src/simulation/ex05/MyScheduler05.java new file mode 100644 index 0000000..2ed33c1 --- /dev/null +++ b/release/src/simulation/ex05/MyScheduler05.java @@ -0,0 +1,37 @@ +package simulation.ex05; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; +import simulation.ex04.MyScheduler04; + +/** + * + * + * + * Let us define explicitly how a simulation step takes place in order to define our own scheduling policy at will. This + * is done by overriding {@link Scheduler#doSimulationStep()}. + */ + +public class MyScheduler05 extends MyScheduler04 { + + /** + * Our step consists in activating the first activator one time and the second two times. It could have been anything + * else. In fact, we could do anything we want here, especially we also define another granularity for the step: 0.5 + */ + @Override + public void doSimulationStep() { + activator1.execute(); + activator2.execute(); + activator2.execute(); + setGVT(getGVT() + 0.5); + } + + /** + * A simple way of launching this scheduler. It is inherited but this is to make the IDE launch this one properly. + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler05.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex06/MyScheduler06.java b/release/src/simulation/ex06/MyScheduler06.java new file mode 100644 index 0000000..518c277 --- /dev/null +++ b/release/src/simulation/ex06/MyScheduler06.java @@ -0,0 +1,61 @@ +package simulation.ex06; + +import madkit.gui.ConsoleAgent; +import madkit.kernel.AbstractAgent; +import madkit.kernel.Madkit; +import madkit.kernel.Scheduler; +import madkit.simulation.activator.GenericBehaviorActivator; + +import static simulation.ex06.MySimulationModel06.MY_COMMUNITY; +import static simulation.ex06.MySimulationModel06.SIMU_GROUP; + +/** + * + * + * In this example, the goal is only to manage the execution of some new agents. The new classes are the + * madkit.kernel.Watcher that manages a madkit.kernel.Probe and a spying agent : + * simulation.ex06.SpyingAgent. + */ + +public class MyScheduler06 extends Scheduler { + + /** + * We define here 2 activators, one is used for the agents and the other one + * is used to activate the spy which probes their name. + */ + protected GenericBehaviorActivator agents; + protected GenericBehaviorActivator spy; + + @Override + protected void activate() { + + // 1 : create the simulation group + createGroup(MY_COMMUNITY, SIMU_GROUP); + + // 2 : request my role + requestRole(MY_COMMUNITY, SIMU_GROUP, MySimulationModel06.SCH_ROLE); + + // 3 : launch an simple agent + launchAgent(new SimulatedAgent06()); + + // 4 : launch the spy agent + launchAgent(new SpyingAgent()); + + // 5 : initialize the activators + // by default, they are activated once each in the order they have been added + agents = new GenericBehaviorActivator<>(MY_COMMUNITY, SIMU_GROUP, MySimulationModel06.AGENT_ROLE, "doIt"); + addActivator(agents); + spy = new GenericBehaviorActivator<>(MY_COMMUNITY, SIMU_GROUP, MySimulationModel06.SPY_ROLE, "spyIt"); + addActivator(spy); + + setDelay(300); + } + + /** + * A simple way of launching this scheduler + */ + public static void main(String[] args) { + new Madkit("--launchAgents", MyScheduler06.class.getName() + ",true;" + ConsoleAgent.class.getName()); + } + +} diff --git a/release/src/simulation/ex06/MySimulationModel06.java b/release/src/simulation/ex06/MySimulationModel06.java new file mode 100644 index 0000000..b428fe6 --- /dev/null +++ b/release/src/simulation/ex06/MySimulationModel06.java @@ -0,0 +1,15 @@ +package simulation.ex06; + +/** + * Stocking some global properties for this tutorial. + */ + + public class MySimulationModel06{ + + public static final String MY_COMMUNITY = "simu"; + public static final String SIMU_GROUP = "simu"; + public static final String AGENT_ROLE = "agent"; + public static final String SPY_ROLE = "spy"; + public static final String SCH_ROLE = "scheduler"; + +} diff --git a/release/src/simulation/ex06/SimulatedAgent06.java b/release/src/simulation/ex06/SimulatedAgent06.java new file mode 100644 index 0000000..e9000a0 --- /dev/null +++ b/release/src/simulation/ex06/SimulatedAgent06.java @@ -0,0 +1,22 @@ +package simulation.ex06; + +import madkit.kernel.AbstractAgent; + +/** + * In this example, we create a simulated agent extended from the AbstractAgent class + * to set a role to this agent. We also give him a name so that the spy can probe his name. + */ + +public class SimulatedAgent06 extends AbstractAgent { + + protected String name = "SimulatedAgent06"; + + @Override + protected void activate() { + requestRole(MySimulationModel06.MY_COMMUNITY, MySimulationModel06.SIMU_GROUP, MySimulationModel06.AGENT_ROLE); + } + + private void doIt() { + getLogger().info("I am doing it"); + } +} diff --git a/release/src/simulation/ex06/SpyingAgent.java b/release/src/simulation/ex06/SpyingAgent.java new file mode 100644 index 0000000..9202896 --- /dev/null +++ b/release/src/simulation/ex06/SpyingAgent.java @@ -0,0 +1,39 @@ +package simulation.ex06; + +import madkit.kernel.Watcher; +import madkit.simulation.probe.PropertyProbe; + +/** + * This class will be used to catch the name of the SimulatedAgent06 thanks to a probe. + * + * The madkit.kernel.Probe class defines a watcher's generic probe. A probe is configured + * according to a community, a group and a role. + */ + +public class SpyingAgent extends Watcher { + + /** + * The probe by which we will get the agents' name. + */ + protected PropertyProbe agentsNameProbe; + + @Override + protected void activate() { + // 1 : request my role + requestRole(MySimulationModel06.MY_COMMUNITY, MySimulationModel06.SIMU_GROUP, MySimulationModel06.SPY_ROLE); + + // 2 initialize the probe + agentsNameProbe = new PropertyProbe<>(MySimulationModel06.MY_COMMUNITY, MySimulationModel06.SIMU_GROUP, MySimulationModel06.AGENT_ROLE, "name"); + addProbe(agentsNameProbe); + } + + // this is just a simple method to be activated + private void spyIt() { + for (SimulatedAgent06 a: agentsNameProbe.getCurrentAgentsList() ) { + // We collect the agent's name in a String + String name = agentsNameProbe.getPropertyValue(a); + getLogger().info("I am spying on the agent " + name); + } + } + +} diff --git a/release/src/simulation/ex07/EnvironmentAgent.java b/release/src/simulation/ex07/EnvironmentAgent.java new file mode 100644 index 0000000..cdb6da8 --- /dev/null +++ b/release/src/simulation/ex07/EnvironmentAgent.java @@ -0,0 +1,53 @@ +package simulation.ex07; + +import java.awt.Dimension; + +import madkit.kernel.AbstractAgent; +import madkit.kernel.Watcher; +import madkit.simulation.probe.PropertyProbe; + +/** + * This agent is used to model a quite simple environment. Nothing in it; It just defines its boundaries and uses a + * {@link PropertyProbe} to set the agents' environment field so that they can use the environment's methods once they + * enter the artificial society. + */ +public class EnvironmentAgent extends Watcher { + + /** + * environment's boundaries + */ + private Dimension dimension; + + /** + * so that the agents can perceive my dimension + */ + public Dimension getDimension() { + return dimension; + } + + @Override + protected void activate() { + dimension = new Dimension(400, 400); + + // 1 : request my role so that the viewer can probe me + requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.ENV_ROLE); + + // 2 : this probe is used to initialize the agents' environment field + addProbe(new AgentsProbe(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE, "environment")); + + } + + class AgentsProbe extends PropertyProbe { + + public AgentsProbe(String community, String group, String role, String fieldName) { + super(community, group, role, fieldName); + } + + @Override + protected void adding(AbstractAgent agent) { + super.adding(agent); + setPropertyValue(agent, EnvironmentAgent.this); + } + } + +} \ No newline at end of file diff --git a/release/src/simulation/ex07/MyScheduler07.java b/release/src/simulation/ex07/MyScheduler07.java new file mode 100644 index 0000000..ce5bd2c --- /dev/null +++ b/release/src/simulation/ex07/MyScheduler07.java @@ -0,0 +1,37 @@ +package simulation.ex07; + +import madkit.kernel.AbstractAgent; +import madkit.kernel.Scheduler; +import madkit.simulation.activator.GenericBehaviorActivator; + +/** + * + * + * Nothing really new here, except that we define an additional Activator which is used to schedule the display. + * Especially, this is about calling the "observe" method of agents having the role of viewer in the organization + */ + +public class MyScheduler07 extends Scheduler { + + protected GenericBehaviorActivator agents; + protected GenericBehaviorActivator viewers; + + @Override + protected void activate() { + + // 1 : request my role + requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.SCH_ROLE); + + // 3 : initialize the activators + // by default, they are activated once each in the order they have been added + agents = new GenericBehaviorActivator<>(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE, "doIt"); + addActivator(agents); + viewers = new GenericBehaviorActivator<>(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.VIEWER_ROLE, "observe"); + addActivator(viewers); + + setDelay(20); + +// 4 : let us start the simulation automatically + setSimulationState(SimulationState.RUNNING); + } +} \ No newline at end of file diff --git a/release/src/simulation/ex07/MySimulationModel.java b/release/src/simulation/ex07/MySimulationModel.java new file mode 100644 index 0000000..ec70cb1 --- /dev/null +++ b/release/src/simulation/ex07/MySimulationModel.java @@ -0,0 +1,48 @@ +package simulation.ex07; + +import madkit.kernel.AbstractAgent; + +/** + * + * + * It is time to display something !! The only purpose of this class is to show an example of what could be a launching + * sequence. The display work is done in {@link Viewer} + */ +public class MySimulationModel extends AbstractAgent { + + // Organizational constants + public static final String MY_COMMUNITY = "simu"; + public static final String SIMU_GROUP = "simu"; + public static final String AGENT_ROLE = "agent"; + public static final String ENV_ROLE = "environment"; + public static final String SCH_ROLE = "scheduler"; + public static final String VIEWER_ROLE = "viewer"; + + @Override + protected void activate() { + // 1 : create the simulation group + createGroup(MY_COMMUNITY, SIMU_GROUP); + + // 2 : create the environment + EnvironmentAgent environment = new EnvironmentAgent(); + launchAgent(environment); + + // 4 : launch some simulated agents + for (int i = 0; i < 10; i++) { + launchAgent(new SituatedAgent()); + } + + // 5 : create the scheduler + MyScheduler07 scheduler = new MyScheduler07(); + launchAgent(scheduler, true); + + // 3 : create the viewer + Viewer viewer = new Viewer(); + launchAgent(viewer, true); + + } + + public static void main(String[] args) { + executeThisAgent(1, false); // no gui for me + } +} diff --git a/release/src/simulation/ex07/SituatedAgent.java b/release/src/simulation/ex07/SituatedAgent.java new file mode 100644 index 0000000..1fdf49a --- /dev/null +++ b/release/src/simulation/ex07/SituatedAgent.java @@ -0,0 +1,43 @@ +package simulation.ex07; + +import java.awt.Dimension; + +import madkit.kernel.AbstractAgent; + +public class SituatedAgent extends AbstractAgent { + + /** + * The agent's environment. Here it is just used to know its boundaries. It will be automatically set by the environment + * agent itself: No need to instantiate anything here. + */ + protected EnvironmentAgent environment; + + /** + * agent's position + */ + protected Dimension location = new Dimension(); + + /** + * initialize my role and fields + */ + @Override + protected void activate() { + requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE); + Dimension envDim = environment.getDimension(); + location.width = (int) (Math.random() * envDim.width); + location.height = (int) (Math.random() * envDim.height); + } + + /** + * A non sense behavior, just moving around. + */ + @SuppressWarnings("unused") + private void doIt() { + Dimension envDim = environment.getDimension(); + location.width += Math.random() * 4 - 1; + location.height += Math.random() * 4 - 1; + location.width %= envDim.width; + location.height %= envDim.height; + } + +} diff --git a/release/src/simulation/ex07/Viewer.java b/release/src/simulation/ex07/Viewer.java new file mode 100644 index 0000000..9ffc98e --- /dev/null +++ b/release/src/simulation/ex07/Viewer.java @@ -0,0 +1,75 @@ +package simulation.ex07; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import madkit.kernel.Watcher; +import madkit.simulation.probe.PropertyProbe; +import madkit.simulation.probe.SingleAgentProbe; +import madkit.simulation.viewer.SwingViewer; + +/** + * This class will be used to display the simulation. We could have extended the {@link Watcher} class, but there are a + * lot of things already defined in {@link SwingViewer}. So why not use it. + */ +public class Viewer extends SwingViewer { + + /** + * environment's size, probed using a {@link SingleAgentProbe}. + */ + private Dimension envSize; + + /** + * The probe by which we will get the agents' location + */ + protected PropertyProbe agentsLocationProbe; + + @Override + protected void activate() { + // 1 : request my role so that the scheduler can take me into account + requestRole(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.VIEWER_ROLE); + + // 2 : adding the probes + + // probing the environment using an anonymous inner class + SingleAgentProbe envProbe = new SingleAgentProbe(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, + MySimulationModel.ENV_ROLE, "dimension") { + + @Override + protected void adding(EnvironmentAgent agent) { + super.adding(agent); + envSize = getPropertyValue(); + } + }; + addProbe(envProbe); + + // probing agents' location + agentsLocationProbe = new PropertyProbe(MySimulationModel.MY_COMMUNITY, MySimulationModel.SIMU_GROUP, MySimulationModel.AGENT_ROLE, "location"); + addProbe(agentsLocationProbe); + + // 3 : Now that the probes are added, + // we can setup the frame for the display according to the environment's properties + getDisplayPane().setPreferredSize(envSize); + getFrame().pack(); + + // 4 (optional) set the synchronous painting mode: The display will be updated + // for each step of the simulation. + // Here it is useful because the simulation goes so fast that the agents + // are almost invisible + setSynchronousPainting(true); + } + + /** + * render is the method where the custom painting has to be done. Here, we just draw red points at the agents' location + */ + @Override + protected void render(Graphics g) { + g.setColor(Color.RED); + for (SituatedAgent a : agentsLocationProbe.getCurrentAgentsList()) { + Dimension location = agentsLocationProbe.getPropertyValue(a); + g.drawRect(location.width, location.height, 1, 1); + } + } + +} diff --git a/release/src/simulation/ex08/ImageViewer.java b/release/src/simulation/ex08/ImageViewer.java new file mode 100644 index 0000000..22a3f60 --- /dev/null +++ b/release/src/simulation/ex08/ImageViewer.java @@ -0,0 +1,35 @@ +package simulation.ex08; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; + +import javax.swing.ImageIcon; + +import simulation.ex07.SituatedAgent; +import simulation.ex07.Viewer; + +/** + * + * + * + * We can of course use images to represent the agents. + */ +public class ImageViewer extends Viewer { + + /** + * Taking an image used in another tutorial + */ + private final Image car = new ImageIcon(getClass().getResource("/gui/ex03_customPanel/agent.png")).getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH); + + /** + * render is the method where the custom painting has to be made. Here, we use the image at the agents' location + */ + @Override + protected void render(Graphics g) { + for (SituatedAgent a : agentsLocationProbe.getCurrentAgentsList()) { + Dimension location = agentsLocationProbe.getPropertyValue(a); + g.drawImage(car, location.width, location.height, null); + } + } +} diff --git a/release/src/simulation/ex08/MySimulationModel08.java b/release/src/simulation/ex08/MySimulationModel08.java new file mode 100644 index 0000000..74decbb --- /dev/null +++ b/release/src/simulation/ex08/MySimulationModel08.java @@ -0,0 +1,23 @@ +package simulation.ex08; + +import simulation.ex07.MySimulationModel; + +/** + * + * It is time to display using an alternative representation for the agents !! See {@link ImageViewer} + */ +public class MySimulationModel08 extends MySimulationModel { + + @Override + protected void activate() { + super.activate(); + + // adding the new viewer + ImageViewer viewer = new ImageViewer(); + launchAgent(viewer, true); + } + + public static void main(String[] args) { + executeThisAgent(1, false); // no gui for me + } +} diff --git a/release/src/simulation/ex08/Test.java b/release/src/simulation/ex08/Test.java new file mode 100644 index 0000000..b0f8093 --- /dev/null +++ b/release/src/simulation/ex08/Test.java @@ -0,0 +1,15 @@ +package simulation.ex08; + +import madkit.kernel.Agent; +import madkit.kernel.Madkit; + +public class Test extends Agent { + + /** + * @param args + */ + public static void main(String[] args) { + new Madkit(); + } + +}