Note: This section is still under construction (incomplete). In the meantime, please refer to Chapter 3. "Agent Server Sample" while illustrates in quite a bit of detail how to build your own agent program (in a multi-client server environment.
The section "Writing Your Own Agent Program" introduces the topic of writing your own agent program. That section has much in common with this section, adding an agent program to your application. In fact this section is a little redundant with that section but this section will be eventually expanded to include a more comprehensive tutorial for marrying your application with an agent program. The purpose of "Writing Your Own Agent Program" is to put writing your own agent in context with using the sample agents and to introduce the basic tasks that are needed for any agent program (yours or the samples).
You add an agent to your application by creating an agent class that inherits from the IAAgent class of the IBM Agent Building Environment Developer's Toolkit, and invoking methods on that class to configure and control the agent. Sample agent programs, iagent for C++ and ibm.AgentBuilder.samples.agent.JavaAgent for Java are provided for reference. See Chapter 6. "Building and Starting Your Agent" for more information on the sample agent.
Note that the sample agent has the option to be run as a background program (a "daemon"). If your application supplies a configuration file and then starts the agent program with the -d option, the agent will be configured and executed on a background thread to your program.
The IAAgent interfaces used by your application to control the agent are described in Chapter 2. "Agent Reference" of the Components and Adapter Reference book. Refer to Chapter 1. "Building ABE-Related Components" for assistance in compiling and linking with the IAAgent and associated classes.
To create an agent object, you must create a class that inherits from the IAAgent class. Refer to Chapter 2. "Agent Reference" of the Components and Adapter Reference book for details on the IAAgent class, including descriptions of its member functions. There are several operations that you must do to the agent. First, you must configure the agent with the components that you desire (engine, adapters ...). Once the agent is configured, then it can be started. After the agent is started, it is able to handle events from the adapters. Finally, once you are done with the agent, you must stop it. Those operations are discussed in the next sections.
Note: Conduct sets can be loaded before or after the agent has been started. However, some adapters require some initialization to occur on the AGENT:CONFIG and/or AGENT:STARTING events. Conduct set using those adapters must be loaded before the agent is started.
After the agent has been configured, use the start() member function of IAAgent to start the agent. As part of start() processing, the agent will cause the "AGENT:CONFIG" and "AGENT:STARTING" events to be inferenced on all loaded conduct sets. After inferencing on those events have completed, all the adapters in your agent are free to use notify() to pass other events to the agent for processing.
When you want to stop your agent, use the stop() member function of the IAAgent object. As part of the stopping process, the agent will call the stop() member function of each component in the agent.