The XMOJO Project
<< Prev 5. Shop Keeper MBean Creation Next >>

 Creating an MBean for Shopkeeper 

We define the management information that will be required by a shopkeeper.  After defining the management information, we proceed with choosing an appropriate MBean (Standard or Dynamic) and then create the MBean.

 Defining the management information 

A shopkeeper would like to manage the inventory level of the existing items.  A shopkeeper might be also interested in providing new items that can be made available for his customers.  The ShoppingCart application does not provide option for providing new items.  So, we will focus on managing the inventory level of an item.

The below given tables summarize the management information that the MBean will expose

Attribute Information
Attribute Name
Attribute Type
Attribute Access
Attribute Description
PetName java.lang.String
read only
The item name
InventoryLevel java.lang.Integer
read only
The number of items available


Operation Information
Operation Name
Signature
Parameters
Operation Description
increaseStock void Integer quantity To increase the inventory level of an item

The increaseStock method can be exposed only if the InventoryLevel decreases to some predetermined value, say 5.

Since the exposure of the above management information is going to be dynamic (i.e, increaseStock will be exposed only if InventoryLevel decreases to a predetermined value), we can write a Dynamic MBean, which is most appropriate.

Creating the MBean 

A DynamicMBean should implement the javax.management.DynamicMBean interface. Let the name of the DynamicMBean class we are going to create be InventoryManager.

Implementing the getMBeanInfo Method of the DynamicMBean Interface

The management information (attributes, operations) are constructed and returned as a MBeanInfo.  This MBeanInfo object is returned by the getMBeanInfo method.  We have to construct a MBeanInfo such that it contains only two read only attributes.  Before constructing this MBeanInfo, we will check whether InventoryLevel  is less than 5.  For doing this check, let us define a method checkInventoryLevel.  If checkInventoryLevel returns true, which means the InventoryLevel is less than 5, we add one more operation increaseStock to the MBeanInfo we construct in the getMBeanInfo method.

Download InventoryManager.java to see the complete implementation details.

<< Prev Home Next >>
Customer MBean Creation
JMX Agent Creation