|
SNMP Stack 5_1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.co.westhawk.snmp.stack.SnmpContextv3Pool
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.
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 |
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
Constructor Detail |
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 beSnmpContextv3.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.SnmpContextv3.SnmpContextv3(String, int, String)
,
SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.TCP_SOCKET
,
SnmpContextBasisFace.NETSCAPE_SOCKET
,
SnmpContextBasisFace.KVM_SOCKET
public 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.SnmpContextv3.SnmpContextv3(String, int, String)
,
SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.TCP_SOCKET
,
SnmpContextBasisFace.NETSCAPE_SOCKET
,
SnmpContextBasisFace.KVM_SOCKET
Method Detail |
public int getVersion()
getVersion
in interface SnmpContextBasisFace
SnmpConstants.SNMP_VERSION_1
,
SnmpConstants.SNMP_VERSION_2c
,
SnmpConstants.SNMP_VERSION_3
public java.lang.String getHost()
getHost
in interface SnmpContextBasisFace
public int getPort()
getPort
in interface SnmpContextBasisFace
public java.lang.String getBindAddress()
SnmpContextBasisFace
getBindAddress
in interface SnmpContextBasisFace
public java.lang.String getTypeSocket()
getTypeSocket
in interface SnmpContextBasisFace
SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.TCP_SOCKET
,
SnmpContextBasisFace.NETSCAPE_SOCKET
,
SnmpContextBasisFace.KVM_SOCKET
public java.lang.String getSendToHostAddress()
SnmpContextBasisFace
getSendToHostAddress
in interface SnmpContextBasisFace
ContextSocketFace.getSendToHostAddress()
public java.lang.String getReceivedFromHostAddress()
SnmpContextBasisFace
getReceivedFromHostAddress
in interface SnmpContextBasisFace
ContextSocketFace.getReceivedFromHostAddress()
public java.lang.String getUserName()
SnmpContextv3Face
getUserName
in interface SnmpContextv3Face
public void setUserName(java.lang.String newUserName)
SnmpContextv3Face
setUserName
in interface SnmpContextv3Face
newUserName
- The new usernamepublic boolean isUseAuthentication()
SnmpContextv3Face
isUseAuthentication
in interface SnmpContextv3Face
public void setUseAuthentication(boolean newUseAuthentication)
SnmpContextv3Face
setUseAuthentication
in interface SnmpContextv3Face
newUseAuthentication
- The use of authenticationpublic java.lang.String getUserAuthenticationPassword()
SnmpContextv3Face
getUserAuthenticationPassword
in interface SnmpContextv3Face
public void setUserAuthenticationPassword(java.lang.String newUserAuthenticationPd)
SnmpContextv3Face
setUserAuthenticationPassword
in interface SnmpContextv3Face
newUserAuthenticationPd
- The user authentication passwordpublic void setAuthenticationProtocol(int protocol) throws java.lang.IllegalArgumentException
SnmpContextv3Face
setAuthenticationProtocol
in interface SnmpContextv3Face
protocol
- The authentication protocol to be used
java.lang.IllegalArgumentException
SnmpContextv3Face.MD5_PROTOCOL
,
SnmpContextv3Face.SHA1_PROTOCOL
public int getAuthenticationProtocol()
SnmpContextv3Face
getAuthenticationProtocol
in interface SnmpContextv3Face
SnmpContextv3Face.MD5_PROTOCOL
,
SnmpContextv3Face.SHA1_PROTOCOL
public boolean isUsePrivacy()
SnmpContextv3Face
isUsePrivacy
in interface SnmpContextv3Face
public void setUsePrivacy(boolean newUsePrivacy)
SnmpContextv3Face
setUsePrivacy
in interface SnmpContextv3Face
newUsePrivacy
- The use of privacypublic java.lang.String getUserPrivacyPassword()
SnmpContextv3Face
getUserPrivacyPassword
in interface SnmpContextv3Face
public void setUserPrivacyPassword(java.lang.String newUserPrivacyPd)
SnmpContextv3Face
setUserPrivacyPassword
in interface SnmpContextv3Face
newUserPrivacyPd
- The user privacy passwordpublic void setContextEngineId(byte[] newContextEngineId) throws java.lang.IllegalArgumentException
SnmpContextv3Face
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.
setContextEngineId
in interface SnmpContextv3Face
newContextEngineId
- The contextEngineID
java.lang.IllegalArgumentException
UsmAgent.getSnmpEngineId()
public byte[] getContextEngineId()
SnmpContextv3Face
getContextEngineId
in interface SnmpContextv3Face
public void setContextName(java.lang.String newContextName)
SnmpContextv3Face
setContextName
in interface SnmpContextv3Face
newContextName
- The contextNameSnmpContextv3Face.Default_ContextName
public java.lang.String getContextName()
SnmpContextv3Face
getContextName
in interface SnmpContextv3Face
public void setUsmAgent(UsmAgent newAgent)
SnmpContextv3Face
setUsmAgent
in interface SnmpContextv3Face
newAgent
- The USM authoritative interfacepublic UsmAgent getUsmAgent()
SnmpContextv3Face
getUsmAgent
in interface SnmpContextv3Face
SnmpContextv3Face.setUsmAgent(uk.co.westhawk.snmp.stack.UsmAgent)
public boolean addDiscoveryPdu(DiscoveryPdu pdu) throws java.io.IOException, PduException, java.lang.IllegalArgumentException
SnmpContextv3Face
addDiscoveryPdu
in interface SnmpContextv3Face
pdu
- the discovery PDU
java.io.IOException
PduException
java.lang.IllegalArgumentException
public boolean addPdu(Pdu pdu) throws java.io.IOException, PduException, java.lang.IllegalArgumentException
SnmpContextBasisFace
addPdu
in interface SnmpContextBasisFace
pdu
- the PDU
java.io.IOException
PduException
java.lang.IllegalArgumentException
public boolean removePdu(int requestId)
SnmpContextBasisFace
removePdu
in interface SnmpContextBasisFace
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
SnmpContextv3Face
encodeDiscoveryPacket
in interface SnmpContextv3Face
java.io.IOException
EncodingException
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
SnmpContextBasisFace
encodePacket
in interface SnmpContextBasisFace
msg_type
- The message typerId
- The message iderrstat
- The error statuserrind
- The error indexve
- The varbind listobj
- Additional object (only used in SNMPv3)
java.io.IOException
EncodingException
public void sendPacket(byte[] packet)
SnmpContextBasisFace
sendPacket
in interface SnmpContextBasisFace
packet
- The encoded packetpublic void destroy()
destroy
in interface SnmpContextBasisFace
public void destroyPool()
destroy()
public boolean isDestroyed()
SnmpContextBasisFace
isDestroyed
in interface SnmpContextBasisFace
protected SnmpContextv3 getMatchingContext() throws java.io.IOException, java.lang.IllegalArgumentException
java.io.IOException
java.lang.IllegalArgumentException
getHashKey()
public void dumpContexts(java.lang.String title)
title
- The title of the dumppublic java.lang.String getHashKey()
getHashKey
in interface SnmpContextBasisFace
public void addTrapListener(TrapListener l) throws java.io.IOException
SnmpContextBasisFace
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.
addTrapListener
in interface SnmpContextBasisFace
l
- The trap listener
java.io.IOException
SnmpContextBasisFace.addTrapListener(TrapListener, int)
,
ListeningContextFace.DEFAULT_TRAP_PORT
public void removeTrapListener(TrapListener l) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The trap listener
java.io.IOException
SnmpContextBasisFace.removeTrapListener(TrapListener, int)
,
ListeningContextFace.DEFAULT_TRAP_PORT
public void addTrapListener(TrapListener l, int port) throws java.io.IOException
SnmpContextBasisFace
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.
addTrapListener
in interface SnmpContextBasisFace
l
- The trap listenerport
- The port the traps are received on
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.addRawPduListener(RawPduListener)
public void removeTrapListener(TrapListener l, int port) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The trap listenerport
- The port the traps are received on
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.removeRawPduListener(RawPduListener)
,
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)
public void addTrapListener(TrapListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFace
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.
addTrapListener
in interface SnmpContextBasisFace
l
- The trap listenerlcontext
- The listening context
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.addRawPduListener(RawPduListener)
public void removeTrapListener(TrapListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The trap listenerlcontext
- The listening context
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.removeRawPduListener(RawPduListener)
,
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)
public void addRequestPduListener(RequestPduListener l) throws java.io.IOException
SnmpContextBasisFace
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.
addRequestPduListener
in interface SnmpContextBasisFace
l
- The request PDU listener
java.io.IOException
SnmpContextBasisFace.addRequestPduListener(RequestPduListener, int)
,
SnmpContextBasisFace.DEFAULT_PORT
public void removeRequestPduListener(RequestPduListener l) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The request PDU listener
java.io.IOException
SnmpContextBasisFace.removeRequestPduListener(RequestPduListener, int)
,
SnmpContextBasisFace.DEFAULT_PORT
public void addRequestPduListener(RequestPduListener l, int port) throws java.io.IOException
SnmpContextBasisFace
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.
addRequestPduListener
in interface SnmpContextBasisFace
l
- The request PDU listenerport
- The port the request PDUs are received on
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.addRawPduListener(RawPduListener)
public void removeRequestPduListener(RequestPduListener l, int port) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The request PDU listenerport
- The port the request PDUs are received on
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.removeRawPduListener(RawPduListener)
,
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)
public void addRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFace
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.
addRequestPduListener
in interface SnmpContextBasisFace
l
- The request PDU listenerlcontext
- The listening context
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.addRawPduListener(RawPduListener)
public void removeRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws java.io.IOException
SnmpContextBasisFace
The 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 SnmpContextBasisFace
l
- The request PDU listenerlcontext
- The listening context
java.io.IOException
ListeningContextPool.ListeningContextPool(int, String, String)
,
ListeningContextPool.removeRawPduListener(RawPduListener)
,
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)
public Pdu processIncomingPdu(byte[] message) throws DecodingException, java.io.IOException
SnmpContextBasisFace
processIncomingPdu
in interface SnmpContextBasisFace
DecodingException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in interface SnmpContextBasisFace
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- Thrown when the constructor
generates an IOException or when in one of the Pool classes.
|
SNMP Stack 5_1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |