Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 5_1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uk.co.westhawk.snmp.stack
Class AbstractSnmpContext

    java.lang.Object
      |
      +--uk.co.westhawk.snmp.stack.AbstractSnmpContext

All Implemented Interfaces:
  java.util.EventListener, RawPduListener, java.lang.Runnable, SnmpContextBasisFace

Direct Known Subclasses:
  SnmpContext, SnmpContextv3Basis

public abstract class AbstractSnmpContext
extends java.lang.Object
implements SnmpContextBasisFace, java.lang.Runnable, RawPduListener

This class contains the abstract SNMP context that is needed by every Pdu to send a SNMP v1, v2c or v3 request. The context also provides functionality to receive PDUs.

`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.30 $ $Date: 2006/06/19 10:45:09 $
Author:
  Tim Panton
See Also:
  `SnmpContext`, `SnmpContextv2c`, `SnmpContextv3`

Field Summary
`protected boolean` | `anyPduExpectingResponse`
`protected java.lang.String` | `bindAddr`
`protected java.lang.String` | `hostname`
`protected int` | `hostPort`
`protected boolean` | `isDestroyed`
`protected int` | `maxRecvSize`
`protected RequestPduReceivedSupport` | `pduSupport`
`protected TrapReceivedSupport` | `trapSupport`
`protected java.lang.String` | `typeSocket`

Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
`DEFAULT_PORT, KVM_SOCKET, MAXPDU, MSS, NETSCAPE_SOCKET, STANDARD_SOCKET, TCP_SOCKET, version_id`

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

Constructor Summary
`protected` | `AbstractSnmpContext(java.lang.String host, int port)` Constructor.
`protected` | `AbstractSnmpContext(java.lang.String host, int port, java.lang.String typeSocketA)` Constructor.
`protected` | `AbstractSnmpContext(java.lang.String host, int port, java.lang.String bindAddress, java.lang.String typeSocketA)` Constructor.

Method Summary
`protected void` | `activate()` Creates and starts the Receive thread that allows this context to receive packets.
`boolean` | `addPdu(Pdu p)` 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 to receive traps on the default trap port 162 from the host that matches this context.
`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.
`abstract java.lang.Object` | `clone()` Returns a clone of this SnmpContext.
`void` | `destroy()` This method will stop the thread.
`abstract byte[]` | `encodePacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve, java.lang.Object obj)` Encodes a PDU.
`protected void` | `freeTransmitters()` Frees the transmitters.
`java.lang.String` | `getBindAddress()` Returns the local bind address.
`java.lang.String` | `getDebugString()` Returns the thread usage of the AbstractSnmpContext.
`abstract java.lang.String` | `getHashKey()` Returns the hash key.
`java.lang.String` | `getHost()` Returns the host.
`java.lang.String` | `getHostAddress()` Deprecated. As of 4_14, use `getSendToHostAddress()`
`int` | `getMaxRecvSize()` Returns the maximum number of bytes this context will read from the socket.
`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.
`abstract int` | `getVersion()` Returns the SNMP version of this context.
`boolean` | `isDestroyed()` Returns whether or not this context has been destroyed.
`abstract Pdu` | `processIncomingPdu(byte[] message)` Processes an incoming pdu (but not a response).
`protected abstract void` | `processIncomingResponse(java.io.ByteArrayInputStream in)` Processes an incoming response.
`void` | `rawPduReceived(RawPduEvent evt)` Invoked when an undecoded pdu is received.
`boolean` | `removePdu(int rid)` 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 from listening for packets on the default trap port 162.
`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` | `run()` We wait for any incoming packets.
`void` | `sendPacket(byte[] p)` Sends an encoded PDU.
`void` | `setMaxRecvSize(int no)` Sets the maximum number of bytes this context will read from the socket.
`void` | `stop()` Deprecated. As of version 4_12, should use `destroy()`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### typeSocket

    protected java.lang.String typeSocket

### hostname

    protected java.lang.String hostname

### bindAddr

    protected java.lang.String bindAddr

### hostPort

    protected int hostPort

### maxRecvSize

    protected int maxRecvSize

### isDestroyed

    protected boolean isDestroyed

### anyPduExpectingResponse

    protected boolean anyPduExpectingResponse

### pduSupport

    protected RequestPduReceivedSupport pduSupport

### trapSupport

    protected TrapReceivedSupport trapSupport

Constructor Detail

### AbstractSnmpContext

    protected AbstractSnmpContext(java.lang.String host,
                                  int port)
                           throws java.io.IOException

  Constructor. The Standard socket type will be used.

Parameters:
  `host` - The host to which the Pdu will be sent
  `port` - The port where the SNMP server will be
See Also:
  `SnmpContextBasisFace.STANDARD_SOCKET`

### AbstractSnmpContext

    protected AbstractSnmpContext(java.lang.String host,
                                  int port,
                                  java.lang.String typeSocketA)
                           throws java.io.IOException

  Constructor. The Standard socket type will be used.

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:
  `SnmpContextBasisFace.STANDARD_SOCKET`

### AbstractSnmpContext

    protected AbstractSnmpContext(java.lang.String host,
                                  int port,
                                  java.lang.String bindAddress,
                                  java.lang.String typeSocketA)
                           throws java.io.IOException

  Constructor. If bindAddress is null, then the system will pick up a valid local address to bind the socket. The typeSocket will indicate which type of socket to use. This way different handlers can be provided for Netscape or Standard JVM. The Netscape implementation will make the necessary security calls to access hosts that are not the applet's webserver. The KVM version will be for small device support (e.g. Palm Pilot).

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.
Throws:
  `java.io.IOException` - Thrown when the socket cannot be created.
Since:
  4_14
See Also:
  `SnmpContextBasisFace.STANDARD_SOCKET`, `SnmpContextBasisFace.TCP_SOCKET`, `SnmpContextBasisFace.NETSCAPE_SOCKET`, `SnmpContextBasisFace.KVM_SOCKET`

Method Detail

### processIncomingResponse

    protected abstract void processIncomingResponse(java.io.ByteArrayInputStream in)
                                             throws DecodingException,
                                                    java.io.IOException

  Processes an incoming response. Has to be overload by each context. This is called in the run() method.

    `DecodingException`
    `java.io.IOException`
  See Also:
    `run()`

### encodePacket

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

  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 interface `SnmpContextBasisFace`
  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`

### processIncomingPdu

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

  Processes an incoming pdu (but not a response). Has to be overload by each context.

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

### getVersion

    public abstract int getVersion()

  Returns the SNMP version of this context. Has to be overload by each context.

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

### getHost

    public java.lang.String getHost()

  Description copied from interface: `SnmpContextBasisFace`
  Returns the host.

  Specified by:
    `getHost` in interface `SnmpContextBasisFace`
  Returns:
    The host

### getHostAddress

    public java.lang.String getHostAddress()

  Deprecated. As of 4_14, use `getSendToHostAddress()`

  Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the host.

  Returns:
    The IP address of the host

### getSendToHostAddress

    public java.lang.String getSendToHostAddress()

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

  Specified by:
    `getSendToHostAddress` in interface `SnmpContextBasisFace`
  Returns:
    The IP address of the host the packets where sent to.
  See Also:
    `ContextSocketFace.getSendToHostAddress()`

### getReceivedFromHostAddress

    public java.lang.String getReceivedFromHostAddress()

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

  Specified by:
    `getReceivedFromHostAddress` in interface `SnmpContextBasisFace`
  Returns:
    The IP address of the (latest) host the packets where received from.
  See Also:
    `ContextSocketFace.getReceivedFromHostAddress()`

### getPort

    public int getPort()

  Description copied from interface: `SnmpContextBasisFace`
  Returns the port number.

  Specified by:
    `getPort` in interface `SnmpContextBasisFace`
  Returns:
    The port no

### getBindAddress

    public java.lang.String getBindAddress()

  Description copied from interface: `SnmpContextBasisFace`
  Returns the local bind address. If bindAddress is null, then the system will pick up a valid local address to bind the socket.

  Specified by:
    `getBindAddress` in interface `SnmpContextBasisFace`
  Returns:
    The local bind address

### getTypeSocket

    public java.lang.String getTypeSocket()

  Description copied from interface: `SnmpContextBasisFace`
  Returns the type of socket.

  Specified by:
    `getTypeSocket` in interface `SnmpContextBasisFace`
  Returns:
    The type of socket
  See Also:
    `SnmpContextBasisFace.STANDARD_SOCKET`, `SnmpContextBasisFace.TCP_SOCKET`, `SnmpContextBasisFace.NETSCAPE_SOCKET`, `SnmpContextBasisFace.KVM_SOCKET`

### getMaxRecvSize

    public int getMaxRecvSize()

  Returns the maximum number of bytes this context will read from the socket. By default this will be set to `MSS` (i.e. 1300).

  Returns:
    The number
  Since:
    4_12
  See Also:
    `SnmpContextBasisFace.MSS`, `setMaxRecvSize(int)`

### setMaxRecvSize

    public void setMaxRecvSize(int no)

  Sets the maximum number of bytes this context will read from the socket. By default this will be set to `MSS` (i.e. 1300). The default size seems a reasonable size. The problem usually occurs when sending Bulk requests.

  If a packet arrives that is bigger than the maximum size of received bytes, the stack will try to decode it nevertheless. The usual error that will occur is:

       Error message: "Incorrect packet. No of bytes received less than packet length."

  Although UDP datagrams can be fragmented (fragmentation is part of the network layer (IP), not the transport layer (UDP/TCP)), some firewalls reject incoming fragments. Therefor it is best not to set maxRecvSize higher than the largest packet size you can get through your network topology.

  Thanks to Pete Kazmier (pete@kazmier.com) for the suggestion.

  Note, this property is NOT supported in any of the SNMPContextXXPool classes.

  Parameters:
    `no` - The new number
  Since:
    4_12
  See Also:
    `SnmpContextBasisFace.MSS`, `getMaxRecvSize()`

### getDebugString

    public java.lang.String getDebugString()

  Returns the thread usage of the AbstractSnmpContext. It returns a String in the form of `=PO=QR--------------0`.

  The String represents the array of transmitters. Each character represents a transmitter slot. The transmitters form a thread pool of a maximum size, MAXPDU. Each transmitter is used to wait for one PDU response at a given moment in time. When the response is received the transmitter will stop running, but is not destroyed. It will be reused.

  Meaning of each character:

  - `-` a transmitter slot has not yet been allocated a thread
  - `=` there is a thread but it is idle
  - `A->Z` the thread is transmitting a Pdu
  - The last character represents the context's recv thread:
    - `0` there isn't one
    - `1` it exists but isn't running
    - `2` it exists and is alive.

  Returns:
    The thread usage of the AbstractSnmpContext
  Since:
    4_12

### destroy

    public void destroy()

  This method will stop the thread. All transmitters, PDUs in flight and traplisteners will be removed when run() finishes.

  It closes the socket. The thread will actually stop/finish when the run() finishes. Since the socket is closed, the run() will fall through almost instantly.

  Note: The thread(s) will not die immediately; this will take about half a minute.

  Specified by:
    `destroy` in interface `SnmpContextBasisFace`
  See Also:
    `ListeningContext.destroy()`, `ListeningContextPool.destroyPool()`

### isDestroyed

    public boolean isDestroyed()

  Description copied from interface: `SnmpContextBasisFace`
  Returns whether or not this context has been destroyed.

  Specified by:
    `isDestroyed` in interface `SnmpContextBasisFace`

### stop

    public void stop()

  Deprecated. As of version 4_12, should use `destroy()`

  This method will stop the thread. All transmitters, PDUs in flight and traplisteners will be removed when run() finishes.

  It does NOT close the socket. The thread will actually stop/finish when the run() finishes. That is when a packet arrives on the socket or when the socket times out.

  We have deprecated this method since there is no point in stopping the context, but not destroying it. The context cannot start again anyway. The difference between destroy() and stop() was not very clear.

  See Also:
    `destroy()`

### run

    public void run()

  We wait for any incoming packets. After receiving one, decode the packet into an Pdu. The Pdu will notify the observers waiting for an response.

  Thanks to Chris Barlock who reported a NullPointerException in run() on variable 'me' and introduced the variable stopRequested.

  Specified by:
    `run` in interface `java.lang.Runnable`

### sendPacket

    public void sendPacket(byte[] p)

  Description copied from interface: `SnmpContextBasisFace`
  Sends an encoded 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:
    `sendPacket` in interface `SnmpContextBasisFace`
  Parameters:
    `p` - The encoded packet

### removePdu

    public boolean removePdu(int rid)

  Description copied from interface: `SnmpContextBasisFace`
  Removes a PDU from the context. 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:
    `removePdu` in interface `SnmpContextBasisFace`
  Returns:
    whether the PDU has been successfully removed

### addPdu

    public boolean addPdu(Pdu p)
                   throws java.io.IOException,
                          PduException

  Description copied from interface: `SnmpContextBasisFace`
  Adds a PDU to the context. 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:
    `addPdu` in interface `SnmpContextBasisFace`
  Parameters:
    `p` - the PDU
  Returns:
    whether the PDU has been successfully added
    `java.io.IOException`
    `PduException`

### addTrapListener

    public void addTrapListener(TrapListener l)
                         throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified trap listener to receive traps on the default trap port 162 from the host that matches this context.

  The 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.

  Specified by:
    `addTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `java.io.IOException`
  See Also:
    `SnmpContextBasisFace.addTrapListener(TrapListener, int)`, `ListeningContextFace.DEFAULT_TRAP_PORT`

### removeTrapListener

    public void removeTrapListener(TrapListener l)
                            throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified trap listener from listening for packets on the default trap port 162.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

  Specified by:
    `removeTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `java.io.IOException`
  See Also:
    `SnmpContextBasisFace.removeTrapListener(TrapListener, int)`, `ListeningContextFace.DEFAULT_TRAP_PORT`

### addTrapListener

    public void addTrapListener(TrapListener l,
                                int port)
                         throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified trap listener to receive traps on the specified port from the host that matches this context.

  The 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.

  Specified by:
    `addTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `port` - The port the traps are received on
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.addRawPduListener(RawPduListener)`

### removeTrapListener

    public void removeTrapListener(TrapListener l,
                                   int port)
                            throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified trap listener from listening for packets on the specified port.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

  Specified by:
    `removeTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `port` - The port the traps are received on
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.removeRawPduListener(RawPduListener)`, `ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)`

### addTrapListener

    public void addTrapListener(TrapListener l,
                                ListeningContextPool lcontext)
                         throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified trap listener to receive traps on the specified listening context that matches this context.

  The 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.

  Specified by:
    `addTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `lcontext` - The listening context
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.addRawPduListener(RawPduListener)`

### removeTrapListener

    public void removeTrapListener(TrapListener l,
                                   ListeningContextPool lcontext)
                            throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified trap listener from listening for packets on the specified listening context.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()

  Specified by:
    `removeTrapListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The trap listener
    `lcontext` - The listening context
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.removeRawPduListener(RawPduListener)`, `ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)`

### addRequestPduListener

    public void addRequestPduListener(RequestPduListener l)
                               throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified request pdu listener to receive PDUs on the default request pdu port 161 from the host that matches this context.

  The 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.

  Specified by:
    `addRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `java.io.IOException`
  See Also:
    `SnmpContextBasisFace.addRequestPduListener(RequestPduListener, int)`, `SnmpContextBasisFace.DEFAULT_PORT`

### removeRequestPduListener

    public void removeRequestPduListener(RequestPduListener l)
                                  throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified request pdu listener from listening for packets on the default request pdu port 161.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

  Specified by:
    `removeRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `java.io.IOException`
  See Also:
    `SnmpContextBasisFace.removeRequestPduListener(RequestPduListener, int)`, `SnmpContextBasisFace.DEFAULT_PORT`

### addRequestPduListener

    public void addRequestPduListener(RequestPduListener l,
                                      int port)
                               throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified request pdu listener to receive PDUs on the specified port from the host that matches this context.

  The 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.

  Specified by:
    `addRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `port` - The port the request PDUs are received on
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.addRawPduListener(RawPduListener)`

### removeRequestPduListener

    public void removeRequestPduListener(RequestPduListener l,
                                         int port)
                                  throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified request pdu listener from listening for packets on the specified port.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

  Specified by:
    `removeRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `port` - The port the request PDUs are received on
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.removeRawPduListener(RawPduListener)`, `ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)`

### addRequestPduListener

    public void addRequestPduListener(RequestPduListener l,
                                      ListeningContextPool lcontext)
                               throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.

  The 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.

  Specified by:
    `addRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `lcontext` - The listening context
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.addRawPduListener(RawPduListener)`

### removeRequestPduListener

    public void removeRequestPduListener(RequestPduListener l,
                                         ListeningContextPool lcontext)
                                  throws java.io.IOException

  Description copied from interface: `SnmpContextBasisFace`
  Removes the specified request pdu listener from listening for packets on the specified listening context.

  The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()

  Specified by:
    `removeRequestPduListener` in interface `SnmpContextBasisFace`
  Parameters:
    `l` - The request PDU listener
    `lcontext` - The listening context
    `java.io.IOException`
  See Also:
    `ListeningContextPool.ListeningContextPool(int, String, String)`, `ListeningContextPool.removeRawPduListener(RawPduListener)`, `ListeningContextPool.removeRawPduListenerFromPool(RawPduListener)`

### rawPduReceived

    public void rawPduReceived(RawPduEvent evt)

  Invoked when an undecoded pdu is received. First the version and the hostaddress are checked, if correct an attempt is made to decode the pdu. When successful the original event is consumed and a decoded pdu event is passed on the listeners.

  Specified by:
    `rawPduReceived` in interface `RawPduListener`
  See Also:
    `RawPduReceivedSupport.fireRawPduReceived(int, java.lang.String, int, byte[])`, `RequestPduReceivedSupport.fireRequestPduReceived(uk.co.westhawk.snmp.stack.Pdu, int)`, `TrapReceivedSupport.fireTrapReceived(uk.co.westhawk.snmp.stack.Pdu, int)`

### activate

    protected void activate()

  Creates and starts the Receive thread that allows this context to receive packets. Subclasses may override this to adjust the threading behaviour.

  See Also:
    `PassiveSnmpContext.activate()`, `PassiveSnmpContextv2c.activate()`

### freeTransmitters

    protected void freeTransmitters()

  Frees the transmitters.

  Since:
    5_1
  See Also:
    `run()`, `destroy()`

### clone

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

  Returns a clone of this SnmpContext.

  Specified by:
    `clone` in interface `SnmpContextBasisFace`
  Overrides:
    `clone` in class `java.lang.Object`
  Throws:
    `java.lang.CloneNotSupportedException` - Thrown when the constructor generates an IOException or when in one of the Pool classes.
  Since:
    4_14

### getHashKey

    public abstract java.lang.String getHashKey()

  Returns the hash key. This key is built out of all properties.

  Specified by:
    `getHashKey` in interface `SnmpContextBasisFace`
  Returns:
    The hash key
  Since:
    4_14

Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 5_1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD