SNMP Stack 5_1

uk.co.westhawk.snmp.stack
Class SnmpContextv3Pool

java.lang.Object
  |
  +--uk.co.westhawk.snmp.stack.SnmpContextv3Pool
All Implemented Interfaces:
SnmpContextBasisFace, SnmpContextv3Face

public class SnmpContextv3Pool
extends java.lang.Object
implements SnmpContextv3Face

This class contains the pool of SNMP v3 contexts. This class reuses the existings contexts instead of creating a new one every time.

Every time a property changes the pool is checked for a SnmpContextv3 context that matches all the new properties of this class. If no such context exists, a new one is made. The PDUs associated with the old context remain associated with the old context.

A counter indicates the number of times the context is referenced. The counter is decreased when destroy() is called. When the counter reaches zero, the context is released.

Note that because the underlying context can change when a property is changed and the PDUs remain associated with the old context, all properties have to be set BEFORE a PDU is sent.

Version:
$Revision: 3.24 $ $Date: 2006/06/19 13:58:52 $
Author:
Birgit Arkesteijn
See Also:
SnmpContextv3, SnmpContextPool, SnmpContextv2cPool

Field Summary
protected  int authenticationProtocol
           
protected  java.lang.String bindAddr
           
protected  SnmpContextv3 context
           
protected  byte[] contextEngineId
           
protected  java.lang.String contextName
           
protected static java.util.Hashtable contextPool
           
protected  boolean hasChanged
           
protected  java.lang.String hostname
           
protected  int hostPort
           
protected  java.lang.String socketType
           
protected  boolean useAuthentication
           
protected  boolean usePrivacy
           
protected  java.lang.String userAuthenticationPassword
           
protected  java.lang.String userName
           
protected  java.lang.String userPrivacyPassword
           
protected  UsmAgent usmAgent
           
 
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextv3Face
Default_ContextName, Default_UserName, MD5_PROTOCOL, ProtocolNames, SHA1_PROTOCOL, SNMPv1_Security_Model, SNMPv2c_Security_Model, USM_Security_Model, version_id
 
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
DEFAULT_PORT, KVM_SOCKET, MAXPDU, MSS, NETSCAPE_SOCKET, STANDARD_SOCKET, TCP_SOCKET
 
Constructor Summary
SnmpContextv3Pool(java.lang.String host, int port)
          Constructor, using the Standard socket.
SnmpContextv3Pool(java.lang.String host, int port, java.lang.String typeSocket)
          Constructor.
SnmpContextv3Pool(java.lang.String host, int port, java.lang.String bindAddress, java.lang.String typeSocket)
          Constructor.
 
Method Summary
 boolean addDiscoveryPdu(DiscoveryPdu pdu)
          Adds a discovery PDU.
 boolean addPdu(Pdu pdu)
          Adds a PDU to the context.
 void addRequestPduListener(RequestPduListener l)
          Adds the specified request pdu listener to receive PDUs on the default request pdu port 161 from the host that matches this context.
 void addRequestPduListener(RequestPduListener l, int port)
          Adds the specified request pdu listener to receive PDUs on the specified port from the host that matches this context.
 void addRequestPduListener(RequestPduListener l, ListeningContextPool lcontext)
          Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.
 void addTrapListener(TrapListener l)
          Adds the specified trap listener to receive traps on the default trap port 162 from the host that matches this context.
 void addTrapListener(TrapListener l, int port)
          Adds the specified trap listener to receive traps on the specified port from the host that matches this context.
 void addTrapListener(TrapListener l, ListeningContextPool lcontext)
          Adds the specified trap listener to receive traps on the specified listening context that matches this context.
 java.lang.Object clone()
          This method is not supported.
 void destroy()
          Releases the resources held by this 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.
 byte[] encodeDiscoveryPacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve, java.lang.Object obj)
          Encodes a discovery PDU.
 byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve, java.lang.Object obj)
          Encodes a PDU.
 int getAuthenticationProtocol()
          Returns the protocol to be used for authentication.
 java.lang.String getBindAddress()
          Returns the local bind address.
 byte[] getContextEngineId()
          Returns the contextEngineID.
 java.lang.String getContextName()
          Returns the contextName.
 java.lang.String getHashKey()
          Returns the hash key.
 java.lang.String getHost()
          Returns the host.
protected  SnmpContextv3 getMatchingContext()
          Returns a context from the pool.
 int getPort()
          Returns the port number.
 java.lang.String getReceivedFromHostAddress()
          Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the (latest) host the packets where received from.
 java.lang.String getSendToHostAddress()
          Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the host the packets where sent to.
 java.lang.String getTypeSocket()
          Returns the type of socket.
 java.lang.String getUserAuthenticationPassword()
          Returns the user authentication password.
 java.lang.String getUserName()
          Returns the username.
 java.lang.String getUserPrivacyPassword()
          Returns the user privacy password.
 UsmAgent getUsmAgent()
          Returns the UsmAgent.
 int getVersion()
          Returns the SNMP version of the context.
 boolean isDestroyed()
          Returns whether or not this context has been destroyed.
 boolean isUseAuthentication()
          Returns if authentication is used or not.
 boolean isUsePrivacy()
          Returns if privacy is used or not.
 Pdu processIncomingPdu(byte[] message)
          Processes an incoming PDU.
 boolean removePdu(int requestId)
          Removes a PDU from the context.
 void removeRequestPduListener(RequestPduListener l)
          Removes the specified request pdu listener from listening for packets on the default request pdu port 161.
 void removeRequestPduListener(RequestPduListener l, int port)
          Removes the specified request pdu listener from listening for packets on the specified port.
 void removeRequestPduListener(RequestPduListener l, ListeningContextPool lcontext)
          Removes the specified request pdu listener from listening for packets on the specified listening context.
 void removeTrapListener(TrapListener l)
          Removes the specified trap listener from listening for packets on the default trap port 162.
 void removeTrapListener(TrapListener l, int port)
          Removes the specified trap listener from listening for packets on the specified port.
 void removeTrapListener(TrapListener l, ListeningContextPool lcontext)
          Removes the specified trap listener from listening for packets on the specified listening context.
 void sendPacket(byte[] packet)
          Sends an encoded PDU.
 void setAuthenticationProtocol(int protocol)
          Sets the protocol to be used for authentication.
 void setContextEngineId(byte[] newContextEngineId)
          Sets the contextEngineID.
 void setContextName(java.lang.String newContextName)
          Sets the contextName.
 void setUseAuthentication(boolean newUseAuthentication)
          Sets whether authentication has to be used.
 void setUsePrivacy(boolean newUsePrivacy)
          Sets whether privacy has to be used.
 void setUserAuthenticationPassword(java.lang.String newUserAuthenticationPd)
          Sets the user authentication password.
 void setUserName(java.lang.String newUserName)
          Sets the username.
 void setUserPrivacyPassword(java.lang.String newUserPrivacyPd)
          Sets the user privacy password.
 void setUsmAgent(UsmAgent newAgent)
          Sets the UsmAgent, needed when this stack is used as authoritative SNMP engine.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contextPool

protected static java.util.Hashtable contextPool

hostname

protected java.lang.String hostname

socketType

protected java.lang.String socketType

bindAddr

protected java.lang.String bindAddr

hostPort

protected int hostPort

context

protected SnmpContextv3 context

userName

protected java.lang.String userName

useAuthentication

protected boolean useAuthentication

userAuthenticationPassword

protected java.lang.String userAuthenticationPassword

usePrivacy

protected boolean usePrivacy

userPrivacyPassword

protected java.lang.String userPrivacyPassword

authenticationProtocol

protected int authenticationProtocol

contextEngineId

protected byte[] contextEngineId

contextName

protected java.lang.String contextName

usmAgent

protected UsmAgent usmAgent

hasChanged

protected boolean hasChanged
Constructor Detail

SnmpContextv3Pool

public SnmpContextv3Pool(java.lang.String host,
                         int port)
                  throws java.io.IOException
Constructor, using the Standard socket.

Parameters:
host - The host to which the PDU will be sent
port - The port where the SNMP server will be
See Also:
SnmpContextv3.SnmpContextv3(String, int)

SnmpContextv3Pool

public SnmpContextv3Pool(java.lang.String host,
                         int port,
                         java.lang.String typeSocket)
                  throws java.io.IOException
Constructor.

Parameters:
host - The host to which the PDU will be sent
port - The port where the SNMP server will be
typeSocket - The type of socket to use.
See Also:
SnmpContextv3.SnmpContextv3(String, int, String), SnmpContextBasisFace.STANDARD_SOCKET, SnmpContextBasisFace.TCP_SOCKET, SnmpContextBasisFace.NETSCAPE_SOCKET, SnmpContextBasisFace.KVM_SOCKET

SnmpContextv3Pool

public SnmpContextv3Pool(java.lang.String host,
                         int port,
                         java.lang.String bindAddress,
                         java.lang.String typeSocket)
                  throws java.io.IOException
Constructor.

Parameters:
host - The host to which the PDU will be sent
port - The port where the SNMP server will be
bindAddress - The local address the server will bind to
typeSocket - The type of socket to use.
Since:
4_14
See Also:
SnmpContextv3.SnmpContextv3(String, int, String), SnmpContextBasisFace.STANDARD_SOCKET, SnmpContextBasisFace.TCP_SOCKET, SnmpContextBasisFace.NETSCAPE_SOCKET, SnmpContextBasisFace.KVM_SOCKET
Method Detail

getVersion

public int getVersion()
Returns the SNMP version of the context.

Specified by:
getVersion in interface SnmpContextBasisFace
Returns:
The version
See Also:
SnmpConstants.SNMP_VERSION_1, SnmpConstants.SNMP_VERSION_2c, SnmpConstants.SNMP_VERSION_3

getHost

public java.lang.String getHost()
Returns the host.

Specified by:
getHost in interface SnmpContextBasisFace
Returns:
The host

getPort

public int getPort()
Returns the port number.

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

getBindAddress

public java.lang.String getBindAddress()
Description copied from interface: SnmpContextBasisFace
Returns the local bind address. If bindAddress is null, then the system will pick up a valid local address to bind the socket.

Specified by:
getBindAddress in interface SnmpContextBasisFace
Returns:
The local bind address

getTypeSocket

public java.lang.String getTypeSocket()
Returns the type of socket.

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

getSendToHostAddress

public java.lang.String getSendToHostAddress()
Description copied from interface: SnmpContextBasisFace
Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the host the packets where sent to.

Specified by:
getSendToHostAddress in interface SnmpContextBasisFace
Returns:
The IP address of the host the packets where sent to.
See Also:
ContextSocketFace.getSendToHostAddress()

getReceivedFromHostAddress

public java.lang.String getReceivedFromHostAddress()
Description copied from interface: SnmpContextBasisFace
Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the (latest) host the packets where received from.

Specified by:
getReceivedFromHostAddress in interface SnmpContextBasisFace
Returns:
The IP address of the (latest) host the packets where received from.
See Also:
ContextSocketFace.getReceivedFromHostAddress()

getUserName

public java.lang.String getUserName()
Description copied from interface: SnmpContextv3Face
Returns the username.

Specified by:
getUserName in interface SnmpContextv3Face
Returns:
the username

setUserName

public void setUserName(java.lang.String newUserName)
Description copied from interface: SnmpContextv3Face
Sets the username. This username will be used for all PDUs sent with this context. The username corresponds to the 'msgUserName' in SNMP-USER-BASED-SM-MIB. The default value is "initial".

Specified by:
setUserName in interface SnmpContextv3Face
Parameters:
newUserName - The new username

isUseAuthentication

public boolean isUseAuthentication()
Description copied from interface: SnmpContextv3Face
Returns if authentication is used or not. By default no authentication will be used.

Specified by:
isUseAuthentication in interface SnmpContextv3Face
Returns:
true if authentication is used, false if not

setUseAuthentication

public void setUseAuthentication(boolean newUseAuthentication)
Description copied from interface: SnmpContextv3Face
Sets whether authentication has to be used. By default no authentication will be used.

Specified by:
setUseAuthentication in interface SnmpContextv3Face
Parameters:
newUseAuthentication - The use of authentication

getUserAuthenticationPassword

public java.lang.String getUserAuthenticationPassword()
Description copied from interface: SnmpContextv3Face
Returns the user authentication password. This password will be transformed into the user authentication secret key.

Specified by:
getUserAuthenticationPassword in interface SnmpContextv3Face
Returns:
The user authentication password

setUserAuthenticationPassword

public void setUserAuthenticationPassword(java.lang.String newUserAuthenticationPd)
Description copied from interface: SnmpContextv3Face
Sets the user authentication password. This password will be transformed into the user authentication secret key. A user MUST set this password.

Specified by:
setUserAuthenticationPassword in interface SnmpContextv3Face
Parameters:
newUserAuthenticationPd - The user authentication password

setAuthenticationProtocol

public void setAuthenticationProtocol(int protocol)
                               throws java.lang.IllegalArgumentException
Description copied from interface: SnmpContextv3Face
Sets the protocol to be used for authentication. This can either be MD5 or SHA-1. By default MD5 will be used.

Specified by:
setAuthenticationProtocol in interface SnmpContextv3Face
Parameters:
protocol - The authentication protocol to be used
java.lang.IllegalArgumentException
See Also:
SnmpContextv3Face.MD5_PROTOCOL, SnmpContextv3Face.SHA1_PROTOCOL

getAuthenticationProtocol

public int getAuthenticationProtocol()
Description copied from interface: SnmpContextv3Face
Returns the protocol to be used for authentication. This can either be MD5 or SHA-1. By default MD5 will be used.

Specified by:
getAuthenticationProtocol in interface SnmpContextv3Face
Returns:
The authentication protocol to be used
See Also:
SnmpContextv3Face.MD5_PROTOCOL, SnmpContextv3Face.SHA1_PROTOCOL

isUsePrivacy

public boolean isUsePrivacy()
Description copied from interface: SnmpContextv3Face
Returns if privacy is used or not. By default no privacy will be used.

Specified by:
isUsePrivacy in interface SnmpContextv3Face
Returns:
true if privacy is used, false if not

setUsePrivacy

public void setUsePrivacy(boolean newUsePrivacy)
Description copied from interface: SnmpContextv3Face
Sets whether privacy has to be used. By default no privacy will be used.

Specified by:
setUsePrivacy in interface SnmpContextv3Face
Parameters:
newUsePrivacy - The use of privacy

getUserPrivacyPassword

public java.lang.String getUserPrivacyPassword()
Description copied from interface: SnmpContextv3Face
Returns the user privacy password. This password will be transformed into the user privacy secret key.

Specified by:
getUserPrivacyPassword in interface SnmpContextv3Face
Returns:
The user privacy password

setUserPrivacyPassword

public void setUserPrivacyPassword(java.lang.String newUserPrivacyPd)
Description copied from interface: SnmpContextv3Face
Sets the user privacy password. This password will be transformed into the user privacy secret key. A user MUST set this password.

Specified by:
setUserPrivacyPassword in interface SnmpContextv3Face
Parameters:
newUserPrivacyPd - The user privacy password

setContextEngineId

public void setContextEngineId(byte[] newContextEngineId)
                        throws java.lang.IllegalArgumentException
Description copied from interface: SnmpContextv3Face
Sets the contextEngineID. See RFC 3411. A contextEngineID uniquely identifies an SNMP entity that may realize an instance of a context with a particular contextName.

Note, when the stack is an authoritative engine, this parameter should equal the UsmAgent.getSnmpEngineId(). See the StackUsage documentation for an explanation.

If the contextEngineID is of length zero, the encoder will use the (discovered) snmpEngineId.

Specified by:
setContextEngineId in interface SnmpContextv3Face
Parameters:
newContextEngineId - The contextEngineID
java.lang.IllegalArgumentException
See Also:
UsmAgent.getSnmpEngineId()

getContextEngineId

public byte[] getContextEngineId()
Description copied from interface: SnmpContextv3Face
Returns the contextEngineID.

Specified by:
getContextEngineId in interface SnmpContextv3Face
Returns:
The contextEngineID

setContextName

public void setContextName(java.lang.String newContextName)
Description copied from interface: SnmpContextv3Face
Sets the contextName. See RFC 3411. A contextName is used to name a context. Each contextName MUST be unique within an SNMP entity. By default this is "".

Specified by:
setContextName in interface SnmpContextv3Face
Parameters:
newContextName - The contextName
See Also:
SnmpContextv3Face.Default_ContextName

getContextName

public java.lang.String getContextName()
Description copied from interface: SnmpContextv3Face
Returns the contextName.

Specified by:
getContextName in interface SnmpContextv3Face
Returns:
The contextName

setUsmAgent

public void setUsmAgent(UsmAgent newAgent)
Description copied from interface: SnmpContextv3Face
Sets the UsmAgent, needed when this stack is used as authoritative SNMP engine. This interface provides authentiation details, like its clock and its Engine ID.

Specified by:
setUsmAgent in interface SnmpContextv3Face
Parameters:
newAgent - The USM authoritative interface

getUsmAgent

public UsmAgent getUsmAgent()
Description copied from interface: SnmpContextv3Face
Returns the UsmAgent.

Specified by:
getUsmAgent in interface SnmpContextv3Face
See Also:
SnmpContextv3Face.setUsmAgent(uk.co.westhawk.snmp.stack.UsmAgent)

addDiscoveryPdu

public boolean addDiscoveryPdu(DiscoveryPdu pdu)
                        throws java.io.IOException,
                               PduException,
                               java.lang.IllegalArgumentException
Description copied from interface: SnmpContextv3Face
Adds a discovery PDU. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.

Specified by:
addDiscoveryPdu in interface SnmpContextv3Face
Parameters:
pdu - the discovery PDU
Returns:
PDU is succesful added
java.io.IOException
PduException
java.lang.IllegalArgumentException

addPdu

public boolean addPdu(Pdu pdu)
               throws java.io.IOException,
                      PduException,
                      java.lang.IllegalArgumentException
Description copied from interface: SnmpContextBasisFace
Adds a PDU to the context. This is for internal use only and should NOT be called by the developer. This is called by the the Pdu itself and is added to the interface to cover the different kind of Contexts.

Specified by:
addPdu in interface SnmpContextBasisFace
Parameters:
pdu - the PDU
Returns:
whether the PDU has been successfully added
java.io.IOException
PduException
java.lang.IllegalArgumentException

removePdu

public boolean removePdu(int requestId)
Description copied from interface: SnmpContextBasisFace
Removes a PDU from the context. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.

Specified by:
removePdu in interface SnmpContextBasisFace
Returns:
whether the PDU has been successfully removed

encodeDiscoveryPacket

public byte[] encodeDiscoveryPacket(byte msg_type,
                                    int rId,
                                    int errstat,
                                    int errind,
                                    java.util.Enumeration ve,
                                    java.lang.Object obj)
                             throws java.io.IOException,
                                    EncodingException
Description copied from interface: SnmpContextv3Face
Encodes a discovery PDU. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.

Specified by:
encodeDiscoveryPacket in interface SnmpContextv3Face
Returns:
The encoded packet
java.io.IOException
EncodingException

encodePacket

public byte[] encodePacket(byte msg_type,
                           int rId,
                           int errstat,
                           int errind,
                           java.util.Enumeration ve,
                           java.lang.Object obj)
                    throws java.io.IOException,
                           EncodingException
Description copied from interface: SnmpContextBasisFace
Encodes a PDU. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.

Specified by:
encodePacket in interface SnmpContextBasisFace
Parameters:
msg_type - The message type
rId - The message id
errstat - The error status
errind - The error index
ve - The varbind list
obj - Additional object (only used in SNMPv3)
Returns:
The encoded packet
java.io.IOException
EncodingException

sendPacket

public void sendPacket(byte[] packet)
Description copied from interface: SnmpContextBasisFace
Sends an encoded PDU. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.

Specified by:
sendPacket in interface SnmpContextBasisFace
Parameters:
packet - The encoded packet

destroy

public void destroy()
Releases the resources held by this context. This method will decrement the reference counter. When the reference counter reaches zero the actual context is removed from the pool and destroyed.

Specified by:
destroy in interface SnmpContextBasisFace

destroyPool

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

Since:
4_14
See Also:
destroy()

isDestroyed

public boolean isDestroyed()
Description copied from interface: SnmpContextBasisFace
Returns whether or not this context has been destroyed.

Specified by:
isDestroyed in interface SnmpContextBasisFace

getMatchingContext

protected SnmpContextv3 getMatchingContext()
                                    throws java.io.IOException,
                                           java.lang.IllegalArgumentException
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
java.io.IOException
java.lang.IllegalArgumentException
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 hashtable of (v3) contexts.

Specified by:
getHashKey in interface SnmpContextBasisFace
Returns:
The hash key

addTrapListener

public void addTrapListener(TrapListener l)
                     throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified trap listener to receive traps on the default trap port 162 from the host that matches this context.

The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.

Specified by:
addTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
java.io.IOException
See Also:
SnmpContextBasisFace.addTrapListener(TrapListener, int), ListeningContextFace.DEFAULT_TRAP_PORT

removeTrapListener

public void removeTrapListener(TrapListener l)
                        throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified trap listener from listening for packets on the default trap port 162.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

Specified by:
removeTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
java.io.IOException
See Also:
SnmpContextBasisFace.removeTrapListener(TrapListener, int), ListeningContextFace.DEFAULT_TRAP_PORT

addTrapListener

public void addTrapListener(TrapListener l,
                            int port)
                     throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified trap listener to receive traps on the specified port from the host that matches this context.

The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.

Specified by:
addTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
port - The port the traps are received on
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.addRawPduListener(RawPduListener)

removeTrapListener

public void removeTrapListener(TrapListener l,
                               int port)
                        throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified trap listener from listening for packets on the specified port.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

Specified by:
removeTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
port - The port the traps are received on
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.removeRawPduListener(RawPduListener), ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)

addTrapListener

public void addTrapListener(TrapListener l,
                            ListeningContextPool lcontext)
                     throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified trap listener to receive traps on the specified listening context that matches this context.

The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.

Specified by:
addTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
lcontext - The listening context
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.addRawPduListener(RawPduListener)

removeTrapListener

public void removeTrapListener(TrapListener l,
                               ListeningContextPool lcontext)
                        throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified trap listener from listening for packets on the specified listening context.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

Specified by:
removeTrapListener in interface SnmpContextBasisFace
Parameters:
l - The trap listener
lcontext - The listening context
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.removeRawPduListener(RawPduListener), ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)

addRequestPduListener

public void addRequestPduListener(RequestPduListener l)
                           throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified request pdu listener to receive PDUs on the default request pdu port 161 from the host that matches this context.

The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.

Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.

Specified by:
addRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
java.io.IOException
See Also:
SnmpContextBasisFace.addRequestPduListener(RequestPduListener, int), SnmpContextBasisFace.DEFAULT_PORT

removeRequestPduListener

public void removeRequestPduListener(RequestPduListener l)
                              throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified request pdu listener from listening for packets on the default request pdu port 161.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

Specified by:
removeRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
java.io.IOException
See Also:
SnmpContextBasisFace.removeRequestPduListener(RequestPduListener, int), SnmpContextBasisFace.DEFAULT_PORT

addRequestPduListener

public void addRequestPduListener(RequestPduListener l,
                                  int port)
                           throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified request pdu listener to receive PDUs on the specified port from the host that matches this context.

The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.

Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.

Specified by:
addRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
port - The port the request PDUs are received on
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.addRawPduListener(RawPduListener)

removeRequestPduListener

public void removeRequestPduListener(RequestPduListener l,
                                     int port)
                              throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified request pdu listener from listening for packets on the specified port.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

Specified by:
removeRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
port - The port the request PDUs are received on
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.removeRawPduListener(RawPduListener), ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)

addRequestPduListener

public void addRequestPduListener(RequestPduListener l,
                                  ListeningContextPool lcontext)
                           throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.

The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.

Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.

Specified by:
addRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
lcontext - The listening context
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.addRawPduListener(RawPduListener)

removeRequestPduListener

public void removeRequestPduListener(RequestPduListener l,
                                     ListeningContextPool lcontext)
                              throws java.io.IOException
Description copied from interface: SnmpContextBasisFace
Removes the specified request pdu listener from listening for packets on the specified listening context.

The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

Specified by:
removeRequestPduListener in interface SnmpContextBasisFace
Parameters:
l - The request PDU listener
lcontext - The listening context
java.io.IOException
See Also:
ListeningContextPool.ListeningContextPool(int, String, String), ListeningContextPool.removeRawPduListener(RawPduListener), ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)

processIncomingPdu

public Pdu processIncomingPdu(byte[] message)
                       throws DecodingException,
                              java.io.IOException
Description copied from interface: SnmpContextBasisFace
Processes an incoming PDU. The context will try to process the incoming PDU, using the SNMP version and other security parameters. If any of these do not correspond, a DecodingException will be thrown.

Specified by:
processIncomingPdu in interface SnmpContextBasisFace
DecodingException
java.io.IOException

toString

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

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

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method is not supported. It will throw a CloneNotSupportedException.

Specified by:
clone in interface SnmpContextBasisFace
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException - Thrown when the constructor generates an IOException or when in one of the Pool classes.
Since:
4_14

SNMP Stack 5_1