com.sun.management.snmp.manager
Class SnmpEventReportDispatcher

java.lang.Object
  extended by com.sun.management.snmp.manager.SnmpEventReportDispatcher
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
SnmpEventReportDispatcher

public class SnmpEventReportDispatcher
extends Object
implements Runnable

Implements an SNMP event report dispatcher.

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

The SnmpEventReportDispatcher class implements Runnable: it is expected to be used as a Thread object. The run method never returns.

An SnmpEventReportDispatcher object maintains 2 lists of listener objects. The listener objects implement the SnmpTrapListener or SnmpInformListener interface and will be activated each time an SNMP event report (trap or inform PDU) is received.

By default, the SnmpEventReportDispatcher will create one thread per received packet, and will invoke listener callbacks in that thread. Subclasses may override this behavior by redefining handlePacket() and handleCallback().

Since:
Java DMK 5.1
See Also:
SnmpTrapListener, SnmpInformListener

Constructor Summary
SnmpEventReportDispatcher()
          Initializes an SnmpEventReportDispatcher which listens on the port 162.
SnmpEventReportDispatcher(int portNumber)
          Initializes an SnmpEventReportDispatcher which listens on the specified port.
SnmpEventReportDispatcher(SnmpEngine engine, int portNumber)
          Initializes an SnmpEventReportDispatcher which listens on the specified port.
SnmpEventReportDispatcher(SnmpEngine engine, int portNumber, InetAddress address)
          Initializes an SnmpEventReportDispatcher which listens on the specified port.
SnmpEventReportDispatcher(SnmpEngineParameters parameters, SnmpEngineFactory factory, int portNumber)
          Initializes an SnmpEventReportDispatcher which listens on the specified port.
SnmpEventReportDispatcher(SnmpEngineParameters parameters, SnmpEngineFactory factory, int portNumber, InetAddress address)
          Initializes an SnmpEventReportDispatcher which listens on the specified port.
 
Method Summary
 void addInformListener(SnmpInformListener handler)
          Adds an inform request listener to this SnmpEventReportDispatcher.
 void addTrapListener(SnmpTrapListener handler)
          Adds a trap listener to this SnmpEventReportDispatcher.
 void close()
          Closes the receiving socket, and terminates the receiving loop.
 boolean containsInformListener(SnmpInformListener handler)
          Returns true if the specified object is listening to inform requests.
 boolean containsTrapListener(SnmpTrapListener handler)
          Returns true if the specified object is listening to traps.
 SnmpEngine getEngine()
          Engine the SnmpEventReportDispatcher is linked with.
 SnmpEngineId getEngineId()
          Get the engine Id.
 Enumeration getInformListeners()
          Gets all of the inform request listeners.
 SnmpPduFactory getPduFactory()
          Gets the PDU factory associated to this SnmpEventReportDispatcher.
 Long getSnmpInASNParseErrs()
          Returns the snmpInASNParseErrs value defined in the RFC 1907 Snmp Group.
 Long getSnmpInBadVersions()
          Returns the snmpInBadVersions value defined in the RFC 1907 Snmp Group.
 Long getSnmpInInforms()
          Returns the number of received informs.
 Long getSnmpInPkts()
          Returns the snmpInPkts value defined in the RFC 1907 Snmp Group.
 Long getSnmpInTraps()
          Returns the number of received traps.
 Long getSnmpInvalidMsgs()
          Returns snmpInvalidMsgs as defined in RFC 2572 SNMP-MPD-MIB.
 Long getSnmpUnknownSecurityModels()
          Returns snmpUnknownSecurityModels as defined in RFC 2572 SNMP-MPD-MIB.
 Enumeration getTrapListeners()
          Gets all of the trap listeners.
protected  void handleCallback(Runnable callbackHandler)
          This method invokes a listener callback.
protected  void handlePacket(Runnable packetHandler)
          This method handles a received SNMP DatagramPacket.
 void removeInformListener(SnmpInformListener handler)
          Removes an inform request listener.
 void removeTrapListener(SnmpTrapListener handler)
          Removes a trap listener.
 void run()
          Dispatching loop.
 void setPduFactory(SnmpPduFactory factory)
          Sets the PDU factory associated to this SnmpEventReportDispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpEventReportDispatcher

public SnmpEventReportDispatcher()
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the port 162. It instantiates an SnmpEngine.

WARNING : The SnmpEngineId is computed as follow:

Throws:
IllegalArgumentException - If one of the specified configuration file doesn't exist.
SocketException - If the object cannot bind to the port 162.

SnmpEventReportDispatcher

public SnmpEventReportDispatcher(int portNumber)
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the specified port. It instantiates an SnmpEngine.

WARNING : The SnmpEngineId is computed as follow:

Parameters:
portNumber - The port number.
Throws:
IllegalArgumentException - If one of the specified configuration file doesn't exist.
SocketException - If the object cannot bind to the specified port.

SnmpEventReportDispatcher

public SnmpEventReportDispatcher(SnmpEngineParameters parameters,
                                 SnmpEngineFactory factory,
                                 int portNumber)
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the specified port. It instantiates an SnmpEngine.

WARNING : The SnmpEngineId is computed as follow:

Parameters:
parameters - The engine parameters to use.
factory - The factory to use in order to create the engine.
portNumber - The port number.
Throws:
IllegalArgumentException - If one of the specified configuration file doesn't exist.
SocketException - If the object cannot bind to the specified port.

SnmpEventReportDispatcher

public SnmpEventReportDispatcher(SnmpEngineParameters parameters,
                                 SnmpEngineFactory factory,
                                 int portNumber,
                                 InetAddress address)
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the specified port. It instantiates an SnmpEngine.

WARNING : The SnmpEngineId is computed as follow:

Parameters:
parameters - The engine parameters to use.
factory - The factory to use in order to create the engine.
portNumber - The port number.
address - The Ip address the dispatcher will listen for events on. If null, the dispatcher will listen on localhost.
Throws:
IllegalArgumentException - If one of the specified configuration file doesn't exist.
SocketException - If the object cannot bind to the specified port.

SnmpEventReportDispatcher

public SnmpEventReportDispatcher(SnmpEngine engine,
                                 int portNumber)
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the specified port.

Parameters:
engine - The SnmpEngine to use.
portNumber - The port number.
Throws:
IllegalArgumentException - if the passed engine is null.
SocketException - If the object cannot bind to the specified port.

SnmpEventReportDispatcher

public SnmpEventReportDispatcher(SnmpEngine engine,
                                 int portNumber,
                                 InetAddress address)
                          throws SocketException,
                                 IllegalArgumentException
Initializes an SnmpEventReportDispatcher which listens on the specified port.

Parameters:
engine - The SnmpEngine to use.
portNumber - The port number.
address - The Ip address the dispatcher will listen for events on. If null, the dispatcher will listen on localhost.
Throws:
IllegalArgumentException - if the passed engine is null.
SocketException - If the object cannot bind to the specified port.
Method Detail

getSnmpInTraps

public Long getSnmpInTraps()
Returns the number of received traps.

Returns:
The number of successfully received traps.

getSnmpInInforms

public Long getSnmpInInforms()
Returns the number of received informs.

Returns:
The number of successfully received informs.

getSnmpInPkts

public Long getSnmpInPkts()
Returns the snmpInPkts value defined in the RFC 1907 Snmp Group.

This value is the total number of received packets. It sums traps, informs, failed decoding packet, bad SNMP version packets and USM discovery requests.

Returns:
The number of received packets.

getSnmpInASNParseErrs

public Long getSnmpInASNParseErrs()
Returns the snmpInASNParseErrs value defined in the RFC 1907 Snmp Group.

Returns:
The number of packets for which the decoding failed.

getSnmpInBadVersions

public Long getSnmpInBadVersions()
Returns the snmpInBadVersions value defined in the RFC 1907 Snmp Group.

Returns:
The number of packets for which the SNMP version was not supported.

getSnmpInvalidMsgs

public Long getSnmpInvalidMsgs()
Returns snmpInvalidMsgs as defined in RFC 2572 SNMP-MPD-MIB.

Returns:
snmpInvalidMsgs counter.

getSnmpUnknownSecurityModels

public Long getSnmpUnknownSecurityModels()
Returns snmpUnknownSecurityModels as defined in RFC 2572 SNMP-MPD-MIB.

Returns:
snmpUnknownSecurityModels counter.

getEngine

public SnmpEngine getEngine()
Engine the SnmpEventReportDispatcher is linked with.


getEngineId

public SnmpEngineId getEngineId()
Get the engine Id. The engine Id is used internally when dealing with import (SNMP V3 authoritative notions.)


close

public void close()
           throws IOException
Closes the receiving socket, and terminates the receiving loop.

Throws:
IOException

handleCallback

protected void handleCallback(Runnable callbackHandler)
This method invokes a listener callback. Do not call this method directly.

This method is provided as a hook for subclasses. The default behavior of this method is:

  protected void handleCallback(final Runnable callbackHandler) {
     callbackHandler.run();
  }
 

Parameters:
callbackHandler - A Runnable object wrapping the listener callback to be invoked.

handlePacket

protected void handlePacket(Runnable packetHandler)
This method handles a received SNMP DatagramPacket. Do not call this method directly.

This method is provided as a hook for subclasses.

  protected void handlePacket(final Runnable packetHandler) {
     (new Thread(packetHandler)).start();
  }
 

Parameters:
packetHandler - A Runnable object wrapping the packet to be handled.

run

public void run()
Dispatching loop. This method waits for an event report to be received and activates each registered listener.

This method is normally called by Thread.start.

Specified by:
run in interface Runnable

addTrapListener

public void addTrapListener(SnmpTrapListener handler)
Adds a trap listener to this SnmpEventReportDispatcher.

Parameters:
handler - The listener to add.

addInformListener

public void addInformListener(SnmpInformListener handler)
Adds an inform request listener to this SnmpEventReportDispatcher.

Parameters:
handler - The listener to add.

removeTrapListener

public void removeTrapListener(SnmpTrapListener handler)
Removes a trap listener.

Parameters:
handler - The listener to be removed.

removeInformListener

public void removeInformListener(SnmpInformListener handler)
Removes an inform request listener.

Parameters:
handler - The listener to be removed.

containsTrapListener

public boolean containsTrapListener(SnmpTrapListener handler)
Returns true if the specified object is listening to traps.

Parameters:
handler - A listener.
Returns:
true if it is a registered listener, false otherwise.

containsInformListener

public boolean containsInformListener(SnmpInformListener handler)
Returns true if the specified object is listening to inform requests.

Parameters:
handler - A listener.
Returns:
true if it is a registered listener, false otherwise.

getTrapListeners

public Enumeration getTrapListeners()
Gets all of the trap listeners.

Returns:
An enumeration of SnmpTrapListener objects.

getInformListeners

public Enumeration getInformListeners()
Gets all of the inform request listeners.

Returns:
An enumeration of SnmpInformListener objects.

getPduFactory

public SnmpPduFactory getPduFactory()
Gets the PDU factory associated to this SnmpEventReportDispatcher.

Returns:
The PDU factory (always non-null).

setPduFactory

public void setPduFactory(SnmpPduFactory factory)
Sets the PDU factory associated to this SnmpEventReportDispatcher.

Parameters:
factory - The PDU factory (if null, the default factory is set).

Open Source build 02
opendmk-1.0-b02 2007.10.01_19:17:46_MEST

Copyright 1998-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.