All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.jaw.snmp.manager.SnmpSession

java.lang.Object
   |
   +----com.sun.jaw.snmp.manager.SnmpSession

public final class SnmpSession
extends Object
implements SnmpManagerSrvIf, SnmpDefinitions, Runnable, Serializable
An SnmpSession object essentially creates, controls, and manages one or more request. A session can be bound to a peer so that all requests created (without specifying a peer) will use this as the default. Alternately, there can be a mixture of peers, that is two requests can talk to two different peers.

Each SnmpSession has a dispatcher that is a thread used to service all the requests it creates. It also uses a socket which defaults to a default SnmpSocket. If desired, the session can be configured to exclusively use a seperate socket. By default, all sessions use the same default socket unless explicitly configured. See SnmpSocket for additional information.

This class implements SNMP commands interface which provides a variety of convenience methods that are used to create requests. Each of the requests perform specific SNMP operation. These methods are simple to use and automatically start the request. The session maintains the list of all active request and responses.

Users can explicitly create and start the requests. This is usually not required for most applications.

Each such method provides specific SNMP operation like SnmpGet, SnmpGetNext, and SnmpSet. The SnmpGet and SnmpGetNext operations can be either poll or non-poll. In addition there is a convenience method which automatically walks through a set of instances starting at any arbitrary place in the MIB hierarchy and terminates when a specified condition becomes true.

The requests are retried when the peer does not respond within a specified time. There is a maximum retry limit. Certain options of sessions can be configured using the SnmpOptions object. This allow enabling and disabling features like fixing protocol data units (PDU) on error, handling SnmpTooBig errors and multiplexing requests.

Once a session is created the user can perform one or more SNMP operation in a one-at-a-time sequence. Usually such a sequence is a set of logical operations which together form a complete operation. For example, a SnmpSet operation, which involves a initial query to the agent for obtaining a valid index. This is followed by one or more SnmpSet commands to complete the set operation.

At any time, one or more requests active in a session can be cancelled.

See Also:
SnmpVar, SnmpVarbindList, SnmpParameters, SnmpPeer, SnmpRequest

Variable Index

 o sessionName
The name identifying this session.
 o snmpOptions
Set of options used to configure all SnmpRequests created in this session.

Constructor Index

 o SnmpSession(String)
Constructor for creating a new session.
 o SnmpSession(String, SnmpAuthHandlerIf)
Constructor for creating new session.
 o SnmpSession(String, SnmpPeer, SnmpAuthHandlerIf)
Constructor for creating new session.

Method Index

 o anyPendingResponses()
Indicates whether there are any responses available for processing.
 o cancelAllRequests()
Cancels all pending requests with this session.
 o checkResponseFor(Request)
Indicates whether a response was received for this request.
 o destroySession()
Destroys any pending requests and then stops the session.
 o finalize()
Removes all the requests for this session, closes the socket and sets all the references to the SnmpSession object to null.
 o getAllRequestsForPeer(SnmpPeer)
Gets a list of requests which have the specified destination.
 o getDefaultPeer()
Gets a default peer (if any) bound to this session.
 o getName()
Gets the session name (often used in identification).
 o getSocket()
Gets the SnmpSocket which will be used by requests created in this session.
 o isEquivalent(SnmpSession)
Two sessions are equivalent if they share the same socket.
 o isSessionActive()
Indicates if the thread for this session is active.
 o run()
Dispatcher method for this session thread.
 o setDefaultPeer(SnmpPeer)
Sets peer as default.
 o setName(String)
Sets the session name (often used in identification).
 o snmpGet(SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP get request on the varbind list.
 o snmpGet(SnmpPeer, SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP get request on the varbind list.
 o snmpGetBulk(SnmpHandlerIf, SnmpVarbindList, int, int)
Performs a single SNMP getbulk request on the varbind list.
 o snmpGetBulk(SnmpPeer, SnmpHandlerIf, SnmpVarbindList, int, int)
Performs a single SNMP getbulk request on the varbind list.
 o snmpGetNext(SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP getnext request on the varbind list.
 o snmpGetNext(SnmpPeer, SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP getnext request on the varbind list.
 o snmpGetNextPoll(SnmpHandlerIf, SnmpVarbindList, int)
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list.
 o snmpGetNextPoll(SnmpPeer, SnmpHandlerIf, SnmpVarbindList, int)
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list.
 o snmpGetPoll(SnmpHandlerIf, SnmpVarbindList, int)
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list.
 o snmpGetPoll(SnmpPeer, SnmpHandlerIf, SnmpVarbindList, int)
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list.
 o snmpSet(SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP set request on the peer for the specified varbind list.
 o snmpSet(SnmpPeer, SnmpHandlerIf, SnmpVarbindList)
Performs a single SNMP set request on the peer for the specified varbind list.
 o snmpWalkUntil(SnmpHandlerIf, SnmpVarbindList, SnmpOid)
Walks through the lexicographic ordering of the agent MIB.
 o snmpWalkUntil(SnmpPeer, SnmpHandlerIf, SnmpVarbindList, SnmpOid)
Walks through the lexicographic ordering of the agent MIB.
 o syncInProgress()
Indicates whether this session is performing synchronous operation for a request.
 o thisSessionContext()
Returns true if the current executing thread is this sessions dispatcher.
 o toString()
Gets a string representation of the session.
 o useExclusiveSocket()
Creates a new socket which it will use exclusively for sending and receiving SNMP requests and responses of this session.
 o useExclusiveSocket(SnmpSocket)
Uses the specified socket to perform an I/O.

Variables

 o sessionName
 public String sessionName
The name identifying this session. Useful in debugging a session.

 o snmpOptions
 public SnmpOptions snmpOptions
Set of options used to configure all SnmpRequests created in this session. The user can directly manipulate the options. Note that this variable is public.

Constructors

 o SnmpSession
 public SnmpSession(String name,
                    SnmpPeer apeer,
                    SnmpAuthHandlerIf auth)
Constructor for creating new session.

Parameters:
name - The session name.
apeer - The default peer to send requests to.
auth - Unused.
 o SnmpSession
 public SnmpSession(String name,
                    SnmpAuthHandlerIf auth)
Constructor for creating new session.

Parameters:
name - The session name.
auth - Unused.
 o SnmpSession
 public SnmpSession(String name)
Constructor for creating a new session. Responses to the request for this session will not be authenticated.

Parameters:
name - The session name.

Methods

 o getName
 public final String getName()
Gets the session name (often used in identification).

Returns:
The session name.
 o setName
 public final void setName(String name)
Sets the session name (often used in identification).

Parameters:
name - The session name.
 o setDefaultPeer
 public final void setDefaultPeer(SnmpPeer apeer)
Sets peer as default. This peer is used when a SNMP command is issued without specifying the destination.

Parameters:
apeer - The default destination.
 o getDefaultPeer
 public final SnmpPeer getDefaultPeer()
Gets a default peer (if any) bound to this session.

Returns:
The default peer object.
 o toString
 public final String toString()
Gets a string representation of the session.

Returns:
A string representation of the session.
Overrides:
toString in class Object
 o getSocket
 public final SnmpSocket getSocket()
Gets the SnmpSocket which will be used by requests created in this session.

Returns:
The socket which will be used in this session.
 o useExclusiveSocket
 public final synchronized void useExclusiveSocket(SnmpSocket sock)
Uses the specified socket to perform an I/O. Note that this socket could be shared with other sessions as well.

Parameters:
sock - The user supplied specific socket to use.
 o useExclusiveSocket
 public final synchronized void useExclusiveSocket() throws SocketException
Creates a new socket which it will use exclusively for sending and receiving SNMP requests and responses of this session.

Throws: SocketException
Unable to create an exclusive socket.
 o isEquivalent
 public final synchronized boolean isEquivalent(SnmpSession arg)
Two sessions are equivalent if they share the same socket.

Parameters:
arg - The session to compare this with.
Returns:
True if they use same socket; false otherwise.
 o isSessionActive
 public final synchronized boolean isSessionActive()
Indicates if the thread for this session is active.

Returns:
True if active; false otherwise.
 o syncInProgress
 public synchronized boolean syncInProgress()
Indicates whether this session is performing synchronous operation for a request.

Returns:
True the session is performing synchronous operation; false otherwise.
 o destroySession
 public final synchronized void destroySession()
Destroys any pending requests and then stops the session. The session will not be usable after this method returns.

 o getAllRequestsForPeer
 public synchronized Vector getAllRequestsForPeer(SnmpPeer apeer)
Gets a list of requests which have the specified destination.

Parameters:
apeer - The SnmpPeer.
Returns:
Vector of requests to the specified peer.
 o cancelAllRequests
 public final synchronized void cancelAllRequests()
Cancels all pending requests with this session.

 o checkResponseFor
 public boolean checkResponseFor(Request req)
Indicates whether a response was received for this request. The status of response is maintained in the request object.

Parameters:
req - The request.
Returns:
True if request has a pending response; false otherwise.
 o thisSessionContext
 public boolean thisSessionContext()
Returns true if the current executing thread is this sessions dispatcher. Typically used to detect if the user is doing a sync operation from this dispatcher context. For instance, a user gives a sync command from within a request callback using its associated session.

Returns:
True if current thread is this session's dispatcher; false otherwise.
 o snmpGet
 public final SnmpRequest snmpGet(SnmpPeer peer,
                                  SnmpHandlerIf cb,
                                  SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP get request on the varbind list. When the command completes, the appropriate callback method is invoked.

Parameters:
peer - The SNMP peer object.
cb - The callback that gets invoked when request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGet
 public final SnmpRequest snmpGet(SnmpHandlerIf cb,
                                  SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP get request on the varbind list. Uses the default peer.

Parameters:
cb - The callback that gets invoked when request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetNext
 public final SnmpRequest snmpGetNext(SnmpPeer peer,
                                      SnmpHandlerIf cb,
                                      SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP getnext request on the varbind list. When the command completes, the appropriate callback method is invoked.

Parameters:
peer - The SNMP peer object.
cb - The callback that is invoked when a request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetNext
 public final SnmpRequest snmpGetNext(SnmpHandlerIf cb,
                                      SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP getnext request on the varbind list. Uses the default peer.

Parameters:
cb - The callback that is invoked when a request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetBulk
 public final SnmpRequest snmpGetBulk(SnmpPeer peer,
                                      SnmpHandlerIf cb,
                                      SnmpVarbindList vblst,
                                      int nonRepeat,
                                      int maxRepeat) throws SnmpStatusException
Performs a single SNMP getbulk request on the varbind list. When the command completes, the appropriate callback method is invoked.

Parameters:
peer - The SNMP peer object.
cb - The callback that is invoked when a request is complete.
vblst - A list of SNMP varbinds.
nonRepeat - Number of varbind to get one time.
maxRepeat - Number of repetition for varbind to get multiple time.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetBulk
 public final SnmpRequest snmpGetBulk(SnmpHandlerIf cb,
                                      SnmpVarbindList vblst,
                                      int nonRepeat,
                                      int maxRepeat) throws SnmpStatusException
Performs a single SNMP getbulk request on the varbind list. Uses the default peer.

Parameters:
cb - The callback that is invoked when a request is complete.
vblst - A list of SNMP varbinds.
nonRepeat - Number of varbind to get one time.
maxRepeat - Number of repetition for varbind to get multiple time.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpSet
 public final SnmpRequest snmpSet(SnmpPeer peer,
                                  SnmpHandlerIf cb,
                                  SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP set request on the peer for the specified varbind list. Because retries on set operations are not performed, the user needs to specify the timeout value within which a response is requested.

Parameters:
peer - The SNMP peer object.
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpSet
 public final SnmpRequest snmpSet(SnmpHandlerIf cb,
                                  SnmpVarbindList vblst) throws SnmpStatusException
Performs a single SNMP set request on the peer for the specified varbind list. Uses the default peer.

Parameters:
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetPoll
 public final SnmpRequest snmpGetPoll(SnmpPeer peer,
                                      SnmpHandlerIf cb,
                                      SnmpVarbindList vblst,
                                      int intrvl) throws SnmpStatusException
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list. It does a SNMP get request on the varbind list. After each poll, the appropriate callback method is invoked.

Parameters:
peer - The SNMP peer object.
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
intrvl - The frequency of polling.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetPoll
 public final SnmpRequest snmpGetPoll(SnmpHandlerIf cb,
                                      SnmpVarbindList vblst,
                                      int intrvl) throws SnmpStatusException
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list. Uses the default peer.

Parameters:
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
intrvl - The frequency of polling.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetNextPoll
 public final SnmpRequest snmpGetNextPoll(SnmpPeer peer,
                                          SnmpHandlerIf cb,
                                          SnmpVarbindList vblst,
                                          int intrvl) throws SnmpStatusException
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list. It saves the original varbind list that is used during each poll. It performs an SNMP getnext request on the saved original varbind list and provides the response to the user via the callback mechanism. This method is similar to snmpGetPoll except that it uses getnext on the original varbind list instead of get.

Parameters:
peer - The SNMP peer object.
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
intrvl - The frequency of polling.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpGetNextPoll
 public final SnmpRequest snmpGetNextPoll(SnmpHandlerIf cb,
                                          SnmpVarbindList vblst,
                                          int intrvl) throws SnmpStatusException
Starts polling the peer at the specified intervals, for the MIB variables in the varbind list. Uses the default peer.

Parameters:
cb - The callback that is invoked when request is complete.
vblst - A list of SNMP varbinds.
intrvl - The frequency of polling.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpHandlerIf
 o snmpWalkUntil
 public final SnmpRequest snmpWalkUntil(SnmpPeer peer,
                                        SnmpHandlerIf cb,
                                        SnmpVarbindList vblst,
                                        SnmpOid key) throws SnmpStatusException
Walks through the lexicographic ordering of the agent MIB. It starts at the specified varbind list and continues until the OID key specified as a parameter is "smaller" than the first variable in the response varbind list or an error occurred. Typically, this feature is used to walk an arbitrary table and obtain all rows satisfying a specific condition. The condition may be a specific instance combination for a MIB variable or a MIB variable OID entry object.
 String var[] = {"sysDescr"} ;
 SnmpVarbindList vblst = new SnmpVarbindList() ;
 vblst.addVariable(var) ;
 SnmpRequest request = session.snmpWalkUntil(null, vblst, new SnmpOid("sysServices")) ;
 
This example walks through the system group and get all the variables in this group.
 SnmpRequest request = session.snmpWalkUntil(null, vblst, new SnmpOid("1.4")) ;
 
This example walks through the entire agent MIB starting at sysDescr.
 String var[] = {"sysDescr.0"} ;
 SnmpVarbindList vblst = new SnmpVarbindList() ;
 vblst.addVariable(var) ;
 SnmpRequest request = session.snmpWalkUntil(null, vblst, new SnmpOid("sysServices.0")) ;
 
This example walks through the system group beginning after the sysDescr variable (not included) and ending with the sysServices variable (included).

If there is more than one variable in the specified varbind list, the request will start at the first variable of the list.

Parameters:
peer - The peer object to talk to.
cb - The callback that is invoked when the request completes.
vblst - The list from SnmpVarbindList.
key - Condition key that must be a subset of the first variable in the response SnmpVarbindList. Walk terminates if this condition is false.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpManagerSrvIf
 o snmpWalkUntil
 public final SnmpRequest snmpWalkUntil(SnmpHandlerIf cb,
                                        SnmpVarbindList vblst,
                                        SnmpOid key) throws SnmpStatusException
Walks through the lexicographic ordering of the agent MIB. Uses the default peer.

Parameters:
cb - The callback that is invoked when the request completes.
vblst - The list from SnmpVarbindList.
key - Condition key that must be a subset of the first variable in the response SnmpVarbindList. Walk terminates if this condition is false.
Throws: SnmpStatusException
You may never get this by using these convenience ftns.
See Also:
SnmpManagerSrvIf
 o anyPendingResponses
 public boolean anyPendingResponses()
Indicates whether there are any responses available for processing. These responses belong to the requests made using this session.

Returns:
True if response is available; false otherwise.
 o run
 public void run()
Dispatcher method for this session thread. This is the dispatcher method which goes in an endless-loop and waits for servicing requests which got a reply from the agent.

 o finalize
 public void finalize()
Removes all the requests for this session, closes the socket and sets all the references to the SnmpSession object to null.

Overrides:
finalize in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index