A direct benefit of using an SNMP agent integrated in this way is that the information contained in the MIB can be browsed through the adaptors provided by the Java Dynamic Management Kit. For instance, if you are using the HTML adaptor, you can view the MIB through a web browser.
FIGURE 18-1 shows the management of a Java Dynamic Management agent by an SNMP manager application. This shows how a Java Dynamic Management agent communicating with an SNMP manager requires metadata so that the managed m-beans are visible to the manager. The SNMP manager application cannot access m-beans registered in the repository that have not been generated by mibgen. RMI or HTTP manager applications, however, are able to manage all m-beans, including those generated by mibgen.

FIGURE 18-1 Integrated SNMP Agent
Standalone Agents
Standalone agents run independently of all other Java Dynamic Management Kit components. These agents are accessible only through SNMP and cannot benefit from Java Dynamic Management Kit services. However, standalone agents minimize the resources used by the Java Dynamic Management Kit at runtime.
Overview of the Agent Development Process
The main steps involved in developing an SNMP agent using the Java Dynamic Management Kit are:
For each variable of a group, mibgen generates:
| CODE EXAMPLE 18-2 Code Generated by mibgen to Implement sysLocation |
Note - The checker method must throw an SnmpStatusException if the requested operation cannot be performed.
Implementing Access Methods for Tables and Entries
Tables are not represented as specific m-beans but as a set of entries. For each table, mibgen generates a Java class containing the SNMP view of the table. In the case of MIB II, the TCP group is represented by an m-bean called tcp. The mibgen compiler generates a Java class called TabletcpConnTable to represent the SNMP view of tcpConnTable. An instance of TabletcpConnTable is created in the constructor of the group. The code generated by mibgen to implement the TCP group is shown in CODE EXAMPLE 18-3.
| CODE EXAMPLE 18-3 Code Generated by mibgen to Implement the TCP Group |
Entries are represented in exactly the same way as groups, that is, as m-beans. A metadata object is generated for each entry type. The tcpConnTable table contains a tcpConnEntry object. Therefore, mibgen generates a tcpConnEntry class to represent an entry in tcpConnTable. The code generated by mibgen to implement tcpConnEntry is shown in CODE EXAMPLE 18-4.
| CODE EXAMPLE 18-4 Code Generated by mibgen to Implement tcpConnEntry |
Table objects provide methods for adding or removing entries from the table. CODE EXAMPLE 18-5 shows how to add a new tcpConnEntry to tcpConnTable.
| CODE EXAMPLE 18-5 Adding a New Entry to a Table |
If you want to be notified each time a table entry is added or removed, instantiate a class that implements the SnmpTableEntryListener interface. This interface defines two callback methods for classes that require such notification. Code for a class implementing the SnmpTableEntryListener interface is shown in CODE EXAMPLE 18-6. An SnmpTableEntryEvent is sent to the class implementing the SnmpTableEntryListener interface.
| CODE EXAMPLE 18-6 Implementing the SnmpTableEntryListener interface |
The class implementing the SnmpTableEntryListener interface must be added as a listener to the table to receive SnmpTableEntryEvent objects. This is shown in CODE EXAMPLE 18-7.
| CODE EXAMPLE 18-7 Adding an SnmpTableEntryListener |
When dealing with tables, SNMP indexes are handled automatically. The table object transparently maps an SNMP index to a Java table entry.
| CODE EXAMPLE 18-8 TabletcpConnTable Class Before Customization |
CODE EXAMPLE 18-9 shows how to customize the TabletcpConnTable class to allow the addition of new entries.
| CODE EXAMPLE 18-9 Customizing the TabletcpConnTable Class |
Note - By default, the generated code does not register table entries with the framework. Table entries are indexed properties within a group.
Loading MIBs Into an SNMP Adaptor
In the Java Dynamic Management Kit, a MIB is represented by a subclass of the SnmpMib class in the com.sun.jaw.impl.adaptor.snmp package. The generated class is named using the module name specified in the MIB definition. For example, mibgen generates a class called RFC1213_MIB.java to represent MIB II. The class initializes all the SNMP metadata required to handle the MIB and creates a new instance of each group.
|
init |
Initializes all the SNMP metadata required to handle the MIB and creates a new instance of each group. |
|
initCmf |
The same as init but in addition it registers each group in the . |
Port Allocations
When an agent instantiates an SNMP adaptor in the Solaris operating environment, it binds by default to port 161. To be able to bind to port 161, the agent must be started by the root user of the system.
|
prompt# /etc/init.d/init.snmpdx stop
|
To bind to a different port, set the object name of the SNMP adaptor explicitly, specifying the port number by using the port=portno search key.
Initializing a MIB Within the Framework
CODE EXAMPLE 18-10 shows how to initialize the MIB within the framework by calling the newObject method of the framework.
| CODE EXAMPLE 18-10 Initializing a MIB Within the Framework |
Initializing a MIB in a Standalone Agent
CODE EXAMPLE 18-11 shows how to initialize a MIB in a standalone agent.
| CODE EXAMPLE 18-11 Initializing a MIB in a Standalone Agent |
Binding a MIB to an SNMP Adaptor
A MIB object needs to be bound to an SNMP adaptor to be manageable through the SNMP protocol. A MIB can be bound or unbound at any time.
| CODE EXAMPLE 18-12 Loading a MIB Statically |