snmp
Class SNMPv1AgentInterface

java.lang.Object
  extended bysnmp.SNMPv1AgentInterface
All Implemented Interfaces:
java.lang.Runnable

public class SNMPv1AgentInterface
extends java.lang.Object
implements java.lang.Runnable

The class SNMPv1AgentInterface implements an interface for responding to requests sent from a remote SNMP manager. The agent simply listens for requests for information, and passes requested OIDs on to concrete subclasses of SNMPRequestListener. These are expected to retrieve requested information from the system, and return this to the agent interface for inclusion in a response to the manager. The approach is that from version 1 of SNMP, using no encryption of data. Communication occurs via UDP, using port 162, the standard SNMP trap port, as the destination port.


Field Summary
 int receiveBufferSize
           
static int SNMP_PORT
           
 
Constructor Summary
SNMPv1AgentInterface(int version)
          Construct a new agent object to listen for requests from remote SNMP managers.
SNMPv1AgentInterface(int version, int localPort)
          Construct a new agent object to listen for requests from remote SNMP managers.
SNMPv1AgentInterface(int version, int localPort, java.io.PrintWriter errorReceiver)
          Construct a new agent object to listen for requests from remote SNMP managers.
SNMPv1AgentInterface(int version, java.io.PrintWriter errorReceiver)
          Construct a new agent object to listen for requests from remote SNMP managers.
 
Method Summary
 void addRequestListener(SNMPRequestListener listener)
           
 int getReceiveBufferSize()
          Returns the current size of the buffer used to receive response packets.
 void removeRequestListener(SNMPRequestListener listener)
           
 void run()
          The run() method for the agent interface's listener.
 void setErrorReceiver(java.io.PrintWriter errorReceiver)
          Set the specified PrintWriter to receive error messages.
 void setReceiveBufferSize(int receiveBufferSize)
          Set the size of the buffer used to receive response packets.
 void startReceiving()
          Start listening for requests from remote managers.
 void stopReceiving()
          Stop listening for requests from remote managers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNMP_PORT

public static final int SNMP_PORT
See Also:
Constant Field Values

receiveBufferSize

public int receiveBufferSize
Constructor Detail

SNMPv1AgentInterface

public SNMPv1AgentInterface(int version)
                     throws java.net.SocketException
Construct a new agent object to listen for requests from remote SNMP managers. The agent listens on the standard SNMP UDP port 161.


SNMPv1AgentInterface

public SNMPv1AgentInterface(int version,
                            int localPort)
                     throws java.net.SocketException
Construct a new agent object to listen for requests from remote SNMP managers. The agent listens on the supplied port.


SNMPv1AgentInterface

public SNMPv1AgentInterface(int version,
                            java.io.PrintWriter errorReceiver)
                     throws java.net.SocketException
Construct a new agent object to listen for requests from remote SNMP managers. The agent listens on the supplied port, and sends error messages to the specified PrintWriter.


SNMPv1AgentInterface

public SNMPv1AgentInterface(int version,
                            int localPort,
                            java.io.PrintWriter errorReceiver)
                     throws java.net.SocketException
Construct a new agent object to listen for requests from remote SNMP managers. The agent listens on the supplied port, and sends error messages to the specified PrintWriter.

Method Detail

setErrorReceiver

public void setErrorReceiver(java.io.PrintWriter errorReceiver)
Set the specified PrintWriter to receive error messages.


addRequestListener

public void addRequestListener(SNMPRequestListener listener)

removeRequestListener

public void removeRequestListener(SNMPRequestListener listener)

startReceiving

public void startReceiving()
Start listening for requests from remote managers.


stopReceiving

public void stopReceiving()
                   throws java.net.SocketException
Stop listening for requests from remote managers.

Throws:
java.net.SocketException

run

public void run()
The run() method for the agent interface's listener. Just waits for SNMP request messages to come in on port 161 (or the port supplied in the constructor), then dispatches the retrieved SNMPPDU and community name to each of the registered SNMPRequestListeners by calling their processRequest() methods.

Specified by:
run in interface java.lang.Runnable

setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)
Set the size of the buffer used to receive response packets. RFC 1157 stipulates that an SNMP implementation must be able to receive packets of at least 484 bytes, so if you try to set the size to a value less than this, the receive buffer size will be set to 484 bytes. In addition, the maximum size of a UDP packet payload is 65535 bytes, so setting the buffer to a larger size will just waste memory. The default value is 512 bytes. The value may need to be increased if get-requests are issued for multiple OIDs.


getReceiveBufferSize

public int getReceiveBufferSize()
Returns the current size of the buffer used to receive response packets.