|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--com.adventnet.snmp.snmp2.SASClient
The SASClient class enables applet services for applets that are limited by the security sandbox that Java applets often run within. In addition to sending and receiving SNMP data, the services available through SASClient allow saving files, creating and deleting directories and files, etc., on the web server that loaded the applet, provided the SAS server is run on the server.
You can also do all these operations using HTTP instead of TCP/IP by setting the value of protocol in SnmpSession using setSASProtocol() to 2 or by using the constructor SASClient(applet,debug, protocol). For using HTTP protocol, you don't have to start the SAServer.
The SASClient class is needed on account of browser security which prevents Java applets from sending data to any host but the applet host when loaded over the network.
This class will not need to be used directly for SNMP operations as the use of SASClient class use will not be transparent to the user. The SNMP library will by default attempt to use SAS if available, or use HTTP if the protocol value is set to 2 but will otherwise use direct socket connections if SAS is unavailable. The file access methods of this class may be used if file operation are required by an applet. For example the applet may use the saveFile method or appendFile method to save data on the applet host.
If the protocol value is 1,which is the default value, this class implements a client to send/receive PDUs from any SNMP peer via a deamon (SAS) on the Applet Host, i.e. Web server. While using Java enabled browsers that do not permit socket connections to anything but the applet host ,your applet will automatically instantiate this class to communicate with an SNMP entity.
If the protocol value is 2,this class uses the servlet loaded with the web-server to send/receive requests.
Use the open method on your session instance to specify whether the SAS or HTTP function needs to be used by your applet. For each session, you will call the open method with your applet instance as an argument. If the connection to the SAS daemon fails(if the value of protocol specified is 1) or if the protocol is not set to 2, the session will try and open a direct local UDP port for SNMP operations.
Enable CALLBACKTHREAD to use the SASClient calls from callback. By default it is disabled.
SnmpSession
, Serialized FormField Summary | |
static int |
HTTP_PROTOCOL
|
static int |
TCP_PROTOCOL
|
Constructor Summary | |
SASClient(java.applet.Applet applet,
boolean debug)
By default this constructor will take the protocol value as 1 and look for the SASPort.html file in the applet html directory. |
|
SASClient(java.applet.Applet applet,
boolean debug,
int protocol)
If the protocol value is set to 1, this constructor will look for the SASPort.html file in the applet html directory. |
Method Summary | |
void |
appendFile(java.lang.String filename,
byte[] data)
The appendFile method for appending data to a file in "SASusers" sub-directory in which SASPort.html was created by the SAServer. |
byte[] |
clientCall(byte[] bytes)
This method is used to build user defined functions around SAS. |
void |
closeDB()
This method is for closing the database connection which is opened through the method connectDB method. |
void |
connectDB(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String pass)
This method is for connecting with the database through SAS. |
void |
createDir(java.lang.String directory)
The createDir method is for creating a directory on the applet host. |
void |
deleteDir(java.lang.String directory)
The deleteDir method for deleting a directory on the applet host. |
void |
deleteFile(java.lang.String filename)
The deleteFile method is for deleting a file on the applet host. |
java.lang.String |
getHostAddress(java.lang.String hostname,
int timeout)
The ip address lookup method is for applet clients. |
java.lang.String |
getHostName(java.lang.String address,
int timeout)
The name lookup method is for applet clients. |
int |
getMaxSasTypes()
This method returns the number of known SAS request types and users are requested to use a number greater than the returned value which will keep changing in the future. |
boolean |
isConnected()
Indicates if the connection to the SNMP Applet Server has been successfully established. |
boolean |
isDBConnected()
This method is for knowing whether the database connection has been established or not. |
static boolean |
isFileReadWrite()
Checks if the fileWrite flag is true. |
boolean |
isKnownSASType(int type)
If the value passed is one of the known request types, it returns true. |
java.sql.ResultSet |
queryDB(java.lang.String queryString)
This method is for doing a database query. |
void |
reqTraps(int port)
Method to request delivery of traps by SAServer arriving at that port. |
void |
run()
Invokes receive() method. |
void |
saveFile(java.lang.String filename,
byte[] data)
The saveFile method for saving data to a file in "SASusers" sub-directory in which SASPort.html was created by the SAServer. |
static void |
setFileReadWrite(boolean writeFlag)
Sets the fileWrite flag. |
void |
setTimeout(int to)
For setting the timeOut value for a synchronous SASClient operation. |
void |
start()
Starts the receiver thread. |
void |
stop()
Stops the receiver thread and closes socket connection with SAServer. |
int |
updateDB(java.lang.String updateString)
This method is for updating the database with a new value. |
byte[] |
userSyncSend(int userType,
byte[] bytes)
Using this method the user can send his own request type. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TCP_PROTOCOL
public static final int HTTP_PROTOCOL
Constructor Detail |
public SASClient(java.applet.Applet applet, boolean debug) throws SnmpException
applet
- applet refernce using this sasclient to talk to SAServer.debug
- Debug messages are printed, if true.SnmpException
- is thrown whenever an error occurs.public SASClient(java.applet.Applet applet, boolean debug, int protocol) throws SnmpException
applet
- applet reference using this sasclient to talk to SAServerdebug
- Debug messages are printed, if true.SnmpException
- is thrown whenever an error occurs.Method Detail |
public void setTimeout(int to)
to
- the timeOut value in milliSeconds.public static boolean isFileReadWrite()
public static void setFileReadWrite(boolean writeFlag)
public boolean isConnected()
public boolean isKnownSASType(int type)
type
- requestTypepublic int getMaxSasTypes()
public void reqTraps(int port) throws java.io.IOException, TransportException
port
- the port at which SAServer to listen for
traps and forward to this client. Multiple
client applications can request for the same
port.java.io.IOException
- on error in writing to SAServerpublic void saveFile(java.lang.String filename, byte[] data) throws TransportException, java.io.IOException
filename
- the file will be saved by this name at the SAServer.data
- the contents of the file.java.io.IOException
- on error in writing to SAServer.public void appendFile(java.lang.String filename, byte[] data) throws TransportException, java.io.IOException
filename
- the data will be appended to file by this name at the SAServer.data
- the contents to be appended to the file.java.io.IOException
- on error in writing to SAServer.public void connectDB(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String pass) throws java.sql.SQLException, java.lang.ClassNotFoundException
driver
- the driver class for database.url
- the url where the database existsuser
- the usernamepass
- the passwordjava.sql.SQLException
- is thrown when unable to create a Connection.java.lang.ClassNotFoundException
- when the driver class specified is
not present.public boolean isDBConnected() throws SnmpException
SnmpException
- if any error occurs.public void closeDB() throws java.sql.SQLException
java.sql.SQLException
- thrown when unable to close the database.public java.sql.ResultSet queryDB(java.lang.String queryString) throws java.sql.SQLException
queryString
- the actual query string that is to be performed on
the database.java.sql.SQLException
- thrown when a database access error occurs.public int updateDB(java.lang.String updateString) throws java.sql.SQLException
updateString
- the sql query string that is to be performed on the
database.java.sql.SQLException
- if a database access error occurs.public void start()
public void run()
run
in interface java.lang.Runnable
public void stop()
public byte[] clientCall(byte[] bytes)
bytes
- The byte array data to be sentpublic byte[] userSyncSend(int userType, byte[] bytes)
userType
- The request type to be sent to SAServer.bytes
- The byte array packet to be sent.public java.lang.String getHostName(java.lang.String address, int timeout) throws TransportException
address
- the ip address of the host.timeout
- the time in ms to wait for the SAServer to respond.
Defaults to 2 Secs.TransportException
- on error in writing to SAServer.public java.lang.String getHostAddress(java.lang.String hostname, int timeout) throws TransportException
hostname
- the host whose ipaddress needs to be looked up.timeout
- the time in ms to wait for the SAServer to respond.
Defaults to 2 Secs.TransportException
- on error in writing to SAServer.public void createDir(java.lang.String directory) throws TransportException, java.io.IOException
directory
- The name of the directory to be createdjava.io.IOException
- on error in Creating Directorypublic void deleteFile(java.lang.String filename) throws TransportException, java.io.IOException
filename
- The name of the file to be deleted.java.io.IOException
- on error in Deleting File .public void deleteDir(java.lang.String directory) throws TransportException, java.io.IOException
directory
- The name for the directory to be deleted.java.io.IOException
- on error in Deleting Directory.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |