Module org.snmp4j
Package org.snmp4j

Interface MessageDispatcher

All Superinterfaces:
TransportListener
All Known Implementing Classes:
MessageDispatcherImpl, MultiThreadedMessageDispatcher

public interface MessageDispatcher extends TransportListener
The MessageDispatcher interface defines common services of instances that process incoming SNMP messages and dispatch them to interested CommandResponder instances. It also provides a service to send out outgoing SNMP messages. A MessageDispatcher needs at least one TransportMapping and at least one MessageProcessingModel in order to be able to process any messages.
Version:
3.2.0
Author:
Frank Fock
  • Method Details

    • getNextRequestID

      int getNextRequestID()
      Gets the next unique request ID. The returned ID is unique across the last 2^31-1 IDs generated by this message dispatcher.
      Returns:
      an integer value in the range 1..2^31-1. The returned ID can be used to map responses to requests send through this message dispatcher.
      Since:
      1.1
    • addMessageProcessingModel

      void addMessageProcessingModel(MessageProcessingModel model)
      Adds a MessageProcessingModel to the dispatcher. In order to support a specific SNMP protocol version, the message dispatcher needs a message processing model to process messages before they can be dispatched.
      Parameters:
      model - a MessageProcessingModel instance.
    • removeMessageProcessingModel

      void removeMessageProcessingModel(MessageProcessingModel model)
      Removes a previously added MessageProcessingModel from the dispatcher.
      Parameters:
      model - a MessageProcessingModel instance.
    • getMessageProcessingModel

      MessageProcessingModel getMessageProcessingModel(int messageProcessingModel)
      Gets the MessageProcessingModel for the supplied message processing model ID.
      Parameters:
      messageProcessingModel - a message processing model ID (see MessageProcessingModel.getID()).
      Returns:
      a MessageProcessingModel instance if the ID is known, otherwise null
    • addTransportMapping

      void addTransportMapping(TransportMapping<? extends Address> transport)
      Adds a TransportMapping to the dispatcher. The transport mapping is used to send and receive messages to/from the network.
      Parameters:
      transport - a TransportMapping instance.
    • removeTransportMapping

      TransportMapping<? extends Address> removeTransportMapping(TransportMapping<? extends Address> transport)
      Removes a previously added TransportMapping from the dispatcher.
      Parameters:
      transport - a TransportMapping instance.
      Returns:
      the TransportMapping instance if it could be successfully removed, null otherwise.
    • addCounterListener

      void addCounterListener(CounterListener counterListener)
      Adds a CounterListener to the dispatcher. The counter listener is informed about errors during message dispatching.
      Parameters:
      counterListener - a CounterListener instance.
      Since:
      3.0
    • removeCounterListener

      CounterListener removeCounterListener(CounterListener counterListener)
      Removes a previously added CounterListener from the dispatcher.
      Parameters:
      counterListener - a CounterListener instance.
      Returns:
      the CounterListener instance if it could be successfully removed, null otherwise.
      Since:
      3.0
    • getTransportMappings

      Collection<TransportMapping<? extends Address>> getTransportMappings()
      Gets the Collection of transport mappings in this message dispatcher.
      Returns:
      a Collection with the registered transport mappings.
    • getTransport

      @Deprecated <A extends Address> TransportMapping<? super A> getTransport(A destAddress)
      Deprecated.
      Use getTransport(Address, TransportType) instead to make sure that the returned mapping supports the intended SNMP application type usage (i.e. command/notification generator or command receiver).
      Returns a transport mapping that can handle the supplied address.
      Type Parameters:
      A - the Address type to get a TransportMapping for.
      Parameters:
      destAddress - an Address instance.
      Returns:
      a TransportMapping instance that can be used to sent a SNMP message to destAddress or null if such a transport mapping does not exists.
      Since:
      1.6
    • getTransport

      <A extends Address> TransportMapping<? super A> getTransport(A destAddress, TransportType transportType)
      Returns a transport mapping that can handle the supplied address.
      Type Parameters:
      A - the Address type to get a TransportMapping for.
      Parameters:
      destAddress - an Address instance.
      transportType - specifies the SNMP application type that will use the returned transport mapping. transportType must be either TransportType.receiver or TransportType.sender. If TransportType.any is provided an IllegalArgumentException will be thrown.
      Returns:
      a TransportMapping instance that can be used to sent a SNMP message to destAddress or null if such a transport mapping does not exists.
      Since:
      1.6
    • addCommandResponder

      void addCommandResponder(CommandResponder listener)
      Adds a CommandResponder instance to the message dispatcher. Successfully processed SNMP messages will be presented to all command responder (in the order in which they have been added) until a responder uses the CommandResponderEvent.setProcessed(boolean processed) to set the processed status of the event to true.
      Parameters:
      listener - a CommandResponder instance.
    • removeCommandResponder

      void removeCommandResponder(CommandResponder listener)
      Removes a previously added CommandResponder instance from the message dispatcher.
      Parameters:
      listener - a CommandResponder instance.
    • sendPdu

      <A extends Address> PduHandle sendPdu(TransportMapping<? super A> transportMapping, Target<A> target, PDU pdu, boolean expectResponse) throws MessageException
      Sends a PDU to the supplied transport address.
      Type Parameters:
      A - the Address type.
      Parameters:
      transportMapping - the TransportMapping to be used to send the PDU. If transportMapping is null the message dispatcher will determine the appropriate transport mapping for the given transport address.
      target - the target which identifies, transport address, message processing model, security model, security name and level.
      pdu - the SNMP Protocol Data Unit
      expectResponse - true if a response is expected and a state reference should be saved (if needed for the supplied message processing model).
      Returns:
      an PduHandle that uniquely identifies this request.
      Throws:
      MessageException - if sending of the PDU failed.
    • sendPdu

      <A extends Address> PduHandle sendPdu(TransportMapping<? super A> transportMapping, Target<A> target, PDU pdu, boolean expectResponse, PduHandleCallback<PDU> callback) throws MessageException
      Sends a PDU to the supplied transport address and returns the PduHandle that uniquely identifies the request as response after the request has been sent and optional, if a PduHandleCallback is given, it returns also the PduHandle just before the request is sent through the the callback interface.
      Type Parameters:
      A - the target Address type.
      Parameters:
      transportMapping - the TransportMapping to be used to send the PDU. If transportMapping is null the message dispatcher will determine the appropriate transport mapping for the given transport address.
      target - the target which identifies, transport address, message processing model, security model, security name and level.
      pdu - the SNMP Protocol Data Unit
      expectResponse - true if a response is expected and a state reference should be saved (if needed for the supplied message processing model).
      callback - an optional callback instance that is informed (if not null) about the newly assigned PduHandle just before the message is sent out.
      Returns:
      an PduHandle that uniquely identifies this request.
      Throws:
      MessageException - if sending of the PDU failed.
    • sendPdu

      <A extends Address> PduHandle sendPdu(Target<A> target, PDU pdu, boolean expectResponse) throws MessageException
      Sends a PDU to the supplied transport address. This method behaves like a call to sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse) with transportMapping set to null.
      Type Parameters:
      A - the target Address type.
      Parameters:
      target - the target which identifies, transport address, message processing model, security model, security name and level.
      pdu - the SNMP Protocol Data Unit
      expectResponse - true if a response is expected and a state reference should be saved (if needed for the supplied message processing model).
      Returns:
      an PduHandle that uniquely identifies this request.
      Throws:
      MessageException - if sending of the PDU failed.
    • returnResponsePdu

      <A extends Address> int returnResponsePdu(int messageProcessingModel, int securityModel, byte[] securityName, int securityLevel, PDU pdu, int maxSizeResponseScopedPDU, StateReference<A> stateReference, StatusInformation statusInformation) throws MessageException
      Returns a response PDU to the sender of the corresponding request PDU.
      Type Parameters:
      A - the Address type.
      Parameters:
      messageProcessingModel - the message processing model, see MessageProcessingModel
      securityModel - the security model to use, see SecurityModel
      securityName - the security name
      securityLevel - the security level for the message to be returned, see SecurityLevel
      pdu - the protocol data unit (PDU) to send.
      maxSizeResponseScopedPDU - the maximum size agreed for the response scoped PDU.
      stateReference - the state reference to be used.
      statusInformation - the status information to be used.
      Returns:
      an MP error status or SnmpConstants.SNMP_MP_OK if the operation was successful.
      Throws:
      MessageException - if message processing fails with a fatal error.
    • processMessage

      <A extends Address> void processMessage(TransportMapping<? super A> sourceTransport, A incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference)
      Process an incoming SNMP message. The message is processed and dispatched according to the message's content, the message processing models, and the command responder available to the dispatcher.
      Specified by:
      processMessage in interface TransportListener
      Type Parameters:
      A - the Address type.
      Parameters:
      sourceTransport - a TransportMapping instance denoting the transport that received the message and that will be used to send any responses to this message. The sourceTransport has to support the incomingAddress's implementation class.
      incomingAddress - the Address from which the message has been received.
      wholeMessage - an ByteBuffer containing the received SNMP message.
      tmStateReference - the transport model state reference as defined by RFC 5590.
    • releaseStateReference

      void releaseStateReference(int messageProcessingModel, PduHandle pduHandle)
      Release any state references associated with the supplied PduHandle in the specified message processing model.
      Parameters:
      messageProcessingModel - a message processing model ID.
      pduHandle - the PduHandle that identifies a confirmed class message.
      See Also:
    • stop

      default void stop()
      Stops this message dispatcher and free all resources (i.e. stop/join internal threads, etc.)
      Since:
      3.5.0