com.sun.jaw.snmp.manager
Class SnmpTrapAgent

java.lang.Object
  |
  +--com.sun.jaw.snmp.manager.SnmpTrapAgent

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

The SnmpTrapAgent class implements an SNMP trap dispatcher.

Listener objects can be registered in an SnmpTrapAgent. The SnmpTrapAgent listens for any incoming trap: each time it receives a trap, it inform all the listeners. By default the dispatcher listens to the UDP port 162.

The SnmpTrapAgent class implements Runnable: it is expected to be used as a Thread object.

An SnmpTrapAgent object maintains two lists of listener objects:

An object may implement both interfaces and register itself in both lists: like this, it will receive both versions of traps.

See Also:
SnmpTrapListener, SnmpV2TrapListener

Constructor Summary
SnmpTrapAgent()
          Initializes an SnmpTrapAgent which listens on the port 162.
SnmpTrapAgent(int portNumber)
          Initializes an SnmpTrapAgent which listens on the specified port.
 
Method Summary
 void addTrapListener(SnmpTrapListener handler)
          Adds a V1 trap listener to this SnmpTrapAgent.
 void addV2TrapListener(SnmpV2TrapListener handler)
          Add a V2 trap listener to this SnmpTrapAgent.
 boolean containsTrapReceiver(SnmpTrapListener handler)
          Returns true if the specified object is listening to V1 traps.
 boolean containsV2TrapReceiver(SnmpV2TrapListener handler)
          Returns true if the specified object is listening to V2 traps.
 SnmpPduFactoryIf getPduFactory()
          Gets the PDU factory associated to this SnmpTrapAgent.
 java.util.Enumeration getTrapListeners()
          Gets all of the V1 trap listeners.
 java.util.Enumeration getV2TrapListeners()
          Gets all of the V2 trap listeners.
 void removeTrapListener(SnmpTrapListener handler)
          Removes a V1 trap listener.
 void removeV2TrapListener(SnmpV2TrapListener handler)
          Removes a V2 trap listener.
 void run()
          Dispatching loop.
 void setPduFactory(SnmpPduFactoryIf factory)
          Sets the PDU factory associated to this SnmpTrapAgent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpTrapAgent

public SnmpTrapAgent()
              throws java.net.SocketException,
                     SnmpStatusException
Initializes an SnmpTrapAgent which listens on the port 162. This constructor invokes SnmpMain.initializeSNMP.
Throws:
java.net.SocketException - If the object cannot bind of the port 162.
SnmpStatusException - If initializeSNMP failed.

SnmpTrapAgent

public SnmpTrapAgent(int portNumber)
              throws java.net.SocketException,
                     SnmpStatusException
Initializes an SnmpTrapAgent which listens on the specified port. This constructor invokes SnmpMain.initializeSNMP.
Parameters:
portNumber - The port number.
Throws:
java.net.SocketException - If the object cannot bind of the specified port.
SnmpStatusException - If initializeSNMP failed.
Method Detail

run

public void run()
Dispatching loop. This method waits for a trap to be received, select a list of listeners according the version of the trap and activate each listener in the list.

This method is normally called by Thread.start.

Specified by:
run in interface java.lang.Runnable

addTrapListener

public void addTrapListener(SnmpTrapListener handler)
Adds a V1 trap listener to this SnmpTrapAgent.
Parameters:
handler - The listener to add.

addV2TrapListener

public void addV2TrapListener(SnmpV2TrapListener handler)
Add a V2 trap listener to this SnmpTrapAgent.
Parameters:
handler - The listener to add.

containsTrapReceiver

public boolean containsTrapReceiver(SnmpTrapListener handler)
Returns true if the specified object is listening to V1 traps.
Parameters:
handler - A listener.
Returns:
True if it is a registered listener; false otherwise.

containsV2TrapReceiver

public boolean containsV2TrapReceiver(SnmpV2TrapListener handler)
Returns true if the specified object is listening to V2 traps.
Parameters:
handler - A listener.
Returns:
True if it is a registered listener; false otherwise.

removeTrapListener

public void removeTrapListener(SnmpTrapListener handler)
Removes a V1 trap listener.
Parameters:
handler - The listener to be removed.

removeV2TrapListener

public void removeV2TrapListener(SnmpV2TrapListener handler)
Removes a V2 trap listener.
Parameters:
handler - The listener to be removed.

getTrapListeners

public java.util.Enumeration getTrapListeners()
Gets all of the V1 trap listeners.
Returns:
An Enumeration of SnmpTrapListener objects.

getV2TrapListeners

public java.util.Enumeration getV2TrapListeners()
Gets all of the V2 trap listeners.
Returns:
An Enumeration of SnmpV2TrapListener objects.

getPduFactory

public SnmpPduFactoryIf getPduFactory()
Gets the PDU factory associated to this SnmpTrapAgent.
Returns:
The PDU factory (always non-null).

setPduFactory

public void setPduFactory(SnmpPduFactoryIf factory)
Sets the PDU factory associated to this SnmpTrapAgent.
Parameters:
factory - The PDU factory (if null, the default factory is set).