ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/branches/aglappe-jung/tools/MySQLConnectionCheck.java
Revision: 110
Committed: Tue Sep 19 13:04:55 2006 UTC (18 years, 1 month ago) by duarte
Original Path: trunk/tools/MySQLConnectionCheck.java
File size: 1378 byte(s)
Log Message:
New class MySQLConnectionCheck, to check whether MySQL servers are alive, uses threads
Changes in DataDistribution:
- new field: String[] nodes, initialised in constructor
- changed constructor to check for nodes that are alive, using new method nodesAlive
- renamed getNodes to getMySQLNodes. New method getNodes just returns the new field String[] nodes
DataDistributer: renamed calls to DataDistribution's getNodes to getMySQLNodes
Line File contents
1 package tools;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6
7 public class MySQLConnectionCheck extends Thread {
8
9 /**
10 * Class to check wheter a MySQL server is alive and contains a certain database,
11 * to be run in different threads so that it can be used to check all nodes in cluster parallely
12 * Once thread is executed we can call the connTestPassed method which returns a boolean that
13 * tells wheter the check was passed or not.
14 *
15 * @author duarte
16 */
17
18 String dbServer;
19 String dbUserName;
20 String dbPassword;
21 String dbName;
22 boolean success;
23
24 public MySQLConnectionCheck(String dbServer,String dbUserName, String dbPassword, String dbName){
25 this.dbServer=dbServer;
26 this.dbUserName=dbUserName;
27 this.dbPassword=dbPassword;
28 this.dbName=dbName;
29 this.success=true;
30 }
31
32 @Override
33 public void run() {
34 MySQLConnection.loadMySQLDriver();
35 String connStr="jdbc:mysql://"+dbServer+"/"+dbName;
36 Connection tryConn = null;
37 try {
38 tryConn = DriverManager.getConnection(connStr, dbUserName, dbPassword);
39 }
40 catch (SQLException e){
41 success = false;
42 }
43 if (tryConn!=null){
44 try {
45 tryConn.close();
46 } catch (SQLException e) {
47 e.printStackTrace();
48 System.err.println("Couldn't close the test connection.");
49 }
50 }
51 }
52
53 public boolean connTestPassed(){
54 return success;
55 }
56
57 }