1 28 29 package net.sf.tapestry.contrib.mckoi; 30 31 import java.io.File ; 32 import java.io.IOException ; 33 34 import javax.management.MBeanServer ; 35 import javax.management.ObjectName ; 36 37 import org.jboss.system.ServiceMBeanSupport; 38 39 import com.mckoi.database.control.DBController; 40 import com.mckoi.database.control.DBSystem; 41 import com.mckoi.database.control.DefaultDBConfig; 42 import com.mckoi.database.control.TCPJDBCServer; 43 44 53 54 public class McKoiDB extends ServiceMBeanSupport implements McKoiDBMBean 55 { 56 private String _configPath; 57 private DBSystem _database; 58 private TCPJDBCServer _server; 59 60 public String getConfigPath() 61 { 62 return _configPath; 63 } 64 65 public void setConfigPath(String path) 66 { 67 log.debug("Config path set to: " + path); 68 _configPath = path; 69 } 70 71 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception 72 { 73 if (name != null) 74 return name; 75 76 return new ObjectName (":service=McKoiDB"); 77 } 78 79 public String getName() 80 { 81 return "McKoiDB"; } 82 83 public void startService() throws Exception 84 { 85 if (_configPath == null) 86 throw new NullPointerException ("McKoiDB: configPath not specified."); 87 88 log.debug("Config path: " + _configPath); 89 90 File configFile = new File (_configPath).getAbsoluteFile(); 91 File rootFile = configFile.getParentFile(); 92 93 DefaultDBConfig config = new DefaultDBConfig(rootFile); 94 95 try 96 { 97 config.loadFromFile(configFile); 98 } 99 catch (IOException ex) 100 { 101 log.error("Unable to initialize McKoi database.", ex); 102 } 103 104 DBController controller = DBController.getDefault(); 105 _database = controller.startDatabase(config); 106 107 _server = new TCPJDBCServer(_database); 108 109 _server.start(); 110 111 log.info(_server); 112 113 } 114 115 public void stopService() 116 { 117 _server.stop(); 118 _database.close(); 119 } 120 } | Popular Tags |