snmp
Class SNMPTrapReceiverInterface

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

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

The class SNMPTrapListenerInterface implements a server which listens for trap and inform request messages sent from remote SNMP entities. The approach is that from version 1 and 2c of SNMP, using no encryption of data. Communication occurs via UDP, using port 162, the standard SNMP trap port. This interface can handle both SNMPv1 and SNMPv2 traps (which have different PDU types), and SNMPv2 Inform Requests. Applications utilize this class with classes which implement the SNMPTrapListener or SNMPv2TrapListener or SNMPv2InformRequestListener interfaces. These must provide a processTrap(), processv2Trap() or processInformRequest() method, and are registered/unregistered with this class through its addv1TrapListener()/removev1TrapListener(), addv2TrapListener()/removev2TrapListener(), or addv2InformRequestListener()/removev2InformRequestListener() methods.


Field Summary
static int SNMP_TRAP_PORT
           
 
Constructor Summary
SNMPTrapReceiverInterface()
          Construct a new trap receiver object to receive traps from remote SNMP hosts.
SNMPTrapReceiverInterface(java.io.PrintWriter errorReceiver)
          Construct a new trap receiver object to receive traps from remote SNMP hosts.
 
Method Summary
 void addv1TrapListener(SNMPv1TrapListener listener)
           
 void addv2InformRequestListener(SNMPv2InformRequestListener listener)
           
 void addv2TrapListener(SNMPv2TrapListener listener)
           
 int getReceiveBufferSize()
          Returns the current size of the buffer used to receive response packets.
 void removev1TrapListener(SNMPv1TrapListener listener)
           
 void removev2InformRequestListener(SNMPv2InformRequestListener listener)
           
 void removev2TrapListener(SNMPv2TrapListener listener)
           
 void run()
          The run() method for the trap 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 trap and inform messages.
 void stopReceiving()
          Stop listening for trap and inform messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNMP_TRAP_PORT

public static final int SNMP_TRAP_PORT
See Also:
Constant Field Values
Constructor Detail

SNMPTrapReceiverInterface

public SNMPTrapReceiverInterface()
                          throws java.net.SocketException
Construct a new trap receiver object to receive traps from remote SNMP hosts. This version will accept messages from all hosts using any community name.


SNMPTrapReceiverInterface

public SNMPTrapReceiverInterface(java.io.PrintWriter errorReceiver)
                          throws java.net.SocketException
Construct a new trap receiver object to receive traps from remote SNMP hosts. This version will accept messages from all hosts using any community name. Uses the specified Writer to deliver error messages.

Method Detail

setErrorReceiver

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


addv1TrapListener

public void addv1TrapListener(SNMPv1TrapListener listener)

removev1TrapListener

public void removev1TrapListener(SNMPv1TrapListener listener)

addv2TrapListener

public void addv2TrapListener(SNMPv2TrapListener listener)

removev2TrapListener

public void removev2TrapListener(SNMPv2TrapListener listener)

addv2InformRequestListener

public void addv2InformRequestListener(SNMPv2InformRequestListener listener)

removev2InformRequestListener

public void removev2InformRequestListener(SNMPv2InformRequestListener listener)

startReceiving

public void startReceiving()
Start listening for trap and inform messages.


stopReceiving

public void stopReceiving()
                   throws java.net.SocketException
Stop listening for trap and inform messages.

Throws:
java.net.SocketException

run

public void run()
The run() method for the trap interface's listener. Just waits for trap or inform messages to come in on port 162, then dispatches the recieved PDUs to each of the registered listeners by calling their processTrap() or processInform() 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.