SNMP Stack 5_1

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:
java.lang.Cloneable, java.util.EventListener, RawPduListener, java.lang.Runnable, SnmpContextBasisFace, SnmpContextFace
Direct Known Subclasses:
PassiveSnmpContext, SnmpContextv2c

public class SnmpContext
extends AbstractSnmpContext
implements SnmpContextFace, java.lang.Cloneable

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.23 $ $Date: 2006/02/09 14:24:15 $
Author:
Tim Panton
See Also:
SnmpContextFace, SnmpContextPool

Field Summary
 
Fields inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext
anyPduExpectingResponse, bindAddr, hostname, hostPort, isDestroyed, maxRecvSize, pduSupport, trapSupport, typeSocket
 
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
 
Fields inherited from interface uk.co.westhawk.snmp.event.RawPduListener
version_id
 
Constructor Summary
SnmpContext(java.lang.String host, int port)
          Constructor.
SnmpContext(java.lang.String host, int port, java.lang.String typeSocketA)
          Constructor.
SnmpContext(java.lang.String host, int port, java.lang.String bindAddress, java.lang.String typeSocketA)
          Constructor.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this SnmpContext.
 byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve, java.lang.Object obj)
          Encodes a PDU.
 byte[] encodePacket(byte msg_type, java.lang.String enterprise, byte[] IpAddress, int generic_trap, int specific_trap, long timeTicks, java.util.Enumeration ve)
           
 java.lang.String getCommunity()
          Returns the community name.
 java.lang.String getHashKey()
          Returns the hash key.
 int getVersion()
          Returns the SNMP version of the context.
 Pdu processIncomingPdu(byte[] message)
          Processes an incoming PDU.
protected  void processIncomingResponse(java.io.ByteArrayInputStream in)
          Processes an incoming SNMP v1 response.
 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 uk.co.westhawk.snmp.stack.AbstractSnmpContext
activate, addPdu, addRequestPduListener, addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, destroy, freeTransmitters, 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, finalize, 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 Detail

SnmpContext

public SnmpContext(java.lang.String host,
                   int port)
            throws java.io.IOException
Constructor.

Parameters:
host - The host to which the PDU will be sent
port - The port where the SNMP server will be
See Also:
AbstractSnmpContext.AbstractSnmpContext(String, int)

SnmpContext

public SnmpContext(java.lang.String host,
                   int port,
                   java.lang.String typeSocketA)
            throws java.io.IOException
Constructor.

Parameters:
host - The host to which the Pdu will be sent
port - The port where the SNMP server will be
typeSocketA - The local address the server will bind to
See Also:
AbstractSnmpContext.AbstractSnmpContext(String, int, String)

SnmpContext

public SnmpContext(java.lang.String host,
                   int port,
                   java.lang.String bindAddress,
                   java.lang.String typeSocketA)
            throws java.io.IOException
Constructor.

Parameters:
host - The host to which the PDU will be sent
port - The port where the SNMP server will be
bindAddress - The local address the server will bind to
typeSocketA - The type of socket to use.
Since:
4_14
See Also:
AbstractSnmpContext.AbstractSnmpContext(String, int, String, String), SnmpContextBasisFace.STANDARD_SOCKET, SnmpContextBasisFace.TCP_SOCKET, SnmpContextBasisFace.NETSCAPE_SOCKET, SnmpContextBasisFace.KVM_SOCKET
Method Detail

getVersion

public int getVersion()
Description copied from interface: SnmpContextBasisFace
Returns the SNMP version of the context.

Specified by:
getVersion in interface SnmpContextBasisFace
Specified by:
getVersion in class AbstractSnmpContext
Returns:
The version
See Also:
SnmpConstants.SNMP_VERSION_1, SnmpConstants.SNMP_VERSION_2c, SnmpConstants.SNMP_VERSION_3

getCommunity

public java.lang.String getCommunity()
Description copied from interface: SnmpContextFace
Returns the community name.

Specified by:
getCommunity in interface SnmpContextFace

setCommunity

public void setCommunity(java.lang.String newCommunity)
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 interface SnmpContextFace
See Also:
SnmpContextFace.DEFAULT_COMMUNITY

encodePacket

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
Description copied from interface: SnmpContextBasisFace
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.

Specified by:
encodePacket in interface SnmpContextBasisFace
Specified by:
encodePacket in class AbstractSnmpContext
Parameters:
msg_type - The message type
rId - The message id
errstat - The error status
errind - The error index
ve - The varbind list
obj - Additional object (only used in SNMPv3)
Returns:
The encoded packet
java.io.IOException
EncodingException

encodePacket

public byte[] encodePacket(byte msg_type,
                           java.lang.String enterprise,
                           byte[] IpAddress,
                           int generic_trap,
                           int specific_trap,
                           long timeTicks,
                           java.util.Enumeration ve)
                    throws java.io.IOException,
                           EncodingException
java.io.IOException
EncodingException

processIncomingResponse

protected void processIncomingResponse(java.io.ByteArrayInputStream in)
                                throws DecodingException,
                                       java.io.IOException
Processes an incoming SNMP v1 response.

Specified by:
processIncomingResponse in class AbstractSnmpContext
DecodingException
java.io.IOException
See Also:
AbstractSnmpContext.run()

processIncomingPdu

public Pdu processIncomingPdu(byte[] message)
                       throws DecodingException,
                              java.io.IOException
Description copied from interface: SnmpContextBasisFace
Processes an incoming PDU. The context will try to process the incoming PDU, using the SNMP version and other security parameters. If any of these do not correspond, a DecodingException will be thrown.

Specified by:
processIncomingPdu in interface SnmpContextBasisFace
Specified by:
processIncomingPdu in class AbstractSnmpContext
DecodingException
java.io.IOException
See Also:
AbstractSnmpContext.rawPduReceived(uk.co.westhawk.snmp.event.RawPduEvent)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone of this SnmpContext.

Specified by:
clone in interface SnmpContextBasisFace
Specified by:
clone in class AbstractSnmpContext
Throws:
java.lang.CloneNotSupportedException - Thrown when the constructor generates an IOException

getHashKey

public java.lang.String 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 interface SnmpContextBasisFace
Specified by:
getHashKey in class AbstractSnmpContext
Returns:
The hash key
Since:
4_14

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
The string

SNMP Stack 5_1