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_SOCKET
public ListeningContextPool(int port, java.lang.String bindAddress)
port
- The local port where packets are receivedbindAddress
- The local address the server will bind toSnmpContextBasisFace.STANDARD_SOCKET
public 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_SOCKET
public int getPort()
ListeningContextFace
getPort
in interface ListeningContextFace
public java.lang.String getBindAddress()
ListeningContextFace
getBindAddress
in interface ListeningContextFace
public java.lang.String getTypeSocket()
ListeningContextFace
getTypeSocket
in interface ListeningContextFace
SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.TCP_SOCKET
public int getMaxRecvSize()
ListeningContextFace
MSS
(i.e. 1300).getMaxRecvSize
in interface ListeningContextFace
SnmpContextBasisFace.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 ListeningContextFace
no
- 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 ListeningContextFace
destroyPool()
,
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
ListeningContextFace
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.
addRawPduListener
in interface ListeningContextFace
l
- 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)
ListeningContextFace
removeRawPduListener
in interface ListeningContextFace
l
- The listener objectpublic void removeRawPduListenerFromPool(RawPduListener l)
public void addUnhandledRawPduListener(RawPduListener l) throws java.io.IOException
ListeningContextFace
Only when a listener is added will this context create a listening socket.
addUnhandledRawPduListener
in interface ListeningContextFace
l
- The listener objectjava.io.IOException
- Thrown when creating a listening
socket failsListeningContextFace.addRawPduListener(RawPduListener)
public void removeUnhandledRawPduListener(RawPduListener l)
ListeningContextFace
removeUnhandledRawPduListener
in interface ListeningContextFace
l
- The listener objectpublic java.lang.String toString()
toString
in class java.lang.Object