Notifications are generated by an Agent to intimate the change of state of a particular variable in the Agent , to the Managers. In this Reference Implementation, Notification Type construct is defined for a variable and on any change of state of that variable, Notification is generated. Lets discuss in detail the implementation details of sending Notifications to the Managers from our shopping cart Agent.
As per the Reference Implementation, the Agent has to send Notifications to the Managers when :
Inventory level exceeds 15 for every pet item.
The maximum inventory level available for all the pet items is 20. Say for example, if the customer places an order for more than 15 for the pet Parrot, then a Notification is generated. This is done through the methods implemented in the java file generated for Traps.
In the main file generated the following code snippet is added inside registerJmxServices method. Once this method is executed (ie) the thread is started, it will execute the run method of inventory monitor class which is defined inside as inner class in ShoppingCartAgent class
|
InventoryMonitor inventoryMonitor = new InventoryMonitor(this,
ShoppingCartTable); |
As long as the agent is alive, it will keep calling monitorAndSendNotif()method for every 10000 seconds, as given in the following code-snippet.
|
public void run(){ |
The monitorAndSendNotif()method first retrieves the inventory level of the following pets : Parrot , Fist,Cat,Dog.
First it checks whether the inventory level of Parrot is less than 5. If it is less than five it calls the sendNotification() method passing the pets name (Parrot) and the inventory level of the Parrot.
This process is done for all the pets.
|
public void { |
Here the Notification is defined with the following inputs:
Notification Type (outOfStockNotification)
Name of the MBean Class
Sequence Number
Time at which the notification is sent
Notification Message which specifies that the inventory level has fallen below the minimum level.
NotificationBroadcaster of ShoppingCartTable is obtained and the same is used to send the notification by calling the sendNotification() passing the Notification which is defined above.
|
public void sendNotification(String petName, Integer level) |
The Notification mechanism is designed to forward only notifications from registered MBeans on the agent side to proper listeners on the manager side.
To view the Notifications through RMI/CORBA/HTTP Adaptors, select the View -> Notification option or View Notification icon in the MBean Browser.
To view the Notifications through TL1 Adaptor, select the Autonomous Message Block in the TL1 Browser.
To view the Notifications through SNMP Adaptor, select View -> Trap Viewer option or Trap Viewer icon of the MIB Browser. Set the port to 8003 in Trap Viewer. Click Start button. The Notification emitted will be listed in the trap viewer .