Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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, java.lang.Runnable, SnmpContextBasisFace, SnmpContextFace, TrapListener

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.18 $ $Date: 2002/10/23 11:48:01 $
Author:
  Tim Panton
See Also:
  `SnmpContextFace`, `SnmpContextPool`

Field Summary
`static java.lang.String` | `Default_Community` The default community name.

Fields inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext
`hostAddr, hostPort, isDestroyed, maxRecvSize, typeSocket`

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`

Fields inherited from interface uk.co.westhawk.snmp.event.TrapListener
`version_id`

Constructor Summary
`SnmpContext(java.lang.String host, int port)` Constructor.
`SnmpContext(java.lang.String host, int port, 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)` Encodes a pdu packet.
`byte[]` | `encodePacket(byte msg_type, java.lang.String enterprise, byte[] IpAddress, int generic_trap, int specific_trap, long timeTicks, java.util.Enumeration ve)` Encodes a Trap1 pdu packet.
`java.lang.String` | `getCommunity()` Returns the community name.
`int` | `getVersion()` Return the SNMP version of the context.
`protected void` | `ProcessIncomingMessage(uk.co.westhawk.snmp.stack.AsnDecoder rpdu, java.io.ByteArrayInputStream in)` Processes an incoming SNMP v1 message.
`Pdu` | `processIncomingTrap(byte[] message)` Processes an incoming trap.
`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, addTrapListener, destroy, getDebugString, getHost, getHostAddress, getMaxRecvSize, getPort, getTypeSocket, removePdu, removeTrapListener, run, sendPacket, setMaxRecvSize, stop, trapReceived`

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, addTrapListener, destroy, getHost, getPort, getTypeSocket, removePdu, removeTrapListener, sendPacket`

Field Detail

### Default_Community

    public static final java.lang.String Default_Community

  The default community name. This is public.

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 send
    `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 send
    `port` - The port where the SNMP server will be
    `typeSocketA` - The type of socket to use.
  See Also:
    `AbstractSnmpContext.AbstractSnmpContext(String, int, String)`, `SnmpContextBasisFace.STANDARD_SOCKET`, `SnmpContextBasisFace.NETSCAPE_SOCKET`, `SnmpContextBasisFace.KVM_SOCKET`

Method Detail

### getVersion

    public int getVersion()

  Description copied from interface: `SnmpContextBasisFace`
  Return the SNMP version of the context.
  Specified by:
    `getVersion` in interface `SnmpContextBasisFace`
  Overrides:
    `getVersion` in class `AbstractSnmpContext`
  Following copied from interface: `uk.co.westhawk.snmp.stack.SnmpContextBasisFace`
  Returns:
    The version

### getCommunity

    public java.lang.String getCommunity()

  Returns the community name.
  Specified by:
    `getCommunity` in interface `SnmpContextFace`

### setCommunity

    public void setCommunity(java.lang.String newCommunity)

  Sets the community name. This community name will be used for all PDU send with this context. The default community name is public.
  Specified by:
    `setCommunity` in interface `SnmpContextFace`
  See Also:
    `Default_Community`

### encodePacket

    public byte[] encodePacket(byte msg_type,
                               int rId,
                               int errstat,
                               int errind,
                               java.util.Enumeration ve)
                        throws java.io.IOException,
                               EncodingException

  Encodes a pdu packet.
  Specified by:
    `encodePacket` in interface `SnmpContextBasisFace`
  Overrides:
    `encodePacket` in class `AbstractSnmpContext`
  Following copied from interface: `uk.co.westhawk.snmp.stack.SnmpContextBasisFace`
  Returns:
    The encoded packet

### 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

  Encodes a Trap1 pdu packet.

### ProcessIncomingMessage

    protected void ProcessIncomingMessage(uk.co.westhawk.snmp.stack.AsnDecoder rpdu,
                                          java.io.ByteArrayInputStream in)
                                   throws DecodingException,
                                          java.io.IOException

  Processes an incoming SNMP v1 message.
  Overrides:
    `ProcessIncomingMessage` in class `AbstractSnmpContext`
  Following copied from class: `uk.co.westhawk.snmp.stack.AbstractSnmpContext`
  See Also:
    `AbstractSnmpContext.run()`

### processIncomingTrap

    public Pdu processIncomingTrap(byte[] message)
                            throws DecodingException,
                                   java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Processes an incoming trap. The context will try to process the incoming trap, using the SNMP version and other security parameters. If any of these do not correspond, a DecodingException will be thrown.
  Specified by:
    `processIncomingTrap` in interface `SnmpContextBasisFace`
  Overrides:
    `processIncomingTrap` in class `AbstractSnmpContext`
  Following copied from class: `uk.co.westhawk.snmp.stack.AbstractSnmpContext`
  See Also:
    `AbstractSnmpContext.trapReceived(uk.co.westhawk.snmp.event.TrapEvent)`

### clone

    public java.lang.Object clone()
                           throws java.lang.CloneNotSupportedException

  Returns a clone of this SnmpContext.
  Overrides:
    `clone` in class `java.lang.Object`
  Throws:
    `java.lang.CloneNotSupportedException` - Thrown when the constructor generates an IOException

### toString

    public java.lang.String toString()

  Returns a string representation of the object.
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    The string

Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD