You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »


This page provides concrete MIB instrumentation sample implementations based on the SNMP4J-AGENT-TUTORIAL-MIB.

Instrumentation using Virtual Tables


With SNMP4J-AgentX's BufferedMOTableModel, you can easily instrument tables based on a virtual table technology. That means, the table is (usually) never hold in with all its rows in memory. Instead, only those rows are fetched from the underlying data source that are actually needed and requested by the currently running requests on the table.

  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:

    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 {
    
        private Snmp4jAgentTutorialMib snmp4jAgentTutorialMib;
    
        public Snmp4jAgentTutorialFactory(Snmp4jAgentTutorialMib snmp4jAgentTutorialMib) {
            this.snmp4jAgentTutorialMib = snmp4jAgentTutorialMib;
        }
    
        @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(
                        snmp4jAgentTutorialMib.getSnmp4jAgentTutorialFileTreeBURootPath(), tableOID, indexDef, columns);
            }
            return super.createTableModel(tableOID, indexDef, columns);
        }
    }
    
    
  2. In the generated Agent.java class file, change the getFactory() method to:

    protected MOFactory getFactory() {
      return new Snmp4jAgentTutorialFactory(modules.getSnmp4jAgentTutorialMib());
    }
    
    
  3. Implement your subclass of the BufferedMOTableModel or BufferedMOMutableTableModel. See the attached file for an example.

 

  • No labels