Package uk.co.westhawk.snmp.stack
Class SnmpContext
java.lang.Object
uk.co.westhawk.snmp.stack.AbstractSnmpContext
uk.co.westhawk.snmp.stack.SnmpContext
- All Implemented Interfaces:
Cloneable
,Runnable
,EventListener
,RawPduListener
,SnmpContextBasisFace
,SnmpContextFace
- Direct Known Subclasses:
PassiveSnmpContext
,SnmpContextv2c
This class contains the SNMP v1 context that is needed by every PDU to
send a SNMP v1 request.
destroy()
should be called when the context is no longer
used. This is the only way the threads will be stopped and garbage
collected.
- Version:
- $Revision: 3.25 $ $Date: 2009/03/05 12:51:29 $
- Author:
- Tim Panton
- See Also:
-
Field Summary
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
DEFAULT_PORT, MAXPDU, MSS, STANDARD_SOCKET, TCP_SOCKET
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextFace
DEFAULT_COMMUNITY
-
Constructor Summary
ConstructorsConstructorDescriptionSnmpContext
(String host, int port) Constructor.SnmpContext
(String host, int port, String typeSocketA) Constructor.SnmpContext
(String host, int port, String bindAddress, String typeSocketA) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this SnmpContext.byte[]
encodePacket
(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) Encodes a PDU.byte[]
encodePacket
(byte msg_type, String enterprise, byte[] IpAddress, int generic_trap, int specific_trap, long timeTicks, Enumeration ve) Returns the community name.Returns the hash key.int
Returns the SNMP version of this context.processIncomingPdu
(byte[] message) Processes an incoming pdu (but not a response).void
setCommunity
(String newCommunity) Sets the community name.toString()
Returns a string representation of the object.Methods inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext
addPdu, addRequestPduListener, addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, destroy, getBindAddress, getDebugString, getHost, getHostAddress, getMaxRecvSize, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, rawPduReceived, removePdu, removeRequestPduListener, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, run, sendPacket, setMaxRecvSize, stop
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
addPdu, addRequestPduListener, addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, destroy, getBindAddress, getHost, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, removePdu, removeRequestPduListener, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, sendPacket
-
Constructor Details
-
SnmpContext
Constructor.- Parameters:
host
- The host to which the PDU will be sentport
- The port where the SNMP server will be- Throws:
IOException
- See Also:
-
AbstractSnmpContext(String, int)
-
SnmpContext
Constructor. Parameter typeSocketA should be either STANDARD_SOCKET, TCP_SOCKET or a fully qualified classname.- Parameters:
host
- The host to which the Pdu will be sentport
- The port where the SNMP server will betypeSocketA
- The local address the server will bind to- Throws:
IOException
- See Also:
-
AbstractSnmpContext(String, int, String)
-
SnmpContext
public SnmpContext(String host, int port, String bindAddress, String typeSocketA) throws IOException Constructor. Parameter typeSocketA should be either STANDARD_SOCKET, TCP_SOCKET or a fully qualified classname.- Parameters:
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 totypeSocketA
- The type of socket to use.- Throws:
IOException
- Since:
- 4_14
- See Also:
-
AbstractSnmpContext(String, int, String, String)
SnmpContextBasisFace.STANDARD_SOCKET
SnmpContextBasisFace.TCP_SOCKET
-
-
Method Details
-
getVersion
public int getVersion()Description copied from class:AbstractSnmpContext
Returns the SNMP version of this context. Has to be overload by each context.- Specified by:
getVersion
in interfaceSnmpContextBasisFace
- Specified by:
getVersion
in classAbstractSnmpContext
- Returns:
- The version
- See Also:
-
getCommunity
Description copied from interface:SnmpContextFace
Returns the community name.- Specified by:
getCommunity
in interfaceSnmpContextFace
-
setCommunity
Description copied from interface:SnmpContextFace
Sets the community name. This community name will be used for all PDUs sent with this context. The default community name is public.- Specified by:
setCommunity
in interfaceSnmpContextFace
- See Also:
-
encodePacket
public byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) throws IOException, EncodingException Description copied from class:AbstractSnmpContext
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. Has to be overload by each context.- Specified by:
encodePacket
in interfaceSnmpContextBasisFace
- Specified by:
encodePacket
in classAbstractSnmpContext
- Parameters:
msg_type
- The message typerId
- The message iderrstat
- The error statuserrind
- The error indexve
- The varbind listobj
- Additional object (only used in SNMPv3)- Returns:
- The encoded packet
- Throws:
IOException
EncodingException
-
encodePacket
public byte[] encodePacket(byte msg_type, String enterprise, byte[] IpAddress, int generic_trap, int specific_trap, long timeTicks, Enumeration ve) throws IOException, EncodingException - Throws:
IOException
EncodingException
-
processIncomingPdu
Description copied from class:AbstractSnmpContext
Processes an incoming pdu (but not a response). Has to be overload by each context.- Specified by:
processIncomingPdu
in interfaceSnmpContextBasisFace
- Specified by:
processIncomingPdu
in classAbstractSnmpContext
- Throws:
DecodingException
IOException
- See Also:
-
clone
Returns a clone of this SnmpContext.- Specified by:
clone
in interfaceSnmpContextBasisFace
- Specified by:
clone
in classAbstractSnmpContext
- Throws:
CloneNotSupportedException
- Thrown when the constructor generates an IOException
-
getHashKey
Returns the hash key. This key is built out of all properties. It serves as key for a hashtable of (v1) contexts.- Specified by:
getHashKey
in interfaceSnmpContextBasisFace
- Specified by:
getHashKey
in classAbstractSnmpContext
- Returns:
- The hash key
- Since:
- 4_14
-
toString
Returns a string representation of the object.
-