Note: This is an
individual assignment. You may brainstorm with other students, but
the bulk of the work and the bulk of the ideas must be your own.
That entails that you may not share a drawing by copy-and-paste or
by any other means. If you do work with other students (or anybody
else) you must cite that collaboration explicitly in your
submitted assignment. This is good practice in any circumstances. |
The objective is to create an new agent that adds a new tab to its AbstractInternalFrame
interface. This is actually rather easy to do. To make it little
harder, the tab component should display a count of all of each kind of
performative it has seen in the messages for both incoming and outgoing
messages (separately). Thus, the contents of the tab should look
something like this:
Received Messages:
request: 3
agree: 2
refuse: 1
Sent Messages:
request: 3
refuse: 3
Most of the information you need for this assignments is in the Feb 13
lecture, User
Interfaces. The tab panel is set up using your choice of Swing Component
class and the TransientAgent
methods described in the lecture notes. You can add your tab in your
agent's initializeThread()
method. You can easily monitor the agent's message events using the Observer
pattern by making your Component
class an Observer which
observes the Agent as a Subject.
The easiest way to test your agent is by including a public
static main(String[] args) method which instantiates your
agent. This will let you easily run a test from the Run menu item from
the Eclipse editor popup menu. For example:
public static void main(String[] args) {
Runnable1<TransientAgent,Void> code = new Runnable1<TransientAgent,Void>() {
public Void run(TransientAgent agent) {
... any code you want to run after your agent initializes ...
}
};
CASAUtil.startAnAgent(TransientAgent.class, "Fred4", 6234, code);
}
The CASAUtil.startAnAgent()
method is only in the latest version of the casa jar, and I've reproduced it
here if you want to just include it in your source rather than download CASA
again:
/**
* Run an agent of type <em>theClass</em> named <em>agentName</em> on port <em>port</em>, optionally
* executing <em>code</em> once the agent is started up. This can be really useful for testing new
* agents.
* @param theClass The class of the agent to start.
* @param agentName The name of the new agent.
* @param port The port for the new agent.
* @param code The code to execute once the agent starts up -- it will be passed the actual agent
* when it is called; may be null.
*/
public static void startAnAgent(Class<?> theClass, String agentName, int port, Runnable1<TransientAgent,Void> code) {
BufferedAgentUI buf = new BufferedAgentUI();
TransientAgent agent = CASAProcess.startAgent(buf, theClass, agentName, port, "PROCESS", "CURRENT", "TRACE", "10", "TRACETAGS", "info5,warning,msg,iRobot,-boundSymbols,-policies9,-commitments,-eventqueue,-conversations");
if (agent==null) {
System.err.println(buf.result());
System.exit(-1);
}
while (!agent.isInitialized()) { //wait for the agent to startup
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
try { // give the agent some time to get started
Thread.sleep(3000);
} catch (InterruptedException e) {
}
if (code!=null) {
code.run(agent);
}
}