Class SnmpTrapSession
- java.lang.Object
-
- org.opennms.protocols.snmp.SnmpTrapSession
-
public final class SnmpTrapSession extends java.lang.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
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PORT
This is the default port where traps should be sent and received as defined by the RFC.static int
ERROR_EXCEPTION
Defines a error due to a thown exception.static int
ERROR_INVALID_PDU
Defines an error condition with an invalid PDU.
-
Constructor Summary
Constructors Constructor Description SnmpTrapSession(SnmpTrapHandler handler)
The default SnmpTrapSession constructor.SnmpTrapSession(SnmpTrapHandler handler, int port)
The default SnmpTrapSession constructor that takes a packet handler as parameter.SnmpTrapSession(SnmpTrapHandler handler, java.net.InetAddress address, int snmpTrapPort)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Used to close the session.AsnEncoder
getAsnEncoder()
Gets the AsnEncoder for the session.SnmpTrapHandler
getHandler()
Returns the trap handler for this trap session.boolean
isClosed()
Returns true if theclose
method has been called.void
send(SnmpPeer peer, SnmpPduPacket pdu)
Transmits the specified SnmpRequest to the SnmpPeer defined.void
send(SnmpPeer peer, SnmpPduTrap trap)
Transmits the specified SnmpPduTrap to the SnmpPeer defined The SnmpPduTrap is encoded using the peer AsnEncoder, as defined by the SnmpParameters.void
setAsnEncoder(AsnEncoder encoder)
Sets the default encoder.void
setHandler(SnmpTrapHandler hdl)
Sets the trap handler for the session.
-
-
-
Field Detail
-
ERROR_EXCEPTION
public static final int ERROR_EXCEPTION
Defines a error due to a thown exception. When the snmpTrapSessionError method is invoked in the trap handler, the exception object is passed as the ref parameter.
-
ERROR_INVALID_PDU
public static final int ERROR_INVALID_PDU
Defines an error condition with an invalid PDU. For the moment this is not actually used, but reserved for future use. When the session trap handler error method is invoke the pdu in error should be passed as the ref parameters
-
DEFAULT_PORT
public static final int DEFAULT_PORT
This is the default port where traps should be sent and received as defined by the RFC.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SnmpTrapSession
public SnmpTrapSession(SnmpTrapHandler handler) throws java.net.SocketException
The default SnmpTrapSession constructor.- Parameters:
handler
- The handler associated for message processing.- Throws:
java.net.SocketException
- If thrown it is from the creation of a DatagramSocket.java.lang.SecurityException
- Thrown if the security manager disallows the creation of the handler.
-
SnmpTrapSession
public SnmpTrapSession(SnmpTrapHandler handler, int port) throws java.net.SocketException
The default SnmpTrapSession constructor that takes a packet handler as parameter. Also changes the default port to listen on- Throws:
java.net.SocketException
- If thrown it is from the creation of a DatagramSocket.
-
SnmpTrapSession
public SnmpTrapSession(SnmpTrapHandler handler, java.net.InetAddress address, int snmpTrapPort) throws java.net.SocketException
- Throws:
java.net.SocketException
-
-
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 theclose
method has been called. The session cannot be used to send request afterclose
has been executed.
-
close
public void close()
Used to close the session. Once called the session should be considered invalid and unusable.- Throws:
java.lang.IllegalStateException
- Thrown if the session was already closed.
-
send
public void send(SnmpPeer peer, SnmpPduTrap trap) throws SnmpPduEncodingException, AsnEncodingException, java.io.IOException
Transmits the specified SnmpPduTrap to the SnmpPeer defined The SnmpPduTrap 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.trap
- The SnmpPduTrap to transmit- Throws:
SnmpPduEncodingException
- Thrown if an encoding exception occurs at the session levelAsnEncodingException
- Thrown if an encoding exception occurs in the AsnEncoder object.java.io.IOException
- Thrown if an error occurs sending the encoded datagramjava.lang.IllegalStateException
- Thrown if the session has been closed.- See Also:
SnmpRequest
,SnmpParameters
,SnmpPeer
-
send
public void send(SnmpPeer peer, SnmpPduPacket pdu) throws SnmpPduEncodingException, AsnEncodingException, java.io.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 levelAsnEncodingException
- Thrown if an encoding exception occurs in the AsnEncoder object.java.io.IOException
- Thrown if an error occurs sending the encoded datagramjava.lang.IllegalStateException
- Thrown if the session has been closed.- See Also:
SnmpRequest
,SnmpParameters
,SnmpPeer
-
-