Class AgentXSubagent

java.lang.Object
org.snmp4j.agent.agentx.subagent.AgentXSubagent
All Implemented Interfaces:
EventListener, AgentXCommandListener, org.snmp4j.agent.NotificationOriginator, org.snmp4j.transport.TransportStateListener

public class AgentXSubagent extends Object implements AgentXCommandListener, org.snmp4j.agent.NotificationOriginator, org.snmp4j.transport.TransportStateListener
The AgentXSubagent class implements the AgentX communication for an AgentX subagent implementation and the agent configuration via AgentConfigManager although many configurations that are necessary for a regular command responder and AgentX master agent are not applicable for a subagent. Since version 3.1.1 this class uses a ConcurrentHashMap to store AgentX sessions, which allows better concurrent operations on agents using multiple sessions.
Version:
3.2.0
Author:
Frank Fock
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    The RequestID uniquely identifies a set request in the request list by the master's address, the AgentX session ID, and the AgentX transaction ID.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The next AgentX transaction ID to be assigned by getNextTransactionID().
    protected final Map<org.snmp4j.smi.Address, AgentXPeer<?>>
    The AgentX peer agents (masters).
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for CleanupSet requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for CommitSet requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for Get requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for GetBulk requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for GetNext requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for TestSet requests.
    protected org.snmp4j.agent.RequestHandler<AgentXRequest>
    Request handler for UndoSet requests.
    The request list.
    protected final Map<Integer, AgentXSession<?>>
    The sessions hold by this sub-agent.
    Shared table support map with a key composed of sessionID + "#" + context.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AgentXSubagent(AgentX agentX, org.snmp4j.smi.OID subagentID, org.snmp4j.smi.OctetString subagentDescr, SubagentXConfigManager configManager, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy)
    Creates a AgentX sub-agent using a SubagentXConfigManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    <A extends org.snmp4j.smi.Address>
    int
    addAgentCaps(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id, org.snmp4j.smi.OctetString descr)
    Registers an agent capability (sysORID) with the master agent for the given context.
    protected <A extends org.snmp4j.smi.Address>
    org.snmp4j.transport.ConnectionOrientedTransportMapping<A>
    addMaster(A localAddress, List<org.snmp4j.transport.TransportStateListener> stateListeners)
    Creates and registers a new ConnectionOrientedTransportMapping for communicating with a master agent, bound to the given local address, and starts listening on it.
    void
    Adds a PingListener that is notified about the results of the periodic ping requests sent to the master agent (see setPingDelay(int)).
    int
    close(AgentXSession<?> session, byte reason)
    Close an AgentX session.
    closeAllSessions(byte reason)
    Close all sessions hold by this sub-agent and return the AgentX status of the close operation together with the AgentXSession object.
    protected int
    closeSession(int sessionID, byte reason)
    Close the AgentX session with the given session ID and reason.
    <A extends org.snmp4j.smi.Address>
    int
    connect(A masterAddress, A localAddress, AgentXSession<A> session)
    Connect to the given AgentX master using the specified local address.
    <A extends org.snmp4j.smi.Address>
    int
    connect(A masterAddress, A localAddress, AgentXSession<A> session, List<org.snmp4j.transport.TransportStateListener> stateListeners)
    Connect to the given AgentX master using the specified local address.
    void
    connectionStateChanged(org.snmp4j.transport.TransportStateEvent transportStateEvent)
     
    protected <R extends org.snmp4j.agent.mo.MOTableRow, A extends org.snmp4j.smi.Address>
    AgentXSharedMOTableSupport<R,?>
    createSharedTableSupport(AgentXSession<A> session, org.snmp4j.smi.OctetString context)
    Create a new AgentXSharedMOTableSupport instance for the given AgentX session and context.
    <A extends org.snmp4j.smi.Address>
    void
    disconnect(A masterAddress)
    Disconnect from master and suspend any sending of packets to the given master address, before actually closing the transport used to communicate with the specified master.
    void
    Dispatches an incoming AgentX command event to the appropriate request handler and sends the response back to the master agent.
    protected void
    Notifies all registered PingListeners about the given ping event.
    final AgentXSession<?>
    Returns the first session that have been opened by this subagent and is still open.
    Collection<org.snmp4j.smi.OctetString>
    Returns all contexts supported by the MOServers registered with this sub-agent.
    byte
    Gets the default priority used to register regions at the master agent.
    protected int
    Get the next AgentX transaction ID.
    protected byte
    getPriority(org.snmp4j.agent.ManagedObject<?> mo, AgentXRegion region)
    Gets the priority with which the supplied managed object and region should be registered at the master agent.
    org.snmp4j.agent.MOServer
    getServer(org.snmp4j.smi.OctetString context)
    Returns the MOServer that serves the given context.
    <A extends org.snmp4j.smi.Address>
    AgentXResponseEvent<A>
    notify(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
    Send an AgentX notification to the master which will then be forwarded to trap/notification targets of the master.
    notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
     
    notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.VariableBinding[] vbs)
    Sends notifications (traps) to all appropriate notification targets through the master agent.
    protected <A extends org.snmp4j.smi.Address>
    int
    openSession(org.snmp4j.transport.ConnectionOrientedTransportMapping<A> transport, A masterAddress, AgentXSession<A> session)
    Open a new AgentX session with the given transport and master address.
    <A extends org.snmp4j.smi.Address>
    void
    Process an AgentX message.
    protected void
    processNextSubRequest(AgentXRequest request, org.snmp4j.agent.MOServer server, org.snmp4j.smi.OctetString context, AgentXRequest.AgentXSubRequest sreq)
    Processes a single GetNext/GetBulk sub-request by looking up the next managed object in the given server and applying it to the sub-request.
    protected void
    Processes an AgentX response received from a master agent.
    protected <A extends org.snmp4j.smi.Address>
    int
    registerRegion(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte priority, org.snmp4j.smi.TimeTicks sysUpTime)
    Registers a single AgentX region at the master agent on behalf of the given session.
    void
    registerRegions(AgentXSession<?> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.TimeTicks sysUpTime, RegistrationCallback registrationCallback)
    Registers the subagent regions at the master agent.
    <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>>
    void
    registerSharedTableRows(AgentXSession<?> session, org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, RegistrationCallback registrationCallback, AgentXSharedMOTableSupport<R,?> sharedTableSupport)
    Registers the indexes and (row) regions of a shared table.
    <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>, A extends org.snmp4j.smi.Address>
    void
    registerSharedTableRows(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, RegistrationCallback registrationCallback)
    protected void
    release(org.snmp4j.agent.MOServer server, AgentXRequest req)
    Releases (unlocks) all managed objects that were locked by the sub-requests of the given request on the specified server.
    <A extends org.snmp4j.smi.Address>
    int
    removeAgentCaps(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id)
    Removes a previously registered agent capability (sysORID) from the master agent for the given context.
    protected void
    removeMaster(org.snmp4j.TransportMapping<?> transport)
    Removes and closes the given transport mapping that was used to communicate with a master agent.
    void
    Removes a previously added PingListener.
    <A extends org.snmp4j.smi.Address>
    boolean
    resetConnection(A masterAddress, boolean sendClosePdu)
    Reset a connection not working anymore either by trying to close all open sessions with an AgentXClosePdu (when sendClosePdu is true) or silently without sending any messages.
    <A extends org.snmp4j.smi.Address>
    boolean
    resumeConnecting(A masterAddress, org.snmp4j.transport.ConnectionOrientedTransportMapping<A> transportMapping)
    Resumes auto connection to the specified address using the given transport.
    protected <A extends org.snmp4j.smi.Address>
    void
    Sends the response PDU of the given request back to the master agent that initiated the command.
    void
    setDefaultPriority(byte priority)
    Sets the default priority used to register regions at the master agent, unless getPriority(ManagedObject, AgentXRegion) is overridden to return an individual priority.
    void
    setPingDelay(int seconds)
    Sets the ping delay in seconds.
    protected <A extends org.snmp4j.smi.Address>
    int
    unregisterRegion(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte timeout)
    Unregisters a single AgentX region at the master agent on behalf of the given session.

    Methods inherited from class Object

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

    • requestList

      protected final Map<AgentXSubagent.RequestID, AgentXRequest> requestList
      The request list.
    • peers

      protected final Map<org.snmp4j.smi.Address, AgentXPeer<?>> peers
      The AgentX peer agents (masters).
    • sessions

      protected final Map<Integer, AgentXSession<?>> sessions
      The sessions hold by this sub-agent.
    • requestHandlerGet

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerGet
      Request handler for Get requests.
    • requestHandlerGetNext

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerGetNext
      Request handler for GetNext requests.
    • requestHandlerGetBulk

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerGetBulk
      Request handler for GetBulk requests.
    • requestHandlerTestSet

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerTestSet
      Request handler for TestSet requests.
    • requestHandlerCommitSet

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerCommitSet
      Request handler for CommitSet requests.
    • requestHandlerUndoSet

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerUndoSet
      Request handler for UndoSet requests.
    • requestHandlerCleanupSet

      protected org.snmp4j.agent.RequestHandler<AgentXRequest> requestHandlerCleanupSet
      Request handler for CleanupSet requests.
    • nextTransactionID

      protected int nextTransactionID
      The next AgentX transaction ID to be assigned by getNextTransactionID().
    • sharedMOTableSupport

      protected Map<String, AgentXSharedMOTableSupport<?,?>> sharedMOTableSupport
      Shared table support map with a key composed of sessionID + "#" + context.
  • Constructor Details

    • AgentXSubagent

      public AgentXSubagent(AgentX agentX, org.snmp4j.smi.OID subagentID, org.snmp4j.smi.OctetString subagentDescr, SubagentXConfigManager configManager, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy)
      Creates a AgentX sub-agent using a SubagentXConfigManager.
      Parameters:
      agentX - the AgentX protocol to be used by this sub-agent.
      subagentID - the unique identifier for this subagent.
      subagentDescr - a textual description for this subagent.
      configManager - the configuration manager that organizes how ManagedObjects of this subagent are initialized, persistently stored, and served to the agent.
      Since:
      3.0
  • Method Details

    • setPingDelay

      public void setPingDelay(int seconds)
      Sets the ping delay in seconds. If greater than zero, for each session a ping PDU is sent to the master to validate the session regularly with the specified delay. To monitor the ping requests, it is necessary to add a PingListener with addPingListener(PingListener).
      Parameters:
      seconds - the delay. If zero or a negative value is supplied, no pings are sent
    • processCommand

      public <A extends org.snmp4j.smi.Address> void processCommand(AgentXCommandEvent<A> event)
      Description copied from interface: AgentXCommandListener
      Process an AgentX message.
      Specified by:
      processCommand in interface AgentXCommandListener
      Type Parameters:
      A - Address type of peer that trigger this command.
      Parameters:
      event - the AgentX message and necessary context information.
    • getNextTransactionID

      protected int getNextTransactionID()
      Get the next AgentX transaction ID.
      Returns:
      a unique AgentX transaction ID for this sub-agent execution runtime.
    • closeSession

      protected int closeSession(int sessionID, byte reason) throws IOException
      Close the AgentX session with the given session ID and reason.
      Parameters:
      sessionID - an AgentX session ID. If such a session does not exist, AgentXProtocol.AGENTX_NOT_OPEN is returned.
      reason - the AgentX reason (AgentXProtocol.REASON_SHUTDOWN, AgentXProtocol.REASON_TIMEOUTS, AgentXProtocol.REASON_BY_MANAGER, AgentXProtocol.REASON_PROTOCOL_ERROR, AgentXProtocol.REASON_PARSE_ERROR, AgentXProtocol.REASON_OTHER) for closing the session.
      Returns:
      the error status returned by the master agent or AgentXProtocol.AGENTX_TIMEOUT if the master did not respond in time.
      Throws:
      IOException - if the IO operation failed.
    • openSession

      protected <A extends org.snmp4j.smi.Address> int openSession(org.snmp4j.transport.ConnectionOrientedTransportMapping<A> transport, A masterAddress, AgentXSession<A> session) throws IOException
      Open a new AgentX session with the given transport and master address.
      Type Parameters:
      A - type of Address for the session's master address.
      Parameters:
      transport - the TransportMapping to use.
      masterAddress - the AgentX master agent address to connect.
      session - a new AgentXSession. On success, the session ID will be set to the value returned by the master.
      Returns:
      the error status returned by the master agent or AgentXProtocol.AGENTX_TIMEOUT if the master did not respond in time.
      Throws:
      IOException - if the IO operation failed.
    • disconnect

      public <A extends org.snmp4j.smi.Address> void disconnect(A masterAddress) throws IOException
      Disconnect from master and suspend any sending of packets to the given master address, before actually closing the transport used to communicate with the specified master.
      Type Parameters:
      A - the Address type.
      Parameters:
      masterAddress - the master's address to suspend and then disconnect.
      Throws:
      IOException - if the closing of the connection fails.
      Since:
      3.2.0
    • resumeConnecting

      public <A extends org.snmp4j.smi.Address> boolean resumeConnecting(A masterAddress, org.snmp4j.transport.ConnectionOrientedTransportMapping<A> transportMapping)
      Resumes auto connection to the specified address using the given transport. This call does not actually send any packets to the address, instead it simply (re)activates the mechanism to automatically establish a connection to the specified address, when a new packet (i.e. openSessionPDU) is sent to the master address. Thus, call openSession(ConnectionOrientedTransportMapping, Address, AgentXSession) immediately after calling this method to reconnect to a master, after a disconnect(Address) with suspend or a resetConnection(Address, boolean) call.
      Type Parameters:
      A - the Address type.
      Parameters:
      masterAddress - the master's address to disconnect and optionally suspend.
      transportMapping - the TransportMapping to resume.
      Returns:
      true if the master address was suspended before and is resumed now, false if resuming the master address was not necessary (i.e. is already active).
      Since:
      3.2.0
    • resetConnection

      public <A extends org.snmp4j.smi.Address> boolean resetConnection(A masterAddress, boolean sendClosePdu)
      Reset a connection not working anymore either by trying to close all open sessions with an AgentXClosePdu (when sendClosePdu is true) or silently without sending any messages. In both cases the connection associated with the given master address is closed (with disconnect(Address)) and all related sessions are removed and closed too.
      Type Parameters:
      A - the Address type of the connection.
      Parameters:
      masterAddress - the address of the peer to reset the connection.
      sendClosePdu - true if this subagent should try to send AgentXClosePdus for each open session before resetting the connection of false if the connection should be closed silently. Close PDU will be sent only if the transport is still listening.
      Returns:
      true if the connection has been successfully reset, false otherwise.
      Since:
      3.1.1
    • connect

      public <A extends org.snmp4j.smi.Address> int connect(A masterAddress, A localAddress, AgentXSession<A> session) throws IOException
      Connect to the given AgentX master using the specified local address.
      Type Parameters:
      A - address type to connect to.
      Parameters:
      masterAddress - the (TCP) address of the master agent.
      localAddress - the local address. Use port 0 to let AgentXSubagent choose an available port.
      session - returns the AgentXSession information of the new AgentX session, i.e., the session ID returned by the * master agent.
      Returns:
      AgentXProtocol.AGENTX_SUCCESS if the session has been established or an AgentX error status, if not.
      Throws:
      IOException - if an IO operation failed.
    • connect

      public <A extends org.snmp4j.smi.Address> int connect(A masterAddress, A localAddress, AgentXSession<A> session, List<org.snmp4j.transport.TransportStateListener> stateListeners) throws IOException
      Connect to the given AgentX master using the specified local address.
      Type Parameters:
      A - address type to connect to.
      Parameters:
      masterAddress - the (TCP) address of the master agent.
      localAddress - the local address. Use port 0 to let AgentXSubagent choose an available port.
      session - returns the AgentXSession information of the new AgentX session, i.e. the session ID returned by the master agent.
      stateListeners - an optional list of TransportStateListener to register for TransportStateEvents before the connection is being established using a new ConnectionOrientedTransportMapping.
      Returns:
      AgentXProtocol.AGENTX_SUCCESS if the session has been established or an AgentX error status, if not.
      Throws:
      IOException - if an IO operation failed.
      Since:
      3.0.1
    • close

      public int close(AgentXSession<?> session, byte reason) throws IOException
      Close an AgentX session.
      Parameters:
      session - a AgentXSession.
      reason - the AgentX reason (AgentXProtocol.REASON_SHUTDOWN, AgentXProtocol.REASON_TIMEOUTS, AgentXProtocol.REASON_BY_MANAGER, AgentXProtocol.REASON_PROTOCOL_ERROR, AgentXProtocol.REASON_PARSE_ERROR, AgentXProtocol.REASON_OTHER) for closing the session.
      Returns:
      AgentXProtocol.AGENTX_SUCCESS if the session has been closed or an AgentX error status, if not.
      Throws:
      IOException - if an IO operation failed.
    • closeAllSessions

      public Map<AgentXSession<?>, Integer> closeAllSessions(byte reason)
      Close all sessions hold by this sub-agent and return the AgentX status of the close operation together with the AgentXSession object.
      Specified by:
      closeAllSessions in interface AgentXCommandListener
      Parameters:
      reason - the AgentX reason (AgentXProtocol.REASON_SHUTDOWN, AgentXProtocol.REASON_TIMEOUTS, AgentXProtocol.REASON_BY_MANAGER, AgentXProtocol.REASON_PROTOCOL_ERROR, AgentXProtocol.REASON_PARSE_ERROR, AgentXProtocol.REASON_OTHER) for closing the session.
      Returns:
      a map of the AgentXSession session objects hold by this agent and the corresponding AgentX error code. An error code of AgentXProtocol.AGENTX_SUCCESS indicates that this session was successfully closed.
      Since:
      3.0.0
    • setDefaultPriority

      public void setDefaultPriority(byte priority)
      Sets the default priority used to register regions at the master agent, unless getPriority(ManagedObject, AgentXRegion) is overridden to return an individual priority.
      Parameters:
      priority - the priority between 0 and 255 (lower value results in higher priority).
    • getDefaultPriority

      public byte getDefaultPriority()
      Gets the default priority used to register regions at the master agent.
      Returns:
      the priority between 0 and 255 (lower value results in higher priority).
    • getPriority

      protected byte getPriority(org.snmp4j.agent.ManagedObject<?> mo, AgentXRegion region)
      Gets the priority with which the supplied managed object and region should be registered at the master agent. Overwrite this method to use individual priorities depending on the registered region/managed object. The default implementation returns getDefaultPriority().
      Parameters:
      mo - ManagedObject a managed object instance that manages region.
      region - the region to be registered.
      Returns:
      the priority between 0 and 255 (lower value results in higher priority).
    • registerRegions

      public void registerRegions(AgentXSession<?> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.TimeTicks sysUpTime, RegistrationCallback registrationCallback)
      Registers the subagent regions at the master agent. It uses the AgentXSharedMOTableSupport instances of AgentXSharedMutableMOTable instances. For any other instances a support object instance will be created for each session and context.
      Parameters:
      session - the session on whose behalf regions are registered.
      context - the context to use for registration.
      sysUpTime - if not null, the master agent's notion of the sysUpTime for the registered context is returned. The input value is always ignored!
      registrationCallback - a possibly null reference to a RegistrationCallback instance to handle registration events.
    • createSharedTableSupport

      protected <R extends org.snmp4j.agent.mo.MOTableRow, A extends org.snmp4j.smi.Address> AgentXSharedMOTableSupport<R,?> createSharedTableSupport(AgentXSession<A> session, org.snmp4j.smi.OctetString context)
      Create a new AgentXSharedMOTableSupport instance for the given AgentX session and context.
      Type Parameters:
      R - the MOTableRow type to support.
      A - address type associated with the AgentXSession for which the shared table support is created.
      Parameters:
      session - an AgentXSession instance.
      context - a AgentX context.
      Returns:
      a (new) AgentXSharedMOTableSupport instance.
    • registerSharedTableRows

      @Deprecated public <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>, A extends org.snmp4j.smi.Address> void registerSharedTableRows(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, RegistrationCallback registrationCallback)
      Deprecated.
      Use registerSharedTableRows(org.snmp4j.agent.agentx.AgentXSession, org.snmp4j.smi.OctetString, AgentXSharedMOTable, RegistrationCallback, AgentXSharedMOTableSupport) instead. This version creates a new table support object for each call (shared table) which is not recommended.
      Registers the indexes and (row) regions of a shared table. This method is called on behalf of registerRegions(org.snmp4j.agent.agentx.AgentXSession, org.snmp4j.smi.OctetString, org.snmp4j.smi.TimeTicks, RegistrationCallback).
      Type Parameters:
      R - the MOTableRow type to support.
      C - the column (base) type of the shared table.
      M - the table model type managing the shared table rows.
      A - address type associated with the AgentXSession for which the shared table support is created.
      Parameters:
      session - the session on whose behalf regions are registered.
      context - the context to use for registration.
      mo - the AgentXSharedMOTable instance to register.
      registrationCallback - if not null the callback is informed when registration of a row succeeded or failed.
    • registerSharedTableRows

      public <R extends org.snmp4j.agent.mo.MOTableRow, C extends org.snmp4j.agent.mo.MOColumn<?>, M extends org.snmp4j.agent.mo.MOTableModel<R>> void registerSharedTableRows(AgentXSession<?> session, org.snmp4j.smi.OctetString context, AgentXSharedMOTable<R,C,M> mo, RegistrationCallback registrationCallback, AgentXSharedMOTableSupport<R,?> sharedTableSupport)
      Registers the indexes and (row) regions of a shared table. This method is called on behalf of registerRegions(org.snmp4j.agent.agentx.AgentXSession, org.snmp4j.smi.OctetString, org.snmp4j.smi.TimeTicks, RegistrationCallback).
      Type Parameters:
      R - the MOTableRow type to support.
      C - the column (base) type of the shared table.
      M - the table model type managing the shared table rows.
      Parameters:
      session - the session on whose behalf regions are registered.
      context - the context to use for registration.
      mo - the AgentXSharedMOTable instance to register.
      registrationCallback - if not null the callback is informed when registration of a row succeeded or failed.
      sharedTableSupport - the shared table support to be used for row registration. If mo has no table support instance and is a AgentXSharedMutableMOTable then its sharedTableSupport will be set to sharedTableSupport.
      Since:
      2.1
    • registerRegion

      protected <A extends org.snmp4j.smi.Address> int registerRegion(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte priority, org.snmp4j.smi.TimeTicks sysUpTime) throws IOException
      Registers a single AgentX region at the master agent on behalf of the given session.
      Type Parameters:
      A - the Address type of the session.
      Parameters:
      session - the session on whose behalf the region is registered. If null or closed, AgentXProtocol.AGENTX_NOT_OPEN is returned.
      context - the context to use for registration.
      region - the AgentXRegion to register.
      priority - the priority between 0 and 255 (lower value results in higher priority).
      sysUpTime - if not null, the master agent's notion of the sysUpTime for the registered context is returned. The input value is always ignored.
      Returns:
      the AgentX error status returned by the master agent, or AgentXProtocol.AGENTX_NOT_OPEN if the session is not open.
      Throws:
      IOException - if the IO operation failed.
    • unregisterRegion

      protected <A extends org.snmp4j.smi.Address> int unregisterRegion(AgentXSession<A> session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte timeout) throws IOException
      Unregisters a single AgentX region at the master agent on behalf of the given session.
      Type Parameters:
      A - the Address type of the session.
      Parameters:
      session - the session on whose behalf the region is unregistered. If null or closed, AgentXProtocol.AGENTX_NOT_OPEN is returned.
      context - the context that was used for registration.
      region - the AgentXRegion to unregister.
      timeout - the timeout in seconds to use for the unregister operation. If zero, the session's timeout is used.
      Returns:
      the AgentX error status returned by the master agent, or AgentXProtocol.AGENTX_NOT_OPEN if the session is not open.
      Throws:
      IOException - if the IO operation failed.
    • addMaster

      protected <A extends org.snmp4j.smi.Address> org.snmp4j.transport.ConnectionOrientedTransportMapping<A> addMaster(A localAddress, List<org.snmp4j.transport.TransportStateListener> stateListeners) throws IOException
      Creates and registers a new ConnectionOrientedTransportMapping for communicating with a master agent, bound to the given local address, and starts listening on it.
      Type Parameters:
      A - the Address type.
      Parameters:
      localAddress - the local address to bind the transport to. Use port 0 to let the transport choose an available port.
      stateListeners - an optional (possibly null) list of TransportStateListeners to register with the new transport before it starts listening.
      Returns:
      the created and listening ConnectionOrientedTransportMapping.
      Throws:
      IOException - if the transport could not be created or could not start listening.
    • removeMaster

      protected void removeMaster(org.snmp4j.TransportMapping<?> transport)
      Removes and closes the given transport mapping that was used to communicate with a master agent.
      Parameters:
      transport - the TransportMapping to remove from the AgentX instance and close.
    • getServer

      public org.snmp4j.agent.MOServer getServer(org.snmp4j.smi.OctetString context)
      Returns the MOServer that serves the given context.
      Parameters:
      context - the context for which the responsible server is returned.
      Returns:
      the MOServer supporting the given context, or null if no server supports it.
    • getContexts

      public Collection<org.snmp4j.smi.OctetString> getContexts()
      Returns all contexts supported by the MOServers registered with this sub-agent.
      Returns:
      a collection of the OctetString context names of all servers of this sub-agent.
    • dispatchCommand

      public void dispatchCommand(AgentXCommandEvent<?> cmd)
      Dispatches an incoming AgentX command event to the appropriate request handler and sends the response back to the master agent. Confirmed PDUs (Get, GetNext, GetBulk, TestSet, CommitSet, UndoSet, CleanupSet, and Close) are processed here, while responses are forwarded to processResponse(AgentXCommandEvent).
      Parameters:
      cmd - the AgentXCommandEvent to dispatch.
    • sendResponse

      protected <A extends org.snmp4j.smi.Address> void sendResponse(AgentXCommandEvent<A> cmd, AgentXRequest request)
      Sends the response PDU of the given request back to the master agent that initiated the command. The session ID, transaction ID, byte order, and packet ID of the response are copied from the initiating command PDU. No response is sent if the request has no response PDU.
      Type Parameters:
      A - the Address type of the command event.
      Parameters:
      cmd - the AgentXCommandEvent that initiated the request.
      request - the AgentXRequest whose response PDU is sent.
    • release

      protected void release(org.snmp4j.agent.MOServer server, AgentXRequest req)
      Releases (unlocks) all managed objects that were locked by the sub-requests of the given request on the specified server.
      Parameters:
      server - the MOServer that holds the locks.
      req - the AgentXRequest whose sub-requests' target managed objects are unlocked.
    • processResponse

      protected void processResponse(AgentXCommandEvent<?> cmd)
      Processes an AgentX response received from a master agent. The default implementation only logs the response at debug level. Overwrite this method to handle responses to unconfirmed PDUs.
      Parameters:
      cmd - the AgentXCommandEvent carrying the received response.
    • processNextSubRequest

      protected void processNextSubRequest(AgentXRequest request, org.snmp4j.agent.MOServer server, org.snmp4j.smi.OctetString context, AgentXRequest.AgentXSubRequest sreq) throws NoSuchElementException
      Processes a single GetNext/GetBulk sub-request by looking up the next managed object in the given server and applying it to the sub-request. If no next object exists, the variable binding is set to endOfMibView.
      Parameters:
      request - the AgentXRequest the sub-request belongs to.
      server - the MOServer to look up the next managed object in.
      context - the context of the request.
      sreq - the AgentXRequest.AgentXSubRequest to process.
      Throws:
      NoSuchElementException - if a required sub-request element cannot be found.
    • notify

      public Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.VariableBinding[] vbs)
      Sends notifications (traps) to all appropriate notification targets through the master agent.
      Specified by:
      notify in interface org.snmp4j.agent.NotificationOriginator
      Parameters:
      context - the context name of the context on whose behalf this notification has been generated.
      notificationID - the object ID that uniquely identifies this notification. For SNMPv1 traps, the notification ID has to be build using the rules provided by RFC 2576.
      vbs - an array of VariableBinding instances representing the payload of the notification.
      Returns:
      an AgentXResponseEvent instance or null if the notification request timed out.
    • notify

      public Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
      Specified by:
      notify in interface org.snmp4j.agent.NotificationOriginator
    • firstSession

      public final AgentXSession<?> firstSession()
      Returns the first session that have been opened by this subagent and is still open. If no open session exists, null is returned.
      Returns:
      an AgentXSession.
    • notify

      public <A extends org.snmp4j.smi.Address> AgentXResponseEvent<A> notify(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs) throws IOException
      Send an AgentX notification to the master which will then be forwarded to trap/notification targets of the master.
      Type Parameters:
      A - address type associated with the AgentXSession for which the notification is created.
      Parameters:
      session - the AgentXSession to be used.
      context - the SNMPv3 (AgentX) context of the notification.
      notificationID - the OID the identifies the notification as defined in the corresponding MIB.
      sysUpTime - the current notion of the sub-agents up-time.
      vbs - a notification payload as an array of VariableBinding instances. AgentXProtocol.AGENTX_SUCCESS if the session has been closed or an AgentX error status, if not.
      Returns:
      a AgentXResponseEvent object that provides detailed information about the response returned by the AgentX peer.
      Throws:
      IOException - if an IO operation failed.
    • addAgentCaps

      public <A extends org.snmp4j.smi.Address> int addAgentCaps(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id, org.snmp4j.smi.OctetString descr)
      Registers an agent capability (sysORID) with the master agent for the given context.
      Type Parameters:
      A - the Address type of the session.
      Parameters:
      session - the AgentXSession to use.
      context - the context for which the capability is registered.
      id - the OID of the capability (an AGENT-CAPABILITIES OID).
      descr - a textual description of the capability.
      Returns:
      the AgentX error status returned by the master agent, or AgentXProtocol.AGENTX_TIMEOUT if no response was received, or AgentXProtocol.AGENTX_NOT_OPEN if the PDU could not be sent.
    • removeAgentCaps

      public <A extends org.snmp4j.smi.Address> int removeAgentCaps(AgentXSession<A> session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id)
      Removes a previously registered agent capability (sysORID) from the master agent for the given context.
      Type Parameters:
      A - the Address type of the session.
      Parameters:
      session - the AgentXSession to use.
      context - the context for which the capability was registered.
      id - the OID of the capability to remove.
      Returns:
      the AgentX error status returned by the master agent, or AgentXProtocol.AGENTX_NOT_OPEN if the PDU could not be sent.
    • addPingListener

      public void addPingListener(PingListener l)
      Adds a PingListener that is notified about the results of the periodic ping requests sent to the master agent (see setPingDelay(int)).
      Parameters:
      l - the PingListener to add.
    • removePingListener

      public void removePingListener(PingListener l)
      Removes a previously added PingListener.
      Parameters:
      l - the PingListener to remove.
    • firePinged

      protected void firePinged(PingEvent<?> event)
      Notifies all registered PingListeners about the given ping event.
      Parameters:
      event - the PingEvent to fire to the registered listeners.
    • connectionStateChanged

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