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
-
CALLBACK_THREAD
- This is set to true if the user wants the callback to be
called from a seperate thread
-
client
- The SnmpClient interface for this session.
-
community
- Community for outgoing requests and (default) authenticating
incoming PDUs.
-
local_port
- Local UDP port number, 0 is the default in which case it's system assigned
-
peername
- Domain name or dotted IP address of default peer
-
remote_port
- UDP port number of peer.
-
retries
- Number of retries before timeout.
-
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.
-
startLocalPort
- Intoduced because of IE4.0 bug with using port 0.
-
timeout
- Number of mS until first timeout, then exponential backoff.
-
SnmpSession(SnmpAPI)
- Constructor - Requires an SnmpAPI object as argument
to provide some important parameters and constants.
-
checkResponses()
- Checks for any outstanding responses that are still in
the receive queue.
-
checkTimeout(int)
- Returns true if the reqid is in the list of this session's timed out requests,
and removes it from the list.
-
close()
- Close Snmp Session and stop receiver thread
-
get(SnmpOID)
- SNMP get request method for single SnmpOID argument.
-
get(String)
- SNMP get request method for single String OID argument.
-
getnext(SnmpOID)
- SNMP getnext request method for single SnmpOID argument.
-
getnext(String)
- SNMP getnext request method for single String OID argument.
-
open()
- Open Snmp Session to communicate with an SNMP peer.
-
open(Applet)
- Open Snmp Session to communicate with an SNMP peer,
using the applet host server as a pasthrough.
-
receive(int)
- Fetch SNMP response PDU, fetches first PDU in response queue
if reqid is 0.
-
run()
- The run method starts the receiver thread for the session.
-
send(SnmpPDU)
- Send SnmpPDU on the given session after encoding the PDU.
-
set(SnmpOID, SnmpVar)
- SNMP set request method for single SnmpOID argument.
-
set(String, String)
- SNMP set request method for single String OID argument.
-
syncSend(SnmpPDU)
- Send SnmpPDU synchronously - returns response SnmpPDU and
throws SnmpException on failure, including timeout on SNMP response.
CALLBACK_THREAD
public boolean CALLBACK_THREAD
- This is set to true if the user wants the callback to be
called from a seperate thread
community
public String community
- Community for outgoing requests and (default) authenticating
incoming PDUs. If null, incoming PDUs are not authenticated.
retries
public int retries
- Number of retries before timeout. Default is 0.
timeout
public int timeout
- Number of mS until first timeout, then exponential backoff.
Default 5000 msec.
peername
public String peername
- Domain name or dotted IP address of default peer
remote_port
public int remote_port
- UDP port number of peer.
local_port
public int local_port
- Local UDP port number, 0 is the default in which case it's system assigned
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
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.
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.
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.
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
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
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
close
public void close()
- Close Snmp Session and stop receiver thread
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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