Module org.snmp4j

Class MultiThreadedMessageDispatcher

    • Constructor Detail

      • MultiThreadedMessageDispatcher

        public MultiThreadedMessageDispatcher​(WorkerPool workerPool,
                                              MessageDispatcher decoratedDispatcher)
        Creates a multi-threaded message dispatcher using the provided ThreadPool to concurrently process incoming messages that are forwarded to the supplied decorated MessageDispatcher.
        Parameters:
        workerPool - a WorkerPool instance (that can be shared). The worker pool has to be stopped externally.
        decoratedDispatcher - the decorated MessageDispatcher that must be multi-threading safe.
    • Method Detail

      • getNextRequestID

        public int getNextRequestID()
        Description copied from interface: MessageDispatcher
        Gets the next unique request ID. The returned ID is unique across the last 2^31-1 IDs generated by this message dispatcher.
        Specified by:
        getNextRequestID in interface MessageDispatcher
        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.
      • addCounterListener

        public void addCounterListener​(CounterListener counterListener)
        Adds a CounterListener to the dispatcher. The counter listener is informed about errors during message dispatching.
        Specified by:
        addCounterListener in interface MessageDispatcher
        Parameters:
        counterListener - a CounterListener instance.
        Since:
        3.0
      • sendPdu

        public PduHandle sendPdu​(TransportMapping transportMapping,
                                 Target target,
                                 PDU pdu,
                                 boolean expectResponse)
                          throws MessageException
        Description copied from interface: MessageDispatcher
        Sends a PDU to the supplied transport address.
        Specified by:
        sendPdu in interface MessageDispatcher
        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

        public PduHandle sendPdu​(TransportMapping transportMapping,
                                 Target target,
                                 PDU pdu,
                                 boolean expectResponse,
                                 PduHandleCallback<PDU> callback)
                          throws MessageException
        Description copied from interface: MessageDispatcher
        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.
        Specified by:
        sendPdu in interface MessageDispatcher
        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.
      • returnResponsePdu

        public int returnResponsePdu​(int messageProcessingModel,
                                     int securityModel,
                                     byte[] securityName,
                                     int securityLevel,
                                     PDU pdu,
                                     int maxSizeResponseScopedPDU,
                                     StateReference stateReference,
                                     StatusInformation statusInformation)
                              throws MessageException
        Description copied from interface: MessageDispatcher
        Returns a response PDU to the sender of the corresponding request PDU.
        Specified by:
        returnResponsePdu in interface MessageDispatcher
        Parameters:
        messageProcessingModel - int
        securityModel - int
        securityName - byte[]
        securityLevel - int
        pdu - PDU
        maxSizeResponseScopedPDU - int
        stateReference - StateReference
        statusInformation - StatusInformation
        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.
      • releaseStateReference

        public void releaseStateReference​(int messageProcessingModel,
                                          PduHandle pduHandle)
        Description copied from interface: MessageDispatcher
        Release any state references associated with the supplied PduHandle in the specified message processing model.
        Specified by:
        releaseStateReference in interface MessageDispatcher
        Parameters:
        messageProcessingModel - a message processing model ID.
        pduHandle - the PduHandle that identifies a confirmed class message.
        See Also:
        MessageProcessingModel
      • getTransport

        public TransportMapping getTransport​(Address destAddress)
        Description copied from interface: MessageDispatcher
        Returns a transport mapping that can handle the supplied address.
        Specified by:
        getTransport in interface MessageDispatcher
        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.
      • processMessage

        public void processMessage​(TransportMapping sourceTransport,
                                   Address incomingAddress,
                                   java.nio.ByteBuffer wholeMessage,
                                   TransportStateReference tmStateReference)
        Description copied from interface: MessageDispatcher
        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 MessageDispatcher
        Specified by:
        processMessage in interface TransportListener
        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.