Class TestSubagent

java.lang.Object
org.snmp4j.agent.agentx.subagent.test.TestSubagent
All Implemented Interfaces:
Runnable, EventListener, RegistrationCallback, org.snmp4j.transport.TransportStateListener

public class TestSubagent extends Object implements Runnable, org.snmp4j.transport.TransportStateListener, RegistrationCallback
The TestSubagent is an example implementation of a simple AgentX subagent with shared tables and multi context registration.
Version:
4.2.0
Author:
Frank Fock
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.snmp4j.smi.OID
    The AgentX subagent identifier used when registering this subagent with the master agent.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TestSubagent(org.snmp4j.smi.Address masterAddress, org.snmp4j.smi.Address localAddress, String configFile)
    Creates a new TestSubagent that connects to the given AgentX master agent.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    connectionStateChanged(org.snmp4j.transport.TransportStateEvent change)
     
    static void
    main(String[] args)
    The program entry point that parses the command line arguments, creates the subagent, adds the local transport mapping, and runs the subagent.
    protected void
    Adds the session context to the server and registers the session dependent managed objects (Snmp4jConfigMib and Snmp4jLogMib) for the current AgentX session.
    void
    registrationEvent(org.snmp4j.smi.OctetString context, org.snmp4j.agent.ManagedObject<?> mo, int status)
    The registration attempt of a ManagedObject succeeded or failed.
    void
    run()
     
    <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>>
    boolean
    tableRegistrationEvent(org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, R row, boolean indexAllocation, int status, int retryCount)
    The registration attempt of a ManagedObject succeeded or failed.
    <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>>
    void
    tableUnregistrationEvent(org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, R row, boolean indexAllocation, int status)
    The unregistration attempt of a ManagedObject succeeded or failed.
    protected void
    Unregisters the session dependent managed objects and removes the session context from the server for the current AgentX session, if any.
    void
    unregistrationEvent(org.snmp4j.smi.OctetString context, org.snmp4j.agent.ManagedObject<?> mo, int status)
    The unregistration attempt of a ManagedObject succeeded or failed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SUBAGENT_ID

      public static final org.snmp4j.smi.OID SUBAGENT_ID
      The AgentX subagent identifier used when registering this subagent with the master agent.
  • Constructor Details

    • TestSubagent

      public TestSubagent(org.snmp4j.smi.Address masterAddress, org.snmp4j.smi.Address localAddress, String configFile)
      Creates a new TestSubagent that connects to the given AgentX master agent. The constructor sets up the AgentX instance and its message dispatcher, the MOServer, the optional persistent storage and configuration factory, and the SubagentXConfigManager that registers the MIB modules and launches the AgentX sessions.
      Parameters:
      masterAddress - the transport address of the AgentX master agent to connect to.
      localAddress - the local transport address used by the subagent.
      configFile - the path to the persistent storage directory, or null to run without persistence.
  • Method Details

    • main

      public static void main(String[] args)
      The program entry point that parses the command line arguments, creates the subagent, adds the local transport mapping, and runs the subagent.
      Parameters:
      args - the command line arguments.
    • unregisterSessionDependent

      protected void unregisterSessionDependent()
      Unregisters the session dependent managed objects and removes the session context from the server for the current AgentX session, if any.
    • registerSessionDependent

      protected void registerSessionDependent()
      Adds the session context to the server and registers the session dependent managed objects (Snmp4jConfigMib and Snmp4jLogMib) for the current AgentX session.
    • connectionStateChanged

      public void connectionStateChanged(org.snmp4j.transport.TransportStateEvent change)
      Specified by:
      connectionStateChanged in interface org.snmp4j.transport.TransportStateListener
    • registrationEvent

      public void registrationEvent(org.snmp4j.smi.OctetString context, org.snmp4j.agent.ManagedObject<?> mo, int status)
      Description copied from interface: RegistrationCallback
      The registration attempt of a ManagedObject succeeded or failed.
      Specified by:
      registrationEvent in interface RegistrationCallback
      Parameters:
      context - the registration context.
      mo - the ManagedObject that was subject to the registration process.
      status - the AgentX status of the registration response.
    • tableRegistrationEvent

      public <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>> boolean tableRegistrationEvent(org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, R row, boolean indexAllocation, int status, int retryCount)
      Description copied from interface: RegistrationCallback
      The registration attempt of a ManagedObject succeeded or failed.
      Specified by:
      tableRegistrationEvent in interface RegistrationCallback
      Type Parameters:
      R - the MOTableRow type to support.
      C - the column (base) type of the table.
      M - the table model type managing the table rows.
      Parameters:
      context - the registration context.
      mo - the MOTable that was subject to the registration process.
      row - the row whose index or region was subject to the allocation/registration.
      indexAllocation - true if this event relates to an index allocation request and false if it relates to a row region registration.
      status - the AgentX status of the registration response.
      retryCount - the number of retries already processed. This value can be used to avoid endless loops.
      Returns:
      true if the caller should retry the registration operation, false otherwise.
    • unregistrationEvent

      public void unregistrationEvent(org.snmp4j.smi.OctetString context, org.snmp4j.agent.ManagedObject<?> mo, int status)
      Description copied from interface: RegistrationCallback
      The unregistration attempt of a ManagedObject succeeded or failed.
      Specified by:
      unregistrationEvent in interface RegistrationCallback
      Parameters:
      context - the registration context.
      mo - the ManagedObject that was subject to the registration process.
      status - the AgentX status of the registration response.
    • tableUnregistrationEvent

      public <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>> void tableUnregistrationEvent(org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, R row, boolean indexAllocation, int status)
      Description copied from interface: RegistrationCallback
      The unregistration attempt of a ManagedObject succeeded or failed.
      Specified by:
      tableUnregistrationEvent in interface RegistrationCallback
      Type Parameters:
      R - the MOTableRow type to support.
      C - the column (base) type of the table.
      M - the table model type managing the table rows.
      Parameters:
      context - the registration context.
      mo - the MOTable that was subject to the registration process.
      row - the row whose index or region was subject to the allocation/registration.
      indexAllocation - true if this event relates to an index allocation request and false if it relates to a row region registration.
      status - the AgentX status of the registration response.
    • run

      public void run()
      Specified by:
      run in interface Runnable