RMA Programmers Guide
From Agent Factory
Contents |
Editorial History
08/07/2008: Version 1 - Initial version of guide
11/12/2008: Version 2 - Reworking of guide as a set of examples that show how to develop systems using the Reactive Message Agent architecture. Any replicated information has been removed.
Introduction
This guide outlines how to create and deploy agent-based applications that are built using the Reactive Message Agent architecture. Basic information on this architecture can be found on the Reactive Message Agent overview page. Instead, this guide focuses on developing some simple example applications that showcase some of the features of both this architecture and the underlying Agent Factory framework.
Requirements
While any Java IDE can be used to develop RMA agents, we recommend using the Agent Factory Netbeans Plugin as it provides templates for key RMA classes and includes support for the deployment of Agent Factory applications.
In terms of Java packages, the following are required to implement and deploy an RMA agent:
- AF-RTE-x.x.x.jar: Contains the basic runtime aparatus for Agent Factory.
- AF-Debugger-x.x.x.jar: The Agent Factory Debugger should be used for debugging your implemented system.
- RMA-DK-x.x.x.jar: Contains the RMA architecture and a plugin for the Agent Factory Debugger.
Also, as a minimum requirement, you should also include the Local Message Transport Service. This is part of the Component Library and is packaged in the Local-MTS-x.x.x.jar package.
All of these components can be downloaded from Sourceforge.net.
Example 1: Hello World
To get things started, this example shows how to create a simple "hello world" agent. To create a Reactive Message Agent, you must extend the com.agentfactory.rma.ReactiveMessageAgent class:
import com.agentfactory.platform.AgentPlatform;
import com.agentfactory.rma.ReactiveMessageAgent;
public class HelloWorldAgent extends ReactiveMessageAgent {
public HelloWorldAgent(String name, AgentPlatform platform) {
super(name, platform);
System.out.println("Hello World!");
}
}
As can be seen in the above code, our first implementation is very simple, as the text "Hello World!" is printed out when the constructor is invoked (i.e. when the agent is created).
A more complex solution, but one which actually makes use of the Reactive Message Agent architecture is to use the built in event handling mechanism. To do this, we must create an Event Handler. For this example, we will implement the event handler as an inner class as follows:
import com.agentfactory.platform.AgentPlatform;
import com.agentfactory.rma.Event;
import com.agentfactory.rma.EventHandler;
import com.agentfactory.rma.ReactiveMessageAgent;
public class HelloWorldAgent extends ReactiveMessageAgent {
public HelloWorldAgent(String name, AgentPlatform platform) {
super(name, platform);
addEventHandler(new HelloWorldEventHandler());
addEvent(new Event("HW"));
}
public class HelloWorldEventHandler extends EventHandler {
@Override
public boolean filter(Event event) {
return event.getType().equals("HW");
}
@Override
public void handle(Event event) {
System.out.println("Hello World!");
}
}
}
Notice that, in the above solution, the HelloWorldEventHandler is added to the agent, and then an event of type "HW" is added to the agents event queue. The result is that, on the first iteration of the Reactive Message Agents execution cycle, the "HW" event is handled by this event handler, and "Hello World!" is printed out.
The advantage of this approach over the simpler approach used first, is that, should we wish to print out "Hello World!" again, all that we need to do is add another "HW" event to the agents event queue.
Finally, to run this application, you need to create the standard Agent Factory deployment files, namely the Agent Platform Script and the Platform Configuration File. Sample files are given below, starting with the Platform Configuration File:
PLATFORM_NAME test PLATFORM_DOMAIN agentfactory.com PLATFORM_GUI com.agentfactory.debugger.Debugger
This creates an Agent Platform with name: "test.agentfactory.com" and loads the Agent Factory Debugger, which includes a Reactive Message Agent plugin. Notice that, unlike the Platform Configuration Files used in the AFAPL2 Programmers Guide, this file contains no AGENT_INTERPRETER statements. This is because we are using the purely Java-based Reactive Message Agent architecture. Similarly, the Agent Platform Script file contains just a single line:
CREATE_AGENT Alive HelloWorldAgent.java
This line declares a new agent, called "Alive" that is an instance of the HelloWorldAgent Java class. If you create these two configuration files and deploy the application using the Netbeans Plugin, you should see the Agent Factory Debugger, which looks something like this (here "Alive" has been double-clicked on to open the associated Agent Inspector).
To see what happens, simply click on the "step" button. This will result in the text "Hello World!" being displayed in the Java standard output console.
Example 2: The Chatter System
T.B.C.

