Class AgentX

java.lang.Object
org.snmp4j.agent.agentx.AgentX
All Implemented Interfaces:
EventListener, AgentXCommandListener

public class AgentX extends Object implements AgentXCommandListener
The AgentX class implements the AgentX protocol that sends and receives AgentX PDUs over one or more transport mappings.
Version:
3.0.0
Author:
Frank Fock
  • Constructor Details

  • Method Details

    • addTransportMapping

      public void addTransportMapping(org.snmp4j.TransportMapping<?> transport)
      Add a TransportMapping for sending/receiving AgentX messages.
      Parameters:
      transport - a TransportMapping.
    • removeTransportMapping

      public void removeTransportMapping(org.snmp4j.TransportMapping<?> transport)
      Remove a TransportMapping for sending/receiving AgentX messages.
      Parameters:
      transport - the TransportMapping to be removed.
    • removeCommandResponder

      public void removeCommandResponder(AgentXCommandListener listener)
      Removes a AgentXCommandListener from this AgentX session.
      Parameters:
      listener - a previously added AgentXCommandListener instance.
    • addCommandResponder

      public void addCommandResponder(AgentXCommandListener listener)
      Adds a AgentXCommandListener to this AgentX session. The command responder will then be informed about incoming SNMP PDUs of any kind that are not related to any outstanding requests of this SNMP session.
      Parameters:
      listener - the AgentXCommandListener instance to be added.
    • send

      public <A extends org.snmp4j.smi.Address> AgentXResponseEvent<A> send(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport) throws IOException
      Sends a AgentXPDU to the given target and returns the response synchronously.
      Type Parameters:
      A - address type associated with the provided TransportMapping.
      Parameters:
      pdu - a AgentXPDU instance.
      target - the AgentXTarget instance representing the target AgentX entity where to send the pdu.
      transport - specifies the TransportMapping to be used when sending the PDU. If transport is null, the associated message dispatcher will try to determine the transport mapping by the target's address.
      Returns:
      the received response encapsulated in a AgentXResponseEvent instance. To obtain the received response AgentXPDU call AgentXResponseEvent.getResponse(). If the request timed out, that method will return null.
      Throws:
      IOException - if the message could not be sent.
    • send

      public <A extends org.snmp4j.smi.Address> void send(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, Object userHandle, AgentXResponseListener listener) throws IOException
      Sends a AgentXPDU to the given target and returns the response asynchronously.
      Type Parameters:
      A - address type associated with the provided TransportMapping.
      Parameters:
      pdu - a AgentXPDU instance.
      target - the AgentXTarget instance representing the target AgentX entity where to send the pdu.
      transport - specifies the TransportMapping to be used when sending the PDU. If transport is null, the associated message dispatcher will try to determine the transport mapping by the target's address.
      userHandle - an arbitrary user handle which is transparently returned to the response listener.
      listener - the listener that should be informed about the reponse or timeout.
      Throws:
      IOException - if the message could not be sent.
    • sendMessage

      protected <A extends org.snmp4j.smi.Address> org.snmp4j.mp.PduHandle sendMessage(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, org.snmp4j.mp.PduHandleCallback<AgentXPDU> pduHandleCallback) throws IOException
      Actually sends a PDU to a target and returns a handle for the sent PDU.
      Type Parameters:
      A - address type associated with the provided TransportMapping.
      Parameters:
      pdu - the PDU instance to be sent.
      target - a AgentXTarget instance denoting the target AgentX entity.
      transport - the (optional) transport mapping to be used to send the request. If transport is null a suitable transport mapping is determined from the target address.
      pduHandleCallback - an optional callback instance that is informed (if not null) about the newly assigned PduHandle just before the message is sent out.
      Returns:
      PduHandle that uniquely identifies the sent PDU for further reference.
      Throws:
      IOException - if the transport fails to send the PDU or the if the message cannot be BER encoded.
    • 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.
    • closeAllSessions

      public Map<AgentXSession<?>,Integer> closeAllSessions(byte reason)
      Throws UnsupportedOperationException because AgentX sessions are not managed on protocol level. Use AgentXCommandListener implementations on agent/application level instead.
      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:
      nothing, instead UnsupportedOperationException is thrown.
      Since:
      3.0.0
    • fireProcessPdu

      protected void fireProcessPdu(AgentXCommandEvent<?> event)
      Fires a CommandResponderEvent event to inform listeners about a received PDU. If a listener has marked the event as processed further listeners will not be informed about the event.
      Parameters:
      event - a CommandResponderEvent.
    • getMessageDispatcher

      public AgentXMessageDispatcher getMessageDispatcher()
      Get the AgentX message dispatcher.
      Returns:
      the associated AgentXMessageDispatcher.