public class ListeningContextPool extends java.lang.Object implements ListeningContextFace
ListeningContext| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
bindAddr |
protected ListeningContext |
context |
protected static java.util.Hashtable |
contextPool |
protected int |
hostPort |
protected java.lang.String |
socketType |
DEFAULT_TRAP_PORT| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected static java.util.Hashtable contextPool
protected ListeningContext context
protected java.lang.String socketType
protected java.lang.String bindAddr
protected int hostPort
public ListeningContextPool(int port)
port - The local port where packets are receivedListeningContextPool(int, String),
SnmpContextBasisFace.STANDARD_SOCKETpublic ListeningContextPool(int port,
java.lang.String bindAddress)
port - The local port where packets are receivedbindAddress - The local address the server will bind toSnmpContextBasisFace.STANDARD_SOCKETpublic ListeningContextPool(int port,
java.lang.String bindAddress,
java.lang.String typeSocket)
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.
port - The local port where packets are receivedbindAddress - The local address the server will bind totypeSocket - The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKETpublic int getPort()
ListeningContextFacegetPort in interface ListeningContextFacepublic java.lang.String getBindAddress()
ListeningContextFacegetBindAddress in interface ListeningContextFacepublic java.lang.String getTypeSocket()
ListeningContextFacegetTypeSocket in interface ListeningContextFaceSnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKETpublic int getMaxRecvSize()
ListeningContextFaceMSS (i.e. 1300).getMaxRecvSize in interface ListeningContextFaceSnmpContextBasisFace.MSS,
ListeningContextFace.setMaxRecvSize(int),
AbstractSnmpContext.setMaxRecvSize(int)public void setMaxRecvSize(int no)
MSS (i.e. 1300).
Only the current context will be affected, not to all the
contexts in the pool.setMaxRecvSize in interface ListeningContextFaceno - The new sizeSnmpContextBasisFace.MSS,
AbstractSnmpContext.getMaxRecvSize()public void destroy()
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.
destroy in interface ListeningContextFacedestroyPool(),
destroy()public void destroyPool()
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.
destroy()protected ListeningContext getMatchingContext()
getHashKey()public void dumpContexts(java.lang.String title)
title - The title of the dumppublic java.lang.String getHashKey()
public void addRawPduListener(RawPduListener l) throws java.io.IOException
ListeningContextFaceAll 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.
addRawPduListener in interface ListeningContextFacel - The listener objectjava.io.IOException - Thrown when creating a listening
socket failsRawPduReceivedSupport.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)public void removeRawPduListener(RawPduListener l)
ListeningContextFaceremoveRawPduListener in interface ListeningContextFacel - The listener objectpublic void removeRawPduListenerFromPool(RawPduListener l)
public void addUnhandledRawPduListener(RawPduListener l) throws java.io.IOException
ListeningContextFaceOnly when a listener is added will this context create a listening socket.
addUnhandledRawPduListener in interface ListeningContextFacel - The listener objectjava.io.IOException - Thrown when creating a listening
socket failsListeningContextFace.addRawPduListener(RawPduListener)public void removeUnhandledRawPduListener(RawPduListener l)
ListeningContextFaceremoveUnhandledRawPduListener in interface ListeningContextFacel - The listener objectpublic java.lang.String toString()
toString in class java.lang.Object