Class SnmpTrapSession


  • public final class SnmpTrapSession
    extends Object

    The trap session is used to send and receives SNMPv1 & v2 trap messages. The messages are received on the configured port, or the default(162) port and then decoded using the set ASN.1 codec. When messages are sent they are encoded using the passed SnmpParameters object that is part of the SnmpPeer object.

    A trap message handler must be bound to the session in order to send or receive messages.

    Version:
    1.1.1.1 2001/11/11 17:27:22
    Author:
    OpenNMS , Brian Weaver , Sowmya
    See Also:
    SnmpTrapHandler
    • Constructor Detail

      • SnmpTrapSession

        public SnmpTrapSession​(SnmpTrapHandler handler)
                        throws SocketException
        The default SnmpTrapSession constructor.
        Parameters:
        handler - The handler associated for message processing.
        Throws:
        SocketException - If thrown it is from the creation of a DatagramSocket.
        SecurityException - Thrown if the security manager disallows the creation of the handler.
      • SnmpTrapSession

        public SnmpTrapSession​(SnmpTrapHandler handler,
                               int port)
                        throws SocketException
        The default SnmpTrapSession constructor that takes a packet handler as parameter. Also changes the default port to listen on
        Throws:
        SocketException - If thrown it is from the creation of a DatagramSocket.
    • Method Detail

      • getHandler

        public SnmpTrapHandler getHandler()
        Returns the trap handler for this trap session.
        Returns:
        The SnmpTrapHandler
      • setHandler

        public void setHandler​(SnmpTrapHandler hdl)
        Sets the trap handler for the session.
        Parameters:
        hdl - The new packet handler
      • setAsnEncoder

        public void setAsnEncoder​(AsnEncoder encoder)
        Sets the default encoder.
        Parameters:
        encoder - The new encoder
      • getAsnEncoder

        public AsnEncoder getAsnEncoder()
        Gets the AsnEncoder for the session.
        Returns:
        the AsnEncoder
      • isClosed

        public boolean isClosed()
        Returns true if the close method has been called. The session cannot be used to send request after close has been executed.
      • close

        public void close()
        Used to close the session. Once called the session should be considered invalid and unusable.
        Throws:
        IllegalStateException - Thrown if the session was already closed.
      • send

        public void send​(SnmpPeer peer,
                         SnmpPduPacket pdu)
                  throws SnmpPduEncodingException,
                         AsnEncodingException,
                         IOException
        Transmits the specified SnmpRequest to the SnmpPeer defined. First the SnmpPdu contained within the request is encoded using the peer AsnEncoder, as defined by the SnmpParameters. Once the packet is encoded it is transmitted to the agent defined by SnmpPeer. If an error occurs an appropiate exception is generated.
        Parameters:
        peer - The remote peer to send to.
        pdu - The pdu to transmit
        Throws:
        SnmpPduEncodingException - Thrown if an encoding exception occurs at the session level
        AsnEncodingException - Thrown if an encoding exception occurs in the AsnEncoder object.
        IOException - Thrown if an error occurs sending the encoded datagram
        IllegalStateException - Thrown if the session has been closed.
        See Also:
        SnmpRequest, SnmpParameters, SnmpPeer