Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create your own sub-class implementation of DefaultMOFactory in order to be able to create/use your own BufferedMOTableModel instead of the default table model generated by AgenPro:

    Code Block
    languagejava
    package org.snmp4j.agent.tutorial;
    
    import org.snmp4j.agent.mo.*;
    import org.snmp4j.agent.tutorial.impl.Snmp4JAgentTutorialFileTreeBUModel;
    import org.snmp4j.smi.OID;
    
    /**
     * The {@link Snmp4jAgentTutorialFactory} implements the {@link org.snmp4j.agent.mo.MOFactory} interface to
     * create the instrumentation implementation for the {@link Snmp4jAgentTutorialMib}.
     *
     * @author Frank Fock
     */
    public class Snmp4jAgentTutorialFactory extends DefaultMOFactory {
    
        @Override
        public <R extends MOTableRow, M extends MOTableModel<? extends R>> M
            createTableModel(OID tableOID, MOTableIndex indexDef, MOColumn[] columns) {
            if (Snmp4jAgentTutorialMib.oidSnmp4jAgentTutorialFileTreeBUEntry.equals(tableOID)) {
                return (M) new Snmp4JAgentTutorialFileTreeBUModel(tableOID, indexDef, columns);
            }
            return super.createTableModel(tableOID, indexDef, columns);
        }
    }
    
    
  2. In the generated Agent.java class file, change the getFactory() method to:

    Code Block
    languagejava
    protected MOFactory getFactory() {
      return new Snmp4jAgentTutorialFactory();
    }
    
    
  3. In the generated Agent.java class file, add the following code starting the "link related MIB objects" comment to the registerMIBs() method in order to let the virtual table model use the associated scalar to determine the root directory for the file tree browsing done by the model:

    Code Block
    languagejava
    /**
     * Register your own MIB modules in the specified context of the agent.
     * The {@link MOFactory} provided to the <code>Modules</code> constructor
     * is returned by {@link #getFactory()}.
     */
    protected void registerMIBs()
    {
      if (modules == null) {
        modules = new Modules(getFactory());
      }
      try {
        modules.registerMOs(server, null);
      }
      catch (DuplicateRegistrationException drex) {
        logger.error("Duplicate registration: "+drex.getMessage()+"."+
                     " MIB object registration may be incomplete!", drex);
      }
      // link related MIB objects
      ((Snmp4JAgentTutorialFileTreeBUModel)modules.getSnmp4jAgentTutorialMib().
              getSnmp4jAgentTutorialFileTreeBUEntry().getModel()).
              setRootPathScalar(modules.getSnmp4jAgentTutorialMib().getSnmp4jAgentTutorialFileTreeBURootPath());
    }
    
    
  4. Implement your subclass of the BufferedMOTableModel or BufferedMOMutableTableModel. See the attached file for Snmp4JAgentTutorialFileTreeBUModel.java for an example.

 

...