Class ListeningContextPool
- All Implemented Interfaces:
ListeningContextFace
- Since:
- 4_14
- Version:
- $Revision: 3.7 $ $Date: 2009/03/05 13:27:41 $
- Author:
- Birgit Arkesteijn
- See Also:
-
Field Summary
Fields inherited from interface uk.co.westhawk.snmp.stack.ListeningContextFace
DEFAULT_TRAP_PORT
-
Constructor Summary
ConstructorsConstructorDescriptionListeningContextPool
(int port) Constructor, using the Standard socket type.ListeningContextPool
(int port, String bindAddress) Constructor, using the Standard socket type.ListeningContextPool
(int port, String bindAddress, String typeSocket) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified PDU listener to receive the undecoded PDUs.void
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
Destroys all the contexts in the pool and empties the pool.void
dumpContexts
(String title) Dumps the pool of contexts.Returns the local address the server will bind to When the address is null, the socket accepts connections on any/all local addresses.Returns the hash key.int
Returns the maximum number of bytes this context will read from the socket.int
getPort()
Returns the port number.Returns the type of socket.void
Removes the specified PDU listener.void
Removes the specified PDU listener from all the contexts in the pool.void
Removes the specified unhandled PDU listener.void
setMaxRecvSize
(int no) Sets the maximum number of bytes this context will read from the socket.toString()
Returns a string representation of the object.
-
Constructor Details
-
ListeningContextPool
public ListeningContextPool(int port) Constructor, using the Standard socket type.- Parameters:
port
- The local port where packets are received- See Also:
-
ListeningContextPool
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- IPv4 only interfaces, use address "0.0.0.0"
- IPv6 only interfaces, use address "::"
- Parameters:
port
- The local port where packets are receivedbindAddress
- The local address the server will bind to- See Also:
-
ListeningContextPool
Constructor. If bindAddress is null, it will accept connections on any/all local addresses. If you want to listen to- IPv4 only interfaces, use address "0.0.0.0"
- IPv6 only interfaces, use address "::"
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 receivedbindAddress
- The local address the server will bind totypeSocket
- The type of socket to use.- See Also:
-
-
Method Details
-
getPort
public int getPort()Description copied from interface:ListeningContextFace
Returns the port number.- Specified by:
getPort
in interfaceListeningContextFace
- Returns:
- The port no
-
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 interfaceListeningContextFace
- Returns:
- The bind address
-
getTypeSocket
Description copied from interface:ListeningContextFace
Returns the type of socket.- Specified by:
getTypeSocket
in interfaceListeningContextFace
- Returns:
- The type of socket
- See Also:
-
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 toMSS
(i.e. 1300).- Specified by:
getMaxRecvSize
in interfaceListeningContextFace
- Returns:
- The number
- See Also:
-
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 toMSS
(i.e. 1300). Only the current context will be affected, not to all the contexts in the pool.- Specified by:
setMaxRecvSize
in interfaceListeningContextFace
- Parameters:
no
- The new size- See Also:
-
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 interfaceListeningContextFace
- See Also:
-
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:
-
dumpContexts
Dumps the pool of contexts. This is for debug purposes.- Parameters:
title
- The title of the dump
-
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
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 interfaceListeningContextFace
- Parameters:
l
- The listener object- Throws:
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
Description copied from interface:ListeningContextFace
Removes the specified PDU listener. When there are no more listeners, calls destroy().- Specified by:
removeRawPduListener
in interfaceListeningContextFace
- Parameters:
l
- The listener object
-
removeRawPduListenerFromPool
Removes the specified PDU listener from all the contexts in the pool. -
addUnhandledRawPduListener
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 interfaceListeningContextFace
- Parameters:
l
- The listener object- Throws:
IOException
- Thrown when creating a listening socket fails- See Also:
-
removeUnhandledRawPduListener
Description copied from interface:ListeningContextFace
Removes the specified unhandled PDU listener. When there are no more listeners, calls destroy().- Specified by:
removeUnhandledRawPduListener
in interfaceListeningContextFace
- Parameters:
l
- The listener object
-
toString
Returns a string representation of the object.
-