|
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.SnmpContextPool
This class contains the pool of SNMP v1 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 SnmpContext 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.
Thanks to Seon Lee (slee@virtc.com) for reporting thread safety problems.
SnmpContext,
SnmpContextv2cPool,
SnmpContextv3Pool| Field Summary | |
protected java.lang.String |
bindAddr
|
protected java.lang.String |
community
|
protected SnmpContext |
context
|
protected static java.util.Hashtable |
contextPool
|
protected java.lang.String |
hostname
|
protected int |
hostPort
|
protected java.lang.String |
socketType
|
| Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextFace |
DEFAULT_COMMUNITY, 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 | |
SnmpContextPool(java.lang.String host,
int port)
Constructor, using the Standard socket. |
|
SnmpContextPool(java.lang.String host,
int port,
java.lang.String typeSocket)
Constructor. |
|
SnmpContextPool(java.lang.String host,
int port,
java.lang.String comm,
java.lang.String typeSocket)
Constructor. |
|
SnmpContextPool(java.lang.String host,
int port,
java.lang.String comm,
java.lang.String bindAddress,
java.lang.String typeSocket)
Constructor. |
|
| Method Summary | |
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. |
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 (v1 and v2c) in the pool and empties the pool. |
void |
dumpContexts(java.lang.String title)
Dumps the pool of contexts. |
byte[] |
encodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
Encodes a PDU packet. |
java.lang.String |
getBindAddress()
Returns the local bind address. |
java.lang.String |
getCommunity()
Returns the community name. |
java.lang.String |
getHashKey()
Returns the hash key. |
java.lang.String |
getHost()
Returns the host. |
protected SnmpContext |
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. |
int |
getVersion()
Returns the SNMP version of the context. |
boolean |
isDestroyed()
Returns whether or not this context has been destroyed. |
Pdu |
processIncomingPdu(byte[] message)
Processes the incoming PDU with the current context. |
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. |
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 |
setCommunity(java.lang.String newCommunity)
Sets the community name. |
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 SnmpContext context
protected java.lang.String hostname
protected java.lang.String socketType
protected java.lang.String bindAddr
protected int hostPort
protected java.lang.String community
| Constructor Detail |
public SnmpContextPool(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 beSnmpContext.SnmpContext(String, int)
public SnmpContextPool(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.SnmpContext.SnmpContext(String, int, String),
SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKET,
SnmpContextBasisFace.NETSCAPE_SOCKET,
SnmpContextBasisFace.KVM_SOCKET
public SnmpContextPool(java.lang.String host,
int port,
java.lang.String comm,
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 becomm - The community name.typeSocket - The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKET,
SnmpContextBasisFace.NETSCAPE_SOCKET,
SnmpContextBasisFace.KVM_SOCKET
public SnmpContextPool(java.lang.String host,
int port,
java.lang.String comm,
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 becomm - The community name.bindAddress - The local address the server will bind totypeSocket - The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKET,
SnmpContextBasisFace.NETSCAPE_SOCKET,
SnmpContextBasisFace.KVM_SOCKET| Method Detail |
public int getVersion()
SnmpContextBasisFace
getVersion in interface SnmpContextBasisFaceSnmpConstants.SNMP_VERSION_1,
SnmpConstants.SNMP_VERSION_2c,
SnmpConstants.SNMP_VERSION_3public java.lang.String getHost()
SnmpContextBasisFace
getHost in interface SnmpContextBasisFacepublic int getPort()
SnmpContextBasisFace
getPort in interface SnmpContextBasisFacepublic java.lang.String getBindAddress()
SnmpContextBasisFace
getBindAddress in interface SnmpContextBasisFacepublic java.lang.String getTypeSocket()
SnmpContextBasisFace
getTypeSocket in interface SnmpContextBasisFaceSnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKET,
SnmpContextBasisFace.NETSCAPE_SOCKET,
SnmpContextBasisFace.KVM_SOCKETpublic java.lang.String getSendToHostAddress()
SnmpContextBasisFace
getSendToHostAddress in interface SnmpContextBasisFaceContextSocketFace.getSendToHostAddress()public java.lang.String getReceivedFromHostAddress()
SnmpContextBasisFace
getReceivedFromHostAddress in interface SnmpContextBasisFaceContextSocketFace.getReceivedFromHostAddress()public java.lang.String getCommunity()
SnmpContextFace
getCommunity in interface SnmpContextFacepublic void setCommunity(java.lang.String newCommunity)
SnmpContextFace
setCommunity in interface SnmpContextFaceSnmpContextFace.DEFAULT_COMMUNITY
public boolean addPdu(Pdu pdu)
throws java.io.IOException,
PduException
SnmpContextBasisFace
addPdu in interface SnmpContextBasisFacepdu - the PDU
java.io.IOException
PduExceptionpublic boolean removePdu(int requestId)
SnmpContextBasisFace
removePdu in interface SnmpContextBasisFace
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
encodePacket 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.IOException
EncodingExceptionpublic void sendPacket(byte[] packet)
SnmpContextBasisFace
sendPacket in interface SnmpContextBasisFacepacket - The encoded packetpublic void destroy()
destroy in interface SnmpContextBasisFacepublic void destroyPool()
destroy()public boolean isDestroyed()
SnmpContextBasisFace
isDestroyed in interface SnmpContextBasisFace
protected SnmpContext getMatchingContext()
throws java.io.IOException
java.io.IOExceptiongetHashKey()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
addTrapListener in interface SnmpContextBasisFacel - The trap listener
java.io.IOExceptionAbstractSnmpContext.addTrapListener(uk.co.westhawk.snmp.event.TrapListener)
public void removeTrapListener(TrapListener l)
throws java.io.IOException
removeTrapListener in interface SnmpContextBasisFacel - The trap listener
java.io.IOExceptionAbstractSnmpContext.removeTrapListener(uk.co.westhawk.snmp.event.TrapListener)
public 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 on
java.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 on
java.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 context
java.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 context
java.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 listener
java.io.IOExceptionSnmpContextBasisFace.addRequestPduListener(RequestPduListener, int),
SnmpContextBasisFace.DEFAULT_PORT
public 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 listener
java.io.IOExceptionSnmpContextBasisFace.removeRequestPduListener(RequestPduListener, int),
SnmpContextBasisFace.DEFAULT_PORT
public 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 on
java.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 on
java.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 context
java.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 context
java.io.IOExceptionListeningContextPool.ListeningContextPool(int, String, String),
ListeningContextPool.removeRawPduListener(RawPduListener),
ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)
public Pdu processIncomingPdu(byte[] message)
throws DecodingException,
java.io.IOException
processIncomingPdu in interface SnmpContextBasisFaceDecodingException
java.io.IOExceptionSnmpContext.processIncomingPdu(byte[])public java.lang.String toString()
toString in class java.lang.Object
public 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.
|
SNMP Stack 5_1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||