All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Snmp.SnmpSession

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----Snmp.SnmpSession

public class SnmpSession
extends Thread
Implements a session to send/receive PDUs from any SNMP peer. You need to instantiate this class to communicate with an SNMP entity.

Once you've created an SnmpAPI instance and run start(), instantiate an Snmp Session and use the open() method to get a socket for SNMP communications. Be sure to set the local_port variable if you're looking to use a specific port, e.g. running a daemon. For applets which may use SAS, use open(applet) instead of open().

You can then create and send PDUs, or receive PDUs on this session.

You can send to multiple SNMP peers via a session instance, but if you set peername and remote_port, then if these are unspecified in the PDU, it will be sent to that host and port. So a separate session instance is useful for hosts you talk to a lot.

You will probably want to create multiple sessions for agents with different community strings. If not, and you're sharing a session for different community strings, some changes are required. You can use your own authentication, if you implement SnmpClient. Or else, with default authentication, you will have to set commmunity on the session to null. Otherwise only PDUs matching the session community string will pass the default authentication.

See Also:
SnmpPDU

Variable Index

 o CALLBACK_THREAD
This is set to true if the user wants the callback to be called from a seperate thread
 o client
The SnmpClient interface for this session.
 o community
Community for outgoing requests and (default) authenticating incoming PDUs.
 o local_port
Local UDP port number, 0 is the default in which case it's system assigned
 o peername
Domain name or dotted IP address of default peer
 o remote_port
UDP port number of peer.
 o retries
Number of retries before timeout.
 o sasclient
To get around socket access restriction in applets, the SASClient allows for using a process on the Applet host as a pass through for Snmp PDUs.
 o startLocalPort
Intoduced because of IE4.0 bug with using port 0.
 o timeout
Number of mS until first timeout, then exponential backoff.

Constructor Index

 o SnmpSession(SnmpAPI)
Constructor - Requires an SnmpAPI object as argument to provide some important parameters and constants.

Method Index

 o checkResponses()
Checks for any outstanding responses that are still in the receive queue.
 o checkTimeout(int)
Returns true if the reqid is in the list of this session's timed out requests, and removes it from the list.
 o close()
Close Snmp Session and stop receiver thread
 o get(SnmpOID)
SNMP get request method for single SnmpOID argument.
 o get(String)
SNMP get request method for single String OID argument.
 o getnext(SnmpOID)
SNMP getnext request method for single SnmpOID argument.
 o getnext(String)
SNMP getnext request method for single String OID argument.
 o open()
Open Snmp Session to communicate with an SNMP peer.
 o open(Applet)
Open Snmp Session to communicate with an SNMP peer, using the applet host server as a pasthrough.
 o receive(int)
Fetch SNMP response PDU, fetches first PDU in response queue if reqid is 0.
 o run()
The run method starts the receiver thread for the session.
 o send(SnmpPDU)
Send SnmpPDU on the given session after encoding the PDU.
 o set(SnmpOID, SnmpVar)
SNMP set request method for single SnmpOID argument.
 o set(String, String)
SNMP set request method for single String OID argument.
 o syncSend(SnmpPDU)
Send SnmpPDU synchronously - returns response SnmpPDU and throws SnmpException on failure, including timeout on SNMP response.

Variables

 o CALLBACK_THREAD
 public boolean CALLBACK_THREAD
This is set to true if the user wants the callback to be called from a seperate thread

 o community
 public String community
Community for outgoing requests and (default) authenticating incoming PDUs. If null, incoming PDUs are not authenticated.

 o retries
 public int retries
Number of retries before timeout. Default is 0.

 o timeout
 public int timeout
Number of mS until first timeout, then exponential backoff. Default 5000 msec.

 o peername
 public String peername
Domain name or dotted IP address of default peer

 o remote_port
 public int remote_port
UDP port number of peer.

 o local_port
 public int local_port
Local UDP port number, 0 is the default in which case it's system assigned

 o startLocalPort
 public static int startLocalPort
Intoduced because of IE4.0 bug with using port 0. Set this so that next available port after this will be used. The default is 6000

 o sasclient
 public SASClient sasclient
To get around socket access restriction in applets, the SASClient allows for using a process on the Applet host as a pass through for Snmp PDUs. If this variable "sasclient" is non-null, this passthrough mechanism will be used for this session instance.

 o client
 public SnmpClient client
The SnmpClient interface for this session. If this is set, the callback assciated with this class object will be called. If this is not set, the default api.callback will be called.

Constructors

 o SnmpSession
 public SnmpSession(SnmpAPI api)
Constructor - Requires an SnmpAPI object as argument to provide some important parameters and constants. Fills in some default values from SnmpAPI object.

Methods

 o run
 public void run()
The run method starts the receiver thread for the session. Waits for incoming datagrams, and updates SnmpSession object with received Datagrams.

Overrides:
run in class Thread
 o open
 public void open() throws SnmpException
Open Snmp Session to communicate with an SNMP peer. Throws SnmpException with error string on certain types of failures.

Throws: SnmpException
is thrown on socket error.
See Also:
SnmpException
 o open
 public void open(Applet applet) throws SnmpException
Open Snmp Session to communicate with an SNMP peer, using the applet host server as a pasthrough. sasclient will be set to the SASClient instance if the connection to the applet server process is successfully established, and set to null if not. If unsuccessful, it will try a local socket.

Throws: SnmpException
is thrown on socket error.
See Also:
SASClient
 o close
 public void close()
Close Snmp Session and stop receiver thread

 o send
 public int send(SnmpPDU pdu) throws SnmpException
Send SnmpPDU on the given session after encoding the PDU. It returns the request id used for this request. This is an asynchronous request, returns after transmission. Use the checkResponses() or checkTimeouts() methods to look for responses or timeouts.

Throws: SnmpException
is thrown on send error.
 o syncSend
 public SnmpPDU syncSend(SnmpPDU pdu) throws SnmpException
Send SnmpPDU synchronously - returns response SnmpPDU and throws SnmpException on failure, including timeout on SNMP response. This is an synchronous request, returns after receiving SNMP response, or timing out.

Throws: SnmpException
is thrown on send error. public SnmpPDU syncSend(SnmpPDU pdu) throws SnmpException { send(pdu); Date d = new Date(); while (true) { // wait for response or timeout yield(); // To ensure we're not a hog, particularly on Solaris try { sleep(10); } // had to put this in to give up cpu catch (InterruptedException e) {} int resp[] = checkResponses(); // check if we got the response if (resp != null) for (int i=0;i
 o get
 public SnmpVar get(String oidString) throws SnmpException
SNMP get request method for single String OID argument. Builds PDU and makes get request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o get
 public SnmpVar get(SnmpOID oid) throws SnmpException
SNMP get request method for single SnmpOID argument. Builds PDU and makes get request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o getnext
 public SnmpVar getnext(String oidString) throws SnmpException
SNMP getnext request method for single String OID argument. Builds PDU and makes getnext request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o getnext
 public SnmpVar getnext(SnmpOID oid) throws SnmpException
SNMP getnext request method for single SnmpOID argument. Builds PDU and makes getnext request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o set
 public SnmpVar set(String oidString,
                    String setString) throws SnmpException
SNMP set request method for single String OID argument. Builds PDU and makes set request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o set
 public SnmpVar set(SnmpOID oid,
                    SnmpVar var) throws SnmpException
SNMP set request method for single SnmpOID argument. Builds PDU and makes set request and waits for response. Returns null if timeout.

Throws: SnmpException
is thrown on error.
 o receive
 public SnmpPDU receive(int reqid)
Fetch SNMP response PDU, fetches first PDU in response queue if reqid is 0. Takes PDU off the response queue.

 o checkTimeout
 public boolean checkTimeout(int reqid)
Returns true if the reqid is in the list of this session's timed out requests, and removes it from the list. Returns false if not in list.

 o checkResponses
 public synchronized int[] checkResponses()
Checks for any outstanding responses that are still in the receive queue. Returns list of requests, i.e. request ids.


All Packages  Class Hierarchy  This Package  Previous  Next  Index