| 
SNMP Stack 4_12 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--uk.co.westhawk.snmp.stack.DefaultTrapContext
The DefaultTrapContext class will enable this stack to receive traps.
 Only one (1) instance of the DefaultTrapContext can exist. The
 context will only start receiving (or listen for) traps when there is
 at least one listener registered. Two kind of listeners can be added; 
 the normal and unhandled trap listeners.
 The normal trap listeners are added via the
 addTrapListener() method, 
 the unhandled trap listeners are added via the 
 addUnhandledTrapListener().
 
 Use one of the getInstance() methods to get the instance and add a trap
 listener. This class will fire undecoded trap events, i.e. the raw
 data is sent and no attempt is made to decode the data into a pdu.
 
The SnmpContext classes provide functionality for decoded trap events. These classes will register themselves to the DefaultTrapContext object and only pass the event on if it matches their configuration.
 
 Note that because only one instance of this class
 can exist, the first call of getInstance() will define 
 the settings
 (i.e. port number and socket type) for the lifetime of the stack. All
 the subsequent calls of getInstance() will return the existing
 instance, irrespective of the arguments.
 
On UNIX and Linux operating systems the default port where trap are send (i.e. 162) can only be opened as root.
AbstractSnmpContext.addTrapListener(uk.co.westhawk.snmp.event.TrapListener)| Field Summary | |
static int | 
DEFAULT_TRAP_PORT
The default port number where we listen for traps.  | 
protected  int | 
maxRecvSize
 | 
| Constructor Summary | |
protected  | 
DefaultTrapContext(int port)
Constructor.  | 
protected  | 
DefaultTrapContext(int port,
                   java.lang.String typeSocketA)
Constructor.  | 
| Method Summary | |
 void | 
addTrapListener(TrapListener listener)
Adds the specified trap listener to receive the undecoded traps.  | 
 void | 
addUnhandledTrapListener(TrapListener listener)
Adds the specified trap listener to receive the undecoded traps when it was not handled (ie not consumed) by any of the trap listeners in addTrapListener().  | 
 void | 
destroy()
This method will stop the thread listening for Traps.  | 
static DefaultTrapContext | 
getInstance(int port)
Returns the instance of DefaultTrapContext.  | 
static DefaultTrapContext | 
getInstance(int port,
            java.lang.String typeSocketA)
Returns the instance of DefaultTrapContext.  | 
 int | 
getMaxRecvSize()
Returns the maximum number of bytes this context will read from the socket.  | 
 void | 
removeTrapListener(TrapListener listener)
Removes the specified trap listener.  | 
 void | 
removeUnhandledTrapListener(TrapListener listener)
Removes the specified unhandled trap listener.  | 
 void | 
run()
We wait for any incoming traps and fire a trap received (undecoded) event if we do.  | 
 void | 
setMaxRecvSize(int no)
Sets the maximum number of bytes this context will read from the socket.  | 
protected  void | 
startListening()
Starts listening for traps if we didn't do so already.  | 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
public static final int DEFAULT_TRAP_PORT
protected int maxRecvSize
| Constructor Detail | 
protected DefaultTrapContext(int port)
                      throws java.io.IOException
port - The local port where traps are receivedSnmpContextBasisFace.STANDARD_SOCKET
protected DefaultTrapContext(int port,
                             java.lang.String typeSocketA)
                      throws java.io.IOException
port - The local port where traps are receivedtypeSocketA - The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET, 
SnmpContextBasisFace.NETSCAPE_SOCKET, 
SnmpContextBasisFace.KVM_SOCKET| Method Detail | 
public static DefaultTrapContext getInstance(int port)
                                      throws java.io.IOException
public static DefaultTrapContext getInstance(int port,
                                             java.lang.String typeSocketA)
                                      throws java.io.IOException
protected void startListening()
addTrapListener(uk.co.westhawk.snmp.event.TrapListener)public int getMaxRecvSize()
MSS (i.e. 1300).SnmpContextBasisFace.MSS, 
setMaxRecvSize(int), 
AbstractSnmpContext.setMaxRecvSize(int)public void setMaxRecvSize(int no)
MSS (i.e. 1300).no - The new numberSnmpContextBasisFace.MSS, 
AbstractSnmpContext.getMaxRecvSize()public void destroy()
Note that by calling this method the whole stack will stop listening for traps! The listeners added via the SnmpContext classes are effected as well.
Thanks to Balakrishnan (bala_tbn@yahoo.com) for pointing out that there was no way of stopping the listener.
public void run()
The undecoded events are fired to all normal listeners (added via addTrapListener()), unless one of them consumes it. The SnmpContext classes will consume the event if it matches their configuration.
If none of them consume the event, the undecoded events are fired to all unhandled trap listeners (added via addUnhandledTrapListener()), unless one of them consumes it.
run in interface java.lang.RunnableTrapReceivedSupport.fireTrapReceived(int, String, byte []), 
addTrapListener(TrapListener), 
addUnhandledTrapListener(TrapListener)public void addTrapListener(TrapListener listener)
All the SnmpContext objects use this method to listen for traps. When a SnmpContext object decodes the trap succesfully, it will consume it.
TrapReceivedSupport.fireTrapReceived(int, String, byte []), 
AbstractSnmpContext.addTrapListener(TrapListener), 
addUnhandledTrapListener(TrapListener)public void removeTrapListener(TrapListener listener)
public void addUnhandledTrapListener(TrapListener listener)
addTrapListener(TrapListener)public void removeUnhandledTrapListener(TrapListener listener)
  | 
SNMP Stack 4_12 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||