SNMP Stack 5_1

uk.co.westhawk.snmp.stack
Class ListeningContextPool

java.lang.Object
  |
  +--uk.co.westhawk.snmp.stack.ListeningContextPool
All Implemented Interfaces:
ListeningContextFace

public class ListeningContextPool
extends java.lang.Object
implements ListeningContextFace

This class contains the pool of listening contexts. The usage of this class will prevent more than one ListeningContext trying to listen to the same port.

Since:
4_14
Version:
$Revision: 3.5 $ $Date: 2006/02/09 14:30:19 $
Author:
Birgit Arkesteijn
See Also:
ListeningContext

Field Summary
protected  java.lang.String bindAddr
           
protected  ListeningContext context
           
protected static java.util.Hashtable contextPool
           
protected  int hostPort
           
protected  java.lang.String socketType
           
 
Fields inherited from interface uk.co.westhawk.snmp.stack.ListeningContextFace
DEFAULT_TRAP_PORT, version_id
 
Constructor Summary
ListeningContextPool(int port)
          Constructor, using the Standard socket type.
ListeningContextPool(int port, java.lang.String bindAddress)
          Constructor, using the Standard socket type.
ListeningContextPool(int port, java.lang.String bindAddress, java.lang.String typeSocket)
          Constructor.
 
Method Summary
 void addRawPduListener(RawPduListener l)
          Adds the specified PDU listener to receive the undecoded PDUs.
 void addUnhandledRawPduListener(RawPduListener l)
          Adds the specified PDU listener to receive the undecoded PDUs when it was not handled (i.e. not consumed) by any of the PDU listeners in addRawPduListener().
 void destroy()
          Destroys the current context.
 void destroyPool()
          Destroys all the contexts in the pool and empties the pool.
 void dumpContexts(java.lang.String title)
          Dumps the pool of contexts.
 java.lang.String getBindAddress()
          Returns the local address the server will bind to When the address is null, the socket accepts connections on any/all local addresses.
 java.lang.String getHashKey()
          Returns the hash key.
protected  ListeningContext getMatchingContext()
          Returns a context from the pool.
 int getMaxRecvSize()
          Returns the maximum number of bytes this context will read from the socket.
 int getPort()
          Returns the port number.
 java.lang.String getTypeSocket()
          Returns the type of socket.
 void removeRawPduListener(RawPduListener l)
          Removes the specified PDU listener.
 void removeRawPduListenerFromPool(RawPduListener l)
          Removes the specified PDU listener from all the contexts in the pool.
 void removeUnhandledRawPduListener(RawPduListener l)
          Removes the specified unhandled PDU listener.
 void setMaxRecvSize(int no)
          Sets the maximum number of bytes this context will read from the socket.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contextPool

protected static java.util.Hashtable contextPool

context

protected ListeningContext context

socketType

protected java.lang.String socketType

bindAddr

protected java.lang.String bindAddr

hostPort

protected int hostPort
Constructor Detail

ListeningContextPool

public ListeningContextPool(int port)
Constructor, using the Standard socket type.

Parameters:
port - The local port where packets are received
See Also:
ListeningContextPool(int, String), SnmpContextBasisFace.STANDARD_SOCKET

ListeningContextPool

public ListeningContextPool(int port,
                            java.lang.String bindAddress)
Constructor, using the Standard socket type. If bindAddress is null, it will accept connections on any/all local addresses. If you want to listen to

Parameters:
port - The local port where packets are received
bindAddress - The local address the server will bind to
See Also:
SnmpContextBasisFace.STANDARD_SOCKET

ListeningContextPool

public ListeningContextPool(int port,
                            java.lang.String bindAddress,
                            java.lang.String typeSocket)
Constructor. If bindAddress is null, it will accept connections on any/all local addresses. If you want to listen to The typeSocket will indicate which type of socket to use. This way different handlers can be provided for Netscape or Standard JVM. The Netscape implementation will make the necessary security calls to access connections that are not the applet's webserver. The KVM version will be for small device support (e.g. Palm Pilot).

Note, the TCP_SOCKET does not provide functionality to send a response back. Listening on such a socket is only useful when listening for traps.

Parameters:
port - The local port where packets are received
bindAddress - The local address the server will bind to
See Also:
SnmpContextBasisFace.STANDARD_SOCKET, SnmpContextBasisFace.TCP_SOCKET, SnmpContextBasisFace.NETSCAPE_SOCKET, SnmpContextBasisFace.KVM_SOCKET
Method Detail

getPort

public int getPort()
Description copied from interface: ListeningContextFace
Returns the port number.

Specified by:
getPort in interface ListeningContextFace
Returns:
The port no

getBindAddress

public java.lang.String getBindAddress()
Description copied from interface: ListeningContextFace
Returns the local address the server will bind to When the address is null, the socket accepts connections on any/all local addresses.

Specified by:
getBindAddress in interface ListeningContextFace
Returns:
The bind address

getTypeSocket

public java.lang.String getTypeSocket()
Description copied from interface: ListeningContextFace
Returns the type of socket.

Specified by:
getTypeSocket in interface ListeningContextFace
Returns:
The type of socket
See Also:
SnmpContextBasisFace.STANDARD_SOCKET, SnmpContextBasisFace.TCP_SOCKET, SnmpContextBasisFace.NETSCAPE_SOCKET, SnmpContextBasisFace.KVM_SOCKET

getMaxRecvSize

public int getMaxRecvSize()
Description copied from interface: ListeningContextFace
Returns the maximum number of bytes this context will read from the socket. By default this will be set to MSS (i.e. 1300).

Specified by:
getMaxRecvSize in interface ListeningContextFace
Returns:
The number
See Also:
SnmpContextBasisFace.MSS, ListeningContextFace.setMaxRecvSize(int), AbstractSnmpContext.setMaxRecvSize(int)

setMaxRecvSize

public void setMaxRecvSize(int no)
Sets the maximum number of bytes this context will read from the socket. By default this will be set to MSS (i.e. 1300). Only the current context will be affected, not to all the contexts in the pool.

Specified by:
setMaxRecvSize in interface ListeningContextFace
Parameters:
no - The new size
See Also:
SnmpContextBasisFace.MSS, AbstractSnmpContext.getMaxRecvSize()

destroy

public void destroy()
Destroys the current context.

Note that by calling this method the whole stack will stop listening for packets on the port this context was listening on! The listeners added via the SnmpContext classes are affected as well.

Specified by:
destroy in interface ListeningContextFace
See Also:
destroyPool(), destroy()

destroyPool

public void destroyPool()
Destroys all the contexts in the pool and empties the pool.

Note that by calling this method the whole stack will stop listening for any packets! The listeners added via the SnmpContext classes are affected as well.

See Also:
destroy()

getMatchingContext

protected ListeningContext getMatchingContext()
Returns a context from the pool. This methods checks for an existing context that matches all our properties. If such a context does not exist, a new one is created and added to the pool.

Returns:
A context from the pool
See Also:
getHashKey()

dumpContexts

public void dumpContexts(java.lang.String title)
Dumps the pool of contexts. This is for debug purposes.

Parameters:
title - The title of the dump

getHashKey

public java.lang.String getHashKey()
Returns the hash key. This key is built out of all properties. It serves as key for the pool of contexts.

Returns:
The hash key

addRawPduListener

public void addRawPduListener(RawPduListener l)
                       throws java.io.IOException
Description copied from interface: ListeningContextFace
Adds the specified PDU listener to receive the undecoded PDUs. When a PDU is received the PDU received event is fired to all listeners, until one of them consumes it.

All the SnmpContext objects use this method to listen for PDUs. When a SnmpContext object decodes the PDU succesfully, it will consume it.

Only when a listener is added will this context create a listening socket.

Specified by:
addRawPduListener in interface ListeningContextFace
Parameters:
l - The listener object
Throws:
java.io.IOException - Thrown when creating a listening socket fails
See Also:
RawPduReceivedSupport.fireRawPduReceived(int, java.lang.String, int, byte[]), AbstractSnmpContext.addTrapListener(uk.co.westhawk.snmp.event.TrapListener), AbstractSnmpContext.addRequestPduListener(uk.co.westhawk.snmp.event.RequestPduListener), ListeningContextFace.addUnhandledRawPduListener(RawPduListener)

removeRawPduListener

public void removeRawPduListener(RawPduListener l)
Description copied from interface: ListeningContextFace
Removes the specified PDU listener. When there are no more listeners, calls destroy().

Specified by:
removeRawPduListener in interface ListeningContextFace
Parameters:
l - The listener object

removeRawPduListenerFromPool

public void removeRawPduListenerFromPool(RawPduListener l)
Removes the specified PDU listener from all the contexts in the pool.

See Also:
ListeningContext.removeRawPduListener(uk.co.westhawk.snmp.event.RawPduListener)

addUnhandledRawPduListener

public void addUnhandledRawPduListener(RawPduListener l)
                                throws java.io.IOException
Description copied from interface: ListeningContextFace
Adds the specified PDU listener to receive the undecoded PDUs when it was not handled (i.e. not consumed) by any of the PDU listeners in addRawPduListener().

Only when a listener is added will this context create a listening socket.

Specified by:
addUnhandledRawPduListener in interface ListeningContextFace
Throws:
java.io.IOException - Thrown when creating a listening socket fails
See Also:
ListeningContextFace.addRawPduListener(RawPduListener)

removeUnhandledRawPduListener

public void removeUnhandledRawPduListener(RawPduListener l)
Description copied from interface: ListeningContextFace
Removes the specified unhandled PDU listener. When there are no more listeners, calls destroy().

Specified by:
removeUnhandledRawPduListener in interface ListeningContextFace

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
The string

SNMP Stack 5_1