|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.management.snmp.manager.SnmpSession
public class SnmpSession
Creates, controls, and manages one or more requests. A session is associated with one SnmpEngine (see RFC 2571). It can construct the engine or make use of an already created one. A session can be bound to a peer so that all requests created (without specifying a peer) will use this as the default. Alternatively, there can be a mixture of peers, that is, two requests can talk to two different peers.
In a typical manager application, a single engine is needed. So you should share a session within your process.
WARNING: Be aware that if you instantiate another session, you will instantiate another engine.
Each SnmpSession
has a dispatcher, which is a
thread used to service all the requests it creates. Each
SnmpSession
uses a separate socket for sending
requests and receiving responses. The socket imposes an upper
limit on the size of response packets. Any packet which exceeds
this limit is truncated. By default, this limit is SnmpPeer.defaultSnmpResponsePktSize
. It can be changed using
setResponsePktSize(int)
.
This class implements an SNMP command interface which provides a variety of convenience methods that are used to create requests. Each of the requests performs a specific SNMP operation. These methods are simple to use and automatically start the request. The session maintains the list of all active requests and responses.
Users can explicitly create and start requests. This is usually not required for most applications.
Each method provides specific SNMP operations 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 try limit. Certain options of
sessions can be configured using the SnmpOptions
object. This allows enabling and disabling of features like fixing
protocol data units (PDU) on error, handling
SnmpTooBig
errors and multiplexing requests. If not
specified, the default value sets the following options:
Once a session is created the user can perform one or more SNMP operations
in a one-at-a-time sequence. Usually this sequence is a set of logical
operations which together form a complete operation.
For example, a SnmpSet
operation, which involves an 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 canceled.
SnmpRequest
,
Serialized FormField Summary | |
---|---|
String |
sessionName
The name identifying this session. |
SnmpOptions |
snmpOptions
Set of options used to configure all SnmpRequests created
in this session. |
Constructor Summary | |
---|---|
SnmpSession(SnmpEngineParameters parameters,
SnmpEngineFactory factory,
String name,
SnmpPeer apeer)
Constructor for creating a new session. |
|
SnmpSession(SnmpEngineParameters parameters,
SnmpEngineFactory factory,
String name,
SnmpPeer apeer,
InetAddress localaddress,
int port)
Constructor for creating a new session. |
|
SnmpSession(SnmpEngineParameters parameters,
SnmpEngineFactory factory,
String name,
SnmpPeer apeer,
InetSocketAddress localaddress)
Constructor for creating a new session. |
|
SnmpSession(SnmpEngine engine,
String name,
SnmpPeer apeer)
Constructor for creating a new session. |
|
SnmpSession(String name)
Constructor for creating a new session. |
|
SnmpSession(String name,
SnmpPeer apeer)
Constructor for creating a new session. |
Method Summary | |
---|---|
boolean |
anyPendingResponses()
Indicates whether there are any responses available for processing. |
void |
cancelAllRequests()
Cancels all pending requests in this session. |
boolean |
checkResponseFor(SnmpRequest req)
Indicates whether a response was received for this request. |
void |
destroySession()
Destroys any pending requests and then stops the session. |
void |
finalize()
Finalizer of the SnmpSession objects. |
Vector |
getAllRequestsForPeer(SnmpPeer apeer)
Gets a list of requests which have the specified destination. |
SnmpPeer |
getDefaultPeer()
Gets a default peer (if any) bound to this session. |
SnmpEngine |
getEngine()
Engine the SnmpSession is linked with. |
SnmpEngineId |
getEngineId()
Get the local engine Id. |
int |
getInPkts()
Gets the number of packets received. |
String |
getName()
Gets the session name (often used in identification). |
int |
getOutPkts()
Gets the number of packets sent. |
SnmpPduFactory |
getPduFactory()
Gets the PDU factory. |
int |
getPktsErrors()
Gets the number of errors that occurred. |
int |
getResponsePktSize()
Gets the maximum size allowed for response packet. |
void |
hideInvalidResponseError(boolean hide)
Hides invalid response errors. |
boolean |
isInvalidResponseErrorHidden()
Checks if invalid response errors are hidden. |
boolean |
isSessionActive()
Indicates whether the thread for this session is active. |
void |
performResetPktStatistics()
Reset all the counters. |
void |
run()
Dispatcher method for this session thread. |
void |
setDefaultPeer(SnmpPeer apeer)
Sets peer as default. |
void |
setName(String name)
Sets the session name (often used in identification). |
void |
setPduFactory(SnmpPduFactory factory)
Sets the PDU factory. |
void |
setResponsePktSize(int size)
Sets the maximum size allowed for response packet. |
SnmpRequest |
snmpGetBulkRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst,
int nonRepeat,
int maxRepeat)
Performs a single SNMP getbulk request on the variable binding list. |
SnmpRequest |
snmpGetBulkRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst,
int nonRepeat,
int maxRepeat)
Performs a single SNMP getbulk request on the variable binding list. |
SnmpRequest |
snmpGetNextPollRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst,
int intrvl)
Starts polling the peer at the specified intervals, for the MIB variables in the variable binding list. |
SnmpRequest |
snmpGetNextPollRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst,
int intrvl)
Starts polling the peer at the specified intervals, for the MIB variables in the variable binding list. |
SnmpRequest |
snmpGetNextRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP getnext request on the variable binding list. |
SnmpRequest |
snmpGetNextRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP getnext request on the variable binding list. |
SnmpRequest |
snmpGetPollRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst,
int intrvl)
Starts polling the peer at the specified intervals, for the MIB variables in the variable binding list. |
SnmpRequest |
snmpGetPollRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst,
int intrvl)
Starts polling the peer at the specified intervals, for the MIB variables in the variable binding list. |
SnmpRequest |
snmpGetRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP get request on the variable binding list. |
SnmpRequest |
snmpGetRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP get request on the variable binding list. |
SnmpRequest |
snmpInformRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpOid trapOid,
SnmpVarBindList vblst)
Performs a single SNMP inform request on the variable binding list. |
SnmpRequest |
snmpInformRequest(SnmpRequestHandler cb,
SnmpOid trapOid,
SnmpVarBindList vblst)
Performs a single SNMP inform request on the variable binding list. |
SnmpRequest |
snmpSetRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP set request on the peer for the
specified variable binding list. |
SnmpRequest |
snmpSetRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst)
Performs a single SNMP set request on the peer for the
specified variable binding list. |
SnmpRequest |
snmpWalkUntilRequest(SnmpPeer peer,
SnmpRequestHandler cb,
SnmpVarBindList vblst,
SnmpOid key)
Walks through the lexicographic ordering of the agent MIB. |
SnmpRequest |
snmpWalkUntilRequest(SnmpRequestHandler cb,
SnmpVarBindList vblst,
SnmpOid key)
Walks through the lexicographic ordering of the agent MIB. |
boolean |
syncInProgress()
Indicates whether this session is performing synchronous operation for a request. |
boolean |
thisSessionContext()
Returns true if the current executing thread is this session's dispatcher. |
String |
toString()
Gets a String representation of the session. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public String sessionName
public SnmpOptions snmpOptions
SnmpRequests
created
in this session. The user can manipulate the options directly.
Note that this variable is public.
Constructor Detail |
---|
public SnmpSession(SnmpEngine engine, String name, SnmpPeer apeer) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is used.
engine
- The engine to use.name
- The session name.apeer
- The default peer to which to send requests.
SnmpStatusException
- Unable to initialize the SNMP
Datagram Socket.
IllegalArgumentException
- if the passed engine is null.public SnmpSession(String name, SnmpPeer apeer) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is instantiated.
The SnmpEngineId is computed as follows:
SnmpEngineId
.
name
- The session name.apeer
- The default peer to which to send requests.
IllegalArgumentException
- If one of the specified configuration files doesn't exist.
SnmpStatusException
- Unable to initialize the Snmp Datagram Socket.public SnmpSession(String name) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is instantiated.
The SnmpEngineId is computed as follows:
SnmpEngineId
.
name
- The session name.
IllegalArgumentException
- If one of the specified configuration files doesn't exist.
SnmpStatusException
- Unable to initialize the SNMP Datagram Socket.public SnmpSession(SnmpEngineParameters parameters, SnmpEngineFactory factory, String name, SnmpPeer apeer) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is instantiated.
The SnmpEngineId is computed as follows:
SnmpEngineId
.
parameters
- The engine parameters to use.factory
- The factory to use in order to create the engine.name
- The session name.apeer
- The default peer to which to send requests.
IllegalArgumentException
- If one of the specified configuration files doesn't exist.
SnmpStatusException
- Unable to initialize the Snmp Datagram Socket.public SnmpSession(SnmpEngineParameters parameters, SnmpEngineFactory factory, String name, SnmpPeer apeer, InetSocketAddress localaddress) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is instantiated.
The SnmpEngineId is computed as follows:
SnmpEngineId
.
parameters
- The engine parameters to use.factory
- The factory to use in order to create the engine.name
- The session name.apeer
- The default peer to which to send requests.localaddress
- A sockect addess to bind the session to.
IllegalArgumentException
- If one of the specified configuration files doesn't exist.
SnmpStatusException
- Unable to initialize the Snmp Datagram Socket.public SnmpSession(SnmpEngineParameters parameters, SnmpEngineFactory factory, String name, SnmpPeer apeer, InetAddress localaddress, int port) throws SnmpStatusException, IllegalArgumentException
SnmpEngine
is instantiated.
The SnmpEngineId is computed as follows:
SnmpEngineId
.
parameters
- The engine parameters to use.factory
- The factory to use in order to create the engine.name
- The session name.apeer
- The default peer to which to send requests.localaddress
- An InetAddress to bind the session to.port
- A port to listen to.
IllegalArgumentException
- If one of the specified configuration files doesn't exist.
SnmpStatusException
- Unable to initialize the Snmp Datagram Socket.Method Detail |
---|
public SnmpEngine getEngine()
SnmpSession
is linked with.
public final String getName()
public final SnmpPduFactory getPduFactory()
public final void setPduFactory(SnmpPduFactory factory)
factory
- The new factory. If null
is passed,
the default factory will be set.public void hideInvalidResponseError(boolean hide)
Invalid response requests (e.g. invalid BER encoding) are dropped by the manager API. This makes the requests to timeout. This behavior can be changed by calling this method and passing it false. By default the errors are hidden.
hide
- True, hide the internal errors, false throw a GenError.public boolean isInvalidResponseErrorHidden()
Invalid response requests (e.g. invalid BER encoding) are dropped by the manager API. This makes the requests to timeout. This behavior can be changed by calling the method hideInvalidResponseError
. By default the errors are hidden.
public final void setName(String name)
name
- The session name.public final SnmpPeer getDefaultPeer()
public final void setDefaultPeer(SnmpPeer apeer)
apeer
- The default destination.public final SnmpEngineId getEngineId()
public final int getResponsePktSize()
SnmpPeer.defaultSnmpResponsePktSize
.
public final void setResponsePktSize(int size)
size
- The maximum size allowed for response packet.public final int getPktsErrors()
public final int getInPkts()
public final int getOutPkts()
public final void performResetPktStatistics()
public final String toString()
String
representation of the session.
toString
in class Object
String
representation of the session.public final boolean isSessionActive()
true
if active, false
otherwise.public boolean syncInProgress()
true
if the session is performing synchronous operation, false
otherwise.public final void destroySession()
public Vector getAllRequestsForPeer(SnmpPeer apeer)
apeer
- The SnmpPeer
.
public final void cancelAllRequests()
public boolean checkResponseFor(SnmpRequest req)
req
- The request.
true
if the request has a pending response, false
otherwise.public boolean thisSessionContext()
true
if the current executing thread is this session's dispatcher.
Typically used to detect whether 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.
true
if current thread is this session's dispatcher, false
otherwise.public final SnmpRequest snmpGetRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
get
request on the variable binding list.
When the command completes, the appropriate callback method is invoked.
peer
- The SNMP peer object.cb
- The callback that gets invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpGetRequest(SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
get
request on the variable binding list.
Uses the default peer.
cb
- The callback that gets invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpGetNextRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
getnext
request on the variable binding list.
When the command completes, the appropriate callback method is invoked.
peer
- The SNMP peer object.cb
- The callback that is invoked when a request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpGetNextRequest(SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
getnext
request on the variable binding list.
Uses the default peer.
cb
- The callback that is invoked when a request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpGetBulkRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst, int nonRepeat, int maxRepeat) throws SnmpStatusException
getbulk
request on the variable binding list.
When the command completes, the appropriate callback method is invoked.
peer
- The SNMP peer object.cb
- The callback that is invoked when a request is complete.vblst
- A list of SnmpVarBind
objects.nonRepeat
- Number of variable bindings to get one time.maxRepeat
- Number of repetitions for the variable bindings to get multiple times.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpGetBulkRequest(SnmpRequestHandler cb, SnmpVarBindList vblst, int nonRepeat, int maxRepeat) throws SnmpStatusException
getbulk
request on the variable binding list.
Uses the default peer.
cb
- The callback that is invoked when a request is complete.vblst
- A list of SnmpVarBind
objects.nonRepeat
- Number of variable bindings to get one time.maxRepeat
- Number of repetitions for the variable bindings to get multiple times.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpSetRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
set
request on the peer for the
specified variable binding list. Because retries on set
operations are not performed, the user needs to specify the timeout value
within which a response is requested.
peer
- The SNMP peer object.cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpSetRequest(SnmpRequestHandler cb, SnmpVarBindList vblst) throws SnmpStatusException
set
request on the peer for the
specified variable binding list.
Uses the default peer.
cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpGetPollRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst, int intrvl) throws SnmpStatusException
get
request on the variable binding list.
After each poll, the appropriate callback method is invoked.
peer
- The SNMP peer object.cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.intrvl
- The frequency of polling (in seconds).
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpGetPollRequest(SnmpRequestHandler cb, SnmpVarBindList vblst, int intrvl) throws SnmpStatusException
cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.intrvl
- The frequency of polling (in seconds).
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpGetNextPollRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst, int intrvl) throws SnmpStatusException
getnext
request on the saved original
variable binding 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 variable binding list instead of
get
.
peer
- The SNMP peer object.cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.intrvl
- The frequency of polling (in seconds).
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpGetNextPollRequest(SnmpRequestHandler cb, SnmpVarBindList vblst, int intrvl) throws SnmpStatusException
cb
- The callback that is invoked when the request is complete.vblst
- A list of SnmpVarBind
objects.intrvl
- The frequency of polling (in seconds).
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpInformRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpOid trapOid, SnmpVarBindList vblst) throws SnmpStatusException
inform
request on the variable binding list.
When the command completes, the appropriate callback method is invoked.
The variable list included in the outgoing inform request is composed of the following items:
sysUpTime.0
with its current value.
snmpTrapOid.0
with the value specified by trapOid
.
all the (oid, values)
from the specified variable binding list.
peer
- The SNMP peer object.cb
- The callback that gets invoked when request is complete.trapOid
- The OID identifying the inform request.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.How to get response data.
public final SnmpRequest snmpInformRequest(SnmpRequestHandler cb, SnmpOid trapOid, SnmpVarBindList vblst) throws SnmpStatusException
inform
request on the variable binding list.
Uses the default peer.
Note:
Take care when using the default SNMP peer in your requests.
Indeed, the default port for sending inform requests (162) is not the same
used for the get
, getnext
, set
etc... operations (161).
So the peer to be used should not be the same.
To avoid any confusion, you can:
cb
- The callback that gets invoked when request is complete.trapOid
- The OID identifying the inform request.vblst
- A list of SnmpVarBind
objects.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.How to get response data.
public final SnmpRequest snmpWalkUntilRequest(SnmpPeer peer, SnmpRequestHandler cb, SnmpVarBindList vblst, SnmpOid key) throws SnmpStatusException
entry
object.
String var[] = {"sysDescr"} ; SnmpVarBindList vblst = new SnmpVarBindList() ; vblst.addVarBind(var) ; SnmpRequest request = session.snmpWalkUntil(null, vblst, new SnmpOid("sysServices")) ;This example walks through the
system
group and gets 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.addVarBind(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 variable binding list, the request will start at the first variable of the list.
The snmpWalkUntil
request can be called in asynchronous mode only.
peer
- The peer object to talk to.cb
- The callback that is invoked when the request completes.vblst
- A list of SnmpVarBind
objects.key
- Condition key that must be a subset of the first variable in
the response variable binding list. Walk terminates if this condition is false
.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If peer parameter is null and no default peer has been set.public final SnmpRequest snmpWalkUntilRequest(SnmpRequestHandler cb, SnmpVarBindList vblst, SnmpOid key) throws SnmpStatusException
The snmpWalkUntil
request can be called in asynchronous mode only.
cb
- The callback that is invoked when the request completes.vblst
- A list of SnmpVarBind
objects.key
- Condition key that must be a subset of the first variable in
the response variable binding list. Walk terminates if this condition is false
.
SnmpStatusException
- An error occurred during the operation.
IllegalArgumentException
- If no default peer has been set.public boolean anyPendingResponses()
true
if a response is available, false
otherwise.public void run()
run
in interface Runnable
public void finalize()
SnmpSession
objects.
This method is called by the garbage collector on an object
when garbage collection determines that there are no more references to the object.
Removes all the requests for this SNMP session, closes the socket and
sets all the references to the SnmpSession
object to null
.
finalize
in class Object
|
Open Source build 02 opendmk-1.0-b02 2007.10.01_19:17:46_MEST |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |