|
SNMP Stack 4_12 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | 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 everytime.
Everytime 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 send.
Thanks to Seon Lee (slee@virtc.com) for reporting thread safety problems.
SnmpContext
,
SnmpContextv2cPool
,
SnmpContextv3Pool
Field Summary | |
protected java.lang.String |
community
|
protected SnmpContext |
context
|
protected static java.util.Hashtable |
contextPool
|
protected java.lang.String |
hostAddr
|
protected int |
hostPort
|
protected java.lang.String |
socketType
|
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextFace |
version_id |
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace |
DEFAULT_PORT, KVM_SOCKET, MAXPDU, MSS, NETSCAPE_SOCKET, STANDARD_SOCKET |
Constructor Summary | |
SnmpContextPool(java.lang.String host,
int port)
Constructor. |
|
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. |
Method Summary | |
boolean |
addPdu(Pdu pdu)
Adds a pdu. |
void |
addTrapListener(TrapListener l)
Adds the specified trap listener. |
void |
destroy()
Releases the resources held by this context. |
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)
Encodes a pdu packet. |
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 |
getTypeSocket()
Returns the type socket |
int |
getVersion()
Return the SNMP version of the context. |
Pdu |
processIncomingTrap(byte[] message)
Processes the incoming trap with the current context. |
boolean |
removePdu(int requestId)
Removes a pdu. |
void |
removeTrapListener(TrapListener l)
Removes the specified trap listener. |
void |
sendPacket(byte[] packet)
Pass a correctly encoded SNMP packet, and we'l send it... |
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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static java.util.Hashtable contextPool
protected SnmpContext context
protected java.lang.String hostAddr
protected java.lang.String socketType
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 sendport
- 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 sendport
- The port where the SNMP server will betypeSocket
- The type of socket to use.SnmpContext.SnmpContext(String, int, String)
,
SnmpContextBasisFace.STANDARD_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
Thanks to Ernest Jones (EJones@netopia.com) for suggesting this constructor.
host
- The host to which the Pdu will sendport
- The port where the SNMP server will becomm
- The community name.typeSocket
- The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.NETSCAPE_SOCKET
,
SnmpContextBasisFace.KVM_SOCKET
Method Detail |
public int getVersion()
getVersion
in interface SnmpContextBasisFace
public java.lang.String getHost()
getHost
in interface SnmpContextBasisFace
public int getPort()
getPort
in interface SnmpContextBasisFace
public java.lang.String getTypeSocket()
getTypeSocket
in interface SnmpContextBasisFace
public java.lang.String getCommunity()
getCommunity
in interface SnmpContextFace
SnmpContext.getCommunity()
public void setCommunity(java.lang.String newCommunity)
setCommunity
in interface SnmpContextFace
SnmpContext.setCommunity(String)
public boolean addPdu(Pdu pdu) throws java.io.IOException, PduException
addPdu
in interface SnmpContextBasisFace
pdu
- the Pdupublic boolean removePdu(int requestId)
removePdu
in interface SnmpContextBasisFace
rid
- the Pdu request idpublic byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve) throws java.io.IOException, EncodingException
encodePacket
in interface SnmpContextBasisFace
uk.co.westhawk.snmp.stack.SnmpContextBasisFace
public void sendPacket(byte[] packet)
sendPacket
in interface SnmpContextBasisFace
uk.co.westhawk.snmp.stack.SnmpContextBasisFace
packet
- The encoded packetpublic void destroy()
destroy
in interface SnmpContextBasisFace
protected SnmpContext getMatchingContext() throws java.io.IOException
getHashKey()
public void dumpContexts(java.lang.String title)
title
- The title of the dumppublic java.lang.String getHashKey()
public void addTrapListener(TrapListener l) throws java.io.IOException
addTrapListener
in interface SnmpContextBasisFace
AbstractSnmpContext.addTrapListener(uk.co.westhawk.snmp.event.TrapListener)
public void removeTrapListener(TrapListener l) throws java.io.IOException
removeTrapListener
in interface SnmpContextBasisFace
AbstractSnmpContext.removeTrapListener(uk.co.westhawk.snmp.event.TrapListener)
public Pdu processIncomingTrap(byte[] message) throws DecodingException, java.io.IOException
processIncomingTrap
in interface SnmpContextBasisFace
SnmpContext.processIncomingTrap(byte[])
public java.lang.String toString()
toString
in class java.lang.Object
|
SNMP Stack 4_12 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |