In the previous section you saw how the stub files are generated. This section deals with the files generated for the scalar group and how they are instrumented.
The file generated for the scalar group shoppingCartSummary is shoppingCartSummaryInstrument.java. The instrument file contains all the getter and setter methods for all the attributes in the MBean . In this tutorial, the scalar attributes are totalItemCount and totalPrice .
The extra code added for instrumentation inside the method getTotalItemCount() shoppingCartSummaryInstrument.java file is available in between the following tags:
/* User code starts here */
/* User code ends here */
|
public Integer getTotalItemCount() /* User code starts here */ totalItemCount = new java.lang.Integer (shoppingCart.getTotalItemCount()); /* User code ends here */ return totalItemCount; } |
The instrumentation code has to be filled between these tags in order to support code merging when regenerated. Note that totalItemCount and totalPrice are "read-only" variables defined in the MIB and hence does not provide SET methods to modify the variable values.
When a get request is made from the manager for the scalar variable TotalItemcount,
The agent calls the getTotalItemcount() method of ShoppingCartSummaryInstrument object
Inside this method, the ShoppingCart object is obtained by calling the getShoppingCart() method of Reference Provider object.
The required TotalItemCount of the shoppingCart application is retrieved using getTotalItemCount() of ShoppingCart object
The getTotalItemCount() of ShoppingCartSummaryInstrument object returns the value obtained from the ShoppingCart application. Hence, the Agent sends this response to the manager.