In the chapter given earlier you saw how to define a MIB for the Shopping Cart application. In this chapter you will see how the stub/instrument files were generated for the defined ShoppingCartMIB. The JMX Compiler tool is used to generate stub files for a given MIB file.
To know more about the options available in the JMX Compiler, please refer topic 5.0 Configuring the Multi-Protocol agent in the section Building Multi-Protocol agents.
Generating Stub Files
The following steps were performed for generating the stub/instrumentation files :
Created a New Project
Start the JMX Compiler application from Agent Toolkit launcher or from <Agent Toolkit Home>/bin directory using JmxCompiler.sh or JmxCompiler.bat file.
The application opens up with the New Project tab.
Specify a workspace for your Project. By default it starts with workspace1. Lets take it to be the same.
Now, fill in the following details :
Name the Project : ShoppingCartAgent.
Location for the Project : As per our tutorial, it is <Agent Toolkit Home>\jmxprojects\ShoppingCartAgent.
And Click OK.
This creates a New Project. You can see ShoppingCartAgent.prj listed in the File View Tab.
Loaded the ShoppingCart MIB
The next step is to load the ShoppingCart MIB that was developed using MIB Editor application.
Load the ShoppingCartMib.mib that we defined, from <Agent Toolkit Home>/mibs directory by selecting the File --> Load Mib menu from the menu bar or clicking the Load MIB module from toolbar icon .
The ShoppingCartMib gets automatically loaded in the MIB View tab and gets listed under Loaded MibModules.
Configured Agent Settings
Now you have to configure all the necessary settings for the Agent using the menus available.
Go to Project -> Settings menu from the menu bar of JMX Compiler application.
You get the settings tree listed on the right side frame.
Do the following changes leaving others to be as default :
Select Source Code Generation -> Storage Model. On the right-side frame, you will find the storage options displayed. Here, expand the MIB and select shoppingCartMeanTable and specify the storage type as User defined.
Select Source Code Generation -> General and specify the Package Name as refimpl.shoppingcart.jmx and Agent Name as ShoppingCartAgent
Generated Stub files
To generate code for the ShoppingCartMib,
Select the Build -> Generate Source option or the generate icon on the toolbar, which generates source files corresponding to the ShoppingCartMib
The Debug window opens and displays information about the generated source files under the projects directory. After the code generation, it says Code generation succeeded for project : ShoppingCartAgent
The files are generated in <Agent Toolkit Home>/jmxprojects/ShoppingCartAgent/agent/src directory.
You can also view the files generated for the ShoppingCartproject in the Fileview Tab of the WorkSpace dialog. The main file will be generated in the name ShoppingCartAgent.java
The output and
source directory are
<Agent Toolkit Home>/reference/jmx/ShoppingCartAgent/agent/bin and <Agent Toolkit Home>/reference/jmx/ShoppingCartAgent/agent/src respectively.
The following files get generated for the shoppingCartMib.mib :
Explanation for the Table, Scalar and Trap files are provided in Implementing Tables, Scalars and Traps sections respectively.
The Main file (ShoppingCartAgent.java) takes care of all the registrations. The following code has been added in the Agent Main file to start the Shopping cart application. This file has been instrumented for instantiating the Application Starter.
/* User code starts here */
This method is required for providing the Reference for the ShoppingCartApplication.
/* User code starts here */
The file ReferenceProvider.java is an additional file created for the Shopping Cart application. The above code in the Main file provides a reference to the ShoppingCartApplication. The instrumentation part in the scalar file and table file takes reference from this file.
Compiling the Stub Files
The next step is to compile the stub files to form a complete Agent. Selecting Build -> Compile Source menu from the menu bar will compile all the source files and form the Agent. On successful compilation a confirmation message saying that the code has been compiled successfully can be seen.
The majority of work gets over here and now you can run the tutorial to test the Agent with default values. To run and test the Agent please refer to Running and Testing the Application. To know how the Shopping Cart application has been instrumented to return specific values on querying, please refer to the following sections : Implementing Scalars, Implementing Tables and Implementing Traps.