Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

1.6.1 Class Containing the SNMP View of a Table (Metadata Class)

The metadata class containing the SNMP view of a table contains all the management of the table index. Usually you do not need to subclass or access the generated table Metadata classes, except when implementing virtual tables. See SNMP Virtual Table example in the Java Dynamic Management Kit 5.1 Tutorial for details.

The class name is derived from the name of the table, and is postfixed by Meta. For example, for a table named sysApplInstallPkgTable in the MIB, mibgen will generate a Metadata class called SysApplInstallPkgTableMeta.

1.6.2 Class Containing the MBean View of the Table

The class containing the MBean view of a table enables you to add or remove entries dynamically from the table. This class contains callbacks and factory methods that enable you to instantiate or delete entries upon receiving requests from a remote SNMP manager. See the Simple SNMP Tables example and SNMP Table Insrtrumentation example in the Java Dynamic Management Kit 5.1 Tutorial for details.

The class name is prefixed with Table, followed by the name of the table. For example, for a table named sysApplInstallPkgTable in the MIB, mibgen will generate an MBean view of the table class called TableSysApplInstallPkgTable.

1.6.3 Skeletal MBeans Representing SNMP Table Entries

For each table in a MIB, the mibgen compiler generates an MBean that represents a table entry. These skeletal MBeans must be completed by adding implementation specific code, called access methods. The generated code is initialized with default values for table-entry fields. Therefore, if you compile the generated code directly, you obtain a running agent. In this case, values returned by the agent when querying the MIBs are not meaningful. The mibgen compiler uses the entry names that are specified in the MIB definition to name MBeans that are generated from table entries. For example, for a table entry definition named sysApplInstallPkgEntry in the MIB, mibgen will generate a skeletal MBean class named SysApplInstallPkgEntry and an interface named SysApplInstallPkgEntryMBean.


Note - Remote creation of table entries is disabled by default, for security reasons. You can dynamically enable and disable remote creation of table entries by calling the setCreationEnabled operation on the generated MBean-like object.


The RowStatus convention, that is defined in RFC 2579, is fully supported by the code generator. When a table is defined using SNMPv2, if it contains a control variable with row status syntax, the mibgen compiler generates a set of methods allowing this table to be remotely controlled by this variable. However, the remote creation and remote deletion of rows remains disabled by default.

Table objects are divided into two categories:

  • A metadata class

  • An MBean-like object

When remote table-entry creation is enabled, and the creation of a new table is requested, a factory method is called on the MBean-like object to instantiate the new table entry. By default, an instance of the skeleton class for that table entry is instantiated.

ProcedureTo Instantiate Your Own Implementation Class

  1. Subclass the MBean-like object to redefine the factory method for remote entry creation.

  2. Redefine this factory method so that it returns an instance of your implementation class, instead of the default skeleton.

  3. Subclass this table's group MBean to instantiate your new MBean-like object, instead of the generated default object.

    This is demonstrated in the RowStatus example, which is presented in the Java Dynamic Management Kit 5.1 Tutorial.

1.6.4 Metadata Files

In addition to generating skeletal MBeans to represent each table entry, the mibgen compiler generates a Java file containing the SNMP view of the MBean. Metadata files do not need to be modified. For metadata files, the Meta suffix is added.

1.6.5 Classes Representing SNMP Enumerated Types

The mibgen compiler generates a specific class for each enumerated type that is defined in the MIB. This class contains all the possible values defined in the enumerated type. The generated class extends the generic class Enumerated, defined in the com.sun.jdmk package. The HTML adaptor can use the Enumerated class to display all the labels that are contained in an enumeration. The mibgen compiler can handle enumerated types defined as part of a type definition or in-line definition.

Generated code representing SNMP enumerated types is prefixed with Enum followed by the type name or the variable name for inline definition.


Note - The mibgen compiler has an option -p prefix that you can use to prefix the names of all generated files with a specific string.


For example, in MIB II, TCP connection states are represented by an enumeration containing all the possible states for a TCP connection. The mibgen compiler generates a Java class named EnumTcpConnState to represent the enumeration.

1.7 Information Mapping

For each group defined in your MIB, the mibgen compiler generates an MBean. Each variable in the group is represented as a property of the MBean. If the MIB allows read access to a variable, the mibgen compiler generates a getter method for the corresponding property. If the MIB allows write access to a variable, the mibgen compiler generates a setter method for the property. Tables are seen as indexed properties whose type corresponds to the table entry type. The SNMP view of the table is maintained by a specific table object contained in the generated MBean. The mibgen compiler maps the MIB variable syntax to a well-defined Java type.

The MBeans that the mibgen compiler generates do not have any dependencies on specific SNMP objects. Therefore, these MBeans can be easily browsed or integrated into the various Java DMK components. The translation between the SNMP syntax and the MBean syntax is performed by the metadata.

MBeans generated by the mibgen compiler must be updated to provide the definitive implementation. The generated code is an operational agent. Thus, the code can be compiled, run, and tested without any modification.

As a general rule, use subclassing to implement your custom behavior. Do not edit the generated file, or your modification will be lost when you regenerate your MIB. Instead of subclassing the generated skeleton classes, you can also provide your own implementation that simply implements the corresponding generated interface, as shown in the SNMP Virtual Tables example in the Java Dynamic Management Kit 5.1 Tutorial.

Example 1-1 shows how to implement a skeletal MBean.

Example 1-1 Implementing a Skeletal MBean

public class g1 implements g1MBean, Serializable { 	
	    protected Integer myVar = new Integer (1);
      public g1(SnmpMib myMib) {
      {
      public Integer getMyVar() throws SnmpStatusException {
          return myVar;
      }

       public void setMyVar(Integer x)  throws SnmpStatusException {
           myVar = x;
      }

}

You must subclass or provide an implementation of the skeletal MBean to implement your MIB behavior. For information about developing an SNMP agent, SNMP Manager, SNMP API, and SNMP Proxy, see the corresponding sections in the Java Dynamic Management Kit 5.1 Tutorial.

Previous Previous     Contents     Index     Next Next