|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.adventnet.snmp.beans.SnmpServer
|
+--com.adventnet.snmp.beans.SnmpRequestServer
This class is an SNMP Server bean for performing asynchronous SNMP requests on a list of variables. It supports event generation per the JDK 1.1 event model. It allows sending request events to it or invoking its asynchronous request methods and receiving response events, i.e. ResultEvent objects, from it when responses arrive or timeout.
See the requestServerDemo.java applet example in the applications directory.
To use in an application, instantiate the server, and register to receive results. For example, the following is a trivial listener that prints the return value.
SnmpRequestServer server = new SnmpRequestServer();
ResultListener listener = new ResultListener() {
public void setResult(ResultEvent evt) {
System.err.println("Response: "+evt.getValue());
}
};
server.addResultListener(listener);
Then use the asynchronous methods to make requests,
or you can generate events, e.g.
RequestEvent evt =
new RequestEvent(b1, getParameter("OID"), RequestEvent.GET);
server.addRequest(evt);
The above is a somewhat simplified example for event generation.
To receive timeout events,use setSendTimeoutEvents(true). Otherwise if the request times out,then the timeout events will not be sent to the listener.
Normally, you would allow registration of RequestListener objects, and send events to all registered listeners. The advantage of generating events really lies in being able to write components that do not know at build time the request server they will send events to.
Major difference between this and SnmpRequestServer is the ability to use the RequestEvent objects to send requests to the SnmpRequestServer. The benefit of this feature is that event connections between sources of request events, and SnmpRequestServer instances can be more readily be defined, in bean builders for example. So a button that generates a request event can be flexibly connected to the appropriate SnmpRequestServer instance in a bean builder. The SnmpRequestServer provides a convenience object for many of the common operations you do with an SNMP agent.
For garbagecollection of the resources used, releaseResources() method should be invoked. Different SnmpRequestServer instances on the same JVM, will reuse the SnmpAPI, SnmpSession and MibOperations instance. So, for releasing these resources, releaseResources() method should be called on every SnmpRequestServer instance created and when this method is called on the final instance of SnmpRequestServer, these will be garbage collected.
Supply the applet in the constructor if using applets and may need to use SAS.
RequestEvent,
ResultEvent, Serialized Form| Field Summary | |
(package private) java.util.Hashtable |
destinations
|
(package private) int |
logID
|
(package private) java.lang.String |
mibModules
|
(package private) int[] |
prevoid
|
(package private) java.util.Hashtable |
requests
|
boolean |
serialize
based on this flag the v3 tables ( USMUserTable and SnmpEngineTable ) will be serialized. |
| Constructor Summary | |
SnmpRequestServer()
Use this constructor for applications. |
|
SnmpRequestServer(java.applet.Applet applet)
Use this constructor for applets. |
|
SnmpRequestServer(java.applet.Applet applet,
int localPort,
java.lang.String sessionName)
Use this constructor for appletswhich will create a session with name and in specific localport.. |
|
SnmpRequestServer(int protocol,
ProtocolOptions options)
Use this constructor for applications which uses protocols other than UDP/IP. |
|
SnmpRequestServer(int localPort,
java.lang.String sessionName)
Use this constructor for applications which will create a session with name and in specific localport. |
|
SnmpRequestServer(java.lang.String[] localAddrs,
java.lang.String sessionName)
Use this constructor for applications in which the session needs to be bound to some local address. |
|
| Method Summary | |
void |
addLogClient(com.adventnet.afp.log.LoggerProperties loggerProps)
Adds the Log client for which the target has to redirect the log messages. |
void |
addLogClient(com.adventnet.utils.LogInterface client)
Add the Log client for which the SnmpRequestServer has to redirect the log messages |
int |
addObjectID(java.lang.String s)
Adds an ObjectID specified by string to the existing OID list. |
int |
addRequest(RequestEvent e)
To add a request to the already existing requests. |
void |
addResultListener(ResultListener l)
Adds a Listener to the list that is notified each time when a response arrives. |
int |
addSnmpOID(SnmpOID oid)
Adds an SnmpOID to the existing list of OIDs. |
void |
addSnmpPropertyListener(SnmpPropertyListener l)
Adds SnmpPropertyListener to the Listeners list. |
void |
addUserError(int errorCode,
java.lang.String errorString)
This method is used to add user defined error codes and the corresponding error string. |
void |
addV3HandShakeResultListener(V3HandShakeResultListener l)
Adds a listener to receive the events when SnmpEngineID discovery and time Synchronization is performed by the method async_create_v3_tables. |
boolean |
authenticate(SnmpPDU pdu,
java.lang.String community)
This is the SnmpClient method implementation used to authenticate a PDU. |
boolean |
callback(SnmpSession session,
SnmpPDU pdu,
int requestID)
This is the SnmpClient method implementation method that processes and forwards the result.The response returned by the RequestServer will be received by this method. |
void |
debugPrint(java.lang.String debugOutput)
This is the SnmpClient method implementation that prints the standard error. |
void |
deSerializeUSM()
This will deserialize the v3 tables like USMUserTable and SnmpEngineTable from serialized file if the serilaized file already exists |
protected void |
genEvent(SnmpPDU pdu)
Generate the response event to the listeners |
protected void |
genTimeoutEvent(SnmpPDU pdu)
Generate the timeout events to the listeners |
boolean |
getAttemptPartial()
Deprecated. SnmpRequestServer cannot get the partial data. It is specifically for SnmpTarget bean which does synchronous comm.. |
java.lang.String |
getAuthPassword()
To get the SNMP V3 AuthPassword |
int |
getAuthProtocol()
To get the SNMP V3 AuthProtocol |
java.lang.String |
getCommunity()
To get the SNMP target Community |
java.lang.String |
getContextID()
To get the SNMP V3 contextID |
java.lang.String |
getContextName()
To get the SNMP V3 Context name |
boolean |
getDebug()
To check if Debug mode is enabled or not |
byte[] |
getEngineID()
To get the SNMP V3 engineID value for v3 |
int |
getErrorCode()
To get the error code from the last request. |
java.lang.String |
getErrorResultString(SnmpPDU pdu)
To get the error string associated with the response PDU |
java.lang.String |
getErrorString()
To get the error string from the last request. |
int |
getMaxRepetitions()
To get the SNMP target max repetitions value for a getbulk request. |
java.lang.String |
getMibModules()
To get the MIBs (/white-space separated list of mib files)that is(/are) loaded in this applet/application |
MibOperations |
getMibOperations()
To get the MibOperations object reference. |
int |
getNonRepeaters()
To get the SNMP target non-repeaters value for a getbulk request. |
java.lang.String |
getObjectID()
To get the first object ID from a list of ObjectIDs. |
java.lang.String |
getObjectID(int index)
To get the object ID at the specified index |
java.lang.String[] |
getObjectIDList()
To get the list of object IDs. |
java.lang.String |
getPrincipal()
To get the SNMP V3 username |
java.lang.String |
getPrivPassword()
To get the SNMP V3 PrivPassword |
int |
getRetries()
To get the SNMP target retries value. |
java.lang.String |
getSecurityLevel()
To get the SNMP V3 SecurityLevel |
int |
getSecurityModel()
To get the SNMP V3 securityModel |
boolean |
getSendTimeoutEvents()
To check if the target will send timeout events to registered listeners. |
SnmpOID |
getSnmpOID()
To get the first SnmpOID from the list of object IDs. |
SnmpOID[] |
getSnmpOIDList()
To get the list of object IDs as an array of SnmpOID instances |
int |
getSnmpVersion()
To get the SNMP target SNMP Version. |
java.lang.String |
getTargetHost()
To get the SNMP target hostname |
int |
getTargetPort()
To get the SNMP target port number |
int |
getTimeout()
To get the SNMP target timeout value in Seconds. |
int |
getUserErrorCode()
Gets the user defined error code for the last request. |
java.lang.String |
getUserErrorString()
This method is used to get the user defined error string to a specific error code. |
java.lang.String |
getWriteCommunity()
To get the SNMP target write Community to be used for set requests |
boolean |
isBroadCastEnabled()
Returns the current status as to whether broadcasting is enabled/disabled. |
boolean |
isSerialize()
To check the status of Serialization of v3 tables (USMUserTable and SnmpEngineTable) |
void |
loadMibs(java.lang.String mibs)
Loads the specified mib. |
void |
readFromDatabase()
This will read the v3table like USmUserTable and SnmpEngineTable from Database after establishing connection |
void |
releaseResources()
Though the resources will be cleaned up by the garbage collector, if the application is no more using the SnmpRequestServer bean instance, this method can be used to immediately release the resources. |
void |
removeLogClient()
Removes the Log client that has been registered to redirect the log Messages for this instance. |
void |
removeResultListener(ResultListener l)
Removes a listener for response events from the list of listeners. |
void |
removeSnmpPropertyListener(SnmpPropertyListener l)
Removes the SnmpPropertyListener from the list. |
void |
removeV3HandShakeListener(V3HandShakeResultListener l)
Removes the listener registered for getting events. |
int |
sendGetBulkRequestList()
To send a GetBulk request to get a list of SNMP variable bindings from the agent using the Object Identifier list previously set in this SnmpRequestServer instance. |
int |
sendGetNextRequest()
To send a getnext request for the SNMP variable identified by the first Object Identifier set in this SnmpRequestServer instance. |
int |
sendGetNextRequest(SnmpOID oid)
To send a getnext request for the SNMP variable identified by specified Object Identifier. |
int |
sendGetNextRequestList()
To send a getnext request for a list of SNMP variable bindings identified by the Object Identifier list previously set in this SnmpRequestServer instance. |
int |
sendGetNextRequestList(SnmpOID[] oids)
To send a getnext request for a list of SNMP variables identified by the Object Identifier list stored in this SnmpRequestServer instance. |
int |
sendGetRequest()
To send a get request for the the SNMP variable identified by the first Object Identifier stored in the SnmpRequestServer instance. |
int |
sendGetRequest(SnmpOID oid)
To send a get request for the the SNMP variable identified by specified Object Identifier. |
int |
sendGetRequestList()
To send a get request for the list of SNMP variable bindings identified by the Object Identifier list previously set in this SnmpRequestServer instance. |
int |
sendGetRequestList(SnmpOID[] oids)
To send a get request for a list of SNMP variables identified by the Object Identifier list. |
int |
sendSetRequest(java.lang.String value)
To send a set request with the value to be set for the ObjectID This method will fail if MIB with this variable is not loaded or this is not a leaf node in the MIB. |
int |
sendSetRequest(java.lang.String value,
byte type)
To send a set request with the value to be set and the type of the variable Throws DataException if no OID specified earlier or in case of errors. |
int |
sendSetRequestList(java.lang.String[] values)
To set the list of SNMP variable bindings on the agent using the Object Identifier list previously set in this SnmpRequestServer instance. |
int |
sendSetRequestVariable(SnmpVar var)
To send a set request to set the specified SnmpVar value for the OID that is set in the SnmpRequestServer instance. |
int |
sendSetRequestVariables(SnmpVar[] values)
To send a set request to set the list of SNMP variable bindings on the agent, using the Object Identifier list previously set in this SnmpRequestServer instance. |
(package private) int |
sendSNMPRequest(SnmpPDU pdu)
This sends the SNMP request. |
void |
sendTrap(SnmpOID enterprise,
java.lang.String agenthost,
int genericType,
int specificType,
long uptime,
SnmpVar[] values)
To send a SNMP trap, with parameters specified and variable bindings using object ids from the Object Identifier list previously set in this SnmpRequestServer instance, and the values specified. |
void |
sendTrap(java.lang.String enterprise,
java.lang.String agenthost,
int genericType,
int specificType,
long uptime,
java.lang.String[] values)
To send a SNMP trap, with parameters specified and variable bindings using object ids from the Object Identifier list previously set in this SnmpRequestServer instance, and the values specified. |
void |
setAttemptPartial(boolean b)
Deprecated. SnmpRequestServer cannot get partial data by enabling the flag. It is specific for SnmpTarget bean which does synchronous comm.. |
void |
setAuthPassword(java.lang.String password)
To set the SNMP V3 AuthPassword |
void |
setAuthProtocol(int protocol)
To set the SNMP V3 AuthProtocol |
void |
setBroadCastEnable(boolean broadcast)
Calling this method with a "true" value will indicate that the request is to be sent as a broadcast request. |
void |
setCommunity(java.lang.String s)
To set the SNMP target Community |
void |
setContextID(java.lang.String ctxtID)
To set the SNMP V3 contextID |
void |
setContextName(java.lang.String cName)
To set the SNMP V3 Context name |
void |
setDebug(boolean debug)
To enable or disable the Debug mode. |
void |
setEngineID(byte[] engID)
To set the SNMP V3 engineID value for v3 |
void |
setMaxRepetitions(int i)
To set the SNMP target max repetitions value for a getbulk request. |
void |
setMibModules(java.lang.String mibs)
To load the MIB in this applet/application. |
void |
setNonRepeaters(int i)
To set the SNMP target non-repeaters value for a getbulk request. |
void |
setObjectID(int index,
java.lang.String s)
Sets the object ID value specified the string at the given index |
void |
setObjectID(java.lang.String s)
Sets the object ID value specified by the string |
void |
setObjectIDList(java.lang.String[] s)
Sets the list of object IDs specified by the string array |
void |
setParams(java.lang.String host,
java.lang.String port,
java.lang.String community,
java.lang.String mib,
java.lang.String oid)
To set Multiple parameters like TargetHost,Port,Community,MibModule and OID. |
void |
setParams(java.lang.String host,
java.lang.String port,
java.lang.String community,
java.lang.String mib,
java.lang.String[] oidlist)
To set Multiple parameters like TargetHost,Port,Community,MibModule and OIDList. |
void |
setPrincipal(java.lang.String uName)
To set the SNMP V3 username |
void |
setPrivPassword(java.lang.String password)
To set the SNMP V3 PrivPassword |
void |
setRetries(int i)
To Set the SNMP target retries value. |
void |
setSecurityLevel(byte sLevel)
To set the SNMP V3 SecurityLevel.The value will be 0 ,1 or 3. |
void |
setSecurityModel(int securityModel)
To set the SNMP V3 SecurityModel |
void |
setSendTimeoutEvents(boolean b)
To set the boolean state of whether this target will send timeout events to registered listeners or not |
void |
setSnmpOID(SnmpOID oid)
Sets the SnmpOID. |
void |
setSnmpOIDList(SnmpOID[] list)
To set the list of object IDs given as an array of SnmpOIDs |
void |
setSnmpVersion(int i)
To set the SNMP target SNMP Version. |
void |
setTargetHost(java.lang.String s)
To set the SNMP target hostname |
void |
setTargetPort(int i)
To set the SNMP target port number |
void |
setTimeout(int i)
To Set the SNMP target timeout value in Seconds. |
void |
setWriteCommunity(java.lang.String s)
To set the SNMP target write Community to be used for set requests |
(package private) void |
updateMibs()
|
void |
vetoableChange(java.beans.PropertyChangeEvent e)
This method is called when a vetoableChange event is fired from the propertySetting bean. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
int logID
java.lang.String mibModules
int[] prevoid
java.util.Hashtable requests
public boolean serialize
java.util.Hashtable destinations
| Constructor Detail |
public SnmpRequestServer()
public SnmpRequestServer(int localPort,
java.lang.String sessionName)
public SnmpRequestServer(int protocol,
ProtocolOptions options)
public SnmpRequestServer(java.applet.Applet applet,
int localPort,
java.lang.String sessionName)
public SnmpRequestServer(java.applet.Applet applet)
public SnmpRequestServer(java.lang.String[] localAddrs,
java.lang.String sessionName)
localAddrs - The local addresses to which the session needs
to be bound.sessionName - Specify unique sessionNames for the instances
which need to use different SnmpSession instances to send data.| Method Detail |
public void loadMibs(java.lang.String mibs)
throws MibException,
java.io.IOException,
java.io.FileNotFoundException
In case of loading the files from space seperated directories, the whole
String should be given within the double quotes.
for example, if the
MIB file is present in the directory 'Program Files',
server.loadMibs("\"../../mibs/Program Files/RFC1213-MIB\"")
public void addResultListener(ResultListener l)
l - an instance of ResultListener.ResultEvent,
ResultListenerpublic void removeResultListener(ResultListener l)
l - ResultListener to be removed.ResultListenerpublic void addSnmpPropertyListener(SnmpPropertyListener l)
l - an instance of SnmpPropertyListener to be added.SnmpPropertyChangeEvent,
SnmpPropertyListenerpublic void removeSnmpPropertyListener(SnmpPropertyListener l)
l - SnmpPropertyListener to be removed.SnmpPropertyListenerpublic void addV3HandShakeResultListener(V3HandShakeResultListener l)
l - the V3HandShakeResultListener to be registered for
getting events.V3HandShakeResultListener,
V3HandShakeResultEventpublic void removeV3HandShakeListener(V3HandShakeResultListener l)
l - the V3HandShakeResultListener to be removed.V3HandShakeResultListener
public void readFromDatabase()
throws java.sql.SQLException
public void deSerializeUSM()
public boolean authenticate(SnmpPDU pdu,
java.lang.String community)
public boolean callback(SnmpSession session,
SnmpPDU pdu,
int requestID)
ErrorMessages,
getErrorCode(),
getErrorString()public void debugPrint(java.lang.String debugOutput)
protected void genTimeoutEvent(SnmpPDU pdu)
protected void genEvent(SnmpPDU pdu)
public int addObjectID(java.lang.String s)
s - the OID to be addedpublic int addSnmpOID(SnmpOID oid)
oid - SnmpOID to be added.public java.lang.String getObjectID(int index)
index - the index of the oid in the oidlist arraypublic java.lang.String getObjectID()
public void setObjectID(java.lang.String s)
s - the oid to be set
public void setObjectID(int index,
java.lang.String s)
index - index in the oidlist where the oid has to be set.s - the oid that has to be set.public java.lang.String[] getObjectIDList()
public void setObjectIDList(java.lang.String[] s)
s[] - an array of ObjectIDs.public SnmpOID getSnmpOID()
public void setSnmpOID(SnmpOID oid)
oid - SnmpOID to be set.public SnmpOID[] getSnmpOIDList()
public void setSnmpOIDList(SnmpOID[] list)
list[] - an array of SnmpOIDspublic java.lang.String getTargetHost()
public void setTargetHost(java.lang.String s)
s - target hostname as a Stringpublic int getTargetPort()
public void setTargetPort(int i)