public class SnmpContextv3Pool extends java.lang.Object implements SnmpContextv3Face
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.
SnmpContextv3,
SnmpContextPool,
SnmpContextv2cPool| Modifier and Type | Field and Description |
|---|---|
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 int |
privacyProtocol |
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 |
AES_ENCRYPT, Default_ContextName, Default_UserName, DES_ENCRYPT, MD5_PROTOCOL, ProtocolNames, SHA1_PROTOCOL, SNMPv1_Security_Model, SNMPv2c_Security_Model, USM_Security_ModelDEFAULT_PORT, MAXPDU, MSS, STANDARD_SOCKET, TCP_SOCKET| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
int |
getPrivacyProtocol()
Returns the protocol to be used for privacy.
|
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 |
setPrivacyProtocol(int protocol)
Sets the protocol to be used for privacy.
|
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.
|
protected static java.util.Hashtable contextPool
protected java.lang.String hostname
protected java.lang.String socketType
protected java.lang.String bindAddr
protected int hostPort
protected SnmpContextv3 context
protected java.lang.String userName
protected boolean useAuthentication
protected java.lang.String userAuthenticationPassword
protected boolean usePrivacy
protected java.lang.String userPrivacyPassword
protected int authenticationProtocol
protected byte[] contextEngineId
protected java.lang.String contextName
protected UsmAgent usmAgent
protected boolean hasChanged
protected int privacyProtocol
public SnmpContextv3Pool(java.lang.String host,
int port)
throws java.io.IOException
host - The host to which the PDU will be sentport - The port where the SNMP server will bejava.io.IOExceptionSnmpContextv3.SnmpContextv3(String, int)public SnmpContextv3Pool(java.lang.String host,
int port,
java.lang.String typeSocket)
throws java.io.IOException
host - The host to which the PDU will be sentport - The port where the SNMP server will betypeSocket - The type of socket to use.java.io.IOExceptionSnmpContextv3.SnmpContextv3(String, int, String),
SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKETpublic SnmpContextv3Pool(java.lang.String host,
int port,
java.lang.String bindAddress,
java.lang.String typeSocket)
throws java.io.IOException
host - The host to which the PDU will be sentport - The port where the SNMP server will bebindAddress - The local address the server will bind totypeSocket - The type of socket to use.java.io.IOExceptionSnmpContextv3.SnmpContextv3(String, int, String),
SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKETpublic int getVersion()
getVersion in interface SnmpContextBasisFaceSnmpConstants.SNMP_VERSION_1,
SnmpConstants.SNMP_VERSION_2c,
SnmpConstants.SNMP_VERSION_3public java.lang.String getHost()
getHost in interface SnmpContextBasisFacepublic int getPort()
getPort in interface SnmpContextBasisFacepublic java.lang.String getBindAddress()
SnmpContextBasisFacegetBindAddress in interface SnmpContextBasisFacepublic java.lang.String getTypeSocket()
getTypeSocket in interface SnmpContextBasisFaceSnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKETpublic java.lang.String getSendToHostAddress()
SnmpContextBasisFacegetSendToHostAddress in interface SnmpContextBasisFaceContextSocketFace.getSendToHostAddress()public java.lang.String getReceivedFromHostAddress()
SnmpContextBasisFacegetReceivedFromHostAddress in interface SnmpContextBasisFaceContextSocketFace.getReceivedFromHostAddress()public java.lang.String getUserName()
SnmpContextv3FacegetUserName in interface SnmpContextv3Facepublic void setUserName(java.lang.String newUserName)
SnmpContextv3FacesetUserName in interface SnmpContextv3FacenewUserName - The new usernamepublic boolean isUseAuthentication()
SnmpContextv3FaceisUseAuthentication in interface SnmpContextv3Facepublic void setUseAuthentication(boolean newUseAuthentication)
SnmpContextv3FacesetUseAuthentication in interface SnmpContextv3FacenewUseAuthentication - The use of authenticationpublic java.lang.String getUserAuthenticationPassword()
SnmpContextv3FacegetUserAuthenticationPassword in interface SnmpContextv3Facepublic void setUserAuthenticationPassword(java.lang.String newUserAuthenticationPd)
SnmpContextv3FacesetUserAuthenticationPassword in interface SnmpContextv3FacenewUserAuthenticationPd - The user authentication passwordpublic void setPrivacyProtocol(int protocol)
throws java.lang.IllegalArgumentException
SnmpContextv3FacesetPrivacyProtocol in interface SnmpContextv3Faceprotocol - The privacy protocol to be usedjava.lang.IllegalArgumentExceptionSnmpContextv3Face.DES_ENCRYPT,
SnmpContextv3Face.AES_ENCRYPTpublic void setAuthenticationProtocol(int protocol)
throws java.lang.IllegalArgumentException
SnmpContextv3FacesetAuthenticationProtocol in interface SnmpContextv3Faceprotocol - The authentication protocol to be usedjava.lang.IllegalArgumentExceptionSnmpContextv3Face.MD5_PROTOCOL,
SnmpContextv3Face.SHA1_PROTOCOLpublic int getPrivacyProtocol()
SnmpContextv3FacegetPrivacyProtocol in interface SnmpContextv3FaceSnmpContextv3Face.DES_ENCRYPT,
SnmpContextv3Face.AES_ENCRYPTpublic int getAuthenticationProtocol()
SnmpContextv3FacegetAuthenticationProtocol in interface SnmpContextv3FaceSnmpContextv3Face.MD5_PROTOCOL,
SnmpContextv3Face.SHA1_PROTOCOLpublic boolean isUsePrivacy()
SnmpContextv3FaceisUsePrivacy in interface SnmpContextv3Facepublic void setUsePrivacy(boolean newUsePrivacy)
SnmpContextv3FacesetUsePrivacy in interface SnmpContextv3FacenewUsePrivacy - The use of privacypublic java.lang.String getUserPrivacyPassword()
SnmpContextv3FacegetUserPrivacyPassword in interface SnmpContextv3Facepublic void setUserPrivacyPassword(java.lang.String newUserPrivacyPd)
SnmpContextv3FacesetUserPrivacyPassword in interface SnmpContextv3FacenewUserPrivacyPd - The user privacy passwordpublic void setContextEngineId(byte[] newContextEngineId)
throws java.lang.IllegalArgumentException
SnmpContextv3FaceNote, 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.
setContextEngineId in interface SnmpContextv3FacenewContextEngineId - The contextEngineIDjava.lang.IllegalArgumentExceptionUsmAgent.getSnmpEngineId()public byte[] getContextEngineId()
SnmpContextv3FacegetContextEngineId in interface SnmpContextv3Facepublic void setContextName(java.lang.String newContextName)
SnmpContextv3FacesetContextName in interface SnmpContextv3FacenewContextName - The contextNameSnmpContextv3Face.Default_ContextNamepublic java.lang.String getContextName()
SnmpContextv3FacegetContextName in interface SnmpContextv3Facepublic void setUsmAgent(UsmAgent newAgent)
SnmpContextv3FacesetUsmAgent in interface SnmpContextv3FacenewAgent - The USM authoritative interfacepublic UsmAgent getUsmAgent()
SnmpContextv3FacegetUsmAgent in interface SnmpContextv3FaceSnmpContextv3Face.setUsmAgent(uk.co.westhawk.snmp.stack.UsmAgent)public boolean addDiscoveryPdu(DiscoveryPdu pdu) throws java.io.IOException, PduException, java.lang.IllegalArgumentException
SnmpContextv3FaceaddDiscoveryPdu in interface SnmpContextv3Facepdu - the discovery PDUjava.io.IOExceptionPduExceptionjava.lang.IllegalArgumentExceptionpublic boolean addPdu(Pdu pdu) throws java.io.IOException, PduException, java.lang.IllegalArgumentException
SnmpContextBasisFaceaddPdu in interface SnmpContextBasisFacepdu - the PDUjava.io.IOExceptionPduExceptionjava.lang.IllegalArgumentExceptionpublic boolean removePdu(int requestId)
SnmpContextBasisFaceremovePdu in interface SnmpContextBasisFacerequestId - the PDU request idpublic byte[] encodeDiscoveryPacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
throws java.io.IOException,
EncodingException
SnmpContextv3FaceencodeDiscoveryPacket in interface SnmpContextv3Facejava.io.IOExceptionEncodingExceptionpublic byte[] encodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
throws java.io.IOException,
EncodingException
SnmpContextBasisFaceencodePacket in interface SnmpContextBasisFacemsg_type - The message typerId - The message iderrstat - The error statuserrind - The error indexve - The varbind listobj - Additional object (only used in SNMPv3)java.io.IOExceptionEncodingExceptionpublic void sendPacket(byte[] packet)
SnmpContextBasisFacesendPacket in interface SnmpContextBasisFacepacket - The encoded packetpublic void destroy()
destroy in interface SnmpContextBasisFacepublic void destroyPool()
destroy()public boolean isDestroyed()
SnmpContextBasisFaceisDestroyed in interface SnmpContextBasisFaceprotected SnmpContextv3 getMatchingContext() throws java.io.IOException, java.lang.IllegalArgumentException
java.io.IOExceptionjava.lang.IllegalArgumentExceptiongetHashKey()public void dumpContexts(java.lang.String title)
title - The title of the dumppublic java.lang.String getHashKey()
getHashKey in interface SnmpContextBasisFacepublic void addTrapListener(TrapListener l) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addTrapListener in interface SnmpContextBasisFacel - The trap listenerjava.io.IOExceptionSnmpContextBasisFace.addTrapListener(TrapListener, int),
ListeningContextFace.DEFAULT_TRAP_PORTpublic void removeTrapListener(TrapListener l) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
removeTrapListener in interface SnmpContextBasisFacel - The trap listenerjava.io.IOExceptionSnmpContextBasisFace.removeTrapListener(TrapListener, int),
ListeningContextFace.DEFAULT_TRAP_PORTpublic void addTrapListener(TrapListener l, int port) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addTrapListener in interface SnmpContextBasisFacel - The trap listenerport - The port the traps are received onjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.addRawPduListener(RawPduListener)public void removeTrapListener(TrapListener l, int port) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
removeTrapListener in interface SnmpContextBasisFacel - The trap listenerport - The port the traps are received onjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.removeRawPduListener(RawPduListener),
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)public void addTrapListener(TrapListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addTrapListener in interface SnmpContextBasisFacel - The trap listenerlcontext - The listening contextjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.addRawPduListener(RawPduListener)public void removeTrapListener(TrapListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
removeTrapListener in interface SnmpContextBasisFacel - The trap listenerlcontext - The listening contextjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.removeRawPduListener(RawPduListener),
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)public void addRequestPduListener(RequestPduListener l) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerjava.io.IOExceptionSnmpContextBasisFace.addRequestPduListener(RequestPduListener, int),
SnmpContextBasisFace.DEFAULT_PORTpublic void removeRequestPduListener(RequestPduListener l) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
removeRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerjava.io.IOExceptionSnmpContextBasisFace.removeRequestPduListener(RequestPduListener, int),
SnmpContextBasisFace.DEFAULT_PORTpublic void addRequestPduListener(RequestPduListener l, int port) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerport - The port the request PDUs are received onjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.addRawPduListener(RawPduListener)public void removeRequestPduListener(RequestPduListener l, int port) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
removeRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerport - The port the request PDUs are received onjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.removeRawPduListener(RawPduListener),
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)public void addRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFaceThe 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.
addRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerlcontext - The listening contextjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.addRawPduListener(RawPduListener)public void removeRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFaceThe listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
removeRequestPduListener in interface SnmpContextBasisFacel - The request PDU listenerlcontext - The listening contextjava.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.removeRawPduListener(RawPduListener),
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)public Pdu processIncomingPdu(byte[] message) throws DecodingException, java.io.IOException
SnmpContextBasisFaceprocessIncomingPdu in interface SnmpContextBasisFaceDecodingExceptionjava.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in interface SnmpContextBasisFaceclone in class java.lang.Objectjava.lang.CloneNotSupportedException - Thrown when the constructor
generates an IOException or when in one of the Pool classes.