Generated Code for the MIB





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

Loaded the ShoppingCart MIB


The next step is to load the ShoppingCart MIB that was developed using MIB Editor application.

Configured Agent  Settings


Now you have to configure all the necessary settings for the Agent using the menus available.

Generated Stub files


To generate code for the ShoppingCartMib,

Files Generated


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.


Main File


The Main file ( 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 */
      // Starting shopping cart application 
      ApplicationStarter appl = new ApplicationStarter();
         Thread appThread = new Thread(appl);
       /* User code ends here */

This method is required for providing the Reference for the ShoppingCartApplication.

Reference Provider


The file 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.


Copyright © 2013, ZOHO Corp. All Rights Reserved.