JoeSNMP API 0.3.4

org.opennms.protocols.snmp
Class SnmpAgentSession

java.lang.Object
  extended by org.opennms.protocols.snmp.SnmpAgentSession

public final class SnmpAgentSession
extends java.lang.Object

The agent session is used to receive SNMPv1 Get, GetNext and Set messages. The messages are received on the configured port, or the default(162) port and then decoded using the set ASN.1 codec.

Author:
OpenNMS, Bob Snider
See Also:
SnmpAgentHandler

Nested Class Summary
private  class SnmpAgentSession.AgentHandler
          The internal trap handler class is designed to receive information from the enclosed SnmpPortal class.
 
Field Summary
static int DEFAULT_PORT
          This is the default port where traps should be sent and received as defined by the RFC.
private static java.lang.String DEFAULT_WRITE_COMMUNITY
          This is the default community string for Gets
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.
private  AsnEncoder m_encoder
          ASN.1 codec used to encode/decode snmp traps that are sent and received by this session.
private  SnmpAgentHandler m_handler
          The public trap handler that process received traps.
private  SnmpPeer m_peer
          Used to hold the community strings for validation, and the agent port to listen on.
private  int m_port
          The default port were traps are sent and received by this session.
private  SnmpPortal m_portal
          The default SNMP trap callback handler.
private  boolean m_threadException
          If this boolean value is set then the receiver thread is terminated due to an exception that was generated in either a handler or a socket error.
private  java.lang.Throwable m_why
          This is the saved fatal exception that can be rethrown by the application
 
Constructor Summary
private SnmpAgentSession()
          Used to disallow the default constructor.
  SnmpAgentSession(SnmpAgentHandler handler)
          The SnmpAgentSession constructor that takes a packet handler as parameter.
  SnmpAgentSession(SnmpAgentHandler handler, SnmpPeer peer)
          The default SnmpAgentSession constructor that takes a packet handler and SnmpPeer as parameter.
  SnmpAgentSession(SnmpAgentHandler handler, SnmpPeer peer, int numOfThreads)
          The SnmpAgentSession constructor that takes a packet handler, SnmpPeer, numOfThreads as parameter.
  SnmpAgentSession(SnmpAgentHandler handler, SnmpPeer peer, int numOfThreads, int receiveBuffer, int sendBuffer)
          The SnmpAgentSession constructor that takes a packet handler, SnmpPeer, numOfThreads as parameter.
 
Method Summary
 void close()
          Used to close the session.
 AsnEncoder getAsnEncoder()
          Gets the AsnEncoder for the session.
 SnmpAgentHandler getHandler()
          Returns the trap handler for this trap session.
 void raise()
          If an exception occurs in the SNMP receiver thread then raise() will rethrow the exception.
 void send(SnmpPeer peer, SnmpPduPacket pdu)
          Transmits the specified SnmpRequest to the SnmpPeer defined.
 void setAsnEncoder(AsnEncoder encoder)
          Sets the default encoder.
 void setHandler(SnmpAgentHandler hdl)
          Sets the trap handler for the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_EXCEPTION

public static final int ERROR_EXCEPTION

Defines a error due to a thown exception. When the SnmpAgentSessionError method is invoked in the trap handler, the exception object is passed as the ref parameter.

See Also:
SnmpAgentSession#SnmpAgentSessionError, Constant Field Values

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

See Also:
SnmpAgentSession#SnmpAgentSessionError, Constant Field Values

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

DEFAULT_WRITE_COMMUNITY

private static final java.lang.String DEFAULT_WRITE_COMMUNITY
This is the default community string for Gets

See Also:
Constant Field Values

m_port

private int m_port
The default port were traps are sent and received by this session.


m_portal

private SnmpPortal m_portal
The default SNMP trap callback handler. If this is not set and it is needed then an SnmpHandlerNotDefinedException is thrown.


m_encoder

private AsnEncoder m_encoder
ASN.1 codec used to encode/decode snmp traps that are sent and received by this session.


m_handler

private SnmpAgentHandler m_handler
The public trap handler that process received traps.


m_threadException

private boolean m_threadException
If this boolean value is set then the receiver thread is terminated due to an exception that was generated in either a handler or a socket error. This is considered a fatal exception.


m_why

private java.lang.Throwable m_why
This is the saved fatal exception that can be rethrown by the application


m_peer

private SnmpPeer m_peer
Used to hold the community strings for validation, and the agent port to listen on.

Constructor Detail

SnmpAgentSession

private SnmpAgentSession()
                  throws java.lang.UnsupportedOperationException
Used to disallow the default constructor.

Throws:
java.lang.UnsupportedOperationException - Thrown if the constructor is called.

SnmpAgentSession

public SnmpAgentSession(SnmpAgentHandler handler)
                 throws java.net.SocketException
The SnmpAgentSession constructor that takes a packet handler as parameter. It will listen on the default port and use the default community strings for validation.

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.

SnmpAgentSession

public SnmpAgentSession(SnmpAgentHandler handler,
                        SnmpPeer peer)
                 throws java.net.SocketException
The default SnmpAgentSession constructor that takes a packet handler and SnmpPeer as parameter. The peer is not used for anything except specifying the port to listen to and the community strings for validation.

Parameters:
handler - The handler associated for message processing.
peer - Specifies the port and community strings.
Throws:
java.net.SocketException - If thrown it is from the creation of a DatagramSocket.

SnmpAgentSession

public SnmpAgentSession(SnmpAgentHandler handler,
                        SnmpPeer peer,
                        int numOfThreads)
                 throws java.net.SocketException
The SnmpAgentSession constructor that takes a packet handler, SnmpPeer, numOfThreads as parameter. The peer is not used for anything except specifying the port to listen to and the community strings for validation.

Parameters:
handler - The handler associated for message processing.
peer - Specifies the port and community strings.
numOfThreads - Specifies the number of threads in thread Pool.
Throws:
java.net.SocketException - If thrown it is from the creation of a DatagramSocket.

SnmpAgentSession

public SnmpAgentSession(SnmpAgentHandler handler,
                        SnmpPeer peer,
                        int numOfThreads,
                        int receiveBuffer,
                        int sendBuffer)
                 throws java.net.SocketException
The SnmpAgentSession constructor that takes a packet handler, SnmpPeer, numOfThreads as parameter. The peer is not used for anything except specifying the port to listen to and the community strings for validation.

Parameters:
handler - The handler associated for message processing.
peer - Specifies the port and community strings.
numOfThreads - Specifies the number of threads in thread Pool.
receiveBuffer - Sets the SO_RCVBUF @see java.net.DatagramSocket#setReceiveBufferSize
sendBuffer - Sets the SO_SNDBUF @see java.net.DatagramSocket#setSendBufferSize
Throws:
java.net.SocketException - If thrown it is from the creation of a DatagramSocket.
Method Detail

getHandler

public SnmpAgentHandler getHandler()
Returns the trap handler for this trap session.

Returns:
The SnmpAgentHandler

setHandler

public void setHandler(SnmpAgentHandler 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

close

public void close()
Used to close the session. Once called the session should be considered invalid and unusable.


raise

public void raise()
           throws java.lang.Throwable
If an exception occurs in the SNMP receiver thread then raise() will rethrow the exception.

Throws:
java.lang.Throwable - The base for thrown exceptions.

send

public void send(SnmpPeer peer,
                 SnmpPduPacket pdu)
          throws 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 level
AsnEncodingException - Thrown if an encoding exception occurs in the AsnEncoder object.
java.io.IOException - Thrown if an error occurs sending the encoded datagram
See Also:
SnmpRequest, SnmpParameters, SnmpPeer

JoeSNMP API 0.3.4

Generated by iurt on 2011.