RMA Programmers Guide
From Agent Factory
Contents |
Editorial History
08/07/2008: Version 1 - Initial version of guide
Introduction
This guide outlines how to create and deploy a Reactive Message Agent and what tools are provided by the RMA Development Kit to support this process. In contrast with other agent architectures, such as that underpinning the the AFAPL2 language, RMA agents are implemented solely in Java by extending the core com.agentfactory.rma.ReactiveMessageAgent base class.
Requirements
The RMA is a purely Java architecture for creating agents. As such, no specific support is currently provided and any Java IDE may be used to develop agents. However, from a deployment perspective, the Agent Factory Netbeans Plugin is recommended.
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.
Creating an RMA Agent
As was implied above, RMA Agents are created by subclassing the com.agentfactory.rma.ReactiveMessageAgent class. However, when doing this, you must create a constructor that takes two arguments:
- A String object that is the name of the agent
- An AgentPlatform object that has a reference to the underlying agent platform.
Also, the first line of this constructor MUST call the corresponding constructor in the parent class. We illustrate this through an example Ping agent that is based on the Ping agent example discussed in the AFAPL2 Programmers Guide.
import com.agentfactory.platform.AgentPlatform;
import com.agentfactory.rma.ReactiveMessageAgent;
public class PingAgent extends ReactiveMessageAgent {
public PingAgent(String name, AgentPlatform platform) {
super(name, platform);
}
}
The code above declares a new type of RMA agent, known as a PingAgent. In order for this agent to do something, we need to write an appropriate set of handlers. For the Ping agent example, the desired behaviour involved the agent responding to a ping request by informing the sender of the request of pong. To realise this behaviour in an RMA agent, we simply create an appropriate Message Handler.
Creating a Message Handler
We illustrate how to create a message handler by creating one for our PingAgent example, which we started above. Specifically, we will create a PingMessageHandler class. This class extends the com.agentfactory.rma.MessageHandler class and implements two methods:
- the filter(...) method checks whether the message is a ping message, and
- the act(...) method implements the behaviour that should be invoked should a ping message be received.
The code below implements the Ping-Pong behaviour:
import com.agentfactory.platform.mts.Message;
import com.agentfactory.rma.MessageHandler;
import com.agentfactory.rma.ReactiveMessageAgent;
public class PingMessageHandler extends MessageHandler {
public PingMessageHandler(ReactiveMessageAgent agent, String performative) {
super(agent, performative);
}
public boolean filter(Message message) {
if (!message.getLanguage().equals("AFAPL")) {
return false;
}
return message.getContent().equals("ping");
}
public boolean act(Message message) {
send(createAFAPLMessage(Message.INFORM, agent.getAgentID(), message, "ping"));
return true;
}
}
As can be seen, the filter(...) method checks that the content is in AFAPL and the the content is the constant "ping". If such a message is received, then the agent responds by sending back a "pong" inform messaqe which is specified in the act(...) method. As can be seen here, the MessageHandler base class includes two support methods:
- the createAFAPLMessage(...) creates a reply message based on the incoming message, and
- the send(...) message sends the message that is created.
